cmQTWrapUICommand.cxx 4.6 KB

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