Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmMakefileUtilityTargetGenerator.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
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"
13
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 //----------------------------------------------------------------------------
22 cmMakefileUtilityTargetGenerator
23 ::cmMakefileUtilityTargetGenerator(cmTarget* target):
24   cmMakefileTargetGenerator(target)
25 {
26   this->CustomCommandDriver = OnUtility;
27   this->OSXBundleGenerator = new cmOSXBundleGenerator(this->Target,
28                                                       this->ConfigName);
29   this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
30 }
31
32 //----------------------------------------------------------------------------
33 cmMakefileUtilityTargetGenerator
34 ::~cmMakefileUtilityTargetGenerator()
35 {
36   delete this->OSXBundleGenerator;
37 }
38
39 //----------------------------------------------------------------------------
40 void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
41 {
42   this->CreateRuleFile();
43
44   *this->BuildFileStream
45     << "# Utility rule file for " << this->Target->GetName() << ".\n\n";
46
47   if(!this->NoRuleMessages)
48     {
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)
58       << "\n\n";
59     }
60
61   // write the custom commands for this target
62   this->WriteTargetBuildRules();
63
64   // Collect the commands and dependencies.
65   std::vector<std::string> commands;
66   std::vector<std::string> depends;
67
68   // Utility targets store their rules in pre- and post-build commands.
69   this->LocalGenerator->AppendCustomDepends
70     (depends, this->Target->GetPreBuildCommands());
71
72   this->LocalGenerator->AppendCustomDepends
73     (depends, this->Target->GetPostBuildCommands());
74
75   this->LocalGenerator->AppendCustomCommands
76     (commands, this->Target->GetPreBuildCommands(), this->Target);
77
78   // Depend on all custom command outputs for sources
79   this->DriveCustomCommands(depends);
80
81   this->LocalGenerator->AppendCustomCommands
82     (commands, this->Target->GetPostBuildCommands(), this->Target);
83
84   // Add dependencies on targets that must be built first.
85   this->AppendTargetDepends(depends);
86
87   // Add a dependency on the rule file itself.
88   this->LocalGenerator->AppendRuleDepend(depends,
89                                          this->BuildFileNameFull.c_str());
90
91   // If the rule is empty add the special empty rule dependency needed
92   // by some make tools.
93   if(depends.empty() && commands.empty())
94     {
95     std::string hack = this->GlobalGenerator->GetEmptyRuleHackDepends();
96     if(!hack.empty())
97       {
98       depends.push_back(hack);
99       }
100     }
101
102   // Write the rule.
103   this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
104                                       this->Target->GetName(),
105                                       depends, commands, true);
106
107   // Write the main driver rule to build everything in this target.
108   this->WriteTargetDriverRule(this->Target->GetName(), false);
109
110   // Write clean target
111   this->WriteTargetCleanRules();
112
113   // Write the dependency generation rule.  This must be done last so
114   // that multiple output pair information is available.
115   this->WriteTargetDependRules();
116
117   // close the streams
118   this->CloseFileStreams();
119 }
120