cmFLTKWrapUICommand.cxx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. depends.push_back(fluid_exe);
  55. std::string cxxres = outputDirectory.c_str();
  56. cxxres += "/" + srcName;
  57. cxxres += ".cxx";
  58. cmCustomCommandLine commandLine;
  59. commandLine.push_back(fluid_exe);
  60. commandLine.push_back("-c"); // instructs Fluid to run in command line
  61. commandLine.push_back("-h"); // optionally rename .h files
  62. commandLine.push_back(hname);
  63. commandLine.push_back("-o"); // optionally rename .cxx files
  64. commandLine.push_back(cxxres);
  65. commandLine.push_back(origname);// name of the GUI fluid file
  66. cmCustomCommandLines commandLines;
  67. commandLines.push_back(commandLine);
  68. // Add command for generating the .h and .cxx files
  69. const char* no_main_dependency = 0;
  70. const char* no_comment = 0;
  71. const char* no_working_dir = 0;
  72. this->Makefile->AddCustomCommandToOutput(cxxres.c_str(),
  73. depends, no_main_dependency,
  74. commandLines, no_comment,
  75. no_working_dir);
  76. this->Makefile->AddCustomCommandToOutput(hname.c_str(),
  77. depends, no_main_dependency,
  78. commandLines, no_comment,
  79. no_working_dir);
  80. cmSourceFile *sf = this->Makefile->GetSource(cxxres.c_str());
  81. sf->GetDepends().push_back(hname);
  82. sf->GetDepends().push_back(origname);
  83. this->GeneratedSourcesClasses.push_back(sf);
  84. }
  85. }
  86. // create the variable with the list of sources in it
  87. size_t lastHeadersClass = this->GeneratedSourcesClasses.size();
  88. std::string sourceListValue;
  89. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  90. {
  91. if (classNum)
  92. {
  93. sourceListValue += ";";
  94. }
  95. sourceListValue += this->GeneratedSourcesClasses[classNum]->GetFullPath();
  96. }
  97. std::string varName = this->Target;
  98. varName += "_FLTK_UI_SRCS";
  99. this->Makefile->AddDefinition(varName.c_str(), sourceListValue.c_str());
  100. return true;
  101. }
  102. void cmFLTKWrapUICommand::FinalPass()
  103. {
  104. // people should add the srcs to the target themselves, but the old command
  105. // didn't support that, so check and see if they added the files in and if
  106. // they didn;t then print a warning and add then anyhow
  107. std::vector<std::string> srcs =
  108. this->Makefile->GetTargets()[this->Target].GetSourceLists();
  109. bool found = false;
  110. for (unsigned int i = 0; i < srcs.size(); ++i)
  111. {
  112. if (srcs[i] ==
  113. this->GeneratedSourcesClasses[0]->GetFullPath())
  114. {
  115. found = true;
  116. break;
  117. }
  118. }
  119. if (!found)
  120. {
  121. std::string msg =
  122. "In CMake 2.2 the FLTK_WRAP_UI command sets a variable to the list of "
  123. "source files that should be added to your executable or library. It "
  124. "appears that you have not added these source files to your target. "
  125. "You should change your CMakeLists.txt file to "
  126. "directly add the generated files to the target. "
  127. "For example FTLK_WRAP_UI(foo src1 src2 src3) "
  128. "will create a variable named foo_FLTK_UI_SRCS that contains the list "
  129. "of sources to add to your target when you call ADD_LIBRARY or "
  130. "ADD_EXECUTABLE. For now CMake will add the sources to your target "
  131. "for you as was done in CMake 2.0 and earlier. In the future this may "
  132. "become an error.";
  133. msg +="The problem was found while processing the source directory: ";
  134. msg += this->Makefile->GetStartDirectory();
  135. cmSystemTools::Message(msg.c_str(),"Warning");
  136. // first we add the rules for all the .fl to .h and .cxx files
  137. size_t lastHeadersClass = this->GeneratedSourcesClasses.size();
  138. // Generate code for all the .fl files
  139. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  140. {
  141. this->Makefile->GetTargets()[this->Target].GetSourceFiles().
  142. push_back(this->GeneratedSourcesClasses[classNum]);
  143. }
  144. }
  145. }