cmFLTKWrapUICommand.cxx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmFLTKWrapUICommand.h"
  11. #include "cmSourceFile.h"
  12. // cmFLTKWrapUICommand
  13. bool cmFLTKWrapUICommand
  14. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  15. {
  16. if(args.size() < 2 )
  17. {
  18. this->SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. // what is the current source dir
  22. std::string cdir = this->Makefile->GetCurrentSourceDirectory();
  23. const char* fluid_exe =
  24. this->Makefile->GetRequiredDefinition("FLTK_FLUID_EXECUTABLE");
  25. // get parameter for the command
  26. this->Target = args[0]; // Target that will use the generated files
  27. // get the list of GUI files from which .cxx and .h will be generated
  28. std::string outputDirectory = this->Makefile->GetCurrentBinaryDirectory();
  29. {
  30. // Some of the generated files are *.h so the directory "GUI"
  31. // where they are created have to be added to the include path
  32. std::vector<std::string> outputDirectories;
  33. outputDirectories.push_back(outputDirectory);
  34. this->Makefile->AddIncludeDirectories( outputDirectories );
  35. }
  36. for(std::vector<std::string>::const_iterator i = (args.begin() + 1);
  37. i != args.end(); i++)
  38. {
  39. cmSourceFile *curr = this->Makefile->GetSource(*i);
  40. // if we should use the source GUI
  41. // to generate .cxx and .h files
  42. if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
  43. {
  44. std::string outName = outputDirectory;
  45. outName += "/";
  46. outName += cmSystemTools::GetFilenameWithoutExtension(*i);
  47. std::string hname = outName;
  48. hname += ".h";
  49. std::string origname = cdir + "/" + *i;
  50. // add starting depends
  51. std::vector<std::string> depends;
  52. depends.push_back(origname);
  53. depends.push_back(fluid_exe);
  54. std::string cxxres = outName;
  55. cxxres += ".cxx";
  56. cmCustomCommandLine commandLine;
  57. commandLine.push_back(fluid_exe);
  58. commandLine.push_back("-c"); // instructs Fluid to run in command line
  59. commandLine.push_back("-h"); // optionally rename .h files
  60. commandLine.push_back(hname);
  61. commandLine.push_back("-o"); // optionally rename .cxx files
  62. commandLine.push_back(cxxres);
  63. commandLine.push_back(origname);// name of the GUI fluid file
  64. cmCustomCommandLines commandLines;
  65. commandLines.push_back(commandLine);
  66. // Add command for generating the .h and .cxx files
  67. std::string no_main_dependency = "";
  68. const char* no_comment = 0;
  69. const char* no_working_dir = 0;
  70. this->Makefile->AddCustomCommandToOutput(cxxres,
  71. depends, no_main_dependency,
  72. commandLines, no_comment,
  73. no_working_dir);
  74. this->Makefile->AddCustomCommandToOutput(hname,
  75. depends, no_main_dependency,
  76. commandLines, no_comment,
  77. no_working_dir);
  78. cmSourceFile *sf = this->Makefile->GetSource(cxxres);
  79. sf->AddDepend(hname.c_str());
  80. sf->AddDepend(origname.c_str());
  81. this->GeneratedSourcesClasses.push_back(sf);
  82. }
  83. }
  84. // create the variable with the list of sources in it
  85. size_t lastHeadersClass = this->GeneratedSourcesClasses.size();
  86. std::string sourceListValue;
  87. for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
  88. {
  89. if (classNum)
  90. {
  91. sourceListValue += ";";
  92. }
  93. sourceListValue += this->GeneratedSourcesClasses[classNum]->GetFullPath();
  94. }
  95. std::string varName = this->Target;
  96. varName += "_FLTK_UI_SRCS";
  97. this->Makefile->AddDefinition(varName, sourceListValue.c_str());
  98. return true;
  99. }
  100. void cmFLTKWrapUICommand::FinalPass()
  101. {
  102. // people should add the srcs to the target themselves, but the old command
  103. // didn't support that, so check and see if they added the files in and if
  104. // they didn;t then print a warning and add then anyhow
  105. cmTarget* target = this->Makefile->FindLocalNonAliasTarget(this->Target);
  106. if(!target)
  107. {
  108. std::string msg =
  109. "FLTK_WRAP_UI was called with a target that was never created: ";
  110. msg += this->Target;
  111. msg +=". The problem was found while processing the source directory: ";
  112. msg += this->Makefile->GetCurrentSourceDirectory();
  113. msg += ". This FLTK_WRAP_UI call will be ignored.";
  114. cmSystemTools::Message(msg.c_str(),"Warning");
  115. return;
  116. }
  117. }