cmFLTKWrapUICommand.cxx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmFLTKWrapUICommand.h"
  4. #include "cmSourceFile.h"
  5. // cmFLTKWrapUICommand
  6. bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args,
  7. cmExecutionStatus&)
  8. {
  9. if (args.size() < 2) {
  10. this->SetError("called with incorrect number of arguments");
  11. return false;
  12. }
  13. // what is the current source dir
  14. std::string cdir = this->Makefile->GetCurrentSourceDirectory();
  15. const char* fluid_exe =
  16. this->Makefile->GetRequiredDefinition("FLTK_FLUID_EXECUTABLE");
  17. // get parameter for the command
  18. this->Target = args[0]; // Target that will use the generated files
  19. // get the list of GUI files from which .cxx and .h will be generated
  20. std::string outputDirectory = this->Makefile->GetCurrentBinaryDirectory();
  21. {
  22. // Some of the generated files are *.h so the directory "GUI"
  23. // where they are created have to be added to the include path
  24. std::vector<std::string> outputDirectories;
  25. outputDirectories.push_back(outputDirectory);
  26. this->Makefile->AddIncludeDirectories(outputDirectories);
  27. }
  28. for (std::vector<std::string>::const_iterator i = (args.begin() + 1);
  29. i != args.end(); i++) {
  30. cmSourceFile* curr = this->Makefile->GetSource(*i);
  31. // if we should use the source GUI
  32. // to generate .cxx and .h files
  33. if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE")) {
  34. std::string outName = outputDirectory;
  35. outName += "/";
  36. outName += cmSystemTools::GetFilenameWithoutExtension(*i);
  37. std::string hname = outName;
  38. hname += ".h";
  39. std::string origname = cdir + "/" + *i;
  40. // add starting depends
  41. std::vector<std::string> depends;
  42. depends.push_back(origname);
  43. depends.push_back(fluid_exe);
  44. std::string cxxres = outName;
  45. cxxres += ".cxx";
  46. cmCustomCommandLine commandLine;
  47. commandLine.push_back(fluid_exe);
  48. commandLine.push_back("-c"); // instructs Fluid to run in command line
  49. commandLine.push_back("-h"); // optionally rename .h files
  50. commandLine.push_back(hname);
  51. commandLine.push_back("-o"); // optionally rename .cxx files
  52. commandLine.push_back(cxxres);
  53. commandLine.push_back(origname); // name of the GUI fluid file
  54. cmCustomCommandLines commandLines;
  55. commandLines.push_back(commandLine);
  56. // Add command for generating the .h and .cxx files
  57. std::string no_main_dependency = "";
  58. const char* no_comment = CM_NULLPTR;
  59. const char* no_working_dir = CM_NULLPTR;
  60. this->Makefile->AddCustomCommandToOutput(
  61. cxxres, depends, no_main_dependency, commandLines, no_comment,
  62. no_working_dir);
  63. this->Makefile->AddCustomCommandToOutput(
  64. hname, depends, no_main_dependency, commandLines, no_comment,
  65. no_working_dir);
  66. cmSourceFile* sf = this->Makefile->GetSource(cxxres);
  67. sf->AddDepend(hname.c_str());
  68. sf->AddDepend(origname.c_str());
  69. this->GeneratedSourcesClasses.push_back(sf);
  70. }
  71. }
  72. // create the variable with the list of sources in it
  73. size_t lastHeadersClass = this->GeneratedSourcesClasses.size();
  74. std::string sourceListValue;
  75. for (size_t classNum = 0; classNum < lastHeadersClass; classNum++) {
  76. if (classNum) {
  77. sourceListValue += ";";
  78. }
  79. sourceListValue += this->GeneratedSourcesClasses[classNum]->GetFullPath();
  80. }
  81. std::string varName = this->Target;
  82. varName += "_FLTK_UI_SRCS";
  83. this->Makefile->AddDefinition(varName, sourceListValue.c_str());
  84. return true;
  85. }
  86. void cmFLTKWrapUICommand::FinalPass()
  87. {
  88. // people should add the srcs to the target themselves, but the old command
  89. // didn't support that, so check and see if they added the files in and if
  90. // they didn;t then print a warning and add then anyhow
  91. cmTarget* target = this->Makefile->FindLocalNonAliasTarget(this->Target);
  92. if (!target) {
  93. std::string msg =
  94. "FLTK_WRAP_UI was called with a target that was never created: ";
  95. msg += this->Target;
  96. msg += ". The problem was found while processing the source directory: ";
  97. msg += this->Makefile->GetCurrentSourceDirectory();
  98. msg += ". This FLTK_WRAP_UI call will be ignored.";
  99. cmSystemTools::Message(msg.c_str(), "Warning");
  100. return;
  101. }
  102. }