cmQTWrapUICommand.cxx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "cmQTWrapUICommand.h"
  4. #include "cmAlgorithms.h"
  5. #include "cmCustomCommandLines.h"
  6. #include "cmMakefile.h"
  7. #include "cmSourceFile.h"
  8. #include "cmSystemTools.h"
  9. #include <utility>
  10. class cmExecutionStatus;
  11. // cmQTWrapUICommand
  12. bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args,
  13. cmExecutionStatus&)
  14. {
  15. if (args.size() < 4) {
  16. this->SetError("called with incorrect number of arguments");
  17. return false;
  18. }
  19. // Get the uic and moc executables to run in the custom commands.
  20. std::string const& uic_exe =
  21. this->Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE");
  22. std::string const& moc_exe =
  23. this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
  24. // Get the variable holding the list of sources.
  25. std::string const& headerList = args[1];
  26. std::string const& sourceList = args[2];
  27. std::string headerListValue = this->Makefile->GetSafeDefinition(headerList);
  28. std::string sourceListValue = this->Makefile->GetSafeDefinition(sourceList);
  29. // Create rules for all sources listed.
  30. for (std::string const& arg : cmMakeRange(args).advance(3)) {
  31. cmSourceFile* curr = this->Makefile->GetSource(arg);
  32. // if we should wrap the class
  33. if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) {
  34. // Compute the name of the files to generate.
  35. std::string srcName =
  36. cmSystemTools::GetFilenameWithoutLastExtension(arg);
  37. std::string hName = this->Makefile->GetCurrentBinaryDirectory();
  38. hName += "/";
  39. hName += srcName;
  40. hName += ".h";
  41. std::string cxxName = this->Makefile->GetCurrentBinaryDirectory();
  42. cxxName += "/";
  43. cxxName += srcName;
  44. cxxName += ".cxx";
  45. std::string mocName = this->Makefile->GetCurrentBinaryDirectory();
  46. mocName += "/moc_";
  47. mocName += srcName;
  48. mocName += ".cxx";
  49. // Compute the name of the ui file from which to generate others.
  50. std::string uiName;
  51. if (cmSystemTools::FileIsFullPath(arg)) {
  52. uiName = arg;
  53. } else {
  54. if (curr && curr->GetIsGenerated()) {
  55. uiName = this->Makefile->GetCurrentBinaryDirectory();
  56. } else {
  57. uiName = this->Makefile->GetCurrentSourceDirectory();
  58. }
  59. uiName += "/";
  60. uiName += arg;
  61. }
  62. // create the list of headers
  63. if (!headerListValue.empty()) {
  64. headerListValue += ";";
  65. }
  66. headerListValue += hName;
  67. // create the list of sources
  68. if (!sourceListValue.empty()) {
  69. sourceListValue += ";";
  70. }
  71. sourceListValue += cxxName;
  72. sourceListValue += ";";
  73. sourceListValue += mocName;
  74. // set up .ui to .h and .cxx command
  75. cmCustomCommandLine hCommand;
  76. hCommand.push_back(uic_exe);
  77. hCommand.push_back("-o");
  78. hCommand.push_back(hName);
  79. hCommand.push_back(uiName);
  80. cmCustomCommandLines hCommandLines;
  81. hCommandLines.push_back(std::move(hCommand));
  82. cmCustomCommandLine cxxCommand;
  83. cxxCommand.push_back(uic_exe);
  84. cxxCommand.push_back("-impl");
  85. cxxCommand.push_back(hName);
  86. cxxCommand.push_back("-o");
  87. cxxCommand.push_back(cxxName);
  88. cxxCommand.push_back(uiName);
  89. cmCustomCommandLines cxxCommandLines;
  90. cxxCommandLines.push_back(std::move(cxxCommand));
  91. cmCustomCommandLine mocCommand;
  92. mocCommand.push_back(moc_exe);
  93. mocCommand.push_back("-o");
  94. mocCommand.push_back(mocName);
  95. mocCommand.push_back(hName);
  96. cmCustomCommandLines mocCommandLines;
  97. mocCommandLines.push_back(std::move(mocCommand));
  98. std::vector<std::string> depends;
  99. depends.push_back(uiName);
  100. std::string no_main_dependency;
  101. const char* no_comment = nullptr;
  102. const char* no_working_dir = nullptr;
  103. this->Makefile->AddCustomCommandToOutput(
  104. hName, depends, no_main_dependency, hCommandLines, no_comment,
  105. no_working_dir);
  106. depends.push_back(hName);
  107. this->Makefile->AddCustomCommandToOutput(
  108. cxxName, depends, no_main_dependency, cxxCommandLines, no_comment,
  109. no_working_dir);
  110. depends.clear();
  111. depends.push_back(hName);
  112. this->Makefile->AddCustomCommandToOutput(
  113. mocName, depends, no_main_dependency, mocCommandLines, no_comment,
  114. no_working_dir);
  115. }
  116. }
  117. // Store the final list of source files and headers.
  118. this->Makefile->AddDefinition(sourceList, sourceListValue.c_str());
  119. this->Makefile->AddDefinition(headerList, headerListValue.c_str());
  120. return true;
  121. }