cmMakefileUtilityTargetGenerator.cxx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "cmGlobalGenerator.h"
  16. #include "cmLocalUnixMakefileGenerator3.h"
  17. #include "cmMakefile.h"
  18. #include "cmSourceFile.h"
  19. #include "cmTarget.h"
  20. //----------------------------------------------------------------------------
  21. void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
  22. {
  23. this->CreateRuleFile();
  24. *this->BuildFileStream
  25. << "# Utility rule file for " << this->Target->GetName() << ".\n\n";
  26. // write the custom commands for this target
  27. this->WriteCustomCommandsForTarget();
  28. // Collect the commands and dependencies.
  29. std::vector<std::string> commands;
  30. std::vector<std::string> depends;
  31. // Utility targets store their rules in pre- and post-build commands.
  32. this->LocalGenerator->AppendCustomDepends
  33. (depends, this->Target->GetPreBuildCommands());
  34. this->LocalGenerator->AppendCustomDepends
  35. (depends, this->Target->GetPostBuildCommands());
  36. this->LocalGenerator->AppendCustomCommands
  37. (commands, this->Target->GetPreBuildCommands());
  38. this->LocalGenerator->AppendCustomCommands
  39. (commands, this->Target->GetPostBuildCommands());
  40. // Add dependencies on targets that must be built first.
  41. this->AppendTargetDepends(depends);
  42. // Add a dependency on the rule file itself.
  43. std::string relPath = this->LocalGenerator->GetHomeRelativeOutputPath();
  44. std::string objTarget = relPath;
  45. objTarget += this->BuildFileName;
  46. this->LocalGenerator->AppendRuleDepend(depends, objTarget.c_str());
  47. // Write the rule.
  48. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
  49. this->Target->GetName(),
  50. depends, commands, true);
  51. // Write convenience targets.
  52. std::string dir = this->Makefile->GetStartOutputDirectory();
  53. dir += "/";
  54. dir += this->LocalGenerator->GetTargetDirectory(*this->Target);
  55. std::string buildTargetRuleName = dir;
  56. buildTargetRuleName += "/build";
  57. buildTargetRuleName =
  58. this->LocalGenerator->Convert(buildTargetRuleName.c_str(),
  59. cmLocalGenerator::HOME_OUTPUT,
  60. cmLocalGenerator::MAKEFILE);
  61. this->LocalGenerator->WriteConvenienceRule(*this->BuildFileStream,
  62. this->Target->GetName(),
  63. buildTargetRuleName.c_str());
  64. // Write clean target
  65. this->WriteTargetCleanRules();
  66. // close the streams
  67. this->CloseFileStreams();
  68. }