cmMakefileUtilityTargetGenerator.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. }
  24. //----------------------------------------------------------------------------
  25. void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
  26. {
  27. this->CreateRuleFile();
  28. *this->BuildFileStream
  29. << "# Utility rule file for " << this->Target->GetName() << ".\n\n";
  30. // write the custom commands for this target
  31. this->WriteTargetBuildRules();
  32. // Collect the commands and dependencies.
  33. std::vector<std::string> commands;
  34. std::vector<std::string> depends;
  35. // Utility targets store their rules in pre- and post-build commands.
  36. this->LocalGenerator->AppendCustomDepends
  37. (depends, this->Target->GetPreBuildCommands());
  38. this->LocalGenerator->AppendCustomDepends
  39. (depends, this->Target->GetPostBuildCommands());
  40. this->LocalGenerator->AppendCustomCommands
  41. (commands, this->Target->GetPreBuildCommands(), this->Target);
  42. // Depend on all custom command outputs for sources
  43. this->DriveCustomCommands(depends);
  44. this->LocalGenerator->AppendCustomCommands
  45. (commands, this->Target->GetPostBuildCommands(), this->Target);
  46. // Add dependencies on targets that must be built first.
  47. this->AppendTargetDepends(depends);
  48. // Add a dependency on the rule file itself.
  49. this->LocalGenerator->AppendRuleDepend(depends,
  50. this->BuildFileNameFull.c_str());
  51. // If the rule is empty add the special empty rule dependency needed
  52. // by some make tools.
  53. if(depends.empty() && commands.empty())
  54. {
  55. std::string hack = this->GlobalGenerator->GetEmptyRuleHackDepends();
  56. if(!hack.empty())
  57. {
  58. depends.push_back(hack);
  59. }
  60. }
  61. // Write the rule.
  62. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  63. this->Target->GetName(),
  64. depends, commands, true);
  65. // Write the main driver rule to build everything in this target.
  66. this->WriteTargetDriverRule(this->Target->GetName(), false);
  67. // Write clean target
  68. this->WriteTargetCleanRules();
  69. // Write the dependency generation rule. This must be done last so
  70. // that multiple output pair information is available.
  71. this->WriteTargetDependRules();
  72. // close the streams
  73. this->CloseFileStreams();
  74. }