cmFLTKWrapUICommand.cxx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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
  17. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  18. {
  19. if(args.size() < 2 )
  20. {
  21. this->SetError("called with incorrect number of arguments");
  22. return false;
  23. }
  24. // what is the current source dir
  25. std::string cdir = this->Makefile->GetCurrentDirectory();
  26. const char* fluid_exe =
  27. this->Makefile->GetRequiredDefinition("FLTK_FLUID_EXECUTABLE");
  28. // get parameter for the command
  29. this->Target = args[0]; // Target that will use the generated files
  30. std::vector<std::string> newArgs;
  31. this->Makefile->ExpandSourceListArguments(args,newArgs, 1);
  32. // get the list of GUI files from which .cxx and .h will be generated
  33. std::string outputDirectory = this->Makefile->GetCurrentOutputDirectory();
  34. // Some of the generated files are *.h so the directory "GUI"
  35. // where they are created have to be added to the include path
  36. this->Makefile->AddIncludeDirectory( outputDirectory.c_str() );
  37. for(std::vector<std::string>::iterator i = (newArgs.begin() + 1);
  38. i != newArgs.end(); i++)
  39. {
  40. cmSourceFile *curr = this->Makefile->GetSource(i->c_str());
  41. // if we should use the source GUI
  42. // to generate .cxx and .h files
  43. if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
  44. {
  45. std::string outName = outputDirectory;
  46. outName += "/";
  47. outName += cmSystemTools::GetFilenameWithoutExtension(*i);
  48. std::string hname = outName;
  49. hname += ".h";
  50. std::string origname = cdir + "/" + *i;
  51. // add starting depends
  52. std::vector<std::string> depends;
  53. depends.push_back(origname);
  54. depends.push_back(fluid_exe);
  55. std::string cxxres = outName;
  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->AddDepend(hname.c_str());
  81. sf->AddDepend(origname.c_str());
  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. cmTarget* target = this->Makefile->FindTarget(this->Target.c_str());
  107. if(!target)
  108. {
  109. std::string msg =
  110. "FLTK_WRAP_UI was called with a target that was never created: ";
  111. msg += this->Target;
  112. msg +=". The problem was found while processing the source directory: ";
  113. msg += this->Makefile->GetStartDirectory();
  114. msg += ". This FLTK_WRAP_UI call will be ignored.";
  115. cmSystemTools::Message(msg.c_str(),"Warning");
  116. return;
  117. }
  118. std::vector<cmSourceFile*> const& srcs =
  119. target->GetSourceFiles();
  120. bool found = false;
  121. for (unsigned int i = 0; i < srcs.size(); ++i)
  122. {
  123. if (srcs[i]->GetFullPath() ==
  124. this->GeneratedSourcesClasses[0]->GetFullPath())
  125. {
  126. found = true;
  127. break;
  128. }
  129. }
  130. if (!found)
  131. {
  132. std::string msg =
  133. "In CMake 2.2 the FLTK_WRAP_UI command sets a variable to the list of "
  134. "source files that should be added to your executable or library. It "
  135. "appears that you have not added these source files to your target. "
  136. "You should change your CMakeLists.txt file to "
  137. "directly add the generated files to the target. "
  138. "For example FTLK_WRAP_UI(foo src1 src2 src3) "
  139. "will create a variable named foo_FLTK_UI_SRCS that contains the list "
  140. "of sources to add to your target when you call ADD_LIBRARY or "
  141. "ADD_EXECUTABLE. For now CMake will add the sources to your target "
  142. "for you as was done in CMake 2.0 and earlier. In the future this may "
  143. "become an error.";
  144. msg +="The problem was found while processing the source directory: ";
  145. msg += this->Makefile->GetStartDirectory();
  146. cmSystemTools::Message(msg.c_str(),"Warning");
  147. // first we add the rules for all the .fl to .h and .cxx files
  148. size_t lastHeadersClass = this->GeneratedSourcesClasses.size();
  149. // Generate code for all the .fl files
  150. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  151. {
  152. this->Makefile->GetTargets()[this->Target]
  153. .AddSourceFile(this->GeneratedSourcesClasses[classNum]);
  154. }
  155. }
  156. }