cmQTWrapUICommand.cxx 6.4 KB

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