cmQTWrapUICommand.cxx 5.6 KB

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