1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
// This class represents a cmake invocation. It is the top level class when
// running cmake. Most cmake based GUIS should primarily create an instance
// of this class and communicate with it.
//
// The basic process for a GUI is as follows:
//
// 1) Create a cmake instance
// 2) Set the Home & Start directories, generator, and cmake command. this
// can be done using the Set methods or by using SetArgs and passing in
// command line arguments.
// 3) Load the cache by calling LoadCache (duh)
// 4) if you are using command line arguments with -D or -C flags then
// call SetCacheArgs (or if for some other reason you want to modify the
// cache, do it now.
// 5) Finally call Configure
// 6) Let the user change values and go back to step 5
// 7) call Generate
//
// If your GUI allows the user to change the start & home directories then
// you must at a minimum redo steps 2 through 7.
//
#ifndef cmake_h
#define cmake_h
#include "cmSystemTools.h"
class cmGlobalGenerator;
class cmLocalGenerator;
class cmCacheManager;
class cmMakefile;
class cmCommand;
class cmVariableWatch;
class cmFileTimeComparison;
class cmake
{
public:
typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
///! construct an instance of cmake
cmake();
///! destruct an instance of cmake
~cmake();
/**
* Return major and minor version numbers for cmake.
*/
static unsigned int GetMajorVersion();
static unsigned int GetMinorVersion();
static const char *GetReleaseVersion();
//@{
/**
* Set/Get the home directory (or output directory) in the project. The
* home directory is the top directory of the project. It is where
* cmake was run. Remember that CMake processes
* CMakeLists files by recursing up the tree starting at the StartDirectory
* and going up until it reaches the HomeDirectory.
*/
void SetHomeDirectory(const char* dir);
const char* GetHomeDirectory() const
{
return m_cmHomeDirectory.c_str();
}
void SetHomeOutputDirectory(const char* lib);
const char* GetHomeOutputDirectory() const
{
return m_HomeOutputDirectory.c_str();
}
//@}
//@{
/**
* Set/Get the start directory (or output directory). The start directory
* is the directory of the CMakeLists.txt file that started the current
* round of processing. Remember that CMake processes CMakeLists files by
* recursing up the tree starting at the StartDirectory and going up until
* it reaches the HomeDirectory.
*/
void SetStartDirectory(const char* dir)
{
m_cmStartDirectory = dir;
cmSystemTools::ConvertToUnixSlashes(m_cmStartDirectory);
}
const char* GetStartDirectory() const
{
return m_cmStartDirectory.c_str();
}
void SetStartOutputDirectory(const char* lib)
{
m_StartOutputDirectory = lib;
cmSystemTools::ConvertToUnixSlashes(m_StartOutputDirectory);
}
const char* GetStartOutputDirectory() const
{
return m_StartOutputDirectory.c_str();
}
//@}
/**
* Dump documentation to a file. If 0 is returned, the
* operation failed.
*/
int DumpDocumentationToFile(std::ostream&);
/**
* Handle a command line invocation of cmake.
*/
int Run(const std::vector<std::string>&args)
{ return this->Run(args, false); }
int Run(const std::vector<std::string>&args, bool noconfigure);
/**
* Generate the SourceFilesList from the SourceLists. This should only be
* done once to be safe. The argument is a list of command line
* arguments. The first argument should be the name or full path
* to the command line version of cmake. For building a GUI,
* you would pass in the following arguments:
* /path/to/cmake -H/path/to/source -B/path/to/build
* If you only want to parse the CMakeLists.txt files,
* but not actually generate the makefiles, use buildMakefiles = false.
*/
int Generate();
/**
* Configure the cmMakefiles. This routine will create a GlobalGenerator if
* one has not already been set. It will then Call Configure on the
* GlobalGenerator. This in turn will read in an process all the CMakeList
* files for the tree. It will not produce any actual Makefiles, or
* workspaces. Generate does that. */
int Configure();
/**
* Configure the cmMakefiles. This routine will create a GlobalGenerator if
* one has not already been set. It will then Call Configure on the
* GlobalGenerator. This in turn will read in an process all the CMakeList
* files for the tree. It will not produce any actual Makefiles, or
* workspaces. Generate does that. */
int LoadCache();
void PreLoadCMakeFiles();
///! Create a GlobalGenerator
cmGlobalGenerator* CreateGlobalGenerator(const char* name);
///! Return the global generator assigned to this instance of cmake
cmGlobalGenerator* GetGlobalGenerator() { return m_GlobalGenerator; };
///! Return the global generator assigned to this instance of cmake
void SetGlobalGenerator(cmGlobalGenerator *);
///! Get the names of the current registered generators
void GetRegisteredGenerators(std::vector<std::string>& names);
///! get the cmCachemManager used by this invocation of cmake
cmCacheManager *GetCacheManager() { return m_CacheManager; }
///! set the cmake command this instance of cmake should use
void SetCMakeCommand(const char* cmd) { m_CMakeCommand = cmd; }
/**
* Given a variable name, return its value (as a string).
*/
const char* GetCacheDefinition(const char*) const;
///! Add an entry into the cache
void AddCacheEntry(const char* key, const char* value,
const char* helpString,
int type);
/**
* Execute commands during the build process. Supports options such
* as echo, remove file etc.
*/
static int CMakeCommand(std::vector<std::string>&);
/**
* Add a command to this cmake instance
*/
void AddCommand(cmCommand* );
void RenameCommand(const char* oldName, const char* newName);
/**
* Get a command by its name
*/
cmCommand *GetCommand(const char *name);
/** Get list of all commands */
RegisteredCommandsMap* GetCommands() { return &m_Commands; }
/** Check if a command exists. */
bool CommandExists(const char* name) const;
///! Parse command line arguments
void SetArgs(const std::vector<std::string>&);
///! Is this cmake running as a result of a TRY_COMPILE command
bool GetIsInTryCompile() { return m_InTryCompile; }
///! Is this cmake running as a result of a TRY_COMPILE command
void SetIsInTryCompile(bool i) { m_InTryCompile = i; }
///! Parse command line arguments that might set cache values
bool SetCacheArgs(const std::vector<std::string>&);
typedef void (*ProgressCallback)(const char*msg, float progress, void *);
/**
* Set the function used by GUI's to receive progress updates
* Function gets passed: message as a const char*, a progress
* amount ranging from 0 to 1.0 and client data. The progress
* number provided may be negative in cases where a message is
* to be displayed without any progress percentage.
*/
void SetProgressCallback(ProgressCallback f, void* clientData=0);
///! this is called by generators to update the progress
void UpdateProgress(const char *msg, float prog);
///! Get the variable watch object
cmVariableWatch* GetVariableWatch() { return m_VariableWatch; }
void GetCommandDocumentation(std::vector<cmDocumentationEntry>&) const;
void GetGeneratorDocumentation(std::vector<cmDocumentationEntry>&);
///! Do all the checks before running configure
int DoPreConfigureChecks();
/**
* Set and get the script mode option. In script mode there is no generator
* and no cache. Also, language are not enabled, so add_executable and things
* do not do anything.
*/
void SetScriptMode(bool mode) { m_ScriptMode = mode; }
bool GetScriptMode() { return m_ScriptMode; }
///! Debug the try compile stuff by not delelting the files
bool GetDebugTryCompile(){return m_DebugTryCompile;}
void DebugTryCompileOn(){m_DebugTryCompile = true;}
///! Get the list of files written by CMake using FILE(WRITE / WRITE_FILE
void AddWrittenFile(const char* file);
bool HasWrittenFile(const char* file);
void CleanupWrittenFiles();
/**
* Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
*/
int AddCMakePaths(const char *arg0);
/**
* Get the file comparison class
*/
cmFileTimeComparison* GetFileComparison() { return m_FileComparison; }
/**
* Get the path to ctest
*/
const char* GetCTestCommand();
const char* GetCPackCommand();
const char* GetCMakeCommand() { return m_CMakeCommand.c_str(); }
protected:
typedef cmGlobalGenerator* (*CreateGeneratorFunctionType)();
typedef std::map<cmStdString,
CreateGeneratorFunctionType> RegisteredGeneratorsMap;
RegisteredCommandsMap m_Commands;
RegisteredGeneratorsMap m_Generators;
void AddDefaultCommands();
void AddDefaultGenerators();
cmGlobalGenerator *m_GlobalGenerator;
cmCacheManager *m_CacheManager;
std::string m_cmHomeDirectory;
std::string m_HomeOutputDirectory;
std::string m_cmStartDirectory;
std::string m_StartOutputDirectory;
std::set<cmStdString> m_WrittenFiles;
///! return true if the same cmake was used to make the cache.
bool CacheVersionMatches();
///! read in a cmake list file to initialize the cache
void ReadListFile(const char *path);
///! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file.
/// If it is set, truncate it to 50kb
void TruncateOutputLog(const char* fname);
/**
* Method called to check build system integrity at build time.
* Returns 1 if CMake should rerun and 0 otherwise.
*/
int CheckBuildSystem();
void SetDirectoriesFromFile(const char* arg);
//! Make sure all commands are what they say they are and there is no macros.
void CleanupCommandsAndMacros();
void GenerateGraphViz(const char* fileName);
cmVariableWatch* m_VariableWatch;
private:
ProgressCallback m_ProgressCallback;
void* m_ProgressCallbackClientData;
bool m_Verbose;
bool m_InTryCompile;
bool m_ScriptMode;
std::string m_CMakeCommand;
std::string m_CXXEnvironment;
std::string m_CCEnvironment;
std::string m_CheckBuildSystem;
std::string m_CTestCommand;
std::string m_CPackCommand;
bool m_ClearBuildSystem;
bool m_DebugTryCompile;
cmFileTimeComparison* m_FileComparison;
std::string m_GraphVizFile;
void UpdateConversionPathTable();
};
#define CMAKE_STANDARD_OPTIONS_TABLE \
{"-C <initial-cache>", "Pre-load a script to populate the cache.", \
"When cmake is first run in an empty build tree, it creates a " \
"CMakeCache.txt file and populates it with customizable settings " \
"for the project. This option may be used to specify a file from " \
"which to load cache entries before the first pass through " \
"the project's cmake listfiles. The loaded entries take priority " \
"over the project's default values. The given file should be a CMake " \
"script containing SET commands that use the CACHE option, " \
"not a cache-format file."}, \
{"-D <var>:<type>=<value>", "Create a cmake cache entry.", \
"When cmake is first run in an empty build tree, it creates a " \
"CMakeCache.txt file and populates it with customizable settings " \
"for the project. This option may be used to specify a setting " \
"that takes priority over the project's default value. The option " \
"may be repeated for as many cache entries as desired."}, \
{"-G <generator-name>", "Specify a makefile generator.", \
"CMake may support multiple native build systems on certain platforms. " \
"A makefile generator is responsible for generating a particular build " \
"system. Possible generator names are specified in the Generators " \
"section."}
#define CMAKE_STANDARD_INTRODUCTION \
{0, \
"CMake is a cross-platform build system generator. Projects " \
"specify their build process with platform-independent CMake listfiles " \
"included in each directory of a source tree with the name CMakeLists.txt. "\
"Users build a project by using CMake to generate a build system " \
"for a native tool on their platform.", 0}
#endif
|