2001-05-18 23:25:08 +04:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2001-05-18 23:25:08 +04:00
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
2002-01-21 23:30:43 +03:00
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
2001-05-18 23:25:08 +04:00
|
|
|
|
|
|
|
=========================================================================*/
|
2002-08-28 22:51:10 +04:00
|
|
|
// This class represents a cmake invocation. It is the top level class when
|
|
|
|
// running cmake. Most cmake based GUIS should primarily create an instance
|
|
|
|
// of this class and communicate with it.
|
2002-09-17 22:12:03 +04:00
|
|
|
//
|
|
|
|
// The basic process for a GUI is as follows:
|
|
|
|
//
|
|
|
|
// 1) Create a cmake instance
|
|
|
|
// 2) 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.
|
|
|
|
// 3) Load the cache by calling LoadCache (duh)
|
|
|
|
// 4) 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.
|
|
|
|
// 5) Finally call Configure
|
|
|
|
// 6) Let the user change values and go back to step 5
|
|
|
|
// 7) 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.
|
|
|
|
//
|
|
|
|
|
2001-05-18 23:25:08 +04:00
|
|
|
|
2004-10-04 20:31:09 +04:00
|
|
|
#ifndef cmake_h
|
|
|
|
#define cmake_h
|
|
|
|
|
2002-09-06 21:06:23 +04:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
|
|
|
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;
|
2001-05-18 23:25:08 +04:00
|
|
|
|
2002-08-24 00:13:34 +04:00
|
|
|
class cmake
|
2001-05-18 23:25:08 +04:00
|
|
|
{
|
|
|
|
public:
|
2003-08-04 04:47:44 +04:00
|
|
|
typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
|
|
|
|
|
2002-09-06 21:06:23 +04:00
|
|
|
///! construct an instance of cmake
|
|
|
|
cmake();
|
|
|
|
///! destruct an instance of cmake
|
|
|
|
~cmake();
|
2001-05-18 23:25:08 +04:00
|
|
|
|
|
|
|
/**
|
2002-09-06 21:06:23 +04:00
|
|
|
* Return major and minor version numbers for cmake.
|
2001-05-18 23:25:08 +04:00
|
|
|
*/
|
2002-09-06 21:06:23 +04:00
|
|
|
static unsigned int GetMajorVersion();
|
|
|
|
static unsigned int GetMinorVersion();
|
|
|
|
static const char *GetReleaseVersion();
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
* Set/Get the home directory (or output directory) in the project. The
|
|
|
|
* home directory is the top directory of the project. It is where
|
|
|
|
* cmake was run. Remember that CMake processes
|
|
|
|
* CMakeLists files by recursing up the tree starting at the StartDirectory
|
|
|
|
* and going up until it reaches the HomeDirectory.
|
|
|
|
*/
|
|
|
|
void SetHomeDirectory(const char* dir);
|
|
|
|
const char* GetHomeDirectory() const
|
|
|
|
{
|
|
|
|
return m_cmHomeDirectory.c_str();
|
|
|
|
}
|
|
|
|
void SetHomeOutputDirectory(const char* lib);
|
|
|
|
const char* GetHomeOutputDirectory() const
|
|
|
|
{
|
|
|
|
return m_HomeOutputDirectory.c_str();
|
|
|
|
}
|
|
|
|
//@}
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void SetStartDirectory(const char* dir)
|
|
|
|
{
|
|
|
|
m_cmStartDirectory = dir;
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(m_cmStartDirectory);
|
|
|
|
}
|
|
|
|
const char* GetStartDirectory() const
|
|
|
|
{
|
|
|
|
return m_cmStartDirectory.c_str();
|
|
|
|
}
|
|
|
|
void SetStartOutputDirectory(const char* lib)
|
|
|
|
{
|
|
|
|
m_StartOutputDirectory = lib;
|
|
|
|
cmSystemTools::ConvertToUnixSlashes(m_StartOutputDirectory);
|
|
|
|
}
|
|
|
|
const char* GetStartOutputDirectory() const
|
|
|
|
{
|
|
|
|
return m_StartOutputDirectory.c_str();
|
|
|
|
}
|
|
|
|
//@}
|
|
|
|
|
2002-09-11 00:51:29 +04:00
|
|
|
/**
|
|
|
|
* Dump documentation to a file. If 0 is returned, the
|
|
|
|
* operation failed.
|
|
|
|
*/
|
|
|
|
int DumpDocumentationToFile(std::ostream&);
|
|
|
|
|
2002-09-06 21:06:23 +04:00
|
|
|
/**
|
|
|
|
* Handle a command line invocation of cmake.
|
|
|
|
*/
|
2003-04-29 18:04:05 +04:00
|
|
|
int Run(const std::vector<std::string>&args)
|
2003-04-30 15:32:30 +04:00
|
|
|
{ return this->Run(args, false); }
|
2003-04-29 18:04:05 +04:00
|
|
|
int Run(const std::vector<std::string>&args, bool noconfigure);
|
2001-05-18 23:25:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the SourceFilesList from the SourceLists. This should only be
|
2001-05-30 23:28:55 +04:00
|
|
|
* done once to be safe. The argument is a list of command line
|
|
|
|
* arguments. The first argument should be the name or full path
|
|
|
|
* to the command line version of cmake. For building a GUI,
|
|
|
|
* you would pass in the following arguments:
|
|
|
|
* /path/to/cmake -H/path/to/source -B/path/to/build
|
2001-07-26 02:30:27 +04:00
|
|
|
* If you only want to parse the CMakeLists.txt files,
|
|
|
|
* but not actually generate the makefiles, use buildMakefiles = false.
|
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();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-11-07 17:04:20 +03:00
|
|
|
int LoadCache();
|
2004-08-17 23:36:08 +04:00
|
|
|
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 m_GlobalGenerator; };
|
|
|
|
|
|
|
|
///! 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);
|
|
|
|
|
|
|
|
///! get the cmCachemManager used by this invocation of cmake
|
|
|
|
cmCacheManager *GetCacheManager() { return m_CacheManager; }
|
|
|
|
|
2002-09-17 21:59:58 +04:00
|
|
|
///! set the cmake command this instance of cmake should use
|
|
|
|
void SetCMakeCommand(const char* cmd) { m_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,
|
|
|
|
int type);
|
2002-06-03 21:08:52 +04:00
|
|
|
/**
|
|
|
|
* Execute commands during the build process. Supports options such
|
|
|
|
* as echo, remove file etc.
|
|
|
|
*/
|
|
|
|
static int CMakeCommand(std::vector<std::string>&);
|
|
|
|
|
2002-09-11 00:51:29 +04:00
|
|
|
/**
|
|
|
|
* Add a command to this cmake instance
|
|
|
|
*/
|
|
|
|
void AddCommand(cmCommand* );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a command by its name
|
|
|
|
*/
|
|
|
|
cmCommand *GetCommand(const char *name);
|
|
|
|
|
2003-08-04 04:47:44 +04:00
|
|
|
/** Get list of all commands */
|
|
|
|
RegisteredCommandsMap* GetCommands() { return &m_Commands; }
|
|
|
|
|
2002-09-11 00:51:29 +04:00
|
|
|
/** Check if a command exists. */
|
|
|
|
bool CommandExists(const char* name) const;
|
|
|
|
|
2002-09-06 21:06:23 +04:00
|
|
|
/**
|
|
|
|
* Is cmake in the process of a local cmake invocation. If so, we know the
|
|
|
|
* cache is already configured and ready to go.
|
|
|
|
*/
|
2002-09-17 21:59:58 +04:00
|
|
|
bool GetLocal() { return m_Local; }
|
2002-09-06 21:06:23 +04:00
|
|
|
|
2001-11-21 01:51:03 +03:00
|
|
|
///! Parse command line arguments
|
2002-09-06 21:06:23 +04:00
|
|
|
void SetArgs(const std::vector<std::string>&);
|
|
|
|
|
2002-09-12 19:08:06 +04:00
|
|
|
///! Is this cmake running as a result of a TRY_COMPILE command
|
|
|
|
bool GetIsInTryCompile() { return m_InTryCompile; }
|
|
|
|
|
|
|
|
///! Is this cmake running as a result of a TRY_COMPILE command
|
|
|
|
void SetIsInTryCompile(bool i) { m_InTryCompile = i; }
|
|
|
|
|
2002-09-17 21:59:58 +04:00
|
|
|
///! Parse command line arguments that might set cache values
|
2003-10-29 17:45:26 +03:00
|
|
|
bool SetCacheArgs(const std::vector<std::string>&);
|
2002-09-13 21:48:14 +04:00
|
|
|
|
2002-09-26 23:14:20 +04:00
|
|
|
typedef void (*ProgressCallback)(const char*msg, float progress, void *);
|
|
|
|
/**
|
|
|
|
* Set the function used by GUI's to receive progress updates
|
|
|
|
* Function gets passed: message as a const char*, a progress
|
|
|
|
* amount ranging from 0 to 1.0 and client data. The progress
|
|
|
|
* number provided may be negative in cases where a message is
|
|
|
|
* to be displayed without any progress percentage.
|
|
|
|
*/
|
|
|
|
void SetProgressCallback(ProgressCallback f, void* clientData=0);
|
|
|
|
|
|
|
|
///! this is called by generators to update the progress
|
|
|
|
void UpdateProgress(const char *msg, float prog);
|
|
|
|
|
2003-01-08 20:59:52 +03:00
|
|
|
|
|
|
|
///! Get the variable watch object
|
|
|
|
cmVariableWatch* GetVariableWatch() { return m_VariableWatch; }
|
|
|
|
|
2003-02-14 18:53:37 +03:00
|
|
|
void GetCommandDocumentation(std::vector<cmDocumentationEntry>&) const;
|
2003-07-08 05:52:10 +04:00
|
|
|
void GetGeneratorDocumentation(std::vector<cmDocumentationEntry>&);
|
2003-05-29 19:14:05 +04:00
|
|
|
|
|
|
|
///! Do all the checks before running configure
|
|
|
|
int DoPreConfigureChecks();
|
2003-10-29 17:45:26 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set and get the script mode option. In script mode there is no generator
|
|
|
|
* and no cache. Also, language are not enabled, so add_executable and things
|
|
|
|
* do not do anything.
|
|
|
|
*/
|
|
|
|
void SetScriptMode(bool mode) { m_ScriptMode = mode; }
|
|
|
|
bool GetScriptMode() { return m_ScriptMode; }
|
2003-02-14 18:53:37 +03:00
|
|
|
|
2003-12-23 23:01:10 +03:00
|
|
|
///! Debug the try compile stuff by not delelting the files
|
|
|
|
bool GetDebugTryCompile(){return m_DebugTryCompile;}
|
|
|
|
void DebugTryCompileOn(){m_DebugTryCompile = true;}
|
2004-04-18 22:41:46 +04:00
|
|
|
|
|
|
|
///! Get the list of files written by CMake using FILE(WRITE / WRITE_FILE
|
|
|
|
void AddWrittenFile(const char* file);
|
|
|
|
bool HasWrittenFile(const char* file);
|
2004-04-26 19:23:06 +04:00
|
|
|
void CleanupWrittenFiles();
|
2004-04-18 22:41:46 +04:00
|
|
|
|
2002-09-06 21:06:23 +04:00
|
|
|
protected:
|
2003-07-08 05:52:10 +04:00
|
|
|
typedef cmGlobalGenerator* (*CreateGeneratorFunctionType)();
|
|
|
|
typedef std::map<cmStdString, CreateGeneratorFunctionType> RegisteredGeneratorsMap;
|
2002-09-11 00:51:29 +04:00
|
|
|
RegisteredCommandsMap m_Commands;
|
2003-07-08 05:52:10 +04:00
|
|
|
RegisteredGeneratorsMap m_Generators;
|
2002-09-11 00:51:29 +04:00
|
|
|
void AddDefaultCommands();
|
2003-07-08 05:52:10 +04:00
|
|
|
void AddDefaultGenerators();
|
2002-09-11 00:51:29 +04:00
|
|
|
|
2002-09-06 21:06:23 +04:00
|
|
|
cmGlobalGenerator *m_GlobalGenerator;
|
|
|
|
cmCacheManager *m_CacheManager;
|
|
|
|
std::string m_cmHomeDirectory;
|
|
|
|
std::string m_HomeOutputDirectory;
|
|
|
|
std::string m_cmStartDirectory;
|
|
|
|
std::string m_StartOutputDirectory;
|
|
|
|
|
2004-04-18 22:41:46 +04:00
|
|
|
std::set<cmStdString> m_WrittenFiles;
|
|
|
|
|
2002-11-13 23:20:20 +03:00
|
|
|
///! return true if the same cmake was used to make the cache.
|
|
|
|
bool CacheVersionMatches();
|
2002-09-06 21:06:23 +04:00
|
|
|
///! read in a cmake list file to initialize the cache
|
|
|
|
void ReadListFile(const char *path);
|
|
|
|
|
|
|
|
///! used by Run
|
|
|
|
int LocalGenerate();
|
2004-10-15 17:24:44 +04:00
|
|
|
int CheckRerun();
|
2002-08-28 22:51:10 +04:00
|
|
|
|
2002-09-17 21:59:58 +04:00
|
|
|
/**
|
|
|
|
* Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
|
|
|
|
*/
|
|
|
|
int AddCMakePaths(const char *arg0);
|
|
|
|
|
2003-08-06 00:36:15 +04:00
|
|
|
void SetDirectoriesFromFile(const char* arg);
|
|
|
|
|
2003-01-08 20:59:52 +03:00
|
|
|
cmVariableWatch* m_VariableWatch;
|
|
|
|
|
2001-09-07 01:28:24 +04:00
|
|
|
private:
|
2002-09-26 23:14:20 +04:00
|
|
|
ProgressCallback m_ProgressCallback;
|
|
|
|
void* m_ProgressCallbackClientData;
|
2001-05-18 23:25:08 +04:00
|
|
|
bool m_Verbose;
|
|
|
|
bool m_Local;
|
2002-09-12 19:08:06 +04:00
|
|
|
bool m_InTryCompile;
|
2003-10-29 17:45:26 +03:00
|
|
|
bool m_ScriptMode;
|
2002-09-17 21:59:58 +04:00
|
|
|
std::string m_CMakeCommand;
|
2004-01-26 21:32:46 +03:00
|
|
|
std::string m_CXXEnvironment;
|
|
|
|
std::string m_CCEnvironment;
|
2004-10-15 17:24:44 +04:00
|
|
|
std::string m_CheckRerun;
|
2003-12-23 23:01:10 +03:00
|
|
|
bool m_DebugTryCompile;
|
2004-10-04 20:31:09 +04:00
|
|
|
|
|
|
|
void UpdateConversionPathTable();
|
2001-05-18 23:25:08 +04:00
|
|
|
};
|
|
|
|
|
2003-04-03 07:48:12 +04:00
|
|
|
#define CMAKE_STANDARD_OPTIONS_TABLE \
|
|
|
|
{"-C<initial-cache>", "Pre-load cmake cache from given file.", \
|
|
|
|
"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."}, \
|
|
|
|
{"-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."}, \
|
|
|
|
{"-G<generator-name>", "Specify a makefile generator.", \
|
|
|
|
"CMake may support multiple native build systems on certain platforms. " \
|
|
|
|
"A makefile generator is responsible for generating a particular build " \
|
2003-07-11 07:22:09 +04:00
|
|
|
"system. Possible generator names are specified in the Generators " \
|
|
|
|
"section."}
|
2003-07-11 07:14:49 +04:00
|
|
|
|
|
|
|
#define CMAKE_STANDARD_INTRODUCTION \
|
|
|
|
{0, \
|
|
|
|
"CMake is a cross-platform build system generator. Projects " \
|
|
|
|
"specify their build process with platform-independent CMake listfiles " \
|
|
|
|
"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
|