1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmMakefileUtilityTargetGenerator.h"
14 #include "cmGeneratedFileStream.h"
15 #include "cmGlobalUnixMakefileGenerator3.h"
16 #include "cmLocalUnixMakefileGenerator3.h"
17 #include "cmMakefile.h"
18 #include "cmSourceFile.h"
21 //----------------------------------------------------------------------------
22 cmMakefileUtilityTargetGenerator
23 ::cmMakefileUtilityTargetGenerator(cmTarget* target):
24 cmMakefileTargetGenerator(target)
26 this->CustomCommandDriver = OnUtility;
27 this->OSXBundleGenerator = new cmOSXBundleGenerator(this->Target,
30 this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
31 this->MacContentDirectory =
32 this->OSXBundleGenerator->GetMacContentDirectory();
35 //----------------------------------------------------------------------------
36 cmMakefileUtilityTargetGenerator
37 ::~cmMakefileUtilityTargetGenerator()
39 delete this->OSXBundleGenerator;
42 //----------------------------------------------------------------------------
43 void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
45 this->CreateRuleFile();
47 *this->BuildFileStream
48 << "# Utility rule file for " << this->Target->GetName() << ".\n\n";
50 if(!this->NoRuleMessages)
52 const char* root = (this->Makefile->IsOn("CMAKE_MAKE_INCLUDE_FROM_ROOT")?
53 "$(CMAKE_BINARY_DIR)/" : "");
54 // Include the progress variables for the target.
55 *this->BuildFileStream
56 << "# Include the progress variables for this target.\n"
57 << this->LocalGenerator->IncludeDirective << " " << root
58 << this->Convert(this->ProgressFileNameFull.c_str(),
59 cmLocalGenerator::HOME_OUTPUT,
60 cmLocalGenerator::MAKEFILE)
64 // write the custom commands for this target
65 this->WriteTargetBuildRules();
67 // Collect the commands and dependencies.
68 std::vector<std::string> commands;
69 std::vector<std::string> depends;
71 // Utility targets store their rules in pre- and post-build commands.
72 this->LocalGenerator->AppendCustomDepends
73 (depends, this->Target->GetPreBuildCommands());
75 this->LocalGenerator->AppendCustomDepends
76 (depends, this->Target->GetPostBuildCommands());
78 this->LocalGenerator->AppendCustomCommands
79 (commands, this->Target->GetPreBuildCommands(), this->Target);
81 // Depend on all custom command outputs for sources
82 this->DriveCustomCommands(depends);
84 this->LocalGenerator->AppendCustomCommands
85 (commands, this->Target->GetPostBuildCommands(), this->Target);
87 // Add dependencies on targets that must be built first.
88 this->AppendTargetDepends(depends);
90 // Add a dependency on the rule file itself.
91 this->LocalGenerator->AppendRuleDepend(depends,
92 this->BuildFileNameFull.c_str());
94 // If the rule is empty add the special empty rule dependency needed
95 // by some make tools.
96 if(depends.empty() && commands.empty())
98 std::string hack = this->GlobalGenerator->GetEmptyRuleHackDepends();
101 depends.push_back(hack);
106 this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
107 this->Target->GetName(),
108 depends, commands, true);
110 // Write the main driver rule to build everything in this target.
111 this->WriteTargetDriverRule(this->Target->GetName(), false);
113 // Write clean target
114 this->WriteTargetCleanRules();
116 // Write the dependency generation rule. This must be done last so
117 // that multiple output pair information is available.
118 this->WriteTargetDependRules();
121 this->CloseFileStreams();