cmQTWrapUICommand.cxx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. m_Makefile->ExpandSourceListArguments(argsIn, args, 3);
  24. // what is the current source dir
  25. std::string cdir = m_Makefile->GetCurrentDirectory();
  26. // keep the library name
  27. m_LibraryName = args[0];
  28. m_HeaderList = args[1];
  29. m_SourceList = args[2];
  30. std::string sourceListValue;
  31. std::string headerListValue;
  32. const char *def = m_Makefile->GetDefinition(m_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 = m_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. m_Makefile->GetCurrentOutputDirectory(),
  51. "h",false);
  52. source_file.SetName(srcName.c_str(),
  53. m_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. m_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( m_Makefile->GetCurrentOutputDirectory() ) + "/" + *j;
  70. }
  71. else
  72. {
  73. origname = cdir + "/" + *j;
  74. }
  75. }
  76. std::string hname = header_file.GetFullPath();
  77. m_WrapUserInterface.push_back(origname);
  78. // add starting depends
  79. moc_file.GetDepends().push_back(hname);
  80. source_file.GetDepends().push_back(hname);
  81. source_file.GetDepends().push_back(origname);
  82. header_file.GetDepends().push_back(origname);
  83. m_WrapHeadersClasses.push_back(header_file);
  84. m_WrapSourcesClasses.push_back(source_file);
  85. m_WrapMocClasses.push_back(moc_file);
  86. m_Makefile->AddSource(header_file);
  87. m_Makefile->AddSource(source_file);
  88. m_Makefile->AddSource(moc_file);
  89. // create the list of headers
  90. if (headerListValue.size() > 0)
  91. {
  92. headerListValue += ";";
  93. }
  94. headerListValue += header_file.GetFullPath();
  95. // create the list of sources
  96. if (sourceListValue.size() > 0)
  97. {
  98. sourceListValue += ";";
  99. }
  100. sourceListValue += source_file.GetFullPath();
  101. sourceListValue += ";";
  102. sourceListValue += moc_file.GetFullPath();
  103. }
  104. }
  105. m_Makefile->AddDefinition(m_SourceList.c_str(), sourceListValue.c_str());
  106. m_Makefile->AddDefinition(m_HeaderList.c_str(), headerListValue.c_str());
  107. return true;
  108. }
  109. void cmQTWrapUICommand::FinalPass()
  110. {
  111. // first we add the rules for all the .ui to .h and .cxx files
  112. size_t lastHeadersClass = m_WrapHeadersClasses.size();
  113. std::vector<std::string> depends;
  114. const char* uic_exe = m_Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE");
  115. const char* moc_exe = m_Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
  116. // wrap all the .h files
  117. depends.push_back(uic_exe);
  118. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  119. {
  120. // set up .ui to .h and .cxx command
  121. std::string hres = m_Makefile->GetCurrentOutputDirectory();
  122. hres += "/";
  123. hres += m_WrapHeadersClasses[classNum].GetSourceName() + "." +
  124. m_WrapHeadersClasses[classNum].GetSourceExtension();
  125. std::string cxxres = m_Makefile->GetCurrentOutputDirectory();
  126. cxxres += "/";
  127. cxxres += m_WrapSourcesClasses[classNum].GetSourceName() + "." +
  128. m_WrapSourcesClasses[classNum].GetSourceExtension();
  129. std::string mocres = m_Makefile->GetCurrentOutputDirectory();
  130. mocres += "/";
  131. mocres += m_WrapMocClasses[classNum].GetSourceName() + "." +
  132. m_WrapMocClasses[classNum].GetSourceExtension();
  133. cmCustomCommandLine hCommand;
  134. hCommand.push_back(uic_exe);
  135. hCommand.push_back("-o");
  136. hCommand.push_back(hres);
  137. hCommand.push_back(m_WrapUserInterface[classNum]);
  138. cmCustomCommandLines hCommandLines;
  139. hCommandLines.push_back(hCommand);
  140. cmCustomCommandLine cxxCommand;
  141. cxxCommand.push_back(uic_exe);
  142. cxxCommand.push_back("-impl");
  143. cxxCommand.push_back(hres);
  144. cxxCommand.push_back("-o");
  145. cxxCommand.push_back(cxxres);
  146. cxxCommand.push_back(m_WrapUserInterface[classNum]);
  147. cmCustomCommandLines cxxCommandLines;
  148. cxxCommandLines.push_back(cxxCommand);
  149. cmCustomCommandLine mocCommand;
  150. mocCommand.push_back(moc_exe);
  151. mocCommand.push_back("-o");
  152. mocCommand.push_back(mocres);
  153. mocCommand.push_back(hres);
  154. cmCustomCommandLines mocCommandLines;
  155. mocCommandLines.push_back(mocCommand);
  156. depends.clear();
  157. depends.push_back(m_WrapUserInterface[classNum]);
  158. const char* no_main_dependency = 0;
  159. const char* no_comment = 0;
  160. const char* no_working_dir = 0;
  161. m_Makefile->AddCustomCommandToOutput(hres.c_str(),
  162. depends,
  163. no_main_dependency,
  164. hCommandLines,
  165. no_comment,
  166. no_working_dir);
  167. depends.push_back(hres);
  168. m_Makefile->AddCustomCommandToOutput(cxxres.c_str(),
  169. depends,
  170. no_main_dependency,
  171. cxxCommandLines,
  172. no_comment,
  173. no_working_dir);
  174. depends.clear();
  175. depends.push_back(hres);
  176. m_Makefile->AddCustomCommandToOutput(mocres.c_str(),
  177. depends,
  178. no_main_dependency,
  179. mocCommandLines,
  180. no_comment,
  181. no_working_dir);
  182. }
  183. }