cmMakefileUtilityTargetGenerator.cxx 3.3 KB

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