cmQTWrapUICommand.cxx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmQTWrapUICommand.h"
  14. // cmQTWrapUICommand
  15. bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& argsIn)
  16. {
  17. if(argsIn.size() < 4 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. std::vector<std::string> args;
  23. this->Makefile->ExpandSourceListArguments(argsIn, args, 3);
  24. // what is the current source dir
  25. std::string cdir = this->Makefile->GetCurrentDirectory();
  26. // keep the library name
  27. this->LibraryName = args[0];
  28. this->HeaderList = args[1];
  29. this->SourceList = args[2];
  30. std::string sourceListValue;
  31. std::string headerListValue;
  32. const char *def = this->Makefile->GetDefinition(this->SourceList.c_str());
  33. if (def)
  34. {
  35. sourceListValue = def;
  36. }
  37. // get the list of classes for this library
  38. for(std::vector<std::string>::iterator j = (args.begin() + 3);
  39. j != args.end(); ++j)
  40. {
  41. cmSourceFile *curr = this->Makefile->GetSource(j->c_str());
  42. // if we should wrap the class
  43. if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
  44. {
  45. cmSourceFile header_file;
  46. cmSourceFile source_file;
  47. cmSourceFile moc_file;
  48. std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*j);
  49. header_file.SetName(srcName.c_str(),
  50. this->Makefile->GetCurrentOutputDirectory(),
  51. "h",false);
  52. source_file.SetName(srcName.c_str(),
  53. this->Makefile->GetCurrentOutputDirectory(),
  54. "cxx",false);
  55. std::string moc_source_name("moc_");
  56. moc_source_name = moc_source_name + srcName;
  57. moc_file.SetName(moc_source_name.c_str(),
  58. this->Makefile->GetCurrentOutputDirectory(),
  59. "cxx",false);
  60. std::string origname;
  61. if ( (*j)[0] == '/' || (*j)[1] == ':' )
  62. {
  63. origname = *j;
  64. }
  65. else
  66. {
  67. if ( curr && curr->GetPropertyAsBool("GENERATED") )
  68. {
  69. origname = std::string(this->Makefile->GetCurrentOutputDirectory())
  70. + "/" + *j;
  71. }
  72. else
  73. {
  74. origname = cdir + "/" + *j;
  75. }
  76. }
  77. std::string hname = header_file.GetFullPath();
  78. this->WrapUserInterface.push_back(origname);
  79. // add starting depends
  80. moc_file.GetDepends().push_back(hname);
  81. source_file.GetDepends().push_back(hname);
  82. source_file.GetDepends().push_back(origname);
  83. header_file.GetDepends().push_back(origname);
  84. this->WrapHeadersClasses.push_back(header_file);
  85. this->WrapSourcesClasses.push_back(source_file);
  86. this->WrapMocClasses.push_back(moc_file);
  87. this->Makefile->AddSource(header_file);
  88. this->Makefile->AddSource(source_file);
  89. this->Makefile->AddSource(moc_file);
  90. // create the list of headers
  91. if (headerListValue.size() > 0)
  92. {
  93. headerListValue += ";";
  94. }
  95. headerListValue += header_file.GetFullPath();
  96. // create the list of sources
  97. if (sourceListValue.size() > 0)
  98. {
  99. sourceListValue += ";";
  100. }
  101. sourceListValue += source_file.GetFullPath();
  102. sourceListValue += ";";
  103. sourceListValue += moc_file.GetFullPath();
  104. }
  105. }
  106. this->Makefile->AddDefinition(this->SourceList.c_str(),
  107. sourceListValue.c_str());
  108. this->Makefile->AddDefinition(this->HeaderList.c_str(),
  109. headerListValue.c_str());
  110. return true;
  111. }
  112. void cmQTWrapUICommand::FinalPass()
  113. {
  114. // first we add the rules for all the .ui to .h and .cxx files
  115. size_t lastHeadersClass = this->WrapHeadersClasses.size();
  116. std::vector<std::string> depends;
  117. const char* uic_exe =
  118. this->Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE");
  119. const char* moc_exe =
  120. this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
  121. // wrap all the .h files
  122. depends.push_back(uic_exe);
  123. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  124. {
  125. // set up .ui to .h and .cxx command
  126. std::string hres = this->Makefile->GetCurrentOutputDirectory();
  127. hres += "/";
  128. hres += this->WrapHeadersClasses[classNum].GetSourceName() + "." +
  129. this->WrapHeadersClasses[classNum].GetSourceExtension();
  130. std::string cxxres = this->Makefile->GetCurrentOutputDirectory();
  131. cxxres += "/";
  132. cxxres += this->WrapSourcesClasses[classNum].GetSourceName() + "." +
  133. this->WrapSourcesClasses[classNum].GetSourceExtension();
  134. std::string mocres = this->Makefile->GetCurrentOutputDirectory();
  135. mocres += "/";
  136. mocres += this->WrapMocClasses[classNum].GetSourceName() + "." +
  137. this->WrapMocClasses[classNum].GetSourceExtension();
  138. cmCustomCommandLine hCommand;
  139. hCommand.push_back(uic_exe);
  140. hCommand.push_back("-o");
  141. hCommand.push_back(hres);
  142. hCommand.push_back(this->WrapUserInterface[classNum]);
  143. cmCustomCommandLines hCommandLines;
  144. hCommandLines.push_back(hCommand);
  145. cmCustomCommandLine cxxCommand;
  146. cxxCommand.push_back(uic_exe);
  147. cxxCommand.push_back("-impl");
  148. cxxCommand.push_back(hres);
  149. cxxCommand.push_back("-o");
  150. cxxCommand.push_back(cxxres);
  151. cxxCommand.push_back(this->WrapUserInterface[classNum]);
  152. cmCustomCommandLines cxxCommandLines;
  153. cxxCommandLines.push_back(cxxCommand);
  154. cmCustomCommandLine mocCommand;
  155. mocCommand.push_back(moc_exe);
  156. mocCommand.push_back("-o");
  157. mocCommand.push_back(mocres);
  158. mocCommand.push_back(hres);
  159. cmCustomCommandLines mocCommandLines;
  160. mocCommandLines.push_back(mocCommand);
  161. depends.clear();
  162. depends.push_back(this->WrapUserInterface[classNum]);
  163. const char* no_main_dependency = 0;
  164. const char* no_comment = 0;
  165. const char* no_working_dir = 0;
  166. this->Makefile->AddCustomCommandToOutput(hres.c_str(),
  167. depends,
  168. no_main_dependency,
  169. hCommandLines,
  170. no_comment,
  171. no_working_dir);
  172. depends.push_back(hres);
  173. this->Makefile->AddCustomCommandToOutput(cxxres.c_str(),
  174. depends,
  175. no_main_dependency,
  176. cxxCommandLines,
  177. no_comment,
  178. no_working_dir);
  179. depends.clear();
  180. depends.push_back(hres);
  181. this->Makefile->AddCustomCommandToOutput(mocres.c_str(),
  182. depends,
  183. no_main_dependency,
  184. mocCommandLines,
  185. no_comment,
  186. no_working_dir);
  187. }
  188. }