cmQTWrapUICommand.cxx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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& args)
  16. {
  17. if(args.size() < 4 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. // Now check and see if the value has been stored in the cache
  23. // already, if so use that value and don't look for the program
  24. const char* QT_WRAP_UI_value = m_Makefile->GetDefinition("QT_WRAP_UI");
  25. if (QT_WRAP_UI_value==0)
  26. {
  27. this->SetError("called with QT_WRAP_UI undefined");
  28. return false;
  29. }
  30. if(cmSystemTools::IsOff(QT_WRAP_UI_value))
  31. {
  32. this->SetError("called with QT_WRAP_UI off : ");
  33. return false;
  34. }
  35. // what is the current source dir
  36. std::string cdir = m_Makefile->GetCurrentDirectory();
  37. // keep the library name
  38. m_LibraryName = args[0];
  39. m_HeaderList = args[1];
  40. m_SourceList = args[2];
  41. // get the list of classes for this library
  42. cmMakefile::SourceMap &Classes = m_Makefile->GetSources();
  43. for(std::vector<std::string>::const_iterator j = (args.begin() + 3);
  44. j != args.end(); ++j)
  45. {
  46. cmMakefile::SourceMap::iterator l = Classes.find(*j);
  47. if (l == Classes.end())
  48. {
  49. this->SetError("bad source list passed to QTWrapUICommand");
  50. return false;
  51. }
  52. for(std::vector<cmSourceFile>::iterator i = l->second.begin();
  53. i != l->second.end(); i++)
  54. {
  55. cmSourceFile &curr = *i;
  56. // if we should wrap the class
  57. if (!curr.GetWrapExclude())
  58. {
  59. cmSourceFile header_file;
  60. cmSourceFile source_file;
  61. cmSourceFile moc_file;
  62. header_file.SetName(curr.GetSourceName().c_str(),
  63. m_Makefile->GetCurrentOutputDirectory(),
  64. "h",false);
  65. source_file.SetName(curr.GetSourceName().c_str(),
  66. m_Makefile->GetCurrentOutputDirectory(),
  67. "cxx",false);
  68. std::string moc_source_name("moc_");
  69. moc_source_name = moc_source_name + curr.GetSourceName().c_str();
  70. moc_file.SetName(moc_source_name.c_str(),
  71. m_Makefile->GetCurrentOutputDirectory(),
  72. "cxx",false);
  73. std::string origname = cdir + "/" + curr.GetSourceName() + "." +
  74. curr.GetSourceExtension();
  75. std::string hname = header_file.GetFullPath();
  76. m_WrapUserInterface.push_back(origname);
  77. // add starting depends
  78. moc_file.GetDepends().push_back(hname);
  79. source_file.GetDepends().push_back(hname);
  80. source_file.GetDepends().push_back(origname);
  81. header_file.GetDepends().push_back(origname);
  82. m_WrapHeadersClasses.push_back(header_file);
  83. m_WrapSourcesClasses.push_back(source_file);
  84. m_WrapMocClasses.push_back(moc_file);
  85. m_Makefile->AddSource(header_file,
  86. m_HeaderList.c_str());
  87. m_Makefile->AddSource(source_file,
  88. m_SourceList.c_str());
  89. m_Makefile->AddSource(moc_file,
  90. m_SourceList.c_str());
  91. }
  92. }
  93. }
  94. return true;
  95. }
  96. void cmQTWrapUICommand::FinalPass()
  97. {
  98. // first we add the rules for all the .ui to .h and .cxx files
  99. size_t lastHeadersClass = m_WrapHeadersClasses.size();
  100. std::vector<std::string> depends;
  101. std::string uic_exe = "${QT_UIC_EXE}";
  102. std::string moc_exe = "${QT_MOC_EXE}";
  103. // wrap all the .h files
  104. depends.push_back(uic_exe);
  105. const char * GENERATED_QT_FILES_value=
  106. m_Makefile->GetDefinition("GENERATED_QT_FILES");
  107. std::string ui_list("");
  108. if (GENERATED_QT_FILES_value!=0)
  109. {
  110. ui_list=ui_list+GENERATED_QT_FILES_value;
  111. }
  112. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  113. {
  114. // set up .ui to .h and .cxx command
  115. std::string hres = m_Makefile->GetCurrentOutputDirectory();
  116. hres += "/";
  117. hres += m_WrapHeadersClasses[classNum].GetSourceName() + "." +
  118. m_WrapHeadersClasses[classNum].GetSourceExtension();
  119. std::string cxxres = m_Makefile->GetCurrentOutputDirectory();
  120. cxxres += "/";
  121. cxxres += m_WrapSourcesClasses[classNum].GetSourceName() + "." +
  122. m_WrapSourcesClasses[classNum].GetSourceExtension();
  123. std::string mocres = m_Makefile->GetCurrentOutputDirectory();
  124. mocres += "/";
  125. mocres += m_WrapMocClasses[classNum].GetSourceName() + "." +
  126. m_WrapMocClasses[classNum].GetSourceExtension();
  127. ui_list = ui_list + " " + hres + " " + cxxres + " " + mocres;
  128. std::vector<std::string> hargs;
  129. hargs.push_back("-o");
  130. hargs.push_back(hres);
  131. hargs.push_back(m_WrapUserInterface[classNum]);
  132. std::vector<std::string> cxxargs;
  133. cxxargs.push_back("-impl");
  134. cxxargs.push_back(hres);
  135. cxxargs.push_back("-o");
  136. cxxargs.push_back(cxxres);
  137. cxxargs.push_back(m_WrapUserInterface[classNum]);
  138. std::vector<std::string> mocargs;
  139. mocargs.push_back("-o");
  140. mocargs.push_back(mocres);
  141. mocargs.push_back(hres);
  142. m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
  143. uic_exe.c_str(), hargs, depends,
  144. hres.c_str(), m_LibraryName.c_str());
  145. depends.push_back(hres);
  146. m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
  147. uic_exe.c_str(), cxxargs, depends,
  148. cxxres.c_str(), m_LibraryName.c_str());
  149. depends.clear();
  150. depends.push_back(moc_exe);
  151. m_Makefile->AddCustomCommand(hres.c_str(),
  152. moc_exe.c_str(), mocargs, depends,
  153. mocres.c_str(), m_LibraryName.c_str());
  154. }
  155. m_Makefile->AddDefinition("GENERATED_QT_FILES",ui_list.c_str());
  156. }