cmQTWrapUICommand.cxx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Author: Franck Bettinger.
  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 "cmQTWrapUICommand.h"
  34. // cmQTWrapUICommand
  35. bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args)
  36. {
  37. if(args.size() < 4 )
  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_UI_value = m_Makefile->GetDefinition("QT_WRAP_UI");
  45. if (QT_WRAP_UI_value==0)
  46. {
  47. this->SetError("called with QT_WRAP_UI undefined");
  48. return false;
  49. }
  50. if(cmSystemTools::IsOff(QT_WRAP_UI_value))
  51. {
  52. this->SetError("called with QT_WRAP_UI 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_HeaderList = args[1];
  60. m_SourceList = args[2];
  61. // get the list of classes for this library
  62. cmMakefile::SourceMap &Classes = m_Makefile->GetSources();
  63. for(std::vector<std::string>::const_iterator j = (args.begin() + 3);
  64. j != args.end(); ++j)
  65. {
  66. cmMakefile::SourceMap::iterator l = Classes.find(*j);
  67. if (l == Classes.end())
  68. {
  69. this->SetError("bad source list passed to QTWrapUICommand");
  70. return false;
  71. }
  72. for(std::vector<cmSourceFile>::iterator i = l->second.begin();
  73. i != l->second.end(); i++)
  74. {
  75. cmSourceFile &curr = *i;
  76. // if we should wrap the class
  77. if (!curr.GetWrapExclude())
  78. {
  79. cmSourceFile header_file;
  80. cmSourceFile source_file;
  81. header_file.SetIsAnAbstractClass(curr.IsAnAbstractClass());
  82. source_file.SetIsAnAbstractClass(curr.IsAnAbstractClass());
  83. header_file.SetName(curr.GetSourceName().c_str(),
  84. m_Makefile->GetCurrentOutputDirectory(),
  85. "h",false);
  86. source_file.SetName(curr.GetSourceName().c_str(),
  87. m_Makefile->GetCurrentOutputDirectory(),
  88. "cxx",false);
  89. std::string origname = cdir + "/" + curr.GetSourceName() + "." +
  90. curr.GetSourceExtension();
  91. std::string hname = cdir + "/" + header_file.GetSourceName() + "." +
  92. header_file.GetSourceExtension();
  93. m_WrapUserInterface.push_back(origname);
  94. // add starting depends
  95. source_file.GetDepends().push_back(hname);
  96. source_file.GetDepends().push_back(origname);
  97. header_file.GetDepends().push_back(origname);
  98. m_WrapHeadersClasses.push_back(header_file);
  99. m_WrapSourcesClasses.push_back(source_file);
  100. unsigned int last_files=m_WrapSourcesClasses.size()-1;
  101. m_Makefile->AddSource(m_WrapHeadersClasses[last_files],
  102. m_HeaderList.c_str());
  103. m_Makefile->AddSource(m_WrapSourcesClasses[last_files],
  104. m_SourceList.c_str());
  105. }
  106. }
  107. }
  108. return true;
  109. }
  110. void cmQTWrapUICommand::FinalPass()
  111. {
  112. // first we add the rules for all the .ui to .h and .cxx files
  113. int lastHeadersClass = m_WrapHeadersClasses.size();
  114. std::vector<std::string> depends;
  115. std::string uic_exe = "${QT_UIC_EXE}";
  116. // wrap all the .h files
  117. depends.push_back(uic_exe);
  118. const char * GENERATED_QT_FILES_value=
  119. m_Makefile->GetDefinition("GENERATED_QT_FILES");
  120. std::string ui_list("");
  121. if (GENERATED_QT_FILES_value!=0)
  122. {
  123. ui_list=ui_list+GENERATED_QT_FILES_value;
  124. }
  125. for(int classNum = 0; classNum < lastHeadersClass; classNum++)
  126. {
  127. // Add output to build list
  128. // set up .ui to .h and .cxx command
  129. std::string hres = m_Makefile->GetCurrentOutputDirectory();
  130. hres += "/";
  131. hres += m_WrapHeadersClasses[classNum].GetSourceName() + "." +
  132. m_WrapHeadersClasses[classNum].GetSourceExtension();
  133. std::string cxxres = m_Makefile->GetCurrentOutputDirectory();
  134. cxxres += "/";
  135. cxxres += m_WrapSourcesClasses[classNum].GetSourceName() + "." +
  136. m_WrapSourcesClasses[classNum].GetSourceExtension();
  137. ui_list = ui_list + " " + hres + " " + cxxres;
  138. std::vector<std::string> hargs;
  139. hargs.push_back("-o");
  140. hargs.push_back(hres);
  141. hargs.push_back(m_WrapUserInterface[classNum]);
  142. std::vector<std::string> cxxargs;
  143. cxxargs.push_back("-impl");
  144. cxxargs.push_back(hres);
  145. cxxargs.push_back("-o");
  146. cxxargs.push_back(cxxres);
  147. cxxargs.push_back(m_WrapUserInterface[classNum]);
  148. m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
  149. uic_exe.c_str(), hargs, depends,
  150. hres.c_str(), m_LibraryName.c_str());
  151. depends.push_back(hres);
  152. m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
  153. uic_exe.c_str(), cxxargs, depends,
  154. cxxres.c_str(), m_LibraryName.c_str());
  155. }
  156. m_Makefile->AddDefinition("GENERATED_QT_FILES",ui_list.c_str());
  157. }