cmMakefileUtilityTargetGenerator.cxx 4.3 KB

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