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,
29 this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
32 //----------------------------------------------------------------------------
33 cmMakefileUtilityTargetGenerator
34 ::~cmMakefileUtilityTargetGenerator()
36 delete this->OSXBundleGenerator;
39 //----------------------------------------------------------------------------
40 void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
42 this->CreateRuleFile();
44 *this->BuildFileStream
45 << "# Utility rule file for " << this->Target->GetName() << ".\n\n";
47 if(!this->NoRuleMessages)
49 const char* root = (this->Makefile->IsOn("CMAKE_MAKE_INCLUDE_FROM_ROOT")?
50 "$(CMAKE_BINARY_DIR)/" : "");
51 // Include the progress variables for the target.
52 *this->BuildFileStream
53 << "# Include the progress variables for this target.\n"
54 << this->LocalGenerator->IncludeDirective << " " << root
55 << this->Convert(this->ProgressFileNameFull.c_str(),
56 cmLocalGenerator::HOME_OUTPUT,
57 cmLocalGenerator::MAKEFILE)
61 // write the custom commands for this target
62 this->WriteTargetBuildRules();
64 // Collect the commands and dependencies.
65 std::vector<std::string> commands;
66 std::vector<std::string> depends;
68 // Utility targets store their rules in pre- and post-build commands.
69 this->LocalGenerator->AppendCustomDepends
70 (depends, this->Target->GetPreBuildCommands());
72 this->LocalGenerator->AppendCustomDepends
73 (depends, this->Target->GetPostBuildCommands());
75 this->LocalGenerator->AppendCustomCommands
76 (commands, this->Target->GetPreBuildCommands(), this->Target);
78 // Depend on all custom command outputs for sources
79 this->DriveCustomCommands(depends);
81 this->LocalGenerator->AppendCustomCommands
82 (commands, this->Target->GetPostBuildCommands(), this->Target);
84 // Add dependencies on targets that must be built first.
85 this->AppendTargetDepends(depends);
87 // Add a dependency on the rule file itself.
88 this->LocalGenerator->AppendRuleDepend(depends,
89 this->BuildFileNameFull.c_str());
91 // If the rule is empty add the special empty rule dependency needed
92 // by some make tools.
93 if(depends.empty() && commands.empty())
95 std::string hack = this->GlobalGenerator->GetEmptyRuleHackDepends();
98 depends.push_back(hack);
103 this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
104 this->Target->GetName(),
105 depends, commands, true);
107 // Write the main driver rule to build everything in this target.
108 this->WriteTargetDriverRule(this->Target->GetName(), false);
110 // Write clean target
111 this->WriteTargetCleanRules();
113 // Write the dependency generation rule. This must be done last so
114 // that multiple output pair information is available.
115 this->WriteTargetDependRules();
118 this->CloseFileStreams();