1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmMakefileUtilityTargetGenerator.cxx,v $
6 Date: $Date: 2007/12/21 17:22:12 $
7 Version: $Revision: 1.7 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmMakefileUtilityTargetGenerator.h"
19 #include "cmGeneratedFileStream.h"
20 #include "cmGlobalUnixMakefileGenerator3.h"
21 #include "cmLocalUnixMakefileGenerator3.h"
22 #include "cmMakefile.h"
23 #include "cmSourceFile.h"
26 //----------------------------------------------------------------------------
27 cmMakefileUtilityTargetGenerator::cmMakefileUtilityTargetGenerator()
29 this->CustomCommandDriver
= OnUtility
;
32 //----------------------------------------------------------------------------
33 void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
35 this->CreateRuleFile();
37 *this->BuildFileStream
38 << "# Utility rule file for " << this->Target
->GetName() << ".\n\n";
40 // write the custom commands for this target
41 this->WriteTargetBuildRules();
43 // Collect the commands and dependencies.
44 std::vector
<std::string
> commands
;
45 std::vector
<std::string
> depends
;
47 // Utility targets store their rules in pre- and post-build commands.
48 this->LocalGenerator
->AppendCustomDepends
49 (depends
, this->Target
->GetPreBuildCommands());
51 this->LocalGenerator
->AppendCustomDepends
52 (depends
, this->Target
->GetPostBuildCommands());
54 this->LocalGenerator
->AppendCustomCommands
55 (commands
, this->Target
->GetPreBuildCommands());
57 // Depend on all custom command outputs for sources
58 this->DriveCustomCommands(depends
);
60 this->LocalGenerator
->AppendCustomCommands
61 (commands
, this->Target
->GetPostBuildCommands());
63 // Add dependencies on targets that must be built first.
64 this->AppendTargetDepends(depends
);
66 // Add a dependency on the rule file itself.
67 this->LocalGenerator
->AppendRuleDepend(depends
,
68 this->BuildFileNameFull
.c_str());
70 // If the rule is empty add the special empty rule dependency needed
71 // by some make tools.
72 if(depends
.empty() && commands
.empty())
74 std::string hack
= this->GlobalGenerator
->GetEmptyRuleHackDepends();
77 depends
.push_back(hack
);
82 this->LocalGenerator
->WriteMakeRule(*this->BuildFileStream
, 0,
83 this->Target
->GetName(),
84 depends
, commands
, true);
86 // Write the main driver rule to build everything in this target.
87 this->WriteTargetDriverRule(this->Target
->GetName(), false);
90 this->WriteTargetCleanRules();
92 // Write the dependency generation rule. This must be done last so
93 // that multiple output pair information is available.
94 this->WriteTargetDependRules();
97 this->CloseFileStreams();