cmQTWrapCPPCommand.cxx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. this->Makefile->ExpandSourceListArguments(argsIn, args, 2);
  24. // what is the current source dir
  25. std::string cdir = this->Makefile->GetCurrentDirectory();
  26. // keep the library name
  27. this->LibraryName = args[0];
  28. this->SourceList = args[1];
  29. std::string sourceListValue;
  30. // was the list already populated
  31. const char *def = this->Makefile->GetDefinition(this->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 = this->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 =
  50. cmSystemTools::GetFilenameWithoutLastExtension(*j);
  51. std::string newName = "moc_" + srcName;
  52. file.SetName(newName.c_str(),
  53. this->Makefile->GetCurrentOutputDirectory(),
  54. "cxx",false);
  55. std::string hname;
  56. if ( (*j)[0] == '/' || (*j)[1] == ':' )
  57. {
  58. hname = *j;
  59. }
  60. else
  61. {
  62. if ( curr && curr->GetPropertyAsBool("GENERATED") )
  63. {
  64. hname = std::string(this->Makefile->GetCurrentOutputDirectory())
  65. + "/" + *j;
  66. }
  67. else
  68. {
  69. hname = cdir + "/" + *j;
  70. }
  71. }
  72. this->WrapHeaders.push_back(hname);
  73. // add starting depends
  74. file.GetDepends().push_back(hname);
  75. this->WrapClasses.push_back(file);
  76. if (sourceListValue.size() > 0)
  77. {
  78. sourceListValue += ";";
  79. }
  80. sourceListValue += newName + ".cxx";
  81. }
  82. }
  83. this->Makefile->AddDefinition(this->SourceList.c_str(),
  84. sourceListValue.c_str());
  85. return true;
  86. }
  87. void cmQTWrapCPPCommand::FinalPass()
  88. {
  89. // first we add the rules for all the .h to Moc files
  90. size_t lastClass = this->WrapClasses.size();
  91. std::vector<std::string> depends;
  92. const char* moc_exe =
  93. this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
  94. // wrap all the .h files
  95. depends.push_back(moc_exe);
  96. for(size_t classNum = 0; classNum < lastClass; classNum++)
  97. {
  98. // Add output to build list
  99. this->Makefile->AddSource(this->WrapClasses[classNum]);
  100. // set up moc command
  101. std::string res = this->Makefile->GetCurrentOutputDirectory();
  102. res += "/";
  103. res += this->WrapClasses[classNum].GetSourceName() + ".cxx";
  104. cmCustomCommandLine commandLine;
  105. commandLine.push_back(moc_exe);
  106. commandLine.push_back("-o");
  107. commandLine.push_back(res);
  108. commandLine.push_back(this->WrapHeaders[classNum]);
  109. cmCustomCommandLines commandLines;
  110. commandLines.push_back(commandLine);
  111. std::vector<std::string> realdepends = depends;
  112. realdepends.push_back(this->WrapHeaders[classNum]);
  113. const char* no_main_dependency = 0;
  114. const char* no_working_dir = 0;
  115. this->Makefile->AddCustomCommandToOutput(res.c_str(),
  116. realdepends,
  117. no_main_dependency,
  118. commandLines,
  119. "QT Wrapped File",
  120. no_working_dir);
  121. }
  122. }