cmQTWrapUICommand.cxx 4.4 KB

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