cmFLTKWrapUICommand.cxx 6.5 KB

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