2001-05-18 19:25:08 +00:00
|
|
|
/*=========================================================================
|
|
|
|
|
|
|
|
Program: Insight Segmentation & Registration Toolkit
|
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-01-21 20:30:43 +00:00
|
|
|
Copyright (c) 2002 Insight Consortium. All rights reserved.
|
|
|
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
|
|
|
|
|
|
|
|
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 19:25:08 +00:00
|
|
|
|
|
|
|
=========================================================================*/
|
2002-08-28 18:51:10 +00: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.
|
2001-05-18 19:25:08 +00:00
|
|
|
|
|
|
|
#include "cmStandardIncludes.h"
|
2002-09-06 17:06:23 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
|
|
|
class cmGlobalGenerator;
|
|
|
|
class cmLocalGenerator;
|
|
|
|
class cmCacheManager;
|
|
|
|
class cmMakefile;
|
2002-09-10 20:51:29 +00:00
|
|
|
class cmCommand;
|
2001-05-18 19:25:08 +00:00
|
|
|
|
2002-08-23 20:13:34 +00:00
|
|
|
class cmake
|
2001-05-18 19:25:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2002-09-06 17:06:23 +00:00
|
|
|
///! construct an instance of cmake
|
|
|
|
cmake();
|
|
|
|
///! destruct an instance of cmake
|
|
|
|
~cmake();
|
2001-05-18 19:25:08 +00:00
|
|
|
|
|
|
|
/**
|
2002-09-06 17:06:23 +00:00
|
|
|
* Return major and minor version numbers for cmake.
|
2001-05-18 19:25:08 +00:00
|
|
|
*/
|
2002-09-06 17:06:23 +00: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-10 20:51:29 +00:00
|
|
|
/**
|
|
|
|
* Dump documentation to a file. If 0 is returned, the
|
|
|
|
* operation failed.
|
|
|
|
*/
|
|
|
|
int DumpDocumentationToFile(std::ostream&);
|
|
|
|
|
2002-09-06 17:06:23 +00:00
|
|
|
/**
|
|
|
|
* Handle a command line invocation of cmake.
|
|
|
|
*/
|
|
|
|
int Run(const std::vector<std::string>&args);
|
2001-05-18 19:25:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the SourceFilesList from the SourceLists. This should only be
|
2001-05-30 19:28:55 +00: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-25 22:30:27 +00:00
|
|
|
* If you only want to parse the CMakeLists.txt files,
|
|
|
|
* but not actually generate the makefiles, use buildMakefiles = false.
|
2001-05-18 19:25:08 +00:00
|
|
|
*/
|
2002-09-06 17:06:23 +00: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 17:59:58 +00: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. */
|
|
|
|
int LoadCache();
|
2002-09-06 17:06:23 +00: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 17:59:58 +00:00
|
|
|
///! set the cmake command this instance of cmake should use
|
|
|
|
void SetCMakeCommand(const char* cmd) { m_CMakeCommand = cmd; }
|
|
|
|
|
2002-09-06 17:06:23 +00:00
|
|
|
/**
|
|
|
|
* Given a variable name, return its value (as a string).
|
|
|
|
*/
|
|
|
|
const char* GetCacheDefinition(const char*) const;
|
2001-05-18 19:25:08 +00:00
|
|
|
|
2002-06-03 17:08:52 +00:00
|
|
|
/**
|
|
|
|
* Execute commands during the build process. Supports options such
|
|
|
|
* as echo, remove file etc.
|
|
|
|
*/
|
|
|
|
static int CMakeCommand(std::vector<std::string>&);
|
|
|
|
|
2002-09-10 20:51:29 +00:00
|
|
|
/**
|
|
|
|
* Add a command to this cmake instance
|
|
|
|
*/
|
|
|
|
void AddCommand(cmCommand* );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a command by its name
|
|
|
|
*/
|
|
|
|
cmCommand *GetCommand(const char *name);
|
|
|
|
|
|
|
|
/** Check if a command exists. */
|
|
|
|
bool CommandExists(const char* name) const;
|
|
|
|
|
2002-09-06 17:06:23 +00: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 17:59:58 +00:00
|
|
|
bool GetLocal() { return m_Local; }
|
2002-09-06 17:06:23 +00:00
|
|
|
|
|
|
|
///! Display command line useage
|
|
|
|
void Usage(const char *program);
|
|
|
|
|
2001-11-20 22:51:03 +00:00
|
|
|
///! Parse command line arguments
|
2002-09-06 17:06:23 +00:00
|
|
|
void SetArgs(const std::vector<std::string>&);
|
|
|
|
|
2002-09-12 15:08:06 +00: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 17:59:58 +00:00
|
|
|
///! Parse command line arguments that might set cache values
|
|
|
|
void SetCacheArgs(const std::vector<std::string>&);
|
2002-09-13 17:48:14 +00:00
|
|
|
|
2002-09-06 17:06:23 +00:00
|
|
|
protected:
|
2002-09-10 20:51:29 +00:00
|
|
|
typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
|
|
|
|
RegisteredCommandsMap m_Commands;
|
|
|
|
void AddDefaultCommands();
|
|
|
|
|
2002-09-06 17:06:23 +00:00
|
|
|
cmGlobalGenerator *m_GlobalGenerator;
|
|
|
|
cmCacheManager *m_CacheManager;
|
|
|
|
std::string m_cmHomeDirectory;
|
|
|
|
std::string m_HomeOutputDirectory;
|
|
|
|
std::string m_cmStartDirectory;
|
|
|
|
std::string m_StartOutputDirectory;
|
|
|
|
|
|
|
|
///! read in a cmake list file to initialize the cache
|
|
|
|
void ReadListFile(const char *path);
|
|
|
|
|
|
|
|
///! used by Run
|
|
|
|
int LocalGenerate();
|
2002-08-28 18:51:10 +00:00
|
|
|
|
2002-09-17 17:59:58 +00:00
|
|
|
/**
|
|
|
|
* Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
|
|
|
|
*/
|
|
|
|
int AddCMakePaths(const char *arg0);
|
|
|
|
|
2001-09-06 21:28:24 +00:00
|
|
|
private:
|
2001-05-18 19:25:08 +00:00
|
|
|
bool m_Verbose;
|
|
|
|
bool m_Local;
|
2002-09-12 15:08:06 +00:00
|
|
|
bool m_InTryCompile;
|
2002-09-17 17:59:58 +00:00
|
|
|
std::string m_CMakeCommand;
|
2001-05-18 19:25:08 +00:00
|
|
|
};
|
|
|
|
|