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
370
371
372
373
374
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2000 National Library of Medicine
All rights reserved.
See COPYRIGHT.txt for copyright details.
=========================================================================*/
#ifndef cmMakefile_h
#define cmMakefile_h
#include "cmStandardIncludes.h"
#include "cmClassFile.h"
#include "cmSystemTools.h"
class cmCommand;
class cmMakefileGenerator;
/** \class cmMakefile
* \brief Process the input CMakeLists.txt file.
*
* Process and store into memory the input CMakeLists.txt file.
* Each CMakeLists.txt file is parsed and the commands found there
* are added into the build process.
*/
class cmMakefile
{
public:
/**
* Construct an empty makefile.
*/
cmMakefile();
/**
* Destructor.
*/
~cmMakefile();
/**
* Read and parse a CMakeLists.txt file.
*/
bool ReadMakefile(const char* makefile, bool inheriting = false);
/**
* Add a wrapper generator.
*/
void AddCommand(cmCommand* );
/**
* Specify the makefile generator. This is platform/compiler
* dependent, although the interface is through a generic
* superclass.
*/
void SetMakefileGenerator(cmMakefileGenerator*);
/**
* Produce the output makefile.
*/
void GenerateMakefile();
/**
* Print the object state to std::cout.
*/
void Print();
/**
* Add a custom command to the build.
*/
void AddCustomCommand(const char* source,
const char* result,
const char* command,
std::vector<std::string>& depends);
/**
* Add a define flag to the build.
*/
void AddDefineFlag(const char* definition);
/**
* Add an executable to the build.
*/
void AddExecutable(cmClassFile&);
/**
* Add a link library to the build.
*/
void AddLinkLibrary(const char*);
/**
* Add a link directory to the build.
*/
void AddLinkDirectory(const char*);
/**
* Add a subdirectory to the build.
*/
void AddSubDirectory(const char*);
/**
* Add an include directory to the build.
*/
void AddIncludeDirectory(const char*);
/**
* Add a variable definition to the build. This variable
* can be used in CMake to refer to lists, directories, etc.
*/
void AddDefinition(const char* name, const char* value);
/**
* Specify the name of the project for this build.
*/
void SetProjectName(const char*);
/**
* Get the name of the project for this build.
*/
const char* GetProjectName()
{
return m_ProjectName.c_str();
}
/**
* Set the name of the library.
*/
void SetLibraryName(const char*);
/**
* Add a class/source file to the build.
*/
void AddClass(cmClassFile& );
/**
* Add an auxiliary directory to the build.
*/
void AddExtraDirectory(const char* dir);
/**
* Specify the home directory for the build.
*/
void SetHomeDirectory(const char* dir)
{
m_cmHomeDirectory = dir;
cmSystemTools::ConvertToUnixSlashes(m_cmHomeDirectory);
}
/**
* Get the home directory for the build.
*/
const char* GetHomeDirectory()
{
return m_cmHomeDirectory.c_str();
}
/**
* Set the current directory in the project.
*/
void SetCurrentDirectory(const char* dir)
{
m_cmCurrentDirectory = dir;
}
/**
* Get the current directory in the project.
*/
const char* GetCurrentDirectory()
{
return m_cmCurrentDirectory.c_str();
}
/**
* Specify the name of the library that is built by this makefile.
*/
const char* GetLibraryName()
{
return m_LibraryName.c_str();
}
/**
* Set the name of the library that is built by this makefile.
*/
void SetOutputDirectory(const char* lib)
{
m_OutputDirectory = lib;
}
/**
* Get the name of the library that is built by this makefile.
*/
const char* GetOutputDirectory()
{
return m_OutputDirectory.c_str();
}
/**
* Set the name of the current output directory.
*/
void SetOutputHomeDirectory(const char* lib)
{
m_OutputHomeDirectory = lib;
}
/**
* Get the name of the current output directory.
*/
const char* GetOutputHomeDirectory()
{
return m_OutputHomeDirectory.c_str();
}
/**
* Get a list of the build subdirectories.
*/
const std::vector<std::string>& GetSubDirectories()
{
return m_SubDirectories;
}
/**
* Return a boolean flag indicating whether the build generates
* any executables.
*/
bool HasExecutables()
{
return m_Executables;
}
/**
* Get a list of include directories in the build.
*/
std::vector<std::string>& GetIncludeDirectories()
{
return m_IncludeDirectories;
}
/**
* Get a list of link directories in the build.
*/
std::vector<std::string>& GetLinkDirectories()
{
return m_LinkDirectories;
}
/**
* Get a list of link libraries in the build.
*/
std::vector<std::string>& GetLinkLibraries()
{
return m_LinkLibraries;
}
/**
* Get a list of Win32 link libraries in the build.
*/
std::vector<std::string>& GetLinkLibrariesWin32()
{
return m_LinkLibrariesWin32;
}
/**
* Get a list of Unix link libraries in the build.
*/
std::vector<std::string>& GetLinkLibrariesUnix()
{
return m_LinkLibrariesUnix;
}
/**
* Return a list of source files in this makefile.
*/
std::vector<cmClassFile>& GetClasses()
{return m_Classes;}
/**
* Obtain a list of auxiliary source directories.
*/
std::vector<std::string>& GetAuxSourceDirectories()
{return m_AuxSourceDirectories;}
/**
* Do not use this.
*/
std::vector<std::string>& GetMakeVerbatim()
{return m_MakeVerbatim;}
/**
* Given a variable name, return its value (as a string).
*/
const char* GetDefinition(const char*);
/**
* Get a list of preprocessor define flags.
*/
const char* GetDefineFlags()
{return m_DefineFlags.c_str();}
/**
* Dump documentation to a file. If 0 is returned, the
* operation failed.
*/
int DumpDocumentationToFile(const char *fileName);
/**
* Expand all defined varibles in the string.
* Defined varibles come from the m_Definitions map.
* They are expanded with ${var} where var is the
* entry in the m_Definitions map. Also @var@ is
* expanded to match autoconf style expansions.
*/
void ExpandVariblesInString(std::string& source);
protected:
bool m_Executables;
std::string m_Prefix;
std::vector<std::string> m_AuxSourceDirectories; //
std::string m_OutputDirectory; // Current output directory for makefile
std::string m_OutputHomeDirectory; // Top level output directory
std::string m_cmHomeDirectory; // Home directory for source
std::string m_cmCurrentDirectory; // current directory in source
std::string m_LibraryName; // library name
std::string m_ProjectName; // project name
std::vector<cmClassFile> m_Classes; // list of classes in makefile
std::vector<std::string> m_SubDirectories; // list of sub directories
std::vector<std::string> m_MakeVerbatim; // lines copied from input file
std::vector<std::string> m_IncludeDirectories;
std::vector<std::string> m_LinkDirectories;
std::vector<std::string> m_LinkLibraries;
std::vector<std::string> m_LinkLibrariesWin32;
std::vector<std::string> m_LinkLibrariesUnix;
std::string m_DefineFlags;
std::string m_SourceHomeDirectory;
struct customCommand
{
std::string m_Source;
std::string m_Result;
std::string m_Command;
std::vector<std::string> m_Depends;
};
std::vector<customCommand> m_CustomCommands;
typedef std::map<std::string, cmCommand*> RegisteredCommandsMap;
typedef std::map<std::string, std::string> DefinitionMap;
DefinitionMap m_Definitions;
RegisteredCommandsMap m_Commands;
std::vector<cmCommand*> m_UsedCommands;
cmMakefileGenerator* m_MakefileGenerator;
private:
/**
* Look for CMakeLists.txt files to parse in dir,
* then in dir's parents, until the SourceHome directory
* is found.
*/
void ParseDirectory(const char* dir);
/**
* Parse a file for includes links and libs
*/
void ExpandVaribles();
void ReadClasses(std::ifstream& fin, bool t);
friend class cmMakeDepend; // make depend needs direct access
// to the m_Classes array
void PrintStringVector(const char* s, std::vector<std::string>& v);
void AddDefaultCommands();
};
#endif
|