cmFLTKWrapUICommand.cxx 4.5 KB

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