cmQTWrapCPPCommand.cxx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "cmQTWrapCPPCommand.h"
  4. #include "cmCustomCommandLines.h"
  5. #include "cmMakefile.h"
  6. #include "cmSourceFile.h"
  7. #include "cmSystemTools.h"
  8. class cmExecutionStatus;
  9. // cmQTWrapCPPCommand
  10. bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args,
  11. cmExecutionStatus&)
  12. {
  13. if (args.size() < 3) {
  14. this->SetError("called with incorrect number of arguments");
  15. return false;
  16. }
  17. // Get the moc executable to run in the custom command.
  18. const char* moc_exe =
  19. this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
  20. // Get the variable holding the list of sources.
  21. std::string const& sourceList = args[1];
  22. std::string sourceListValue = this->Makefile->GetSafeDefinition(sourceList);
  23. // Create a rule for all sources listed.
  24. for (std::vector<std::string>::const_iterator j = (args.begin() + 2);
  25. j != args.end(); ++j) {
  26. cmSourceFile* curr = this->Makefile->GetSource(*j);
  27. // if we should wrap the class
  28. if (!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE"))) {
  29. // Compute the name of the file to generate.
  30. std::string srcName = cmSystemTools::GetFilenameWithoutLastExtension(*j);
  31. std::string newName = this->Makefile->GetCurrentBinaryDirectory();
  32. newName += "/moc_";
  33. newName += srcName;
  34. newName += ".cxx";
  35. cmSourceFile* sf = this->Makefile->GetOrCreateSource(newName, true);
  36. if (curr) {
  37. sf->SetProperty("ABSTRACT", curr->GetProperty("ABSTRACT"));
  38. }
  39. // Compute the name of the header from which to generate the file.
  40. std::string hname;
  41. if (cmSystemTools::FileIsFullPath(j->c_str())) {
  42. hname = *j;
  43. } else {
  44. if (curr && curr->GetPropertyAsBool("GENERATED")) {
  45. hname = this->Makefile->GetCurrentBinaryDirectory();
  46. } else {
  47. hname = this->Makefile->GetCurrentSourceDirectory();
  48. }
  49. hname += "/";
  50. hname += *j;
  51. }
  52. // Append the generated source file to the list.
  53. if (!sourceListValue.empty()) {
  54. sourceListValue += ";";
  55. }
  56. sourceListValue += newName;
  57. // Create the custom command to generate the file.
  58. cmCustomCommandLine commandLine;
  59. commandLine.push_back(moc_exe);
  60. commandLine.push_back("-o");
  61. commandLine.push_back(newName);
  62. commandLine.push_back(hname);
  63. cmCustomCommandLines commandLines;
  64. commandLines.push_back(commandLine);
  65. std::vector<std::string> depends;
  66. depends.push_back(moc_exe);
  67. depends.push_back(hname);
  68. std::string no_main_dependency;
  69. const char* no_working_dir = CM_NULLPTR;
  70. this->Makefile->AddCustomCommandToOutput(
  71. newName, depends, no_main_dependency, commandLines, "Qt Wrapped File",
  72. no_working_dir);
  73. }
  74. }
  75. // Store the final list of source files.
  76. this->Makefile->AddDefinition(sourceList, sourceListValue.c_str());
  77. return true;
  78. }