cmQTWrapCPPCommand.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 "cmQTWrapCPPCommand.h"
  14. // cmQTWrapCPPCommand
  15. bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. if(args.size() < 3 )
  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_CPP_value = m_Makefile->GetDefinition("QT_WRAP_CPP");
  25. if (QT_WRAP_CPP_value==0)
  26. {
  27. this->SetError("called with QT_WRAP_CPP undefined");
  28. return false;
  29. }
  30. if(cmSystemTools::IsOff(QT_WRAP_CPP_value))
  31. {
  32. this->SetError("called with QT_WRAP_CPP 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_SourceList = args[1];
  40. // get the list of classes for this library
  41. cmMakefile::SourceMap &Classes = m_Makefile->GetSources();
  42. for(std::vector<std::string>::const_iterator j = (args.begin() + 2);
  43. j != args.end(); ++j)
  44. {
  45. cmMakefile::SourceMap::iterator l = Classes.find(*j);
  46. if (l == Classes.end())
  47. {
  48. this->SetError("bad source list passed to QTWrapCPPCommand");
  49. return false;
  50. }
  51. for(std::vector<cmSourceFile>::iterator i = l->second.begin();
  52. i != l->second.end(); i++)
  53. {
  54. cmSourceFile &curr = *i;
  55. // if we should wrap the class
  56. if (!curr.GetWrapExclude())
  57. {
  58. cmSourceFile file;
  59. file.SetIsAnAbstractClass(curr.IsAnAbstractClass());
  60. std::string newName = "moc_" + curr.GetSourceName();
  61. file.SetName(newName.c_str(), m_Makefile->GetCurrentOutputDirectory(),
  62. "cxx",false);
  63. std::string hname = cdir + "/" + curr.GetSourceName() + "." +
  64. curr.GetSourceExtension();
  65. m_WrapHeaders.push_back(hname);
  66. // add starting depends
  67. file.GetDepends().push_back(hname);
  68. m_WrapClasses.push_back(file);
  69. }
  70. }
  71. }
  72. return true;
  73. }
  74. void cmQTWrapCPPCommand::FinalPass()
  75. {
  76. // first we add the rules for all the .h to Moc files
  77. int lastClass = m_WrapClasses.size();
  78. std::vector<std::string> depends;
  79. std::string moc_exe = "${QT_MOC_EXE}";
  80. // wrap all the .h files
  81. depends.push_back(moc_exe);
  82. const char * GENERATED_QT_FILES_value=
  83. m_Makefile->GetDefinition("GENERATED_QT_FILES");
  84. std::string moc_list("");
  85. if (GENERATED_QT_FILES_value!=0)
  86. {
  87. moc_list=moc_list+GENERATED_QT_FILES_value;
  88. }
  89. for(int classNum = 0; classNum < lastClass; classNum++)
  90. {
  91. // Add output to build list
  92. m_Makefile->AddSource(m_WrapClasses[classNum],m_SourceList.c_str());
  93. // set up moc command
  94. std::string res = m_Makefile->GetCurrentOutputDirectory();
  95. res += "/";
  96. res += m_WrapClasses[classNum].GetSourceName() + ".cxx";
  97. moc_list = moc_list + " " + res;
  98. std::vector<std::string> args;
  99. args.push_back("-o");
  100. args.push_back(res);
  101. args.push_back(m_WrapHeaders[classNum]);
  102. m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
  103. moc_exe.c_str(), args, depends,
  104. res.c_str(), m_LibraryName.c_str());
  105. }
  106. m_Makefile->AddDefinition("GENERATED_QT_FILES",moc_list.c_str());
  107. }