cmQTWrapCPPCommand.cxx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Author: Ian Scott.
  8. Copyright (c) 2001 Insight Consortium
  9. All rights reserved.
  10. Redistribution and use in source and binary forms, with or without
  11. modification, are permitted provided that the following conditions are met:
  12. * Redistributions of source code must retain the above copyright notice,
  13. this list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright notice,
  15. this list of conditions and the following disclaimer in the documentation
  16. and/or other materials provided with the distribution.
  17. * The name of the Insight Consortium, nor the names of any consortium members,
  18. nor of any contributors, may be used to endorse or promote products derived
  19. from this software without specific prior written permission.
  20. * Modified source versions must be plainly marked as such, and must not be
  21. misrepresented as being the original software.
  22. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
  23. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
  26. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. =========================================================================*/
  33. #include "cmQTWrapCPPCommand.h"
  34. // cmQTWrapCPPCommand
  35. bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& args)
  36. {
  37. if(args.size() < 3 )
  38. {
  39. this->SetError("called with incorrect number of arguments");
  40. return false;
  41. }
  42. // Now check and see if the value has been stored in the cache
  43. // already, if so use that value and don't look for the program
  44. const char* QT_WRAP_CPP_value = m_Makefile->GetDefinition("QT_WRAP_CPP");
  45. if (QT_WRAP_CPP_value==0)
  46. {
  47. this->SetError("called with QT_WRAP_CPP undefined");
  48. return false;
  49. }
  50. if(cmSystemTools::IsOff(QT_WRAP_CPP_value))
  51. {
  52. this->SetError("called with QT_WRAP_CPP off : ");
  53. return false;
  54. }
  55. // what is the current source dir
  56. std::string cdir = m_Makefile->GetCurrentDirectory();
  57. // keep the library name
  58. m_LibraryName = args[0];
  59. m_SourceList = args[1];
  60. // get the list of classes for this library
  61. cmMakefile::SourceMap &Classes = m_Makefile->GetSources();
  62. for(std::vector<std::string>::const_iterator j = (args.begin() + 2);
  63. j != args.end(); ++j)
  64. {
  65. cmMakefile::SourceMap::iterator l = Classes.find(*j);
  66. if (l == Classes.end())
  67. {
  68. this->SetError("bad source list passed to QTWrapCPPCommand");
  69. return false;
  70. }
  71. for(std::vector<cmSourceFile>::iterator i = l->second.begin();
  72. i != l->second.end(); i++)
  73. {
  74. cmSourceFile &curr = *i;
  75. // if we should wrap the class
  76. if (!curr.GetWrapExclude())
  77. {
  78. cmSourceFile file;
  79. file.SetIsAnAbstractClass(curr.IsAnAbstractClass());
  80. std::string newName = "moc_" + curr.GetSourceName();
  81. file.SetName(newName.c_str(), m_Makefile->GetCurrentOutputDirectory(),
  82. "cxx",false);
  83. std::string hname = cdir + "/" + curr.GetSourceName() + "." +
  84. curr.GetSourceExtension();
  85. m_WrapHeaders.push_back(hname);
  86. // add starting depends
  87. file.GetDepends().push_back(hname);
  88. m_WrapClasses.push_back(file);
  89. m_OriginalNames.push_back(curr.GetSourceName());
  90. }
  91. }
  92. }
  93. return true;
  94. }
  95. void cmQTWrapCPPCommand::FinalPass()
  96. {
  97. // first we add the rules for all the .h to Moc files
  98. int lastClass = m_WrapClasses.size();
  99. std::vector<std::string> depends;
  100. std::string moc_exe = "${QT_MOC_EXE}";
  101. // wrap all the .h files
  102. depends.push_back(moc_exe);
  103. std::string moc_list("");
  104. for(int classNum = 0; classNum < lastClass; classNum++)
  105. {
  106. // Add output to build list
  107. m_Makefile->AddSource(m_WrapClasses[classNum],m_SourceList.c_str());
  108. // set up moc command
  109. std::string res = m_Makefile->GetCurrentOutputDirectory();
  110. res += "/";
  111. res += m_WrapClasses[classNum].GetSourceName() + ".cxx";
  112. moc_list = moc_list + " " + res;
  113. std::vector<std::string> args;
  114. args.push_back("-o");
  115. args.push_back(res);
  116. args.push_back(m_WrapHeaders[classNum]);
  117. m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
  118. moc_exe.c_str(), args, depends,
  119. res.c_str(), m_LibraryName.c_str());
  120. }
  121. m_Makefile->AddDefinition("GENERATED_QT_FILES",moc_list.c_str());
  122. }