cmMakefileUtilityTargetGenerator.cxx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "cmMakefileUtilityTargetGenerator.h"
  11. #include "cmGeneratedFileStream.h"
  12. #include "cmGeneratorTarget.h"
  13. #include "cmGlobalUnixMakefileGenerator3.h"
  14. #include "cmLocalUnixMakefileGenerator3.h"
  15. #include "cmMakefile.h"
  16. #include "cmOSXBundleGenerator.h"
  17. #include "cmOutputConverter.h"
  18. #include <ostream>
  19. #include <string>
  20. #include <vector>
  21. cmMakefileUtilityTargetGenerator::cmMakefileUtilityTargetGenerator(
  22. cmGeneratorTarget* target)
  23. : cmMakefileTargetGenerator(target)
  24. {
  25. this->CustomCommandDriver = OnUtility;
  26. this->OSXBundleGenerator =
  27. new cmOSXBundleGenerator(target, this->ConfigName);
  28. this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
  29. }
  30. cmMakefileUtilityTargetGenerator::~cmMakefileUtilityTargetGenerator()
  31. {
  32. delete this->OSXBundleGenerator;
  33. }
  34. void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
  35. {
  36. this->CreateRuleFile();
  37. *this->BuildFileStream << "# Utility rule file for "
  38. << this->GeneratorTarget->GetName() << ".\n\n";
  39. if (!this->NoRuleMessages) {
  40. const char* root = (this->Makefile->IsOn("CMAKE_MAKE_INCLUDE_FROM_ROOT")
  41. ? "$(CMAKE_BINARY_DIR)/"
  42. : "");
  43. // Include the progress variables for the target.
  44. *this->BuildFileStream
  45. << "# Include the progress variables for this target.\n"
  46. << this->GlobalGenerator->IncludeDirective << " " << root
  47. << this->Convert(this->ProgressFileNameFull,
  48. cmOutputConverter::HOME_OUTPUT,
  49. cmOutputConverter::MAKERULE)
  50. << "\n\n";
  51. }
  52. // write the custom commands for this target
  53. this->WriteTargetBuildRules();
  54. // Collect the commands and dependencies.
  55. std::vector<std::string> commands;
  56. std::vector<std::string> depends;
  57. // Utility targets store their rules in pre- and post-build commands.
  58. this->LocalGenerator->AppendCustomDepends(
  59. depends, this->GeneratorTarget->GetPreBuildCommands());
  60. this->LocalGenerator->AppendCustomDepends(
  61. depends, this->GeneratorTarget->GetPostBuildCommands());
  62. this->LocalGenerator->AppendCustomCommands(
  63. commands, this->GeneratorTarget->GetPreBuildCommands(),
  64. this->GeneratorTarget);
  65. // Depend on all custom command outputs for sources
  66. this->DriveCustomCommands(depends);
  67. this->LocalGenerator->AppendCustomCommands(
  68. commands, this->GeneratorTarget->GetPostBuildCommands(),
  69. this->GeneratorTarget);
  70. // Add dependencies on targets that must be built first.
  71. this->AppendTargetDepends(depends);
  72. // Add a dependency on the rule file itself.
  73. this->LocalGenerator->AppendRuleDepend(depends,
  74. this->BuildFileNameFull.c_str());
  75. // If the rule is empty add the special empty rule dependency needed
  76. // by some make tools.
  77. if (depends.empty() && commands.empty()) {
  78. std::string hack = this->GlobalGenerator->GetEmptyRuleHackDepends();
  79. if (!hack.empty()) {
  80. depends.push_back(hack);
  81. }
  82. }
  83. // Write the rule.
  84. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, CM_NULLPTR,
  85. this->GeneratorTarget->GetName(),
  86. depends, commands, true);
  87. // Write the main driver rule to build everything in this target.
  88. this->WriteTargetDriverRule(this->GeneratorTarget->GetName(), false);
  89. // Write clean target
  90. this->WriteTargetCleanRules();
  91. // Write the dependency generation rule. This must be done last so
  92. // that multiple output pair information is available.
  93. this->WriteTargetDependRules();
  94. // close the streams
  95. this->CloseFileStreams();
  96. }