Introduce "generator expressions" to add_test()
[cmake.git] / Source / cmMakefileTargetGenerator.h
blob93d7ff95d7748b5e1df09880faec87c6c9ce6f4e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmMakefileTargetGenerator.h,v $
5 Language: C++
6 Date: $Date: 2009-07-03 12:41:10 $
7 Version: $Revision: 1.31 $
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;
24 class cmDepends;
25 class cmGeneratedFileStream;
26 class cmGlobalUnixMakefileGenerator3;
27 class cmLocalUnixMakefileGenerator3;
28 class cmMakefile;
29 class cmTarget;
30 class cmSourceFile;
32 /** \class cmMakefileTargetGenerator
33 * \brief Support Routines for writing makefiles
36 class cmMakefileTargetGenerator
38 public:
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
47 with this target */
48 virtual void WriteRuleFiles() = 0;
50 /* return the number of actions that have progress reporting on them */
51 virtual unsigned long GetNumberOfProgressActions() {
52 return this->NumberOfProgressActions;}
53 std::string GetProgressFileNameFull()
54 { return this->ProgressFileNameFull; }
56 cmTarget* GetTarget() { return this->Target;}
57 protected:
59 // create the file and directory etc
60 void CreateRuleFile();
62 // outputs the rules for object files and custom commands used by
63 // this target
64 void WriteTargetBuildRules();
66 // write some common code at the top of build.make
67 void WriteCommonCodeRules();
68 void WriteTargetLanguageFlags();
70 // write the provide require rules for this target
71 void WriteTargetRequiresRules();
73 // write the clean rules for this target
74 void WriteTargetCleanRules();
76 // write the depend rules for this target
77 void WriteTargetDependRules();
79 // write rules for Mac OS X Application Bundle content.
80 void WriteMacOSXContentRules(cmSourceFile& source, const char* pkgloc);
82 // write the rules for an object
83 void WriteObjectRuleFiles(cmSourceFile& source);
85 // write the build rule for an object
86 void WriteObjectBuildFile(std::string &obj,
87 const char *lang,
88 cmSourceFile& source,
89 std::vector<std::string>& depends);
91 // write the depend.make file for an object
92 void WriteObjectDependRules(cmSourceFile& source,
93 std::vector<std::string>& depends);
95 // write the build rule for a custom command
96 void GenerateCustomRuleFile(const cmCustomCommand& cc);
98 // write a rule to drive building of more than one output from
99 // another rule
100 void GenerateExtraOutput(const char* out, const char* in,
101 bool symbolic = false);
103 void AppendProgress(std::vector<std::string>& commands);
105 // write out the variable that lists the objects for this target
106 void WriteObjectsVariable(std::string& variableName,
107 std::string& variableNameExternal);
108 void WriteObjectsString(std::string& buildObjs);
109 void WriteObjectsStrings(std::vector<std::string>& objStrings,
110 std::string::size_type limit = std::string::npos);
112 // write the driver rule to build target outputs
113 void WriteTargetDriverRule(const char* main_output, bool relink);
115 void DriveCustomCommands(std::vector<std::string>& depends);
117 // Return the a string with -F flags on apple
118 std::string GetFrameworkFlags();
120 // append intertarget dependencies
121 void AppendTargetDepends(std::vector<std::string>& depends);
123 /** In order to support parallel builds for custom commands with
124 multiple outputs the outputs are given a serial order, and only
125 the first output actually has the build rule. Other outputs
126 just depend on the first one. The check-build-system step must
127 remove a dependee if the depender is missing to make sure both
128 are regenerated properly. This method is used by the local
129 makefile generators to register such pairs. */
130 void AddMultipleOutputPair(const char* depender, const char* dependee);
132 /** Create a script to hold link rules and a command to invoke the
133 script at build time. */
134 void CreateLinkScript(const char* name,
135 std::vector<std::string> const& link_commands,
136 std::vector<std::string>& makefile_commands,
137 std::vector<std::string>& makefile_depends);
139 /** Create a response file with the given set of options. Returns
140 the relative path from the target build working directory to the
141 response file name. */
142 std::string CreateResponseFile(const char* name,
143 std::string const& options,
144 std::vector<std::string>& makefile_depends);
146 /** Create lists of object files for linking and cleaning. */
147 void CreateObjectLists(bool useLinkScript, bool useArchiveRules,
148 bool useResponseFile, std::string& buildObjs,
149 std::vector<std::string>& makefile_depends);
151 virtual void CloseFileStreams();
152 void RemoveForbiddenFlags(const char* flagVar, const char* linkLang,
153 std::string& linkFlags);
154 cmTarget *Target;
155 cmLocalUnixMakefileGenerator3 *LocalGenerator;
156 cmGlobalUnixMakefileGenerator3 *GlobalGenerator;
157 cmMakefile *Makefile;
158 const char *ConfigName;
160 enum CustomCommandDriveType { OnBuild, OnDepends, OnUtility };
161 CustomCommandDriveType CustomCommandDriver;
163 // the full path to the build file
164 std::string BuildFileName;
165 std::string BuildFileNameFull;
167 // the full path to the progress file
168 std::string ProgressFileNameFull;
169 unsigned long NumberOfProgressActions;
170 bool NoRuleMessages;
172 // the path to the directory the build file is in
173 std::string TargetBuildDirectory;
174 std::string TargetBuildDirectoryFull;
176 // the stream for the build file
177 cmGeneratedFileStream *BuildFileStream;
179 // the stream for the flag file
180 std::string FlagFileNameFull;
181 cmGeneratedFileStream *FlagFileStream;
183 // the stream for the info file
184 std::string InfoFileNameFull;
185 cmGeneratedFileStream *InfoFileStream;
187 // files to clean
188 std::vector<std::string> CleanFiles;
190 // objects used by this target
191 std::vector<std::string> Objects;
192 std::vector<std::string> ExternalObjects;
194 // Set of object file names that will be built in this directory.
195 std::set<cmStdString> ObjectFiles;
197 // Set of extra output files to be driven by the build.
198 std::set<cmStdString> ExtraFiles;
200 typedef std::map<cmStdString, cmStdString> MultipleOutputPairsType;
201 MultipleOutputPairsType MultipleOutputPairs;
203 // Target name info.
204 std::string TargetNameOut;
205 std::string TargetNameSO;
206 std::string TargetNameReal;
207 std::string TargetNameImport;
208 std::string TargetNamePDB;
210 // Mac OS X content info.
211 std::string MacContentDirectory;
212 std::set<cmStdString> MacContentFolders;
214 // Target-wide Fortran module output directory.
215 bool FortranModuleDirectoryComputed;
216 std::string FortranModuleDirectory;
217 const char* GetFortranModuleDirectory();
219 // Compute target-specific Fortran language flags.
220 void AddFortranFlags(std::string& flags);
222 //==================================================================
223 // Convenience routines that do nothing more than forward to
224 // implementaitons
225 std::string Convert(const char* source,
226 cmLocalGenerator::RelativeRoot relative,
227 cmLocalGenerator::OutputFormat output =
228 cmLocalGenerator::UNCHANGED,
229 bool optional = false)
231 return this->LocalGenerator->Convert(source, relative, output, optional);
236 #endif