1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmMakefileTargetGenerator.h,v $
6 Date: $Date: 2009-03-16 20:55:58 $
7 Version: $Revision: 1.29 $
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 void AppendProgress(std::vector
<std::string
>& commands
);
108 // write out the variable that lists the objects for this target
109 void WriteObjectsVariable(std::string
& variableName
,
110 std::string
& variableNameExternal
);
111 void WriteObjectsString(std::string
& buildObjs
);
112 void WriteObjectsStrings(std::vector
<std::string
>& objStrings
,
113 std::string::size_type limit
= std::string::npos
);
115 // write the driver rule to build target outputs
116 void WriteTargetDriverRule(const char* main_output
, bool relink
);
118 void DriveCustomCommands(std::vector
<std::string
>& depends
);
120 // Return the a string with -F flags on apple
121 std::string
GetFrameworkFlags();
123 // append intertarget dependencies
124 void AppendTargetDepends(std::vector
<std::string
>& depends
);
126 /** In order to support parallel builds for custom commands with
127 multiple outputs the outputs are given a serial order, and only
128 the first output actually has the build rule. Other outputs
129 just depend on the first one. The check-build-system step must
130 remove a dependee if the depender is missing to make sure both
131 are regenerated properly. This method is used by the local
132 makefile generators to register such pairs. */
133 void AddMultipleOutputPair(const char* depender
, const char* dependee
);
135 /** Create a script to hold link rules and a command to invoke the
136 script at build time. */
137 void CreateLinkScript(const char* name
,
138 std::vector
<std::string
> const& link_commands
,
139 std::vector
<std::string
>& makefile_commands
,
140 std::vector
<std::string
>& makefile_depends
);
142 /** Create a response file with the given set of options. Returns
143 the relative path from the target build working directory to the
144 response file name. */
145 std::string
CreateResponseFile(const char* name
,
146 std::string
const& options
,
147 std::vector
<std::string
>& makefile_depends
);
149 /** Create lists of object files for linking and cleaning. */
150 void CreateObjectLists(bool useLinkScript
, bool useArchiveRules
,
151 bool useResponseFile
, std::string
& buildObjs
,
152 std::vector
<std::string
>& makefile_depends
);
154 virtual void CloseFileStreams();
155 void RemoveForbiddenFlags(const char* flagVar
, const char* linkLang
,
156 std::string
& linkFlags
);
158 cmLocalUnixMakefileGenerator3
*LocalGenerator
;
159 cmGlobalUnixMakefileGenerator3
*GlobalGenerator
;
160 cmMakefile
*Makefile
;
162 enum CustomCommandDriveType
{ OnBuild
, OnDepends
, OnUtility
};
163 CustomCommandDriveType CustomCommandDriver
;
165 // the full path to the build file
166 std::string BuildFileName
;
167 std::string BuildFileNameFull
;
169 // the full path to the progress file
170 std::string ProgressFileName
;
171 std::string ProgressFileNameFull
;
172 unsigned long NumberOfProgressActions
;
175 // the path to the directory the build file is in
176 std::string TargetBuildDirectory
;
177 std::string TargetBuildDirectoryFull
;
179 // the stream for the build file
180 cmGeneratedFileStream
*BuildFileStream
;
182 // the stream for the flag file
183 std::string FlagFileNameFull
;
184 cmGeneratedFileStream
*FlagFileStream
;
186 // the stream for the info file
187 std::string InfoFileNameFull
;
188 cmGeneratedFileStream
*InfoFileStream
;
191 std::vector
<std::string
> CleanFiles
;
193 // objects used by this target
194 std::vector
<std::string
> Objects
;
195 std::vector
<std::string
> ExternalObjects
;
197 // Set of object file names that will be built in this directory.
198 std::set
<cmStdString
> ObjectFiles
;
200 // Set of extra output files to be driven by the build.
201 std::set
<cmStdString
> ExtraFiles
;
203 typedef std::map
<cmStdString
, cmStdString
> MultipleOutputPairsType
;
204 MultipleOutputPairsType MultipleOutputPairs
;
207 std::string TargetNameOut
;
208 std::string TargetNameSO
;
209 std::string TargetNameReal
;
210 std::string TargetNameImport
;
211 std::string TargetNamePDB
;
213 // Mac OS X content info.
214 std::string MacContentDirectory
;
215 std::set
<cmStdString
> MacContentFolders
;
217 // Target-wide Fortran module output directory.
218 bool FortranModuleDirectoryComputed
;
219 std::string FortranModuleDirectory
;
220 const char* GetFortranModuleDirectory();
222 // Compute target-specific Fortran language flags.
223 void AddFortranFlags(std::string
& flags
);
225 //==================================================================
226 // Convenience routines that do nothing more than forward to
228 std::string
Convert(const char* source
,
229 cmLocalGenerator::RelativeRoot relative
,
230 cmLocalGenerator::OutputFormat output
=
231 cmLocalGenerator::UNCHANGED
,
232 bool optional
= false)
234 return this->LocalGenerator
->Convert(source
, relative
, output
, optional
);