cmFLTKWrapUICommand.cxx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 "cmFLTKWrapUICommand.h"
  14. // cmFLTKWrapUICommand
  15. bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. if(args.size() < 2 )
  18. {
  19. this->SetError("called with incorrect number of arguments");
  20. return false;
  21. }
  22. // Now check and see if the value has been stored in the cache
  23. // already, if so use that value and don't look for the program
  24. const char* FLTK_WRAP_UI_value = m_Makefile->GetDefinition("FLTK_WRAP_UI");
  25. if (FLTK_WRAP_UI_value==0)
  26. {
  27. this->SetError("called with FLTK_WRAP_UI undefined");
  28. return false;
  29. }
  30. if(cmSystemTools::IsOff(FLTK_WRAP_UI_value))
  31. {
  32. this->SetError("called with FLTK_WRAP_UI off : ");
  33. return false;
  34. }
  35. // what is the current source dir
  36. std::string cdir = m_Makefile->GetCurrentDirectory();
  37. // get parameter for the command
  38. m_Target = args[0]; // Target that will use the generated files
  39. m_GUISourceList = args[1]; // Source List of the GUI source files
  40. cmMakefile::SourceMap &GUISources = m_Makefile->GetSources();
  41. // get the list of GUI files from which .cxx and .h will be generated
  42. cmMakefile::SourceMap::iterator l = GUISources.find( m_GUISourceList );
  43. if (l == GUISources.end())
  44. {
  45. this->SetError("bad source list passed to FLTKWrapUICommand");
  46. return false;
  47. }
  48. std::string outputDirectory = m_Makefile->GetCurrentOutputDirectory();
  49. // Some of the generated files are *.h so the directory "GUI"
  50. // where they are created have to be added to the include path
  51. m_Makefile->AddIncludeDirectory( outputDirectory.c_str() );
  52. for(std::vector<cmSourceFile>::iterator i = l->second.begin();
  53. i != l->second.end(); i++)
  54. {
  55. cmSourceFile &curr = *i;
  56. // if we should use the source GUI
  57. // to generate .cxx and .h files
  58. if (!curr.GetWrapExclude())
  59. {
  60. cmSourceFile header_file;
  61. cmSourceFile source_file;
  62. const bool headerFileOnly = true;
  63. header_file.SetName(curr.GetSourceName().c_str(),
  64. outputDirectory.c_str(), "h",headerFileOnly);
  65. source_file.SetName(curr.GetSourceName().c_str(),
  66. outputDirectory.c_str(), "cxx",!headerFileOnly);
  67. std::string origname = cdir + "/" + curr.GetSourceName() + "." +
  68. curr.GetSourceExtension();
  69. std::string hname = header_file.GetFullPath();
  70. std::string cxxname = source_file.GetFullPath();
  71. m_WrapUserInterface.push_back(origname);
  72. // add starting depends
  73. source_file.GetDepends().push_back(hname);
  74. source_file.GetDepends().push_back(origname);
  75. header_file.GetDepends().push_back(origname);
  76. m_GeneratedHeadersClasses.push_back(header_file);
  77. m_GeneratedSourcesClasses.push_back(source_file);
  78. }
  79. }
  80. return true;
  81. }
  82. void cmFLTKWrapUICommand::FinalPass()
  83. {
  84. // first we add the rules for all the .fl to .h and .cxx files
  85. int lastHeadersClass = m_GeneratedHeadersClasses.size();
  86. std::string fluid_exe = "${FLTK_FLUID_EXE}";
  87. std::string outputGUIDirectory = m_Makefile->GetCurrentOutputDirectory();
  88. // Generate code for all the .fl files
  89. for(int classNum = 0; classNum < lastHeadersClass; classNum++)
  90. {
  91. // set up .fl to .h and .cxx command
  92. std::string hres = outputGUIDirectory;
  93. hres += "/";
  94. hres += m_GeneratedHeadersClasses[classNum].GetSourceName() + "." +
  95. m_GeneratedHeadersClasses[classNum].GetSourceExtension();
  96. std::string cxxres = outputGUIDirectory;
  97. cxxres += "/";
  98. cxxres += m_GeneratedSourcesClasses[classNum].GetSourceName() + "." +
  99. m_GeneratedSourcesClasses[classNum].GetSourceExtension();
  100. std::vector<std::string> cxxargs;
  101. cxxargs.push_back("-c"); // instructs Fluid to run in command line
  102. cxxargs.push_back("-h"); // optionally rename .h files
  103. cxxargs.push_back(hres);
  104. cxxargs.push_back("-o"); // optionally rename .cxx files
  105. cxxargs.push_back(cxxres);
  106. cxxargs.push_back(m_WrapUserInterface[classNum]);// name of the GUI fluid file
  107. std::vector<std::string> depends;
  108. std::vector<std::string> outputs;
  109. outputs.push_back( cxxres );
  110. outputs.push_back( hres );
  111. // Add command for generating the .h and .cxx files
  112. m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
  113. fluid_exe.c_str(), cxxargs, depends,
  114. outputs, m_Target.c_str() );
  115. m_Makefile->GetTargets()[m_Target].GetSourceFiles().push_back( m_GeneratedSourcesClasses[classNum] );
  116. }
  117. }