cmFLTKWrapUICommand.cxx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. // 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. std::string fluid_exe = "${FLTK_FLUID_EXECUTABLE}";
  38. // get parameter for the command
  39. m_Target = args[0]; // Target that will use the generated 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. std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*i);
  57. const bool headerFileOnly = true;
  58. header_file.SetName(srcName.c_str(),
  59. outputDirectory.c_str(), "h",headerFileOnly);
  60. std::string origname = cdir + "/" + *i;
  61. std::string hname = header_file.GetFullPath();
  62. // add starting depends
  63. std::vector<std::string> depends;
  64. depends.push_back(origname);
  65. std::string cxxres = outputDirectory.c_str();
  66. cxxres += "/" + srcName;
  67. cxxres += ".cxx";
  68. std::vector<std::string> cxxargs;
  69. cxxargs.push_back("-c"); // instructs Fluid to run in command line
  70. cxxargs.push_back("-h"); // optionally rename .h files
  71. cxxargs.push_back(hname);
  72. cxxargs.push_back("-o"); // optionally rename .cxx files
  73. cxxargs.push_back(cxxres);
  74. cxxargs.push_back(origname);// name of the GUI fluid file
  75. // Add command for generating the .h and .cxx files
  76. m_Makefile->AddCustomCommandToOutput(cxxres.c_str(),
  77. fluid_exe.c_str(),
  78. cxxargs,
  79. 0,
  80. depends);
  81. m_Makefile->AddCustomCommandToOutput(hname.c_str(),
  82. fluid_exe.c_str(),
  83. cxxargs,
  84. 0,
  85. depends);
  86. cmSourceFile *sf = m_Makefile->GetSource(cxxres.c_str());
  87. sf->GetDepends().push_back(hname);
  88. sf->GetDepends().push_back(origname);
  89. m_GeneratedSourcesClasses.push_back(sf);
  90. }
  91. }
  92. return true;
  93. }
  94. void cmFLTKWrapUICommand::FinalPass()
  95. {
  96. // first we add the rules for all the .fl to .h and .cxx files
  97. size_t lastHeadersClass = m_GeneratedSourcesClasses.size();
  98. // Generate code for all the .fl files
  99. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  100. {
  101. m_Makefile->GetTargets()[m_Target].GetSourceFiles().push_back(
  102. m_GeneratedSourcesClasses[classNum]);
  103. }
  104. }