cmQTWrapUICommand.cxx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 = cdir + "/" + *j;
  74. std::string hname = header_file.GetFullPath();
  75. m_WrapUserInterface.push_back(origname);
  76. // add starting depends
  77. moc_file.GetDepends().push_back(hname);
  78. source_file.GetDepends().push_back(hname);
  79. source_file.GetDepends().push_back(origname);
  80. header_file.GetDepends().push_back(origname);
  81. m_WrapHeadersClasses.push_back(header_file);
  82. m_WrapSourcesClasses.push_back(source_file);
  83. m_WrapMocClasses.push_back(moc_file);
  84. m_Makefile->AddSource(header_file);
  85. m_Makefile->AddSource(source_file);
  86. m_Makefile->AddSource(moc_file);
  87. // create the list of sources
  88. if (headerListValue.size() > 0)
  89. {
  90. headerListValue += ";";
  91. }
  92. headerListValue += header_file.GetSourceName() + ".h";
  93. // create the list of sources
  94. if (sourceListValue.size() > 0)
  95. {
  96. sourceListValue += ";";
  97. }
  98. sourceListValue += source_file.GetSourceName() + ".cxx";
  99. sourceListValue += ";";
  100. sourceListValue += moc_file.GetSourceName() + ".cxx";
  101. }
  102. }
  103. m_Makefile->AddDefinition(m_SourceList.c_str(), sourceListValue.c_str());
  104. m_Makefile->AddDefinition(m_HeaderList.c_str(), headerListValue.c_str());
  105. return true;
  106. }
  107. void cmQTWrapUICommand::FinalPass()
  108. {
  109. // first we add the rules for all the .ui to .h and .cxx files
  110. size_t lastHeadersClass = m_WrapHeadersClasses.size();
  111. std::vector<std::string> depends;
  112. std::string uic_exe = "${QT_UIC_EXECUTABLE}";
  113. std::string moc_exe = "${QT_MOC_EXECUTABLE}";
  114. // wrap all the .h files
  115. depends.push_back(uic_exe);
  116. const char * GENERATED_QT_FILES_value=
  117. m_Makefile->GetDefinition("GENERATED_QT_FILES");
  118. std::string ui_list("");
  119. if (GENERATED_QT_FILES_value!=0)
  120. {
  121. ui_list=ui_list+GENERATED_QT_FILES_value;
  122. }
  123. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  124. {
  125. // set up .ui to .h and .cxx command
  126. std::string hres = m_Makefile->GetCurrentOutputDirectory();
  127. hres += "/";
  128. hres += m_WrapHeadersClasses[classNum].GetSourceName() + "." +
  129. m_WrapHeadersClasses[classNum].GetSourceExtension();
  130. std::string cxxres = m_Makefile->GetCurrentOutputDirectory();
  131. cxxres += "/";
  132. cxxres += m_WrapSourcesClasses[classNum].GetSourceName() + "." +
  133. m_WrapSourcesClasses[classNum].GetSourceExtension();
  134. std::string mocres = m_Makefile->GetCurrentOutputDirectory();
  135. mocres += "/";
  136. mocres += m_WrapMocClasses[classNum].GetSourceName() + "." +
  137. m_WrapMocClasses[classNum].GetSourceExtension();
  138. ui_list = ui_list + " " + hres + " " + cxxres + " " + mocres;
  139. std::vector<std::string> hargs;
  140. hargs.push_back("-o");
  141. hargs.push_back(hres);
  142. hargs.push_back(m_WrapUserInterface[classNum]);
  143. std::vector<std::string> cxxargs;
  144. cxxargs.push_back("-impl");
  145. cxxargs.push_back(hres);
  146. cxxargs.push_back("-o");
  147. cxxargs.push_back(cxxres);
  148. cxxargs.push_back(m_WrapUserInterface[classNum]);
  149. std::vector<std::string> mocargs;
  150. mocargs.push_back("-o");
  151. mocargs.push_back(mocres);
  152. mocargs.push_back(hres);
  153. m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
  154. uic_exe.c_str(), hargs, depends,
  155. hres.c_str(), m_LibraryName.c_str());
  156. depends.push_back(hres);
  157. m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
  158. uic_exe.c_str(), cxxargs, depends,
  159. cxxres.c_str(), m_LibraryName.c_str());
  160. depends.clear();
  161. depends.push_back(moc_exe);
  162. m_Makefile->AddCustomCommand(hres.c_str(),
  163. moc_exe.c_str(), mocargs, depends,
  164. mocres.c_str(), m_LibraryName.c_str());
  165. }
  166. m_Makefile->AddDefinition("GENERATED_QT_FILES",ui_list.c_str());
  167. }