cmFLTKWrapUICommand.cxx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. std::vector<std::string> newArgs;
  41. m_Makefile->ExpandSourceListArguments(args,newArgs, 1);
  42. // get the list of GUI files from which .cxx and .h will be generated
  43. std::string outputDirectory = m_Makefile->GetCurrentOutputDirectory();
  44. // Some of the generated files are *.h so the directory "GUI"
  45. // where they are created have to be added to the include path
  46. m_Makefile->AddIncludeDirectory( outputDirectory.c_str() );
  47. for(std::vector<std::string>::iterator i = (newArgs.begin() + 1);
  48. i != newArgs.end(); i++)
  49. {
  50. cmSourceFile *curr = m_Makefile->GetSource(i->c_str());
  51. // if we should use the source GUI
  52. // to generate .cxx and .h files
  53. if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
  54. {
  55. cmSourceFile header_file;
  56. cmSourceFile source_file;
  57. std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*i);
  58. const bool headerFileOnly = true;
  59. header_file.SetName(srcName.c_str(),
  60. outputDirectory.c_str(), "h",headerFileOnly);
  61. source_file.SetName(srcName.c_str(),
  62. outputDirectory.c_str(), "cxx",!headerFileOnly);
  63. std::string origname = cdir + "/" + *i;
  64. std::string hname = header_file.GetFullPath();
  65. m_WrapUserInterface.push_back(origname);
  66. // add starting depends
  67. source_file.GetDepends().push_back(hname);
  68. source_file.GetDepends().push_back(origname);
  69. header_file.GetDepends().push_back(origname);
  70. m_GeneratedHeadersClasses.push_back(header_file);
  71. m_GeneratedSourcesClasses.push_back(source_file);
  72. }
  73. }
  74. return true;
  75. }
  76. void cmFLTKWrapUICommand::FinalPass()
  77. {
  78. // first we add the rules for all the .fl to .h and .cxx files
  79. size_t lastHeadersClass = m_GeneratedHeadersClasses.size();
  80. std::string fluid_exe = "${FLTK_FLUID_EXECUTABLE}";
  81. std::string outputGUIDirectory = m_Makefile->GetCurrentOutputDirectory();
  82. // Generate code for all the .fl files
  83. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  84. {
  85. // set up .fl to .h and .cxx command
  86. std::string hres = outputGUIDirectory;
  87. hres += "/";
  88. hres += m_GeneratedHeadersClasses[classNum].GetSourceName() + "." +
  89. m_GeneratedHeadersClasses[classNum].GetSourceExtension();
  90. std::string cxxres = outputGUIDirectory;
  91. cxxres += "/";
  92. cxxres += m_GeneratedSourcesClasses[classNum].GetSourceName() + "." +
  93. m_GeneratedSourcesClasses[classNum].GetSourceExtension();
  94. std::vector<std::string> cxxargs;
  95. cxxargs.push_back("-c"); // instructs Fluid to run in command line
  96. cxxargs.push_back("-h"); // optionally rename .h files
  97. cxxargs.push_back(hres);
  98. cxxargs.push_back("-o"); // optionally rename .cxx files
  99. cxxargs.push_back(cxxres);
  100. cxxargs.push_back(m_WrapUserInterface[classNum]);// name of the GUI fluid file
  101. std::vector<std::string> depends;
  102. std::vector<std::string> outputs;
  103. outputs.push_back( cxxres );
  104. outputs.push_back( hres );
  105. // Add command for generating the .h and .cxx files
  106. m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
  107. fluid_exe.c_str(), cxxargs, depends,
  108. outputs, m_Target.c_str() );
  109. cmSourceFile* sf = m_Makefile->AddSource(m_GeneratedSourcesClasses[classNum]);
  110. m_Makefile->GetTargets()[m_Target].GetSourceFiles().push_back( sf );
  111. }
  112. }