cmFLTKWrapUICommand.cxx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 "cmFLTKWrapUICommand.h"
  34. // cmFLTKWrapUICommand
  35. bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args)
  36. {
  37. if(args.size() < 2 )
  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* FLTK_WRAP_UI_value = m_Makefile->GetDefinition("FLTK_WRAP_UI");
  45. if (FLTK_WRAP_UI_value==0)
  46. {
  47. this->SetError("called with FLTK_WRAP_UI undefined");
  48. return false;
  49. }
  50. if(cmSystemTools::IsOff(FLTK_WRAP_UI_value))
  51. {
  52. this->SetError("called with FLTK_WRAP_UI off : ");
  53. return false;
  54. }
  55. std::string outputGUIDirectory = m_Makefile->GetCurrentOutputDirectory();
  56. if(!cmSystemTools::MakeDirectory( outputGUIDirectory.c_str() ) )
  57. {
  58. cmSystemTools::Error("Error failed create GUI directory:",
  59. outputGUIDirectory.c_str() );
  60. }
  61. // what is the current source dir
  62. std::string cdir = m_Makefile->GetCurrentDirectory();
  63. // keep the library name
  64. m_GUISourceList = args[0]; // Source List of the GUI source files
  65. m_GeneratedSourceList = args[1]; // Source List to insert the generated .cxx files
  66. cmMakefile::SourceMap &GUISources = m_Makefile->GetSources();
  67. // get the list of GUI files from which .cxx and .h will be generated
  68. cmMakefile::SourceMap::iterator l = GUISources.find( m_GUISourceList );
  69. if (l == GUISources.end())
  70. {
  71. this->SetError("bad source list passed to FLTKWrapUICommand");
  72. return false;
  73. }
  74. // Some of the generated files are *.h so the directory "GUI"
  75. // where they are created have to be added to the include path
  76. m_Makefile->AddIncludeDirectory( outputGUIDirectory.c_str() );
  77. for(std::vector<cmSourceFile>::iterator i = l->second.begin();
  78. i != l->second.end(); i++)
  79. {
  80. cmSourceFile &curr = *i;
  81. // if we should use the source GUI
  82. // to generate .cxx and .h files
  83. if (!curr.GetWrapExclude())
  84. {
  85. cmSourceFile header_file;
  86. cmSourceFile source_file;
  87. const bool headerFileOnly = true;
  88. header_file.SetName(curr.GetSourceName().c_str(),
  89. outputGUIDirectory.c_str(), "h",headerFileOnly);
  90. source_file.SetName(curr.GetSourceName().c_str(),
  91. outputGUIDirectory.c_str(), "cxx",!headerFileOnly);
  92. std::string origname = cdir + "/" + curr.GetSourceName() + "." +
  93. curr.GetSourceExtension();
  94. std::string hname = header_file.GetFullPath();
  95. std::string cxxname = source_file.GetFullPath();
  96. m_WrapUserInterface.push_back(origname);
  97. // add starting depends
  98. source_file.GetDepends().push_back(hname);
  99. source_file.GetDepends().push_back(origname);
  100. header_file.GetDepends().push_back(origname);
  101. m_GeneratedHeadersClasses.push_back(header_file);
  102. m_GeneratedSourcesClasses.push_back(source_file);
  103. m_Makefile->AddSource(header_file, m_GeneratedSourceList.c_str());
  104. m_Makefile->AddSource(source_file, m_GeneratedSourceList.c_str());
  105. m_Makefile->AddSource(header_file, m_GeneratedSourceList.c_str());
  106. m_Makefile->AddSource(source_file, m_GeneratedSourceList.c_str());
  107. cmTarget cxxtarget;
  108. cxxtarget.SetType( cmTarget::GENERATED_CODE );
  109. cmTargets::value_type cxxpair( cxxname, cxxtarget );
  110. m_Makefile->GetTargets().insert( cxxpair );
  111. }
  112. }
  113. return true;
  114. }
  115. void cmFLTKWrapUICommand::FinalPass()
  116. {
  117. // first we add the rules for all the .fl to .h and .cxx files
  118. int lastHeadersClass = m_GeneratedHeadersClasses.size();
  119. std::string fluid_exe = "${FLTK_FLUID_EXE}";
  120. std::string outputGUIDirectory = m_Makefile->GetCurrentOutputDirectory();
  121. // Generate code for all the .fl files
  122. for(int classNum = 0; classNum < lastHeadersClass; classNum++)
  123. {
  124. // set up .fl to .h and .cxx command
  125. std::string hres = outputGUIDirectory;
  126. hres += "/";
  127. hres += m_GeneratedHeadersClasses[classNum].GetSourceName() + "." +
  128. m_GeneratedHeadersClasses[classNum].GetSourceExtension();
  129. std::string cxxres = outputGUIDirectory;
  130. cxxres += "/";
  131. cxxres += m_GeneratedSourcesClasses[classNum].GetSourceName() + "." +
  132. m_GeneratedSourcesClasses[classNum].GetSourceExtension();
  133. std::vector<std::string> cxxargs;
  134. cxxargs.push_back("-c"); // instructs Fluid to run in command line
  135. cxxargs.push_back("-h"); // optionally rename .h files
  136. cxxargs.push_back(hres);
  137. cxxargs.push_back("-o"); // optionally rename .cxx files
  138. cxxargs.push_back(cxxres);
  139. cxxargs.push_back(m_WrapUserInterface[classNum]);// name of the GUI fluid file
  140. std::vector<std::string> depends;
  141. std::vector<std::string> outputs;
  142. outputs.push_back( cxxres );
  143. outputs.push_back( hres );
  144. // Add command for generating the .h file
  145. m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
  146. fluid_exe.c_str(), cxxargs, depends,
  147. outputs, cxxres.c_str() );
  148. }
  149. }