cmQTWrapUICommand.cxx 4.6 KB

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