cmQTWrapUICommand.cxx 5.8 KB

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