cmFLTKWrapUICommand.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. // what is the current source dir
  24. std::string cdir = m_Makefile->GetCurrentDirectory();
  25. std::string fluid_exe = "${FLTK_FLUID_EXECUTABLE}";
  26. // get parameter for the command
  27. m_Target = args[0]; // Target that will use the generated files
  28. std::vector<std::string> newArgs;
  29. m_Makefile->ExpandSourceListArguments(args,newArgs, 1);
  30. // get the list of GUI files from which .cxx and .h will be generated
  31. std::string outputDirectory = m_Makefile->GetCurrentOutputDirectory();
  32. // Some of the generated files are *.h so the directory "GUI"
  33. // where they are created have to be added to the include path
  34. m_Makefile->AddIncludeDirectory( outputDirectory.c_str() );
  35. for(std::vector<std::string>::iterator i = (newArgs.begin() + 1);
  36. i != newArgs.end(); i++)
  37. {
  38. cmSourceFile *curr = m_Makefile->GetSource(i->c_str());
  39. // if we should use the source GUI
  40. // to generate .cxx and .h files
  41. if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
  42. {
  43. cmSourceFile header_file;
  44. std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*i);
  45. const bool headerFileOnly = true;
  46. header_file.SetName(srcName.c_str(),
  47. outputDirectory.c_str(), "h",headerFileOnly);
  48. std::string origname = cdir + "/" + *i;
  49. std::string hname = header_file.GetFullPath();
  50. // add starting depends
  51. std::vector<std::string> depends;
  52. depends.push_back(origname);
  53. std::string cxxres = outputDirectory.c_str();
  54. cxxres += "/" + srcName;
  55. cxxres += ".cxx";
  56. std::vector<std::string> cxxargs;
  57. cxxargs.push_back("-c"); // instructs Fluid to run in command line
  58. cxxargs.push_back("-h"); // optionally rename .h files
  59. cxxargs.push_back(hname);
  60. cxxargs.push_back("-o"); // optionally rename .cxx files
  61. cxxargs.push_back(cxxres);
  62. cxxargs.push_back(origname);// name of the GUI fluid file
  63. // Add command for generating the .h and .cxx files
  64. m_Makefile->AddCustomCommandToOutput(cxxres.c_str(),
  65. fluid_exe.c_str(),
  66. cxxargs,
  67. 0,
  68. depends);
  69. m_Makefile->AddCustomCommandToOutput(hname.c_str(),
  70. fluid_exe.c_str(),
  71. cxxargs,
  72. 0,
  73. depends);
  74. cmSourceFile *sf = m_Makefile->GetSource(cxxres.c_str());
  75. sf->GetDepends().push_back(hname);
  76. sf->GetDepends().push_back(origname);
  77. m_GeneratedSourcesClasses.push_back(sf);
  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. size_t lastHeadersClass = m_GeneratedSourcesClasses.size();
  86. // Generate code for all the .fl files
  87. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  88. {
  89. m_Makefile->GetTargets()[m_Target].GetSourceFiles().push_back(
  90. m_GeneratedSourcesClasses[classNum]);
  91. }
  92. }