cmFLTKWrapUICommand.cxx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmFLTKWrapUICommand.h"
  14. #include "cmSourceFile.h"
  15. // cmFLTKWrapUICommand
  16. bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 2 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. // what is the current source dir
  24. std::string cdir = this->Makefile->GetCurrentDirectory();
  25. const char* fluid_exe =
  26. this->Makefile->GetRequiredDefinition("FLTK_FLUID_EXECUTABLE");
  27. // get parameter for the command
  28. this->Target = args[0]; // Target that will use the generated files
  29. std::vector<std::string> newArgs;
  30. this->Makefile->ExpandSourceListArguments(args,newArgs, 1);
  31. // get the list of GUI files from which .cxx and .h will be generated
  32. std::string outputDirectory = this->Makefile->GetCurrentOutputDirectory();
  33. // Some of the generated files are *.h so the directory "GUI"
  34. // where they are created have to be added to the include path
  35. this->Makefile->AddIncludeDirectory( outputDirectory.c_str() );
  36. for(std::vector<std::string>::iterator i = (newArgs.begin() + 1);
  37. i != newArgs.end(); i++)
  38. {
  39. cmSourceFile *curr = this->Makefile->GetSource(i->c_str());
  40. // if we should use the source GUI
  41. // to generate .cxx and .h files
  42. if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
  43. {
  44. cmSourceFile header_file;
  45. std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*i);
  46. const bool headerFileOnly = true;
  47. header_file.SetName(srcName.c_str(),
  48. outputDirectory.c_str(), "h",headerFileOnly);
  49. std::string origname = cdir + "/" + *i;
  50. std::string hname = header_file.GetFullPath();
  51. // add starting depends
  52. std::vector<std::string> depends;
  53. depends.push_back(origname);
  54. std::string cxxres = outputDirectory.c_str();
  55. cxxres += "/" + srcName;
  56. cxxres += ".cxx";
  57. cmCustomCommandLine commandLine;
  58. commandLine.push_back(fluid_exe);
  59. commandLine.push_back("-c"); // instructs Fluid to run in command line
  60. commandLine.push_back("-h"); // optionally rename .h files
  61. commandLine.push_back(hname);
  62. commandLine.push_back("-o"); // optionally rename .cxx files
  63. commandLine.push_back(cxxres);
  64. commandLine.push_back(origname);// name of the GUI fluid file
  65. cmCustomCommandLines commandLines;
  66. commandLines.push_back(commandLine);
  67. // Add command for generating the .h and .cxx files
  68. const char* no_main_dependency = 0;
  69. const char* no_comment = 0;
  70. const char* no_working_dir = 0;
  71. this->Makefile->AddCustomCommandToOutput(cxxres.c_str(),
  72. depends, no_main_dependency,
  73. commandLines, no_comment,
  74. no_working_dir);
  75. this->Makefile->AddCustomCommandToOutput(hname.c_str(),
  76. depends, no_main_dependency,
  77. commandLines, no_comment,
  78. no_working_dir);
  79. cmSourceFile *sf = this->Makefile->GetSource(cxxres.c_str());
  80. sf->GetDepends().push_back(hname);
  81. sf->GetDepends().push_back(origname);
  82. this->GeneratedSourcesClasses.push_back(sf);
  83. }
  84. }
  85. // create the variable with the list of sources in it
  86. size_t lastHeadersClass = this->GeneratedSourcesClasses.size();
  87. std::string sourceListValue;
  88. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  89. {
  90. if (classNum)
  91. {
  92. sourceListValue += ";";
  93. }
  94. sourceListValue += this->GeneratedSourcesClasses[classNum]->GetFullPath();
  95. }
  96. std::string varName = this->Target;
  97. varName += "_FLTK_UI_SRCS";
  98. this->Makefile->AddDefinition(varName.c_str(), sourceListValue.c_str());
  99. return true;
  100. }
  101. void cmFLTKWrapUICommand::FinalPass()
  102. {
  103. // people should add the srcs to the target themselves, but the old command
  104. // didn't support that, so check and see if they added the files in and if
  105. // they didn;t then print a warning and add then anyhow
  106. std::vector<std::string> srcs =
  107. this->Makefile->GetTargets()[this->Target].GetSourceLists();
  108. bool found = false;
  109. for (unsigned int i = 0; i < srcs.size(); ++i)
  110. {
  111. if (srcs[i] ==
  112. this->GeneratedSourcesClasses[0]->GetFullPath())
  113. {
  114. found = true;
  115. break;
  116. }
  117. }
  118. if (!found)
  119. {
  120. std::string msg = "In CMake 2.2 the FLTK_WRAP_UI command sets a variable to the list of source files that should be added to your executable or library. It appears that you have not added these source files to your target. You should change your CMakeLists.txt file to directly add the generated files to the target. For example FTLK_WRAP_UI(foo src1 src2 src3) will create a variable named foo_FLTK_UI_SRCS that contains the list of sources to add to your target when you call ADD_LIBRARY or ADD_EXECUTABLE. For now CMake 2.2 will add the sources to your target for you as was done in CMake 2.0 and earlier. In the future this may become an error. ";
  121. msg += "The problem was found while processing the source directory: ";
  122. msg += this->Makefile->GetStartDirectory();
  123. cmSystemTools::Message(msg.c_str(),"Warning");
  124. // first we add the rules for all the .fl to .h and .cxx files
  125. size_t lastHeadersClass = this->GeneratedSourcesClasses.size();
  126. // Generate code for all the .fl files
  127. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  128. {
  129. this->Makefile->GetTargets()[this->Target].GetSourceFiles().push_back(
  130. this->GeneratedSourcesClasses[classNum]);
  131. }
  132. }
  133. }