cmQTWrapCPPCommand.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. m_Makefile->ExpandSourceListArguments(argsIn, args, 2);
  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. std::string sourceListValue;
  43. // was the list already populated
  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() + 2);
  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 file;
  58. if (curr)
  59. {
  60. file.SetIsAnAbstractClass(curr->IsAnAbstractClass());
  61. }
  62. std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*j);
  63. std::string newName = "moc_" + srcName;
  64. file.SetName(newName.c_str(), m_Makefile->GetCurrentOutputDirectory(),
  65. "cxx",false);
  66. std::string hname = cdir + "/" + *j;
  67. m_WrapHeaders.push_back(hname);
  68. // add starting depends
  69. file.GetDepends().push_back(hname);
  70. m_WrapClasses.push_back(file);
  71. if (sourceListValue.size() > 0)
  72. {
  73. sourceListValue += ";";
  74. }
  75. sourceListValue += newName + ".cxx";
  76. }
  77. }
  78. m_Makefile->AddDefinition(m_SourceList.c_str(), sourceListValue.c_str());
  79. return true;
  80. }
  81. void cmQTWrapCPPCommand::FinalPass()
  82. {
  83. // first we add the rules for all the .h to Moc files
  84. size_t lastClass = m_WrapClasses.size();
  85. std::vector<std::string> depends;
  86. std::string moc_exe = "${QT_MOC_EXE}";
  87. // wrap all the .h files
  88. depends.push_back(moc_exe);
  89. const char * GENERATED_QT_FILES_value=
  90. m_Makefile->GetDefinition("GENERATED_QT_FILES");
  91. std::string moc_list("");
  92. if (GENERATED_QT_FILES_value!=0)
  93. {
  94. moc_list=moc_list+GENERATED_QT_FILES_value;
  95. }
  96. for(size_t classNum = 0; classNum < lastClass; classNum++)
  97. {
  98. // Add output to build list
  99. m_Makefile->AddSource(m_WrapClasses[classNum]);
  100. // set up moc command
  101. std::string res = m_Makefile->GetCurrentOutputDirectory();
  102. res += "/";
  103. res += m_WrapClasses[classNum].GetSourceName() + ".cxx";
  104. moc_list = moc_list + " " + res;
  105. std::vector<std::string> args;
  106. args.push_back("-o");
  107. args.push_back(res);
  108. args.push_back(m_WrapHeaders[classNum]);
  109. m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
  110. moc_exe.c_str(), args, depends,
  111. res.c_str(), m_LibraryName.c_str());
  112. }
  113. m_Makefile->AddDefinition("GENERATED_QT_FILES",moc_list.c_str());
  114. }