Imported Upstream version 2.8.9
[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->TargetNameOut,
29                                                       this->ConfigName);
30   this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
31   this->MacContentDirectory =
32     this->OSXBundleGenerator->GetMacContentDirectory();
33 }
34
35 //----------------------------------------------------------------------------
36 cmMakefileUtilityTargetGenerator
37 ::~cmMakefileUtilityTargetGenerator()
38 {
39   delete this->OSXBundleGenerator;
40 }
41
42 //----------------------------------------------------------------------------
43 void cmMakefileUtilityTargetGenerator::WriteRuleFiles()
44 {
45   this->CreateRuleFile();
46
47   *this->BuildFileStream
48     << "# Utility rule file for " << this->Target->GetName() << ".\n\n";
49
50   if(!this->NoRuleMessages)
51     {
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)
61       << "\n\n";
62     }
63
64   // write the custom commands for this target
65   this->WriteTargetBuildRules();
66
67   // Collect the commands and dependencies.
68   std::vector<std::string> commands;
69   std::vector<std::string> depends;
70
71   // Utility targets store their rules in pre- and post-build commands.
72   this->LocalGenerator->AppendCustomDepends
73     (depends, this->Target->GetPreBuildCommands());
74
75   this->LocalGenerator->AppendCustomDepends
76     (depends, this->Target->GetPostBuildCommands());
77
78   this->LocalGenerator->AppendCustomCommands
79     (commands, this->Target->GetPreBuildCommands(), this->Target);
80
81   // Depend on all custom command outputs for sources
82   this->DriveCustomCommands(depends);
83
84   this->LocalGenerator->AppendCustomCommands
85     (commands, this->Target->GetPostBuildCommands(), this->Target);
86
87   // Add dependencies on targets that must be built first.
88   this->AppendTargetDepends(depends);
89
90   // Add a dependency on the rule file itself.
91   this->LocalGenerator->AppendRuleDepend(depends,
92                                          this->BuildFileNameFull.c_str());
93
94   // If the rule is empty add the special empty rule dependency needed
95   // by some make tools.
96   if(depends.empty() && commands.empty())
97     {
98     std::string hack = this->GlobalGenerator->GetEmptyRuleHackDepends();
99     if(!hack.empty())
100       {
101       depends.push_back(hack);
102       }
103     }
104
105   // Write the rule.
106   this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, 0,
107                                       this->Target->GetName(),
108                                       depends, commands, true);
109
110   // Write the main driver rule to build everything in this target.
111   this->WriteTargetDriverRule(this->Target->GetName(), false);
112
113   // Write clean target
114   this->WriteTargetCleanRules();
115
116   // Write the dependency generation rule.  This must be done last so
117   // that multiple output pair information is available.
118   this->WriteTargetDependRules();
119
120   // close the streams
121   this->CloseFileStreams();
122 }
123