CMake/Source/cmake.h

534 lines
19 KiB
C
Raw Normal View History

/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
2001-05-18 23:25:08 +04:00
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
2001-05-18 23:25:08 +04:00
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
2001-05-18 23:25:08 +04:00
#ifndef cmake_h
#define cmake_h
2002-09-06 21:06:23 +04:00
#include "cmSystemTools.h"
#include "cmPropertyDefinitionMap.h"
#include "cmPropertyMap.h"
2002-09-06 21:06:23 +04:00
class cmGlobalGeneratorFactory;
2002-09-06 21:06:23 +04:00
class cmGlobalGenerator;
class cmLocalGenerator;
class cmCacheManager;
class cmMakefile;
2002-09-11 00:51:29 +04:00
class cmCommand;
2003-01-08 20:59:52 +03:00
class cmVariableWatch;
class cmFileTimeComparison;
class cmExternalMakefileProjectGenerator;
class cmDocumentationSection;
class cmPolicies;
class cmListFileBacktrace;
class cmTarget;
class cmGeneratedFileStream;
2001-05-18 23:25:08 +04:00
/** \brief Represents a cmake invocation.
*
* This class represents a cmake invocation. It is the top level class when
2012-11-07 20:13:09 +04:00
* 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:
*
* -# Create a cmake instance
* -# 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.
* -# Load the cache by calling LoadCache (duh)
* -# 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.
* -# Finally call Configure
* -# Let the user change values and go back to step 5
* -# 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.
*/
2002-08-24 00:13:34 +04:00
class cmake
2001-05-18 23:25:08 +04:00
{
public:
2008-03-11 17:29:56 +03:00
enum MessageType
{ AUTHOR_WARNING,
FATAL_ERROR,
INTERNAL_ERROR,
2008-03-11 17:29:56 +03:00
MESSAGE,
WARNING,
LOG
};
/** \brief Describes the working modes of cmake */
enum WorkingMode
{
NORMAL_MODE, ///< Cmake runs to create project files
/** \brief Script mode (started by using -P).
*
* In script mode there is no generator and no cache. Also,
* languages are not enabled, so add_executable and things do
* nothing.
*/
SCRIPT_MODE,
/** \brief A pkg-config like mode
*
* In this mode cmake just searches for a package and prints the results to
* stdout. This is similar to SCRIPT_MODE, but commands like add_library()
* work too, since they may be used e.g. in exported target files. Started
* via --find-package.
*/
FIND_PACKAGE_MODE
};
typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
/// Default constructor
2002-09-06 21:06:23 +04:00
cmake();
/// Destructor
2002-09-06 21:06:23 +04:00
~cmake();
2001-05-18 23:25:08 +04:00
static const char *GetCMakeFilesDirectory() {return "/CMakeFiles";};
2006-06-15 19:51:51 +04:00
static const char *GetCMakeFilesDirectoryPostSlash() {
return "CMakeFiles/";};
2002-09-06 21:06:23 +04:00
//@{
/**
* Set/Get the home directory (or output directory) in the project. The
2012-03-20 02:05:21 +04:00
* home directory is the top directory of the project. It is the
* path-to-source cmake was run with. Remember that CMake processes
2002-09-06 21:06:23 +04:00
* CMakeLists files by recursing up the tree starting at the StartDirectory
* and going up until it reaches the HomeDirectory.
2002-09-06 21:06:23 +04:00
*/
void SetHomeDirectory(const char* dir);
const char* GetHomeDirectory() const
{
2006-03-15 19:02:08 +03:00
return this->cmHomeDirectory.c_str();
2002-09-06 21:06:23 +04:00
}
void SetHomeOutputDirectory(const char* lib);
const char* GetHomeOutputDirectory() const
{
2006-03-15 19:02:08 +03:00
return this->HomeOutputDirectory.c_str();
2002-09-06 21:06:23 +04:00
}
//@}
//@{
/**
* 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.
2002-09-06 21:06:23 +04:00
*/
void SetStartDirectory(const char* dir)
2002-09-06 21:06:23 +04:00
{
2006-03-15 19:02:08 +03:00
this->cmStartDirectory = dir;
cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory);
2002-09-06 21:06:23 +04:00
}
const char* GetStartDirectory() const
{
2006-03-15 19:02:08 +03:00
return this->cmStartDirectory.c_str();
2002-09-06 21:06:23 +04:00
}
void SetStartOutputDirectory(const char* lib)
{
2006-03-15 19:02:08 +03:00
this->StartOutputDirectory = lib;
cmSystemTools::ConvertToUnixSlashes(this->StartOutputDirectory);
2002-09-06 21:06:23 +04:00
}
const char* GetStartOutputDirectory() const
{
2006-03-15 19:02:08 +03:00
return this->StartOutputDirectory.c_str();
2002-09-06 21:06:23 +04:00
}
//@}
/**
* Handle a command line invocation of cmake.
*/
int Run(const std::vector<std::string>&args)
2003-04-30 15:32:30 +04:00
{ return this->Run(args, false); }
int Run(const std::vector<std::string>&args, bool noconfigure);
2001-05-18 23:25:08 +04:00
/**
* Run the global generator Generate step.
2001-05-18 23:25:08 +04:00
*/
2002-09-06 21:06:23 +04:00
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. */
2002-09-17 21:59:58 +04:00
int Configure();
int ActualConfigure();
2002-09-17 21:59:58 +04:00
2002-11-07 17:04:20 +03:00
int LoadCache();
void PreLoadCMakeFiles();
2002-09-06 21:06:23 +04:00
///! Create a GlobalGenerator
cmGlobalGenerator* CreateGlobalGenerator(const char* name);
///! Return the global generator assigned to this instance of cmake
cmGlobalGenerator* GetGlobalGenerator() { return this->GlobalGenerator; }
///! Return the global generator assigned to this instance of cmake, const
const cmGlobalGenerator* GetGlobalGenerator() const
{ return this->GlobalGenerator; }
2002-09-06 21:06:23 +04:00
///! 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);
///! Set the name of the selected generator-specific toolset.
void SetGeneratorToolset(std::string const& ts)
{ this->GeneratorToolset = ts; }
///! Get the name of the selected generator-specific toolset.
std::string const& GetGeneratorToolset() const
{ return this->GeneratorToolset; }
2002-09-06 21:06:23 +04:00
///! get the cmCachemManager used by this invocation of cmake
2006-03-15 19:02:08 +03:00
cmCacheManager *GetCacheManager() { return this->CacheManager; }
2002-09-17 21:59:58 +04:00
///! set the cmake command this instance of cmake should use
2006-03-15 19:02:08 +03:00
void SetCMakeCommand(const char* cmd) { this->CMakeCommand = cmd; }
2002-09-06 21:06:23 +04:00
/**
* Given a variable name, return its value (as a string).
*/
const char* GetCacheDefinition(const char*) const;
2002-12-04 18:57:22 +03:00
///! Add an entry into the cache
void AddCacheEntry(const char* key, const char* value,
const char* helpString,
2002-12-04 18:57:22 +03:00
int type);
2002-06-03 21:08:52 +04:00
/**
* Get the system information and write it to the file specified
*/
int GetSystemInformation(std::vector<std::string>&);
2002-09-11 00:51:29 +04:00
/**
* Add a command to this cmake instance
*/
void AddCommand(cmCommand* );
void RenameCommand(const char* oldName, const char* newName);
void RemoveCommand(const char* name);
void RemoveUnscriptableCommands();
2002-09-11 00:51:29 +04:00
/**
* Get a command by its name
*/
cmCommand *GetCommand(const char *name);
/** Get list of all commands */
2006-03-15 19:02:08 +03:00
RegisteredCommandsMap* GetCommands() { return &this->Commands; }
2002-09-11 00:51:29 +04:00
/** Check if a command exists. */
bool CommandExists(const char* name) const;
///! Parse command line arguments
2010-10-06 23:00:52 +04:00
void SetArgs(const std::vector<std::string>&,
bool directoriesSetBefore = false);
2002-09-06 21:06:23 +04:00
///! Is this cmake running as a result of a TRY_COMPILE command
2006-03-15 19:02:08 +03:00
bool GetIsInTryCompile() { return this->InTryCompile; }
///! Is this cmake running as a result of a TRY_COMPILE command
2006-03-15 19:02:08 +03:00
void SetIsInTryCompile(bool i) { this->InTryCompile = i; }
2002-09-17 21:59:58 +04:00
///! Parse command line arguments that might set cache values
bool SetCacheArgs(const std::vector<std::string>&);
2002-09-13 21:48:14 +04:00
2006-03-15 19:02:08 +03:00
typedef void (*ProgressCallbackType)
(const char*msg, float progress, void *);
2002-09-26 23:14:20 +04:00
/**
2012-11-07 20:13:09 +04:00
* Set the function used by GUIs to receive progress updates
* Function gets passed: message as a const char*, a progress
2002-09-26 23:14:20 +04:00
* amount ranging from 0 to 1.0 and client data. The progress
* number provided may be negative in cases where a message is
2002-09-26 23:14:20 +04:00
* to be displayed without any progress percentage.
*/
2006-03-15 19:02:08 +03:00
void SetProgressCallback(ProgressCallbackType f, void* clientData=0);
2002-09-26 23:14:20 +04:00
///! this is called by generators to update the progress
void UpdateProgress(const char *msg, float prog);
///! get the cmake policies instance
cmPolicies *GetPolicies() {return this->Policies;} ;
2003-01-08 20:59:52 +03:00
///! Get the variable watch object
2006-03-15 19:02:08 +03:00
cmVariableWatch* GetVariableWatch() { return this->VariableWatch; }
2003-01-08 20:59:52 +03:00
/** Get the documentation entries for the supported commands.
* If withCurrentCommands is true, the documentation for the
* recommended set of commands is included.
* If withCompatCommands is true, the documentation for discouraged
* (compatibility) commands is included.
* You probably don't want to set both to false.
*/
void GetCommandDocumentation(std::vector<cmDocumentationEntry>& entries,
bool withCurrentCommands = true,
bool withCompatCommands = true) const;
void GetPropertiesDocumentation(std::map<std::string,
cmDocumentationSection *>&);
void GetGeneratorDocumentation(std::vector<cmDocumentationEntry>&);
void GetPolicyDocumentation(std::vector<cmDocumentationEntry>& entries);
///! Set/Get a property of this target file
void SetProperty(const char *prop, const char *value);
void AppendProperty(const char *prop, const char *value,bool asString=false);
const char *GetProperty(const char *prop);
const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
bool GetPropertyAsBool(const char *prop);
// Get the properties
cmPropertyMap &GetProperties() { return this->Properties; };
///! Do all the checks before running configure
int DoPreConfigureChecks();
void SetWorkingMode(WorkingMode mode) { this->CurrentWorkingMode = mode; }
WorkingMode GetWorkingMode() { return this->CurrentWorkingMode; }
2012-03-20 02:05:21 +04:00
///! Debug the try compile stuff by not deleting the files
2006-03-15 19:02:08 +03:00
bool GetDebugTryCompile(){return this->DebugTryCompile;}
void DebugTryCompileOn(){this->DebugTryCompile = true;}
2005-05-02 23:51:12 +04:00
/**
* Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
*/
int AddCMakePaths();
2005-05-02 23:51:12 +04:00
/**
* Get the file comparison class
*/
2006-03-15 19:02:08 +03:00
cmFileTimeComparison* GetFileComparison() { return this->FileComparison; }
2006-02-23 18:00:44 +03:00
/**
* Get the path to ctest
*/
const char* GetCTestCommand();
const char* GetCPackCommand();
const char* GetCMakeCommand();
2006-02-23 18:00:44 +03:00
// Do we want debug output during the cmake run.
bool GetDebugOutput() { return this->DebugOutput; }
void SetDebugOutputOn(bool b) { this->DebugOutput = b;}
2008-07-31 18:33:25 +04:00
// Do we want trace output during the cmake run.
bool GetTrace() { return this->Trace;}
void SetTrace(bool b) { this->Trace = b;}
bool GetWarnUninitialized() { return this->WarnUninitialized;}
void SetWarnUninitialized(bool b) { this->WarnUninitialized = b;}
2010-08-25 20:36:21 +04:00
bool GetWarnUnused() { return this->WarnUnused;}
void SetWarnUnused(bool b) { this->WarnUnused = b;}
bool GetWarnUnusedCli() { return this->WarnUnusedCli;}
void SetWarnUnusedCli(bool b) { this->WarnUnusedCli = b;}
2010-09-01 19:24:20 +04:00
bool GetCheckSystemVars() { return this->CheckSystemVars;}
void SetCheckSystemVars(bool b) { this->CheckSystemVars = b;}
void MarkCliAsUsed(const std::string& variable);
// Define a property
void DefineProperty(const char *name, cmProperty::ScopeType scope,
const char *ShortDescription,
const char *FullDescription,
bool chain = false,
const char *variableGroup = 0);
// get property definition
cmPropertyDefinition *GetPropertyDefinition
(const char *name, cmProperty::ScopeType scope);
// Is a property defined?
bool IsPropertyDefined(const char *name, cmProperty::ScopeType scope);
bool IsPropertyChained(const char *name, cmProperty::ScopeType scope);
/** Get the list of configurations (in upper case) considered to be
debugging configurations.*/
std::vector<std::string> const& GetDebugConfigs();
// record accesses of properties and variables
void RecordPropertyAccess(const char *name, cmProperty::ScopeType scope);
void ReportUndefinedPropertyAccesses(const char *filename);
// Define the properties
static void DefineProperties(cmake *cm);
2008-02-12 17:49:42 +03:00
void SetCMakeEditCommand(const char* s)
{
this->CMakeEditCommand = s;
}
void SetSuppressDevWarnings(bool v)
{
this->SuppressDevWarnings = v;
2008-03-29 20:16:02 +03:00
this->DoSuppressDevWarnings = true;
}
/** Display a message to the user. */
void IssueMessage(cmake::MessageType t, std::string const& text,
cmListFileBacktrace const& backtrace);
2012-03-20 02:05:21 +04:00
///! run the --build option
int Build(const std::string& dir,
const std::string& target,
const std::string& config,
const std::vector<std::string>& nativeOptions,
bool clean,
cmSystemTools::OutputOption outputflag);
void UnwatchUnusedCli(const char* var);
void WatchUnusedCli(const char* var);
protected:
void RunCheckForUnusedVariables();
void InitializeProperties();
int HandleDeleteCacheVariables(const char* var);
cmPropertyMap Properties;
std::set<std::pair<cmStdString,cmProperty::ScopeType> > AccessedProperties;
std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>
PropertyDefinitions;
typedef
cmExternalMakefileProjectGenerator* (*CreateExtraGeneratorFunctionType)();
typedef std::map<cmStdString,
CreateExtraGeneratorFunctionType> RegisteredExtraGeneratorsMap;
typedef std::vector<cmGlobalGeneratorFactory*> RegisteredGeneratorsVector;
2006-03-15 19:02:08 +03:00
RegisteredCommandsMap Commands;
RegisteredGeneratorsVector Generators;
RegisteredExtraGeneratorsMap ExtraGenerators;
2002-09-11 00:51:29 +04:00
void AddDefaultCommands();
void AddDefaultGenerators();
void AddDefaultExtraGenerators();
void AddExtraGenerator(const char* name,
2007-07-20 16:36:16 +04:00
CreateExtraGeneratorFunctionType newFunction);
2002-09-11 00:51:29 +04:00
cmPolicies *Policies;
2006-03-15 19:02:08 +03:00
cmGlobalGenerator *GlobalGenerator;
cmCacheManager *CacheManager;
std::string cmHomeDirectory;
2006-03-15 19:02:08 +03:00
std::string HomeOutputDirectory;
std::string cmStartDirectory;
2006-03-15 19:02:08 +03:00
std::string StartOutputDirectory;
bool SuppressDevWarnings;
bool DoSuppressDevWarnings;
std::string GeneratorToolset;
2002-09-06 21:06:23 +04:00
///! read in a cmake list file to initialize the cache
void ReadListFile(const std::vector<std::string>& args, const char *path);
bool FindPackage(const std::vector<std::string>& args);
///! 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);
2006-05-12 22:36:39 +04:00
//! Make sure all commands are what they say they are and there is no
2012-03-20 02:05:21 +04:00
/// macros.
void CleanupCommandsAndMacros();
void GenerateGraphViz(const char* fileName) const;
2006-03-15 19:02:08 +03:00
cmVariableWatch* VariableWatch;
///! Find the full path to one of the cmake programs like ctest, cpack, etc.
std::string FindCMakeProgram(const char* name) const;
private:
cmake(const cmake&); // Not implemented.
void operator=(const cmake&); // Not implemented.
2006-03-15 19:02:08 +03:00
ProgressCallbackType ProgressCallback;
void* ProgressCallbackClientData;
bool Verbose;
bool InTryCompile;
WorkingMode CurrentWorkingMode;
bool DebugOutput;
2008-07-31 18:33:25 +04:00
bool Trace;
bool WarnUninitialized;
2010-08-25 20:36:21 +04:00
bool WarnUnused;
bool WarnUnusedCli;
2010-09-01 19:24:20 +04:00
bool CheckSystemVars;
std::map<cmStdString, bool> UsedCliVariables;
2008-02-12 17:49:42 +03:00
std::string CMakeEditCommand;
2006-03-15 19:02:08 +03:00
std::string CMakeCommand;
std::string CXXEnvironment;
std::string CCEnvironment;
std::string CheckBuildSystemArgument;
std::string CheckStampFile;
std::string CheckStampList;
std::string VSSolutionFile;
2006-03-15 19:02:08 +03:00
std::string CTestCommand;
std::string CPackCommand;
bool ClearBuildSystem;
bool DebugTryCompile;
cmFileTimeComparison* FileComparison;
std::string GraphVizFile;
std::vector<std::string> DebugConfigs;
void UpdateConversionPathTable();
2001-05-18 23:25:08 +04:00
};
#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."}, \
{"-U <globbing_expr>", "Remove matching entries from CMake cache.", \
"This option may be used to remove one or more variables from the " \
"CMakeCache.txt file, globbing expressions using * and ? are supported. "\
"The option may be repeated for as many cache entries as desired.\n" \
"Use with care, you can make your CMakeCache.txt non-working."}, \
{"-G <generator-name>", "Specify a build system generator.", \
"CMake may support multiple native build systems on certain platforms. " \
"A generator is responsible for generating a particular build " \
"system. Possible generator names are specified in the Generators " \
2008-03-11 23:02:10 +03:00
"section."},\
{"-T <toolset-name>", "Specify toolset name if supported by generator.", \
"Some CMake generators support a toolset name to be given to the " \
"native build system to choose a compiler. " \
"This is supported only on specific generators:\n" \
" Visual Studio >= 10\n" \
" Xcode >= 3.0\n" \
"See native build system documentation for allowed toolset names."}, \
2008-03-11 23:02:10 +03:00
{"-Wno-dev", "Suppress developer warnings.",\
"Suppress warnings that are meant for the author"\
" of the CMakeLists.txt files."},\
{"-Wdev", "Enable developer warnings.",\
"Enable warnings that are meant for the author"\
" of the CMakeLists.txt files."}
#define CMAKE_STANDARD_INTRODUCTION \
{0, \
"CMake is a cross-platform build system generator. Projects " \
"specify their build process with platform-independent CMake listfiles " \
2006-05-12 22:36:39 +04:00
"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}
2003-12-23 23:01:10 +03:00
#endif