cmFLTKWrapUICommand.cxx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html 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. #include "cmSourceFile.h"
  15. // cmFLTKWrapUICommand
  16. bool cmFLTKWrapUICommand::InitialPass(std::vector<std::string> const& args)
  17. {
  18. if(args.size() < 2 )
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. // Now check and see if the value has been stored in the cache
  24. // already, if so use that value and don't look for the program
  25. const char* FLTK_WRAP_UI_value = m_Makefile->GetDefinition("FLTK_WRAP_UI");
  26. if (FLTK_WRAP_UI_value==0)
  27. {
  28. this->SetError("called with FLTK_WRAP_UI undefined");
  29. return false;
  30. }
  31. if(cmSystemTools::IsOff(FLTK_WRAP_UI_value))
  32. {
  33. this->SetError("called with FLTK_WRAP_UI off : ");
  34. return false;
  35. }
  36. // what is the current source dir
  37. std::string cdir = m_Makefile->GetCurrentDirectory();
  38. std::string fluid_exe = "${FLTK_FLUID_EXECUTABLE}";
  39. // get parameter for the command
  40. m_Target = args[0]; // Target that will use the generated files
  41. std::vector<std::string> newArgs;
  42. m_Makefile->ExpandSourceListArguments(args,newArgs, 1);
  43. // get the list of GUI files from which .cxx and .h will be generated
  44. std::string outputDirectory = m_Makefile->GetCurrentOutputDirectory();
  45. // Some of the generated files are *.h so the directory "GUI"
  46. // where they are created have to be added to the include path
  47. m_Makefile->AddIncludeDirectory( outputDirectory.c_str() );
  48. for(std::vector<std::string>::iterator i = (newArgs.begin() + 1);
  49. i != newArgs.end(); i++)
  50. {
  51. cmSourceFile *curr = m_Makefile->GetSource(i->c_str());
  52. // if we should use the source GUI
  53. // to generate .cxx and .h files
  54. if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
  55. {
  56. cmSourceFile header_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. std::string origname = cdir + "/" + *i;
  62. std::string hname = header_file.GetFullPath();
  63. // add starting depends
  64. std::vector<std::string> depends;
  65. depends.push_back(origname);
  66. std::string cxxres = outputDirectory.c_str();
  67. cxxres += "/" + srcName;
  68. cxxres += ".cxx";
  69. std::vector<std::string> cxxargs;
  70. cxxargs.push_back("-c"); // instructs Fluid to run in command line
  71. cxxargs.push_back("-h"); // optionally rename .h files
  72. cxxargs.push_back(hname);
  73. cxxargs.push_back("-o"); // optionally rename .cxx files
  74. cxxargs.push_back(cxxres);
  75. cxxargs.push_back(origname);// name of the GUI fluid file
  76. // Add command for generating the .h and .cxx files
  77. m_Makefile->AddCustomCommandToOutput(cxxres.c_str(),
  78. fluid_exe.c_str(),
  79. cxxargs,
  80. 0,
  81. depends);
  82. m_Makefile->AddCustomCommandToOutput(hname.c_str(),
  83. fluid_exe.c_str(),
  84. cxxargs,
  85. 0,
  86. depends);
  87. cmSourceFile *sf = m_Makefile->GetSource(cxxres.c_str());
  88. sf->GetDepends().push_back(hname);
  89. sf->GetDepends().push_back(origname);
  90. m_GeneratedSourcesClasses.push_back(sf);
  91. }
  92. }
  93. return true;
  94. }
  95. void cmFLTKWrapUICommand::FinalPass()
  96. {
  97. // first we add the rules for all the .fl to .h and .cxx files
  98. size_t lastHeadersClass = m_GeneratedSourcesClasses.size();
  99. // Generate code for all the .fl files
  100. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  101. {
  102. m_Makefile->GetTargets()[m_Target].GetSourceFiles().push_back(
  103. m_GeneratedSourcesClasses[classNum]);
  104. }
  105. }