1
/*=========================================================================
3
Program: Insight Segmentation & Registration Toolkit
4
Module: $RCSfile: cmMakefile.h,v $
6
Date: $Date: 2002/01/15 20:46:34 $
7
Version: $Revision: 1.92 $
9
Copyright (c) 2001 Insight Consortium
12
Redistribution and use in source and binary forms, with or without
13
modification, are permitted provided that the following conditions are met:
15
* Redistributions of source code must retain the above copyright notice,
16
this list of conditions and the following disclaimer.
18
* Redistributions in binary form must reproduce the above copyright notice,
19
this list of conditions and the following disclaimer in the documentation
20
and/or other materials provided with the distribution.
22
* The name of the Insight Consortium, nor the names of any consortium members,
23
nor of any contributors, may be used to endorse or promote products derived
24
from this software without specific prior written permission.
26
* Modified source versions must be plainly marked as such, and must not be
27
misrepresented as being the original software.
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
30
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
33
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
=========================================================================*/
44
#include "cmStandardIncludes.h"
46
#include "cmSourceFile.h"
47
#include "cmSystemTools.h"
48
#include "cmSourceGroup.h"
50
#include "cmCacheManager.h"
52
class cmFunctionBlocker;
54
class cmMakefileGenerator;
57
* \brief Process the input CMakeLists.txt file.
59
* Process and store into memory the input CMakeLists.txt file.
60
* Each CMakeLists.txt file is parsed and the commands found there
61
* are added into the build process.
67
* Return major and minor version numbers for cmake.
69
static unsigned int GetMajorVersion() { return 1;}
70
static unsigned int GetMinorVersion() { return 2;}
71
static const char *GetReleaseVersion() { return "release";}
74
* Return the major and minor version of the cmake that
75
* was used to write the currently loaded cache, note
76
* this method will not work before the cache is loaded.
78
static unsigned int GetCacheMajorVersion();
79
static unsigned int GetCacheMinorVersion();
82
* Construct an empty makefile.
92
* Read and parse a CMakeLists.txt file.
94
bool ReadListFile(const char* listfile, const char* external= 0);
97
* Add a wrapper generator.
99
void AddCommand(cmCommand* );
102
* Add a function blocker to this makefile
104
void AddFunctionBlocker(cmFunctionBlocker *fb)
105
{ m_FunctionBlockers.insert(fb);}
106
void RemoveFunctionBlocker(cmFunctionBlocker *fb)
107
{ m_FunctionBlockers.erase(fb);}
108
void RemoveFunctionBlocker(const char *name, const std::vector<std::string> &args);
111
* Specify the makefile generator. This is platform/compiler
112
* dependent, although the interface is through a generic
115
void SetMakefileGenerator(cmMakefileGenerator*);
117
///! Get the current makefile generator.
118
cmMakefileGenerator* GetMakefileGenerator()
119
{ return m_MakefileGenerator;}
122
* Produce the output makefile.
124
void GenerateMakefile();
127
* run the final pass on all commands.
132
* Print the object state to std::cout.
137
* Add a custom command to the build.
139
void AddCustomCommand(const char* source,
141
const std::vector<std::string>& commandArgs,
142
const std::vector<std::string>& depends,
143
const std::vector<std::string>& outputs,
146
void AddCustomCommand(const char* source,
148
const std::vector<std::string>& commandArgs,
149
const std::vector<std::string>& depends,
154
* Add a define flag to the build.
156
void AddDefineFlag(const char* definition);
159
* Add an executable to the build.
161
void AddExecutable(const char *exename,
162
const std::vector<std::string> &srcs);
163
void AddExecutable(const char *exename,
164
const std::vector<std::string> &srcs, bool win32);
167
* Add a utility to the build. A utiltity target is
168
* a command that is run every time a target is built.
170
void AddUtilityCommand(const char* utilityName,
172
const char* arguments,
174
void AddUtilityCommand(const char* utilityName,
176
const char* arguments,
178
const std::vector<std::string> &depends,
179
const std::vector<std::string> &outputs);
182
* Get a list of link libraries in the build.
184
cmTarget::LinkLibraries& GetLinkLibraries()
186
return m_LinkLibraries;
190
* Get a list of link libraries in the build.
192
const cmTarget::LinkLibraries& GetLinkLibraries() const
194
return m_LinkLibraries;
198
* Add a link library to the build.
200
void AddLinkLibrary(const char*);
201
void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type);
202
void AddLinkLibraryForTarget(const char *tgt, const char*,
203
cmTarget::LinkLibraryType type);
206
* Add a link directory to the build.
208
void AddLinkDirectory(const char*);
211
* Add a subdirectory to the build.
213
void AddSubDirectory(const char*);
216
* Add an include directory to the build.
218
void AddIncludeDirectory(const char*, bool before = false);
221
* Add a variable definition to the build. This variable
222
* can be used in CMake to refer to lists, directories, etc.
224
void AddDefinition(const char* name, const char* value);
225
///! Add a definition to this makefile and the global cmake cache.
226
void AddCacheDefinition(const char* name, const char* value,
228
cmCacheManager::CacheEntryType type);
231
* Add bool variable definition to the build.
233
void AddDefinition(const char* name, bool);
234
///! Add a definition to this makefile and the global cmake cache.
235
void AddCacheDefinition(const char* name, bool, const char* doc);
238
* Specify the name of the project for this build.
240
void SetProjectName(const char*);
243
* Get the name of the project for this build.
245
const char* GetProjectName()
247
return m_ProjectName.c_str();
251
* Set the name of the library.
253
void AddLibrary(const char *libname, int shared,
254
const std::vector<std::string> &srcs);
257
* Add a class/source file to the build.
259
void AddSource(cmSourceFile& ,const char *srcListName);
262
* Remove a class/source file from the build.
264
void RemoveSource(cmSourceFile& ,const char *srcListName);
267
* Add a source group for consideration when adding a new source.
269
void AddSourceGroup(const char* name, const char* regex);
272
* Add an auxiliary directory to the build.
274
void AddExtraDirectory(const char* dir);
278
* Add an auxiliary directory to the build.
280
void MakeStartDirectoriesCurrent()
282
m_cmCurrentDirectory = m_cmStartDirectory;
283
m_CurrentOutputDirectory = m_StartOutputDirectory;
288
* Set/Get the home directory (or output directory) in the project. The
289
* home directory is the top directory of the project. It is where
290
* CMakeSetup or configure was run. Remember that CMake processes
291
* CMakeLists files by recursing up the tree starting at the StartDirectory
292
* and going up until it reaches the HomeDirectory.
294
void SetHomeDirectory(const char* dir);
295
const char* GetHomeDirectory() const
297
return m_cmHomeDirectory.c_str();
299
void SetHomeOutputDirectory(const char* lib);
300
const char* GetHomeOutputDirectory() const
302
return m_HomeOutputDirectory.c_str();
308
* Set/Get the start directory (or output directory). The start directory
309
* is the directory of the CMakeLists.txt file that started the current
310
* round of processing. Remember that CMake processes CMakeLists files by
311
* recursing up the tree starting at the StartDirectory and going up until
312
* it reaches the HomeDirectory.
314
void SetStartDirectory(const char* dir)
316
m_cmStartDirectory = dir;
317
cmSystemTools::ConvertToUnixSlashes(m_cmStartDirectory);
319
const char* GetStartDirectory() const
321
return m_cmStartDirectory.c_str();
323
void SetStartOutputDirectory(const char* lib)
325
m_StartOutputDirectory = lib;
326
cmSystemTools::ConvertToUnixSlashes(m_StartOutputDirectory);
327
cmSystemTools::MakeDirectory(m_StartOutputDirectory.c_str());
329
const char* GetStartOutputDirectory() const
331
return m_StartOutputDirectory.c_str();
337
* Set/Get the current directory (or output directory) in the project. The
338
* current directory is the directory of the CMakeLists.txt file that is
339
* currently being processed. Remember that CMake processes CMakeLists
340
* files by recursing up the tree starting at the StartDirectory and going
341
* up until it reaches the HomeDirectory.
343
void SetCurrentDirectory(const char* dir)
345
m_cmCurrentDirectory = dir;
346
cmSystemTools::ConvertToUnixSlashes(m_cmCurrentDirectory);
348
const char* GetCurrentDirectory() const
350
return m_cmCurrentDirectory.c_str();
352
void SetCurrentOutputDirectory(const char* lib)
354
m_CurrentOutputDirectory = lib;
355
cmSystemTools::ConvertToUnixSlashes(m_CurrentOutputDirectory);
357
const char* GetCurrentOutputDirectory() const
359
return m_CurrentOutputDirectory.c_str();
362
/* Get the current CMakeLists.txt file that is being processed. This
363
* is just used in order to be able to 'branch' from one file to a second
365
const char* GetCurrentListFile() const
367
return m_cmCurrentListFile.c_str();
373
* Set a regular expression that include files must match
374
* in order to be considered as part of the depend information.
376
void SetIncludeRegularExpression(const char* regex)
378
m_IncludeFileRegularExpression = regex;
382
* Set a regular expression that include files that are not found
383
* must match in order to be considered a problem.
385
void SetComplainRegularExpression(const char* regex)
387
m_ComplainFileRegularExpression = regex;
391
* Get the list of targets
393
cmTargets &GetTargets() { return m_Targets; }
394
const cmTargets &GetTargets() const { return m_Targets; }
397
* Get a list of the build subdirectories.
399
const std::vector<std::string>& GetSubDirectories()
401
return m_SubDirectories;
405
* Get a list of include directories in the build.
407
std::vector<std::string>& GetIncludeDirectories()
409
return m_IncludeDirectories;
411
const std::vector<std::string>& GetIncludeDirectories() const
413
return m_IncludeDirectories;
417
* Get a list of link directories in the build.
419
std::vector<std::string>& GetLinkDirectories()
421
return m_LinkDirectories;
425
* Return a list of source files in this makefile.
427
typedef std::map<cmStdString,std::vector<cmSourceFile> > SourceMap;
428
const SourceMap &GetSources() const {return m_Sources;}
429
SourceMap &GetSources() {return m_Sources;}
430
cmSourceFile *GetSource(const char *srclist, const char *sourceName);
433
* Obtain a list of auxiliary source directories.
435
std::vector<std::string>& GetAuxSourceDirectories()
436
{return m_AuxSourceDirectories;}
440
* Return a list of extensions associated with source and header
443
const std::vector<std::string>& GetSourceExtensions() const
444
{return m_SourceFileExtensions;}
445
const std::vector<std::string>& GetHeaderExtensions() const
446
{return m_HeaderFileExtensions;}
450
* Given a variable name, return its value (as a string).
451
* If the variable is not found in this makefile instance, the
452
* cache is then queried.
454
const char* GetDefinition(const char*) const;
456
/** Test a boolean cache entry to see if it is true or false,
457
* returns false if no entry defined.
459
bool IsOn(const char* name);
462
* Get a list of preprocessor define flags.
464
const char* GetDefineFlags()
465
{return m_DefineFlags.c_str();}
468
* Get the vector of used command instances.
470
const std::vector<cmCommand*>& GetUsedCommands() const
471
{return m_UsedCommands;}
474
* Get the vector source groups.
476
const std::vector<cmSourceGroup>& GetSourceGroups() const
477
{ return m_SourceGroups; }
480
* Get the vector of list files on which this makefile depends
482
const std::vector<std::string>& GetListFiles() const
483
{ return m_ListFiles; }
485
///! When the file changes cmake will be re-run from the build system.
486
void AddCMakeDependFile(const char* file)
487
{ m_ListFiles.push_back(file);}
490
* Dump documentation to a file. If 0 is returned, the
493
int DumpDocumentationToFile(std::ostream&);
496
* Expand all defined varibles in the string.
497
* Defined varibles come from the m_Definitions map.
498
* They are expanded with ${var} where var is the
499
* entry in the m_Definitions map. Also @var@ is
500
* expanded to match autoconf style expansions.
502
const char *ExpandVariablesInString(std::string& source) const;
503
const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
504
bool atOnly = false) const;
507
* Remove any remaining variables in the string. Anything with ${var} or
508
* @var@ will be removed.
510
void RemoveVariablesInString(std::string& source, bool atOnly = false) const;
513
* Expand variables in the makefiles ivars such as link directories etc
515
void ExpandVariables();
517
/** Recursivly read and create a cmMakefile object for
518
* all CMakeLists.txt files in the GetSubDirectories list.
519
* Once the file is found, it ReadListFile is called on
520
* the cmMakefile created for it.
522
void FindSubDirectoryCMakeListsFiles(std::vector<cmMakefile*>& makefiles);
525
* find what source group this source is in
527
cmSourceGroup& FindSourceGroup(const char* source,
528
std::vector<cmSourceGroup> &groups);
530
void RegisterData(cmData*);
531
void RegisterData(const char*, cmData*);
532
cmData* LookupData(const char*) const;
535
* execute a single CMake command
537
void ExecuteCommand(std::string &name, std::vector<std::string> const& args);
539
/** Check if a command exists. */
540
bool CommandExists(const char* name) const;
543
std::string m_Prefix;
544
std::vector<std::string> m_AuxSourceDirectories; //
546
std::string m_cmCurrentDirectory;
547
std::string m_CurrentOutputDirectory;
548
std::string m_cmStartDirectory;
549
std::string m_StartOutputDirectory;
550
std::string m_cmHomeDirectory;
551
std::string m_HomeOutputDirectory;
552
std::string m_cmCurrentListFile;
554
std::string m_ProjectName; // project name
556
// libraries, classes, and executables
560
std::vector<std::string> m_SubDirectories; // list of sub directories
561
struct StringSet : public std::set<cmStdString>
565
// The include and link-library paths. These may have order
566
// dependency, so they must be vectors (not set).
567
std::vector<std::string> m_IncludeDirectories;
568
std::vector<std::string> m_LinkDirectories;
570
std::vector<std::string> m_ListFiles; // list of command files loaded
573
cmTarget::LinkLibraries m_LinkLibraries;
575
std::string m_IncludeFileRegularExpression;
576
std::string m_ComplainFileRegularExpression;
577
std::vector<std::string> m_SourceFileExtensions;
578
std::vector<std::string> m_HeaderFileExtensions;
579
std::string m_DefineFlags;
580
std::vector<cmSourceGroup> m_SourceGroups;
581
typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
582
typedef std::map<cmStdString, cmStdString> DefinitionMap;
583
DefinitionMap m_Definitions;
584
RegisteredCommandsMap m_Commands;
585
std::vector<cmCommand*> m_UsedCommands;
586
cmMakefileGenerator* m_MakefileGenerator;
587
bool IsFunctionBlocked(const char *name, std::vector<std::string> const& args);
591
* Get the name of the parent directories CMakeLists file
592
* given a current CMakeLists file name
594
std::string GetParentListFileName(const char *listFileName);
596
void ReadSources(std::ifstream& fin, bool t);
597
friend class cmMakeDepend; // make depend needs direct access
598
// to the m_Sources array
599
void PrintStringVector(const char* s, const std::vector<std::string>& v) const;
600
void AddDefaultCommands();
601
void AddDefaultDefinitions();
602
std::set<cmFunctionBlocker *> m_FunctionBlockers;
604
typedef std::map<cmStdString, cmData*> DataMap;