cmQTWrapCPPCommand.cxx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. // 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->GetPropertyAsBool("WRAP_EXCLUDE"))
  56. {
  57. cmSourceFile file;
  58. if (curr)
  59. {
  60. file.SetProperty("ABSTRACT",curr->GetProperty("ABSTRACT"));
  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;
  67. if ( (*j)[0] == '/' || (*j)[1] == ':' )
  68. {
  69. hname = *j;
  70. }
  71. else
  72. {
  73. if ( curr && curr->GetPropertyAsBool("GENERATED") )
  74. {
  75. hname = std::string( m_Makefile->GetCurrentOutputDirectory() ) + "/" + *j;
  76. }
  77. else
  78. {
  79. hname = cdir + "/" + *j;
  80. }
  81. }
  82. m_WrapHeaders.push_back(hname);
  83. // add starting depends
  84. file.GetDepends().push_back(hname);
  85. m_WrapClasses.push_back(file);
  86. if (sourceListValue.size() > 0)
  87. {
  88. sourceListValue += ";";
  89. }
  90. sourceListValue += newName + ".cxx";
  91. }
  92. }
  93. m_Makefile->AddDefinition(m_SourceList.c_str(), sourceListValue.c_str());
  94. return true;
  95. }
  96. void cmQTWrapCPPCommand::FinalPass()
  97. {
  98. // first we add the rules for all the .h to Moc files
  99. size_t lastClass = m_WrapClasses.size();
  100. std::vector<std::string> depends;
  101. std::string moc_exe = "${QT_MOC_EXECUTABLE}";
  102. // wrap all the .h files
  103. depends.push_back(moc_exe);
  104. const char * GENERATED_QT_FILES_value=
  105. m_Makefile->GetDefinition("GENERATED_QT_FILES");
  106. std::string moc_list("");
  107. if (GENERATED_QT_FILES_value!=0)
  108. {
  109. moc_list=moc_list+GENERATED_QT_FILES_value;
  110. }
  111. for(size_t classNum = 0; classNum < lastClass; classNum++)
  112. {
  113. // Add output to build list
  114. m_Makefile->AddSource(m_WrapClasses[classNum]);
  115. // set up moc command
  116. std::string res = m_Makefile->GetCurrentOutputDirectory();
  117. res += "/";
  118. res += m_WrapClasses[classNum].GetSourceName() + ".cxx";
  119. moc_list = moc_list + " " + res;
  120. std::vector<std::string> args;
  121. args.push_back("-o");
  122. args.push_back(res);
  123. args.push_back(m_WrapHeaders[classNum]);
  124. m_Makefile->AddCustomCommandToOutput(
  125. res.c_str(),
  126. moc_exe.c_str(),
  127. args,
  128. 0,
  129. depends,
  130. "QT Wrapped File",
  131. 0);
  132. }
  133. m_Makefile->AddDefinition("GENERATED_QT_FILES",moc_list.c_str());
  134. }