cmQTWrapUICommand.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "cmExecutionStatus.h"
  6. #include "cmMakefile.h"
  7. #include "cmPolicies.h"
  8. #include "cmRange.h"
  9. #include "cmSourceFile.h"
  10. #include "cmStringAlgorithms.h"
  11. #include "cmSystemTools.h"
  12. bool cmQTWrapUICommand(std::vector<std::string> const& args,
  13. cmExecutionStatus& status)
  14. {
  15. if (args.size() < 4) {
  16. status.SetError("called with incorrect number of arguments");
  17. return false;
  18. }
  19. cmMakefile& mf = status.GetMakefile();
  20. // Get the uic and moc executables to run in the custom commands.
  21. std::string const& uic_exe = mf.GetRequiredDefinition("QT_UIC_EXECUTABLE");
  22. std::string const& moc_exe = mf.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 = mf.GetSafeDefinition(headerList);
  27. std::string sourceListValue = mf.GetSafeDefinition(sourceList);
  28. // Create rules for all sources listed.
  29. for (std::string const& arg : cmMakeRange(args).advance(3)) {
  30. cmSourceFile* curr = mf.GetSource(arg);
  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 =
  35. cmSystemTools::GetFilenameWithoutLastExtension(arg);
  36. std::string hName =
  37. cmStrCat(mf.GetCurrentBinaryDirectory(), '/', srcName, ".h");
  38. std::string cxxName =
  39. cmStrCat(mf.GetCurrentBinaryDirectory(), '/', srcName, ".cxx");
  40. std::string mocName =
  41. cmStrCat(mf.GetCurrentBinaryDirectory(), "/moc_", srcName, ".cxx");
  42. // Compute the name of the ui file from which to generate others.
  43. std::string uiName;
  44. if (cmSystemTools::FileIsFullPath(arg)) {
  45. uiName = arg;
  46. } else {
  47. if (curr && curr->GetIsGenerated()) {
  48. uiName = mf.GetCurrentBinaryDirectory();
  49. } else {
  50. uiName = mf.GetCurrentSourceDirectory();
  51. }
  52. uiName += "/";
  53. uiName += arg;
  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. cmCustomCommandLines hCommandLines =
  69. cmMakeSingleCommandLine({ uic_exe, "-o", hName, uiName });
  70. cmCustomCommandLines cxxCommandLines = cmMakeSingleCommandLine(
  71. { uic_exe, "-impl", hName, "-o", cxxName, uiName });
  72. cmCustomCommandLines mocCommandLines =
  73. cmMakeSingleCommandLine({ moc_exe, "-o", mocName, hName });
  74. std::vector<std::string> depends;
  75. depends.push_back(uiName);
  76. std::string no_main_dependency;
  77. const char* no_comment = nullptr;
  78. const char* no_working_dir = nullptr;
  79. mf.AddCustomCommandToOutput(hName, depends, no_main_dependency,
  80. hCommandLines, no_comment, no_working_dir,
  81. mf.GetPolicyStatus(cmPolicies::CMP0116));
  82. depends.push_back(hName);
  83. mf.AddCustomCommandToOutput(cxxName, depends, no_main_dependency,
  84. cxxCommandLines, no_comment, no_working_dir,
  85. mf.GetPolicyStatus(cmPolicies::CMP0116));
  86. depends.clear();
  87. depends.push_back(hName);
  88. mf.AddCustomCommandToOutput(mocName, depends, no_main_dependency,
  89. mocCommandLines, no_comment, no_working_dir,
  90. mf.GetPolicyStatus(cmPolicies::CMP0116));
  91. }
  92. }
  93. // Store the final list of source files and headers.
  94. mf.AddDefinition(sourceList, sourceListValue);
  95. mf.AddDefinition(headerList, headerListValue);
  96. return true;
  97. }