cmQTWrapCPPCommand.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmQTWrapCPPCommand.h"
  11. // cmQTWrapCPPCommand
  12. bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& argsIn,
  13. cmExecutionStatus &)
  14. {
  15. if(argsIn.size() < 3 )
  16. {
  17. this->SetError("called with incorrect number of arguments");
  18. return false;
  19. }
  20. // This command supports source list inputs for compatibility.
  21. std::vector<std::string> args;
  22. this->Makefile->ExpandSourceListArguments(argsIn, args, 2);
  23. // Get the moc executable to run in the custom command.
  24. const char* moc_exe =
  25. this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
  26. // Get the variable holding the list of sources.
  27. std::string const& sourceList = args[1];
  28. std::string sourceListValue =
  29. this->Makefile->GetSafeDefinition(sourceList.c_str());
  30. // Create a rule for all sources listed.
  31. for(std::vector<std::string>::iterator j = (args.begin() + 2);
  32. j != args.end(); ++j)
  33. {
  34. cmSourceFile *curr = this->Makefile->GetSource(j->c_str());
  35. // if we should wrap the class
  36. if(!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE")))
  37. {
  38. // Compute the name of the file to generate.
  39. std::string srcName =
  40. cmSystemTools::GetFilenameWithoutLastExtension(*j);
  41. std::string newName = this->Makefile->GetCurrentOutputDirectory();
  42. newName += "/moc_";
  43. newName += srcName;
  44. newName += ".cxx";
  45. cmSourceFile* sf =
  46. this->Makefile->GetOrCreateSource(newName.c_str(), true);
  47. if (curr)
  48. {
  49. sf->SetProperty("ABSTRACT", curr->GetProperty("ABSTRACT"));
  50. }
  51. // Compute the name of the header from which to generate the file.
  52. std::string hname;
  53. if(cmSystemTools::FileIsFullPath(j->c_str()))
  54. {
  55. hname = *j;
  56. }
  57. else
  58. {
  59. if(curr && curr->GetPropertyAsBool("GENERATED"))
  60. {
  61. hname = this->Makefile->GetCurrentOutputDirectory();
  62. }
  63. else
  64. {
  65. hname = this->Makefile->GetCurrentDirectory();
  66. }
  67. hname += "/";
  68. hname += *j;
  69. }
  70. // Append the generated source file to the list.
  71. if(!sourceListValue.empty())
  72. {
  73. sourceListValue += ";";
  74. }
  75. sourceListValue += newName;
  76. // Create the custom command to generate the file.
  77. cmCustomCommandLine commandLine;
  78. commandLine.push_back(moc_exe);
  79. commandLine.push_back("-o");
  80. commandLine.push_back(newName);
  81. commandLine.push_back(hname);
  82. cmCustomCommandLines commandLines;
  83. commandLines.push_back(commandLine);
  84. std::vector<std::string> depends;
  85. depends.push_back(moc_exe);
  86. depends.push_back(hname);
  87. std::string no_main_dependency = "";
  88. const char* no_working_dir = 0;
  89. this->Makefile->AddCustomCommandToOutput(newName.c_str(),
  90. depends,
  91. no_main_dependency,
  92. commandLines,
  93. "Qt Wrapped File",
  94. no_working_dir);
  95. }
  96. }
  97. // Store the final list of source files.
  98. this->Makefile->AddDefinition(sourceList.c_str(),
  99. sourceListValue.c_str());
  100. return true;
  101. }