cmQTWrapUICommand.cxx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. std::string uic_exe = "${QT_UIC_EXECUTABLE}";
  115. std::string moc_exe = "${QT_MOC_EXECUTABLE}";
  116. // wrap all the .h files
  117. depends.push_back(uic_exe);
  118. const char * GENERATED_QT_FILES_value=
  119. m_Makefile->GetDefinition("GENERATED_QT_FILES");
  120. std::string ui_list("");
  121. if (GENERATED_QT_FILES_value!=0)
  122. {
  123. ui_list=ui_list+GENERATED_QT_FILES_value;
  124. }
  125. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  126. {
  127. // set up .ui to .h and .cxx command
  128. std::string hres = m_Makefile->GetCurrentOutputDirectory();
  129. hres += "/";
  130. hres += m_WrapHeadersClasses[classNum].GetSourceName() + "." +
  131. m_WrapHeadersClasses[classNum].GetSourceExtension();
  132. std::string cxxres = m_Makefile->GetCurrentOutputDirectory();
  133. cxxres += "/";
  134. cxxres += m_WrapSourcesClasses[classNum].GetSourceName() + "." +
  135. m_WrapSourcesClasses[classNum].GetSourceExtension();
  136. std::string mocres = m_Makefile->GetCurrentOutputDirectory();
  137. mocres += "/";
  138. mocres += m_WrapMocClasses[classNum].GetSourceName() + "." +
  139. m_WrapMocClasses[classNum].GetSourceExtension();
  140. ui_list = ui_list + " " + hres + " " + cxxres + " " + mocres;
  141. std::vector<std::string> hargs;
  142. hargs.push_back("-o");
  143. hargs.push_back(hres);
  144. hargs.push_back(m_WrapUserInterface[classNum]);
  145. std::vector<std::string> cxxargs;
  146. cxxargs.push_back("-impl");
  147. cxxargs.push_back(hres);
  148. cxxargs.push_back("-o");
  149. cxxargs.push_back(cxxres);
  150. cxxargs.push_back(m_WrapUserInterface[classNum]);
  151. std::vector<std::string> mocargs;
  152. mocargs.push_back("-o");
  153. mocargs.push_back(mocres);
  154. mocargs.push_back(hres);
  155. depends.clear();
  156. depends.push_back(m_WrapUserInterface[classNum]);
  157. m_Makefile->AddCustomCommandToOutput(
  158. hres.c_str(),
  159. uic_exe.c_str(), hargs, 0,
  160. depends);
  161. depends.push_back(hres);
  162. m_Makefile->AddCustomCommandToOutput(
  163. cxxres.c_str(),
  164. uic_exe.c_str(), cxxargs, 0, depends);
  165. depends.clear();
  166. depends.push_back(hres);
  167. m_Makefile->AddCustomCommandToOutput(
  168. mocres.c_str(),
  169. moc_exe.c_str(), mocargs, 0, depends);
  170. }
  171. m_Makefile->AddDefinition("GENERATED_QT_FILES",ui_list.c_str());
  172. }