1
1
/*=========================================================================
3
Program: Insight Segmentation & Registration Toolkit
3
Program: CMake - Cross-Platform Makefile Generator
4
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.
6
Date: $Date: 2004/05/25 15:31:22 $
7
Version: $Revision: 1.147.2.1 $
9
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12
This software is distributed WITHOUT ANY WARRANTY; without even
13
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
PURPOSE. See the above copyright notices for more information.
40
16
=========================================================================*/
41
17
#ifndef cmMakefile_h
42
18
#define cmMakefile_h
44
#include "cmStandardIncludes.h"
45
20
#include "cmData.h"
46
#include "cmSourceFile.h"
47
21
#include "cmSystemTools.h"
48
22
#include "cmSourceGroup.h"
49
23
#include "cmTarget.h"
24
#include "cmListFileCache.h"
50
25
#include "cmCacheManager.h"
27
#include <cmsys/RegularExpression.hxx>
52
29
class cmFunctionBlocker;
54
class cmMakefileGenerator;
31
class cmLocalGenerator;
34
class cmVariableWatch;
56
37
/** \class cmMakefile
57
38
* \brief Process the input CMakeLists.txt file.
67
48
* 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";}
50
static unsigned int GetMajorVersion() { return CMake_VERSION_MAJOR; }
51
static unsigned int GetMinorVersion() { return CMake_VERSION_MINOR; }
52
static const char* GetReleaseVersion();
74
55
* Return the major and minor version of the cmake that
75
56
* was used to write the currently loaded cache, note
76
57
* this method will not work before the cache is loaded.
78
static unsigned int GetCacheMajorVersion();
79
static unsigned int GetCacheMinorVersion();
59
unsigned int GetCacheMajorVersion();
60
unsigned int GetCacheMinorVersion();
82
63
* Construct an empty makefile.
94
75
bool ReadListFile(const char* listfile, const char* external= 0);
97
* Add a wrapper generator.
99
void AddCommand(cmCommand* );
102
78
* Add a function blocker to this makefile
104
80
void AddFunctionBlocker(cmFunctionBlocker *fb)
105
{ m_FunctionBlockers.insert(fb);}
81
{ m_FunctionBlockers.push_back(fb);}
106
82
void RemoveFunctionBlocker(cmFunctionBlocker *fb)
107
{ m_FunctionBlockers.erase(fb);}
108
void RemoveFunctionBlocker(const char *name, const std::vector<std::string> &args);
83
{ m_FunctionBlockers.remove(fb);}
84
void RemoveFunctionBlocker(const cmListFileFunction& lff);
87
* Add file to the written file list. These file should not be in the list
88
* of dependencies because they cause infinite loops.
90
void AddWrittenFile(const char* file);
91
bool HasWrittenFile(const char* file);
94
* Check if there are any infinite loops
96
bool CheckInfiniteLoops();
99
* Try running cmake and building a file. This is used for dynalically
100
* loaded commands, not as part of the usual build process.
102
int TryCompile(const char *srcdir, const char *bindir,
103
const char *projectName, const char *targetName,
104
const std::vector<std::string> *cmakeArgs,
105
std::string *output);
111
108
* Specify the makefile generator. This is platform/compiler
112
109
* dependent, although the interface is through a generic
115
void SetMakefileGenerator(cmMakefileGenerator*);
112
void SetLocalGenerator(cmLocalGenerator*);
117
114
///! Get the current makefile generator.
118
cmMakefileGenerator* GetMakefileGenerator()
119
{ return m_MakefileGenerator;}
115
cmLocalGenerator* GetLocalGenerator()
116
{ return m_LocalGenerator;}
122
* Produce the output makefile.
119
* Perform FinalPass, Library dependency analysis etc before output of the
124
void GenerateMakefile();
122
void ConfigureFinalPass();
127
125
* run the final pass on all commands.
137
135
* Add a custom command to the build.
137
void AddCustomCommandToOutput(const char* output,
139
const std::vector<std::string>& commandArgs,
140
const char *main_dependency,
141
const std::vector<std::string>& depends,
142
const char *comment = 0,
143
bool replace = false);
144
void AddCustomCommandToTarget(const char* target,
146
const std::vector<std::string>& commandArgs,
147
cmTarget::CustomCommandType type,
148
const char *comment = 0);
149
void AddCustomCommandToTarget(const char* target,
151
const std::vector<std::string>& commandArgs,
152
cmTarget::CustomCommandType type,
154
const std::vector<std::string>& depends);
157
* Add a custom command to the build.
139
159
void AddCustomCommand(const char* source,
140
160
const char* command,
141
161
const std::vector<std::string>& commandArgs,
142
162
const std::vector<std::string>& depends,
143
163
const std::vector<std::string>& outputs,
165
const char *comment = 0);
146
167
void AddCustomCommand(const char* source,
147
168
const char* command,
154
175
* Add a define flag to the build.
156
177
void AddDefineFlag(const char* definition);
178
void RemoveDefineFlag(const char* definition);
159
181
* Add an executable to the build.
161
void AddExecutable(const char *exename,
183
cmTarget* AddExecutable(const char *exename,
162
184
const std::vector<std::string> &srcs);
163
void AddExecutable(const char *exename,
164
const std::vector<std::string> &srcs, bool win32);
167
187
* Add a utility to the build. A utiltity target is
179
200
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
203
* Add a link library to the build.
200
205
void AddLinkLibrary(const char*);
201
206
void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type);
202
207
void AddLinkLibraryForTarget(const char *tgt, const char*,
203
208
cmTarget::LinkLibraryType type);
209
void AddLinkDirectoryForTarget(const char *tgt, const char* d);
206
212
* Add a link directory to the build.
208
214
void AddLinkDirectory(const char*);
217
* Get the list of link directories
219
std::vector<std::string>& GetLinkDirectories()
221
return m_LinkDirectories;
223
const std::vector<std::string>& GetLinkDirectories() const
225
return m_LinkDirectories;
227
void SetLinkDirectories(const std::vector<std::string>& vec)
229
m_LinkDirectories = vec;
211
233
* Add a subdirectory to the build.
213
void AddSubDirectory(const char*);
235
void AddSubDirectory(const char*, bool includeTopLevel=true, bool preorder = false);
216
238
* Add an include directory to the build.
413
449
return m_IncludeDirectories;
417
* Get a list of link directories in the build.
419
std::vector<std::string>& GetLinkDirectories()
421
return m_LinkDirectories;
451
void SetIncludeDirectories(const std::vector<std::string>& vec)
453
m_IncludeDirectories = vec;
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);
456
/** Expand out any arguements in the vector that have ; separated
457
* strings into multiple arguements. A new vector is created
458
* containing the expanded versions of all arguments in argsIn.
459
* This method differes from the one in cmSystemTools in that if
460
* the CmakeLists file is version 1.2 or earlier it will check for
461
* source lists being used without ${} around them
463
void ExpandSourceListArguments(std::vector<std::string> const& argsIn,
464
std::vector<std::string>& argsOut,
465
unsigned int startArgumentIndex);
467
/** Get a cmSourceFile pointer for a given source name, if the name is
468
* not found, then a null pointer is returned.
470
cmSourceFile* GetSource(const char* sourceName) const;
471
///! Add a new cmSourceFile to the list of sources for this makefile.
472
cmSourceFile* AddSource(cmSourceFile const&);
474
/** Get a cmSourceFile pointer for a given source name, if the name is
475
* not found, then create the source file and return it. generated
476
* indicates if it is a generated file, this is used in determining
477
* how to create the source file instance e.g. name
479
cmSourceFile* GetOrCreateSource(const char* sourceName,
480
bool generated = false);
433
483
* Obtain a list of auxiliary source directories.
452
502
* cache is then queried.
454
504
const char* GetDefinition(const char*) const;
505
const char* GetSafeDefinition(const char*) const;
508
* Get the list of all variables in the current space. If argument
509
* cacheonly is specified and is greater than 0, then only cache
510
* variables will be listed.
512
std::vector<std::string> GetDefinitions(int cacheonly=0) const;
456
514
/** Test a boolean cache entry to see if it is true or false,
457
515
* returns false if no entry defined.
459
bool IsOn(const char* name);
517
bool IsOn(const char* name) const;
462
520
* Get a list of preprocessor define flags.
513
570
* Expand variables in the makefiles ivars such as link directories etc
515
572
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);
573
void ExpandVariablesInCustomCommands();
576
* Replace variables and #cmakedefine lines in the given string.
577
* See cmConfigureFileCommand for details.
579
void ConfigureString(const std::string& input, std::string& output,
580
bool atOnly, bool escapeQuotes);
583
* Copy file but change lines acording to ConfigureString
585
int ConfigureFile(const char* infile, const char* outfile,
586
bool copyonly, bool atOnly, bool escapeQuotes);
525
589
* find what source group this source is in
527
591
cmSourceGroup& FindSourceGroup(const char* source,
528
592
std::vector<cmSourceGroup> &groups);
530
593
void RegisterData(cmData*);
531
594
void RegisterData(const char*, cmData*);
532
595
cmData* LookupData(const char*) const;
535
* execute a single CMake command
598
* Execute a single CMake command. Returns true if the command
599
* succeeded or false if it failed.
537
void ExecuteCommand(std::string &name, std::vector<std::string> const& args);
601
bool ExecuteCommand(const cmListFileFunction& lff);
539
603
/** Check if a command exists. */
540
604
bool CommandExists(const char* name) const;
607
* Add a command to this cmake instance
609
void AddCommand(cmCommand* );
611
///! Enable support for the named language, if null then all languages are enabled.
612
void EnableLanguage(const char* );
615
* Set/Get the name of the parent directories CMakeLists file
616
* given a current CMakeLists file name
618
cmCacheManager *GetCacheManager() const;
619
cmVariableWatch* GetVariableWatch() const;
621
//! Determine wether this is a local or global build.
622
bool GetLocal() const;
624
///! Display progress or status message.
625
void DisplayStatus(const char*, float);
628
* Expand the given list file arguments into the full set after
629
* variable replacement and list expansion.
631
void ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
632
std::vector<std::string>& outArgs);
636
cmake *GetCMakeInstance() const;
639
* Get all the source files this makefile knows about
641
const std::vector<cmSourceFile*> &GetSourceFiles() const
642
{return m_SourceFiles;}
643
std::vector<cmSourceFile*> &GetSourceFiles() {return m_SourceFiles;}
646
* Is there a source file that has the provided source file as an output?
647
* if so then return it
649
cmSourceFile *GetSourceFileWithOutput(const char *outName);
652
* Add a macro to the list of macros. The arguments should be name of the
653
* macro and a documentation signature of it
655
void AddMacro(const char* name, const char* signature);
658
* Get a list of macros as a ; separated string
660
void GetListOfMacros(std::string& macros);
663
* Return a location of a file in cmake or custom modules directory
665
std::string GetModulesFile(const char* name);
667
///! Return true if the directory is preorder.
668
bool IsDirectoryPreOrder(const char* dir);
670
///! Set/Get a property of this directory
671
void SetProperty(const char *prop, const char *value);
672
const char *GetProperty(const char *prop) const;
673
bool GetPropertyAsBool(const char *prop) const;
676
// add link libraries and directories to the target
677
void AddGlobalLinkInformation(const char* name, cmTarget& target);
543
679
std::string m_Prefix;
544
680
std::vector<std::string> m_AuxSourceDirectories; //
551
687
std::string m_HomeOutputDirectory;
552
688
std::string m_cmCurrentListFile;
554
std::string m_ProjectName; // project name
690
std::string m_ProjectName; // project name
691
std::vector<std::string> m_ParentProjects;
556
693
// libraries, classes, and executables
557
694
cmTargets m_Targets;
695
std::vector<cmSourceFile*> m_SourceFiles;
560
std::vector<std::string> m_SubDirectories; // list of sub directories
697
std::vector<std::pair<cmStdString, bool> > m_SubDirectories; // list of sub directories
561
698
struct StringSet : public std::set<cmStdString>
578
715
std::vector<std::string> m_HeaderFileExtensions;
579
716
std::string m_DefineFlags;
580
717
std::vector<cmSourceGroup> m_SourceGroups;
581
typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
582
718
typedef std::map<cmStdString, cmStdString> DefinitionMap;
583
719
DefinitionMap m_Definitions;
584
RegisteredCommandsMap m_Commands;
585
720
std::vector<cmCommand*> m_UsedCommands;
586
cmMakefileGenerator* m_MakefileGenerator;
587
bool IsFunctionBlocked(const char *name, std::vector<std::string> const& args);
721
cmLocalGenerator* m_LocalGenerator;
722
bool IsFunctionBlocked(const cmListFileFunction& lff);
594
729
std::string GetParentListFileName(const char *listFileName);
596
731
void ReadSources(std::ifstream& fin, bool t);
597
friend class cmMakeDepend; // make depend needs direct access
598
// to the m_Sources array
732
friend class cmMakeDepend; // make depend needs direct access
733
// to the m_Sources array
734
void PrintStringVector(const char* s, const std::vector<std::pair<cmStdString, bool> >& v) const;
599
735
void PrintStringVector(const char* s, const std::vector<std::string>& v) const;
600
void AddDefaultCommands();
601
736
void AddDefaultDefinitions();
602
std::set<cmFunctionBlocker *> m_FunctionBlockers;
737
std::list<cmFunctionBlocker *> m_FunctionBlockers;
604
739
typedef std::map<cmStdString, cmData*> DataMap;
605
740
DataMap m_DataMap;
606
741
bool m_Inheriting;
743
typedef std::map<cmStdString, cmStdString> StringStringMap;
744
StringStringMap m_MacrosMap;
746
std::map<cmStdString, bool> m_SubDirectoryOrder;
747
// used in AddDefinition for performance improvement
748
DefinitionMap::key_type m_TemporaryDefinitionKey;
750
cmsys::RegularExpression m_cmDefineRegex;
752
std::map<cmStdString,cmStdString> m_Properties;