1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmMakefileTargetGenerator.h,v $
6 Date: $Date: 2008-04-08 04:06:46 $
7 Version: $Revision: 1.25 $
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 #ifndef cmMakefileTargetGenerator_h
18 #define cmMakefileTargetGenerator_h
20 #include "cmLocalUnixMakefileGenerator3.h"
22 class cmCustomCommand
;
23 class cmDependInformation
;
25 class cmGeneratedFileStream
;
26 class cmGlobalUnixMakefileGenerator3
;
27 class cmLocalUnixMakefileGenerator3
;
32 /** \class cmMakefileTargetGenerator
33 * \brief Support Routines for writing makefiles
36 class cmMakefileTargetGenerator
39 // constructor to set the ivars
40 cmMakefileTargetGenerator(cmTarget
* target
);
41 virtual ~cmMakefileTargetGenerator() {};
43 // construct using this factory call
44 static cmMakefileTargetGenerator
*New(cmTarget
*tgt
);
46 /* the main entry point for this class. Writes the Makefiles associated
48 virtual void WriteRuleFiles() = 0;
50 /* the main entry point for this class. Writes the Makefiles associated
52 virtual void WriteProgressVariables(unsigned long total
,
53 unsigned long ¤t
);
55 /* return the number of actions that have progress reporting on them */
56 virtual unsigned long GetNumberOfProgressActions() {
57 return this->NumberOfProgressActions
;}
59 cmTarget
* GetTarget() { return this->Target
;}
62 // create the file and directory etc
63 void CreateRuleFile();
65 // outputs the rules for object files and custom commands used by
67 void WriteTargetBuildRules();
69 // write some common code at the top of build.make
70 void WriteCommonCodeRules();
71 void WriteTargetLanguageFlags();
73 // write the provide require rules for this target
74 void WriteTargetRequiresRules();
76 // write the clean rules for this target
77 void WriteTargetCleanRules();
79 // write the depend rules for this target
80 void WriteTargetDependRules();
82 // write rules for Mac OS X Application Bundle content.
83 void WriteMacOSXContentRules(cmSourceFile
& source
, const char* pkgloc
);
85 // write the rules for an object
86 void WriteObjectRuleFiles(cmSourceFile
& source
);
88 // write the build rule for an object
89 void WriteObjectBuildFile(std::string
&obj
,
92 std::vector
<std::string
>& depends
);
94 // write the depend.make file for an object
95 void WriteObjectDependRules(cmSourceFile
& source
,
96 std::vector
<std::string
>& depends
);
98 // write the build rule for a custom command
99 void GenerateCustomRuleFile(const cmCustomCommand
& cc
);
101 // write a rule to drive building of more than one output from
103 void GenerateExtraOutput(const char* out
, const char* in
,
104 bool symbolic
= false);
106 // write out the variable that lists the objects for this target
107 void WriteObjectsVariable(std::string
& variableName
,
108 std::string
& variableNameExternal
);
109 void WriteObjectsString(std::string
& buildObjs
);
110 void WriteObjectsStrings(std::vector
<std::string
>& objStrings
,
111 std::string::size_type limit
= std::string::npos
);
113 // write the driver rule to build target outputs
114 void WriteTargetDriverRule(const char* main_output
, bool relink
);
116 void DriveCustomCommands(std::vector
<std::string
>& depends
);
118 // Return the a string with -F flags on apple
119 std::string
GetFrameworkFlags();
121 // append intertarget dependencies
122 void AppendTargetDepends(std::vector
<std::string
>& depends
);
124 /** In order to support parallel builds for custom commands with
125 multiple outputs the outputs are given a serial order, and only
126 the first output actually has the build rule. Other outputs
127 just depend on the first one. The check-build-system step must
128 remove a dependee if the depender is missing to make sure both
129 are regenerated properly. This method is used by the local
130 makefile generators to register such pairs. */
131 void AddMultipleOutputPair(const char* depender
, const char* dependee
);
133 /** Create a script to hold link rules and a command to invoke the
134 script at build time. */
135 void CreateLinkScript(const char* name
,
136 std::vector
<std::string
> const& link_commands
,
137 std::vector
<std::string
>& makefile_commands
,
138 std::vector
<std::string
>& makefile_depends
);
140 /** Create a response file with the given set of options. Returns
141 the relative path from the target build working directory to the
142 response file name. */
143 std::string
CreateResponseFile(const char* name
,
144 std::string
const& options
,
145 std::vector
<std::string
>& makefile_depends
);
147 virtual void CloseFileStreams();
148 void RemoveForbiddenFlags(const char* flagVar
, const char* linkLang
,
149 std::string
& linkFlags
);
151 cmLocalUnixMakefileGenerator3
*LocalGenerator
;
152 cmGlobalUnixMakefileGenerator3
*GlobalGenerator
;
153 cmMakefile
*Makefile
;
155 enum CustomCommandDriveType
{ OnBuild
, OnDepends
, OnUtility
};
156 CustomCommandDriveType CustomCommandDriver
;
158 // the full path to the build file
159 std::string BuildFileName
;
160 std::string BuildFileNameFull
;
162 // the full path to the progress file
163 std::string ProgressFileName
;
164 std::string ProgressFileNameFull
;
165 unsigned long NumberOfProgressActions
;
167 // the path to the directory the build file is in
168 std::string TargetBuildDirectory
;
169 std::string TargetBuildDirectoryFull
;
171 // the stream for the build file
172 cmGeneratedFileStream
*BuildFileStream
;
174 // the stream for the flag file
175 std::string FlagFileNameFull
;
176 cmGeneratedFileStream
*FlagFileStream
;
178 // the stream for the info file
179 std::string InfoFileNameFull
;
180 cmGeneratedFileStream
*InfoFileStream
;
183 std::vector
<std::string
> CleanFiles
;
185 // objects used by this target
186 std::vector
<std::string
> Objects
;
187 std::vector
<std::string
> ExternalObjects
;
189 // Set of object file names that will be built in this directory.
190 std::set
<cmStdString
> ObjectFiles
;
192 // Set of extra output files to be driven by the build.
193 std::set
<cmStdString
> ExtraFiles
;
195 typedef std::map
<cmStdString
, cmStdString
> MultipleOutputPairsType
;
196 MultipleOutputPairsType MultipleOutputPairs
;
199 std::string TargetNameOut
;
200 std::string TargetNameSO
;
201 std::string TargetNameReal
;
202 std::string TargetNameImport
;
203 std::string TargetNamePDB
;
205 // Mac OS X content info.
206 std::string MacContentDirectory
;
207 std::set
<cmStdString
> MacContentFolders
;
209 // Target-wide Fortran module output directory.
210 bool FortranModuleDirectoryComputed
;
211 std::string FortranModuleDirectory
;
212 const char* GetFortranModuleDirectory();
214 // Compute target-specific Fortran language flags.
215 void AddFortranFlags(std::string
& flags
);
217 //==================================================================
218 // Convenience routines that do nothing more than forward to
220 std::string
Convert(const char* source
,
221 cmLocalGenerator::RelativeRoot relative
,
222 cmLocalGenerator::OutputFormat output
=
223 cmLocalGenerator::UNCHANGED
,
224 bool optional
= false)
226 return this->LocalGenerator
->Convert(source
, relative
, output
, optional
);