cmQTWrapCPPCommand.cxx 2.9 KB

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