cmMakefile.h 8.15 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*=========================================================================

  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
18

19
#include "cmStandardIncludes.h"
20
#include "cmClassFile.h"
21
#include "cmSystemTools.h"
22

23
24
25
class cmRuleMaker;
class cmMakefileGenerator;

26
27
28
29
30
31
32
/** \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 rules found there
 * are added into the build process.
 */
33
34
35
class cmMakefile
{
public:
36
37
38
  /**
   * Construct an empty makefile.
   */
39
  cmMakefile();
40
41
42
43

  /**
   * Destructor.
   */
44
  ~cmMakefile();
45
46
47
48

  /**
   * Read and parse a CMakeLists.txt file.
   */
49
  bool ReadMakefile(const char* makefile, bool inheriting = false); 
50
51
52
53

  /**
   * Add a wrapper generator.
   */
54
  void AddRuleMaker(cmRuleMaker* );
55
56
57
58
59
60

  /**
   * Specify the makefile generator. This is platform/compiler
   * dependent, although the interface is through a generic
   * superclass.
   */
61
  void SetMakefileGenerator(cmMakefileGenerator*);
62
63
64
65

  /**
   * Produce the output makefile.
   */
66
67
  void GenerateMakefile();
  
68
69
70
  /**
   * Print the object state to std::cout.
   */
71
  void Print();
72
  
73
74
75
  /**
   * Add a custom rule to the build.
   */
76
77
78
79
  void AddCustomRule(const char* source,
                     const char* result,
                     const char* command,
                     std::vector<std::string>& depends);
80
81
82
  /**
   * Add a define flag to the build.
   */
83
  void AddDefineFlag(const char* definition);
84
85
86
87

  /**
   * Add an executable to the build.
   */
88
  void AddExecutable(cmClassFile&);
89
90
91
92

  /**
   * Add a link library to the build.
   */
93
  void AddLinkLibrary(const char*);
94
95
96
97

  /**
   * Add a link directory to the build.
   */
98
  void AddLinkDirectory(const char*);
99
100
101
102

  /**
   * Add a subdirectory to the build.
   */
103
  void AddSubDirectory(const char*);
104
105
106
107

  /**
   * Add an include directory to the build.
   */
108
  void AddIncludeDirectory(const char*);
109
110
111
112
113

  /**
   * Add a variable definition to the build. This variable
   * can be used in CMake to refer to lists, directories, etc.
   */
114
  void AddDefinition(const char* name, const char* value);
115
116
117
118

  /**
   * Specify the name of the project for this build.
   */
119
  void SetProjectName(const char*);
120
121
122
123
124
125
126
127
128
129
130
131

  /**
   * Get the name of the project for this build.
   */
  const char* GetProjectName()
    {
    return m_ProjectName.c_str();
    }
  
  /**
   * Set the name of the library.
   */
132
  void SetLibraryName(const char*);
133
134
135
136

  /**
   * Add a class/source file to the build.
   */
137
  void AddClass(cmClassFile& );
138
139
140
141

  /**
   * Add an auxiliary directory to the build.
   */
142
143
  void AddExtraDirectory(const char* dir);
  
144
145
146
  /**
   * Specify the home directory for the build.
   */
147
148
  void SetHomeDirectory(const char* dir) 
    {
149
150
    m_cmHomeDirectory = dir;
    cmSystemTools::ConvertToUnixSlashes(m_cmHomeDirectory);
151
    }
152
153
154
155

  /**
   * Get the home directory for the build.
   */
156
157
  const char* GetHomeDirectory() 
    {
158
    return m_cmHomeDirectory.c_str();
159
    }
160
161
162
163

  /**
   * Set the current directory in the project.
   */
164
165
  void SetCurrentDirectory(const char* dir) 
    {
166
    m_cmCurrentDirectory = dir;
167
    }
168
169
170
171

  /**
   * Get the current directory in the project.
   */
172
173
  const char* GetCurrentDirectory() 
    {
174
    return m_cmCurrentDirectory.c_str();
175
    }
176
177
178
179

  /**
   * Specify the name of the library that is built by this makefile.
   */
180
181
  const char* GetLibraryName()
    {
182
    return m_LibraryName.c_str();
183
    }
184

185
186
187
  /**
   * Set the name of the library that is built by this makefile.
   */
188
189
  void SetOutputDirectory(const char* lib)
    {
190
    m_OutputDirectory = lib;
191
    }
192
193
194
195

  /**
   * Get the name of the library that is built by this makefile.
   */
196
197
  const char* GetOutputDirectory()
    {
198
    return m_OutputDirectory.c_str();
199
    }
200
201
202
203

  /**
   * Set the name of the current output directory.
   */
204
205
  void SetOutputHomeDirectory(const char* lib)
    {
206
    m_OutputHomeDirectory = lib;
207
    }
208
209
210
211

  /**
   * Get the name of the current output directory.
   */
212
213
  const char* GetOutputHomeDirectory()
    {
214
    return m_OutputHomeDirectory.c_str();
215
    }
216
217
218
219

  /**
   * Get a list of the build subdirectories.
   */
220
221
  const std::vector<std::string>& GetSubDirectories()
    { 
222
    return m_SubDirectories;
223
    }
224
225
226
227
228

  /**
   * Return a boolean flag indicating whether the build generates
   * any executables.
   */
229
230
  bool HasExecutables() 
    {
231
    return m_Executables;
232
    }
233
234
235
236

  /**
   * Get a list of include directories in the build.
   */
237
238
  std::vector<std::string>& GetIncludeDirectories()
    { 
239
    return m_IncludeDirectories;
240
    }
241
242
243
244

  /**
   * Get a list of link directories in the build.
   */
245
246
  std::vector<std::string>& GetLinkDirectories()
    { 
247
    return m_LinkDirectories;
248
249
    }
  
250
251
252
  /**
   * Get a list of link libraries in the build.
   */
253
254
  std::vector<std::string>& GetLinkLibraries()
    { 
255
    return m_LinkLibraries;
256
    }
257
258
259
260

  /**
   * Get a list of Win32 link libraries in the build.
   */
261
262
  std::vector<std::string>& GetLinkLibrariesWin32()
    { 
263
    return m_LinkLibrariesWin32;
264
265
    }
  
266
267
268
  /**
   * Get a list of Unix link libraries in the build.
   */
269
270
  std::vector<std::string>& GetLinkLibrariesUnix()
    { 
271
    return m_LinkLibrariesUnix;
272
    }
273
274
275
276
277
278
279
280
281
282

  /**
   * Return a list of source files in this makefile.
   */
  std::vector<cmClassFile>& GetClasses()
    {return  m_Classes;}

  /**
   * Obtain a list of auxiliary source directories.
   */
283
  std::vector<std::string>& GetAuxSourceDirectories()
284
    {return m_AuxSourceDirectories;}
285

286
287
288
289
290
  /**
   * Do not use this.
   */
  std::vector<std::string>& GetMakeVerbatim() 
    {return m_MakeVerbatim;}
291

292
293
  /**
   * Given a variable name, return its value (as a string).
294
   */
295
296
  const char* GetDefinition(const char*);

297
  /**
298
   * Get a list of preprocessor define flags.
299
   */
300
301
302
  const char* GetDefineFlags()
    {return m_DefineFlags.c_str();}

303
304
305
306
307
308
  /**
   * Dump documentation to a file. If 0 is returned, the
   * operation failed.
   */
  int DumpDocumentationToFile(const char *fileName);

309
310
311
protected:
  bool m_Executables;
  std::string m_Prefix;
312
  std::vector<std::string> m_AuxSourceDirectories; // 
313
314
315
316
317
  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
318
  std::string m_ProjectName;	// project name
319
320
  std::vector<cmClassFile> m_Classes; // list of classes in makefile
  std::vector<std::string> m_SubDirectories; // list of sub directories
321
  std::vector<std::string> m_MakeVerbatim; // lines copied from input file
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
  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 customRule
  {
    std::string m_Source;
    std::string m_Result;
    std::string m_Command;
    std::vector<std::string> m_Depends;
  };
  std::vector<customRule> m_CustomRules;
  typedef std::map<std::string, cmRuleMaker*> StringRuleMakerMap;
  typedef std::map<std::string, std::string> DefinitionMap;
  DefinitionMap m_Definitions;
  StringRuleMakerMap m_RuleMakers;
  std::vector<cmRuleMaker*> m_UsedRuleMakers;
  cmMakefileGenerator* m_MakefileGenerator;
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
  
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 AddDefaultRules();
  
363
364
365
366
};


#endif