cmQTWrapUICommand.cxx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. // Now check and see if the value has been stored in the cache
  25. // already, if so use that value and don't look for the program
  26. const char* QT_WRAP_UI_value = m_Makefile->GetDefinition("QT_WRAP_UI");
  27. if (QT_WRAP_UI_value==0)
  28. {
  29. this->SetError("called with QT_WRAP_UI undefined");
  30. return false;
  31. }
  32. if(cmSystemTools::IsOff(QT_WRAP_UI_value))
  33. {
  34. this->SetError("called with QT_WRAP_UI off : ");
  35. return false;
  36. }
  37. // what is the current source dir
  38. std::string cdir = m_Makefile->GetCurrentDirectory();
  39. // keep the library name
  40. m_LibraryName = args[0];
  41. m_HeaderList = args[1];
  42. m_SourceList = args[2];
  43. std::string sourceListValue;
  44. std::string headerListValue;
  45. const char *def = m_Makefile->GetDefinition(m_SourceList.c_str());
  46. if (def)
  47. {
  48. sourceListValue = def;
  49. }
  50. // get the list of classes for this library
  51. for(std::vector<std::string>::iterator j = (args.begin() + 3);
  52. j != args.end(); ++j)
  53. {
  54. cmSourceFile *curr = m_Makefile->GetSource(j->c_str());
  55. // if we should wrap the class
  56. if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
  57. {
  58. cmSourceFile header_file;
  59. cmSourceFile source_file;
  60. cmSourceFile moc_file;
  61. std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*j);
  62. header_file.SetName(srcName.c_str(),
  63. m_Makefile->GetCurrentOutputDirectory(),
  64. "h",false);
  65. source_file.SetName(srcName.c_str(),
  66. m_Makefile->GetCurrentOutputDirectory(),
  67. "cxx",false);
  68. std::string moc_source_name("moc_");
  69. moc_source_name = moc_source_name + srcName;
  70. moc_file.SetName(moc_source_name.c_str(),
  71. m_Makefile->GetCurrentOutputDirectory(),
  72. "cxx",false);
  73. std::string origname;
  74. if ( (*j)[0] == '/' || (*j)[1] == ':' )
  75. {
  76. origname = *j;
  77. }
  78. else
  79. {
  80. if ( curr && curr->GetPropertyAsBool("GENERATED") )
  81. {
  82. origname = std::string( m_Makefile->GetCurrentOutputDirectory() ) + "/" + *j;
  83. }
  84. else
  85. {
  86. origname = cdir + "/" + *j;
  87. }
  88. }
  89. std::string hname = header_file.GetFullPath();
  90. m_WrapUserInterface.push_back(origname);
  91. // add starting depends
  92. moc_file.GetDepends().push_back(hname);
  93. source_file.GetDepends().push_back(hname);
  94. source_file.GetDepends().push_back(origname);
  95. header_file.GetDepends().push_back(origname);
  96. m_WrapHeadersClasses.push_back(header_file);
  97. m_WrapSourcesClasses.push_back(source_file);
  98. m_WrapMocClasses.push_back(moc_file);
  99. m_Makefile->AddSource(header_file);
  100. m_Makefile->AddSource(source_file);
  101. m_Makefile->AddSource(moc_file);
  102. // create the list of headers
  103. if (headerListValue.size() > 0)
  104. {
  105. headerListValue += ";";
  106. }
  107. headerListValue += header_file.GetFullPath();
  108. // create the list of sources
  109. if (sourceListValue.size() > 0)
  110. {
  111. sourceListValue += ";";
  112. }
  113. sourceListValue += source_file.GetFullPath();
  114. sourceListValue += ";";
  115. sourceListValue += moc_file.GetFullPath();
  116. }
  117. }
  118. m_Makefile->AddDefinition(m_SourceList.c_str(), sourceListValue.c_str());
  119. m_Makefile->AddDefinition(m_HeaderList.c_str(), headerListValue.c_str());
  120. return true;
  121. }
  122. void cmQTWrapUICommand::FinalPass()
  123. {
  124. // first we add the rules for all the .ui to .h and .cxx files
  125. size_t lastHeadersClass = m_WrapHeadersClasses.size();
  126. std::vector<std::string> depends;
  127. std::string uic_exe = "${QT_UIC_EXECUTABLE}";
  128. std::string moc_exe = "${QT_MOC_EXECUTABLE}";
  129. // wrap all the .h files
  130. depends.push_back(uic_exe);
  131. const char * GENERATED_QT_FILES_value=
  132. m_Makefile->GetDefinition("GENERATED_QT_FILES");
  133. std::string ui_list("");
  134. if (GENERATED_QT_FILES_value!=0)
  135. {
  136. ui_list=ui_list+GENERATED_QT_FILES_value;
  137. }
  138. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  139. {
  140. // set up .ui to .h and .cxx command
  141. std::string hres = m_Makefile->GetCurrentOutputDirectory();
  142. hres += "/";
  143. hres += m_WrapHeadersClasses[classNum].GetSourceName() + "." +
  144. m_WrapHeadersClasses[classNum].GetSourceExtension();
  145. std::string cxxres = m_Makefile->GetCurrentOutputDirectory();
  146. cxxres += "/";
  147. cxxres += m_WrapSourcesClasses[classNum].GetSourceName() + "." +
  148. m_WrapSourcesClasses[classNum].GetSourceExtension();
  149. std::string mocres = m_Makefile->GetCurrentOutputDirectory();
  150. mocres += "/";
  151. mocres += m_WrapMocClasses[classNum].GetSourceName() + "." +
  152. m_WrapMocClasses[classNum].GetSourceExtension();
  153. ui_list = ui_list + " " + hres + " " + cxxres + " " + mocres;
  154. std::vector<std::string> hargs;
  155. hargs.push_back("-o");
  156. hargs.push_back(hres);
  157. hargs.push_back(m_WrapUserInterface[classNum]);
  158. std::vector<std::string> cxxargs;
  159. cxxargs.push_back("-impl");
  160. cxxargs.push_back(hres);
  161. cxxargs.push_back("-o");
  162. cxxargs.push_back(cxxres);
  163. cxxargs.push_back(m_WrapUserInterface[classNum]);
  164. std::vector<std::string> mocargs;
  165. mocargs.push_back("-o");
  166. mocargs.push_back(mocres);
  167. mocargs.push_back(hres);
  168. depends.clear();
  169. depends.push_back(m_WrapUserInterface[classNum]);
  170. m_Makefile->AddCustomCommandToOutput(
  171. hres.c_str(),
  172. uic_exe.c_str(), hargs, 0,
  173. depends);
  174. depends.push_back(hres);
  175. m_Makefile->AddCustomCommandToOutput(
  176. cxxres.c_str(),
  177. uic_exe.c_str(), cxxargs, 0, depends);
  178. depends.clear();
  179. depends.push_back(hres);
  180. m_Makefile->AddCustomCommandToOutput(
  181. mocres.c_str(),
  182. moc_exe.c_str(), mocargs, 0, depends);
  183. }
  184. m_Makefile->AddDefinition("GENERATED_QT_FILES",ui_list.c_str());
  185. }