cmQTWrapCPPCommand.cxx 4.0 KB

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