1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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 #ifndef cmGlobalUnixMakefileGenerator3_h
13 #define cmGlobalUnixMakefileGenerator3_h
15 #include "cmGlobalGenerator.h"
17 class cmGeneratedFileStream;
18 class cmMakefileTargetGenerator;
19 class cmLocalUnixMakefileGenerator3;
21 /** \class cmGlobalUnixMakefileGenerator3
22 * \brief Write a Unix makefiles.
24 * cmGlobalUnixMakefileGenerator3 manages UNIX build process for a tree
27 The basic approach of this generator is to produce Makefiles that will all
28 be run with the current working directory set to the Home Output
29 directory. The one exception to this is the subdirectory Makefiles which are
30 created as a convenience and just cd up to the Home Output directory and
31 invoke the main Makefiles.
33 The make process starts with Makefile. Makefile should only contain the
34 targets the user is likely to invoke directly from a make command line. No
35 internal targets should be in this file. Makefile2 contains the internal
36 targets that are required to make the process work.
38 Makefile2 in turn will recursively make targets in the correct order. Each
39 target has its own directory \<target\>.dir and its own makefile build.make in
40 that directory. Also in that directory is a couple makefiles per source file
41 used by the target. Typically these are named source.obj.build.make and
42 source.obj.build.depend.make. The source.obj.build.make contains the rules
43 for building, cleaning, and computing dependencies for the given source
44 file. The build.depend.make contains additional dependencies that were
45 computed during dependency scanning. An additional file called
46 source.obj.depend is used as a marker to indicate when dependencies must be
49 Rules for custom commands follow the same model as rules for source files.
53 class cmGlobalUnixMakefileGenerator3 : public cmGlobalGenerator
56 cmGlobalUnixMakefileGenerator3();
57 static cmGlobalGenerator* New() {
58 return new cmGlobalUnixMakefileGenerator3; }
60 ///! Get the name for the generator.
61 virtual const char* GetName() const {
62 return cmGlobalUnixMakefileGenerator3::GetActualName();}
63 static const char* GetActualName() {return "Unix Makefiles";}
65 /** Get the documentation entry for this generator. */
66 virtual void GetDocumentation(cmDocumentationEntry& entry) const;
68 ///! Create a local generator appropriate to this Global Generator3
69 virtual cmLocalGenerator *CreateLocalGenerator();
72 * Try to determine system infomation such as shared library
73 * extension, pthreads, byte order etc.
75 virtual void EnableLanguage(std::vector<std::string>const& languages,
76 cmMakefile *, bool optional);
79 * Generate the all required files for building this project/tree. This
80 * basically creates a series of LocalGenerators for each directory and
81 * requests that they Generate.
83 virtual void Generate();
86 void WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream,
87 std::vector<cmLocalGenerator *> &);
89 // write out the help rule listing the valid targets
90 void WriteHelpRule(std::ostream& ruleFileStream,
91 cmLocalUnixMakefileGenerator3 *);
93 // write the top level target rules
94 void WriteConvenienceRules(std::ostream& ruleFileStream,
95 std::set<cmStdString> &emitted);
97 /** Get the command to use for a target that has no rule. This is
98 used for multiple output dependencies and for cmake_force. */
99 std::string GetEmptyRuleHackCommand() { return this->EmptyRuleHackCommand; }
101 /** Get the fake dependency to use when a rule has no real commands
103 std::string GetEmptyRuleHackDepends() { return this->EmptyRuleHackDepends; }
105 // change the build command for speed
106 virtual std::string GenerateBuildCommand
107 (const char* makeProgram,
108 const char *projectName, const char* additionalOptions,
109 const char *targetName,
110 const char* config, bool ignoreErrors, bool fast);
112 /** Record per-target progress information. */
113 void RecordTargetProgress(cmMakefileTargetGenerator* tg);
115 void AddCXXCompileCommand(const std::string &sourceFile,
116 const std::string &workingDirectory,
117 const std::string &compileCommand);
120 void WriteMainMakefile2();
121 void WriteMainCMakefile();
123 void WriteConvenienceRules2(std::ostream& ruleFileStream,
124 cmLocalUnixMakefileGenerator3*);
126 void WriteDirectoryRule2(std::ostream& ruleFileStream,
127 cmLocalUnixMakefileGenerator3* lg,
128 const char* pass, bool check_all,
130 void WriteDirectoryRules2(std::ostream& ruleFileStream,
131 cmLocalUnixMakefileGenerator3* lg);
133 void AppendGlobalTargetDepends(std::vector<std::string>& depends,
136 // does this generator need a requires step for any of its targets
137 bool NeedRequiresStep(cmTarget const&);
139 // Target name hooks for superclass.
140 const char* GetAllTargetName() const { return "all"; }
141 const char* GetInstallTargetName() const { return "install"; }
142 const char* GetInstallLocalTargetName() const { return "install/local"; }
143 const char* GetInstallStripTargetName() const { return "install/strip"; }
144 const char* GetPreinstallTargetName() const { return "preinstall"; }
145 const char* GetTestTargetName() const { return "test"; }
146 const char* GetPackageTargetName() const { return "package"; }
147 const char* GetPackageSourceTargetName() const { return "package_source"; }
148 const char* GetEditCacheTargetName() const { return "edit_cache"; }
149 const char* GetRebuildCacheTargetName() const { return "rebuild_cache"; }
150 const char* GetCleanTargetName() const { return "clean"; }
152 virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; }
154 // Some make programs (Borland) do not keep a rule if there are no
155 // dependencies or commands. This is a problem for creating rules
156 // that might not do anything but might have other dependencies
157 // added later. If non-empty this variable holds a fake dependency
158 // that can be added.
159 std::string EmptyRuleHackDepends;
161 // Some make programs (Watcom) do not like rules with no commands.
162 // If non-empty this variable holds a bogus command that may be put
163 // in the rule to satisfy the make program.
164 std::string EmptyRuleHackCommand;
166 // Store per-target progress counters.
167 struct TargetProgress
169 TargetProgress(): NumberOfActions(0) {}
170 unsigned long NumberOfActions;
171 std::string VariableFile;
172 std::vector<unsigned long> Marks;
173 void WriteProgressVariables(unsigned long total, unsigned long& current);
175 struct ProgressMapCompare { bool operator()(cmTarget*,cmTarget*) const; };
176 typedef std::map<cmTarget*, TargetProgress,
177 ProgressMapCompare> ProgressMapType;
178 ProgressMapType ProgressMap;
180 size_t CountProgressMarksInTarget(cmTarget* target,
181 std::set<cmTarget*>& emitted);
182 size_t CountProgressMarksInAll(cmLocalUnixMakefileGenerator3* lg);
184 cmGeneratedFileStream *CommandDatabase;
186 virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const;