cmQTWrapUICommand.cxx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. cmSystemTools::ExpandListArguments(argsIn, args);
  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. // get the list of classes for this library
  44. cmMakefile::SourceMap &Classes = m_Makefile->GetSources();
  45. for(std::vector<std::string>::const_iterator j = (args.begin() + 3);
  46. j != args.end(); ++j)
  47. {
  48. cmMakefile::SourceMap::iterator l = Classes.find(*j);
  49. if (l == Classes.end())
  50. {
  51. this->SetError("bad source list passed to QTWrapUICommand");
  52. return false;
  53. }
  54. for(std::vector<cmSourceFile*>::iterator i = l->second.begin();
  55. i != l->second.end(); i++)
  56. {
  57. cmSourceFile &curr = *(*i);
  58. // if we should wrap the class
  59. if (!curr.GetWrapExclude())
  60. {
  61. cmSourceFile header_file;
  62. cmSourceFile source_file;
  63. cmSourceFile moc_file;
  64. header_file.SetName(curr.GetSourceName().c_str(),
  65. m_Makefile->GetCurrentOutputDirectory(),
  66. "h",false);
  67. source_file.SetName(curr.GetSourceName().c_str(),
  68. m_Makefile->GetCurrentOutputDirectory(),
  69. "cxx",false);
  70. std::string moc_source_name("moc_");
  71. moc_source_name = moc_source_name + curr.GetSourceName().c_str();
  72. moc_file.SetName(moc_source_name.c_str(),
  73. m_Makefile->GetCurrentOutputDirectory(),
  74. "cxx",false);
  75. std::string origname = cdir + "/" + curr.GetSourceName() + "." +
  76. curr.GetSourceExtension();
  77. std::string hname = header_file.GetFullPath();
  78. m_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. m_WrapHeadersClasses.push_back(header_file);
  85. m_WrapSourcesClasses.push_back(source_file);
  86. m_WrapMocClasses.push_back(moc_file);
  87. m_Makefile->AddSource(header_file,
  88. m_HeaderList.c_str());
  89. m_Makefile->AddSource(source_file,
  90. m_SourceList.c_str());
  91. m_Makefile->AddSource(moc_file,
  92. m_SourceList.c_str());
  93. }
  94. }
  95. }
  96. return true;
  97. }
  98. void cmQTWrapUICommand::FinalPass()
  99. {
  100. // first we add the rules for all the .ui to .h and .cxx files
  101. size_t lastHeadersClass = m_WrapHeadersClasses.size();
  102. std::vector<std::string> depends;
  103. std::string uic_exe = "${QT_UIC_EXE}";
  104. std::string moc_exe = "${QT_MOC_EXE}";
  105. // wrap all the .h files
  106. depends.push_back(uic_exe);
  107. const char * GENERATED_QT_FILES_value=
  108. m_Makefile->GetDefinition("GENERATED_QT_FILES");
  109. std::string ui_list("");
  110. if (GENERATED_QT_FILES_value!=0)
  111. {
  112. ui_list=ui_list+GENERATED_QT_FILES_value;
  113. }
  114. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  115. {
  116. // set up .ui to .h and .cxx command
  117. std::string hres = m_Makefile->GetCurrentOutputDirectory();
  118. hres += "/";
  119. hres += m_WrapHeadersClasses[classNum].GetSourceName() + "." +
  120. m_WrapHeadersClasses[classNum].GetSourceExtension();
  121. std::string cxxres = m_Makefile->GetCurrentOutputDirectory();
  122. cxxres += "/";
  123. cxxres += m_WrapSourcesClasses[classNum].GetSourceName() + "." +
  124. m_WrapSourcesClasses[classNum].GetSourceExtension();
  125. std::string mocres = m_Makefile->GetCurrentOutputDirectory();
  126. mocres += "/";
  127. mocres += m_WrapMocClasses[classNum].GetSourceName() + "." +
  128. m_WrapMocClasses[classNum].GetSourceExtension();
  129. ui_list = ui_list + " " + hres + " " + cxxres + " " + mocres;
  130. std::vector<std::string> hargs;
  131. hargs.push_back("-o");
  132. hargs.push_back(hres);
  133. hargs.push_back(m_WrapUserInterface[classNum]);
  134. std::vector<std::string> cxxargs;
  135. cxxargs.push_back("-impl");
  136. cxxargs.push_back(hres);
  137. cxxargs.push_back("-o");
  138. cxxargs.push_back(cxxres);
  139. cxxargs.push_back(m_WrapUserInterface[classNum]);
  140. std::vector<std::string> mocargs;
  141. mocargs.push_back("-o");
  142. mocargs.push_back(mocres);
  143. mocargs.push_back(hres);
  144. m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
  145. uic_exe.c_str(), hargs, depends,
  146. hres.c_str(), m_LibraryName.c_str());
  147. depends.push_back(hres);
  148. m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
  149. uic_exe.c_str(), cxxargs, depends,
  150. cxxres.c_str(), m_LibraryName.c_str());
  151. depends.clear();
  152. depends.push_back(moc_exe);
  153. m_Makefile->AddCustomCommand(hres.c_str(),
  154. moc_exe.c_str(), mocargs, depends,
  155. mocres.c_str(), m_LibraryName.c_str());
  156. }
  157. m_Makefile->AddDefinition("GENERATED_QT_FILES",ui_list.c_str());
  158. }