cmQTWrapCPPCommand.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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. // what is the current source dir
  25. std::string cdir = m_Makefile->GetCurrentDirectory();
  26. // keep the library name
  27. m_LibraryName = args[0];
  28. m_SourceList = args[1];
  29. std::string sourceListValue;
  30. // was the list already populated
  31. const char *def = m_Makefile->GetDefinition(m_SourceList.c_str());
  32. if (def)
  33. {
  34. sourceListValue = def;
  35. }
  36. // get the list of classes for this library
  37. for(std::vector<std::string>::iterator j = (args.begin() + 2);
  38. j != args.end(); ++j)
  39. {
  40. cmSourceFile *curr = m_Makefile->GetSource(j->c_str());
  41. // if we should wrap the class
  42. if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
  43. {
  44. cmSourceFile file;
  45. if (curr)
  46. {
  47. file.SetProperty("ABSTRACT",curr->GetProperty("ABSTRACT"));
  48. }
  49. std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*j);
  50. std::string newName = "moc_" + srcName;
  51. file.SetName(newName.c_str(), m_Makefile->GetCurrentOutputDirectory(),
  52. "cxx",false);
  53. std::string hname;
  54. if ( (*j)[0] == '/' || (*j)[1] == ':' )
  55. {
  56. hname = *j;
  57. }
  58. else
  59. {
  60. if ( curr && curr->GetPropertyAsBool("GENERATED") )
  61. {
  62. hname = std::string( m_Makefile->GetCurrentOutputDirectory() ) + "/" + *j;
  63. }
  64. else
  65. {
  66. hname = cdir + "/" + *j;
  67. }
  68. }
  69. m_WrapHeaders.push_back(hname);
  70. // add starting depends
  71. file.GetDepends().push_back(hname);
  72. m_WrapClasses.push_back(file);
  73. if (sourceListValue.size() > 0)
  74. {
  75. sourceListValue += ";";
  76. }
  77. sourceListValue += newName + ".cxx";
  78. }
  79. }
  80. m_Makefile->AddDefinition(m_SourceList.c_str(), sourceListValue.c_str());
  81. return true;
  82. }
  83. void cmQTWrapCPPCommand::FinalPass()
  84. {
  85. // first we add the rules for all the .h to Moc files
  86. size_t lastClass = m_WrapClasses.size();
  87. std::vector<std::string> depends;
  88. const char* moc_exe = m_Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
  89. // wrap all the .h files
  90. depends.push_back(moc_exe);
  91. for(size_t classNum = 0; classNum < lastClass; classNum++)
  92. {
  93. // Add output to build list
  94. m_Makefile->AddSource(m_WrapClasses[classNum]);
  95. // set up moc command
  96. std::string res = m_Makefile->GetCurrentOutputDirectory();
  97. res += "/";
  98. res += m_WrapClasses[classNum].GetSourceName() + ".cxx";
  99. cmCustomCommandLine commandLine;
  100. commandLine.push_back(moc_exe);
  101. commandLine.push_back("-o");
  102. commandLine.push_back(res);
  103. commandLine.push_back(m_WrapHeaders[classNum]);
  104. cmCustomCommandLines commandLines;
  105. commandLines.push_back(commandLine);
  106. std::vector<std::string> realdepends = depends;
  107. realdepends.push_back(m_WrapHeaders[classNum]);
  108. const char* no_main_dependency = 0;
  109. m_Makefile->AddCustomCommandToOutput(res.c_str(),
  110. realdepends,
  111. no_main_dependency,
  112. commandLines,
  113. "QT Wrapped File");
  114. }
  115. }