cmFLTKWrapUICommand.cxx 4.4 KB

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