1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmake.h,v $
6 Date: $Date: 2002-09-26 19:13:11 $
7 Version: $Revision: 1.23 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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.
16 =========================================================================*/
17 // This class represents a cmake invocation. It is the top level class when
18 // running cmake. Most cmake based GUIS should primarily create an instance
19 // of this class and communicate with it.
21 // The basic process for a GUI is as follows:
23 // 1) Create a cmake instance
24 // 2) Set the Home & Start directories, generator, and cmake command. this
25 // can be done using the Set methods or by using SetArgs and passing in
26 // command line arguments.
27 // 3) Load the cache by calling LoadCache (duh)
28 // 4) if you are using command line arguments with -D or -C flags then
29 // call SetCacheArgs (or if for some other reason you want to modify the
31 // 5) Finally call Configure
32 // 6) Let the user change values and go back to step 5
35 // If your GUI allows the user to change the start & home directories then
36 // you must at a minimum redo steps 2 through 7.
40 #include "cmStandardIncludes.h"
41 #include "cmSystemTools.h"
43 class cmGlobalGenerator
;
44 class cmLocalGenerator
;
52 ///! construct an instance of cmake
54 ///! destruct an instance of cmake
58 * Return major and minor version numbers for cmake.
60 static unsigned int GetMajorVersion();
61 static unsigned int GetMinorVersion();
62 static const char *GetReleaseVersion();
66 * Set/Get the home directory (or output directory) in the project. The
67 * home directory is the top directory of the project. It is where
68 * cmake was run. Remember that CMake processes
69 * CMakeLists files by recursing up the tree starting at the StartDirectory
70 * and going up until it reaches the HomeDirectory.
72 void SetHomeDirectory(const char* dir
);
73 const char* GetHomeDirectory() const
75 return m_cmHomeDirectory
.c_str();
77 void SetHomeOutputDirectory(const char* lib
);
78 const char* GetHomeOutputDirectory() const
80 return m_HomeOutputDirectory
.c_str();
86 * Set/Get the start directory (or output directory). The start directory
87 * is the directory of the CMakeLists.txt file that started the current
88 * round of processing. Remember that CMake processes CMakeLists files by
89 * recursing up the tree starting at the StartDirectory and going up until
90 * it reaches the HomeDirectory.
92 void SetStartDirectory(const char* dir
)
94 m_cmStartDirectory
= dir
;
95 cmSystemTools::ConvertToUnixSlashes(m_cmStartDirectory
);
97 const char* GetStartDirectory() const
99 return m_cmStartDirectory
.c_str();
101 void SetStartOutputDirectory(const char* lib
)
103 m_StartOutputDirectory
= lib
;
104 cmSystemTools::ConvertToUnixSlashes(m_StartOutputDirectory
);
106 const char* GetStartOutputDirectory() const
108 return m_StartOutputDirectory
.c_str();
113 * Dump documentation to a file. If 0 is returned, the
116 int DumpDocumentationToFile(std::ostream
&);
119 * Handle a command line invocation of cmake.
121 int Run(const std::vector
<std::string
>&args
);
124 * Generate the SourceFilesList from the SourceLists. This should only be
125 * done once to be safe. The argument is a list of command line
126 * arguments. The first argument should be the name or full path
127 * to the command line version of cmake. For building a GUI,
128 * you would pass in the following arguments:
129 * /path/to/cmake -H/path/to/source -B/path/to/build
130 * If you only want to parse the CMakeLists.txt files,
131 * but not actually generate the makefiles, use buildMakefiles = false.
136 * Configure the cmMakefiles. This routine will create a GlobalGenerator if
137 * one has not already been set. It will then Call Configure on the
138 * GlobalGenerator. This in turn will read in an process all the CMakeList
139 * files for the tree. It will not produce any actual Makefiles, or
140 * workspaces. Generate does that. */
144 * Configure the cmMakefiles. This routine will create a GlobalGenerator if
145 * one has not already been set. It will then Call Configure on the
146 * GlobalGenerator. This in turn will read in an process all the CMakeList
147 * files for the tree. It will not produce any actual Makefiles, or
148 * workspaces. Generate does that. */
151 ///! Create a GlobalGenerator
152 cmGlobalGenerator
* CreateGlobalGenerator(const char* name
);
154 ///! Return the global generator assigned to this instance of cmake
155 cmGlobalGenerator
* GetGlobalGenerator() { return m_GlobalGenerator
; };
157 ///! Return the global generator assigned to this instance of cmake
158 void SetGlobalGenerator(cmGlobalGenerator
*);
160 ///! Get the names of the current registered generators
161 void GetRegisteredGenerators(std::vector
<std::string
>& names
);
163 ///! get the cmCachemManager used by this invocation of cmake
164 cmCacheManager
*GetCacheManager() { return m_CacheManager
; }
166 ///! set the cmake command this instance of cmake should use
167 void SetCMakeCommand(const char* cmd
) { m_CMakeCommand
= cmd
; }
170 * Given a variable name, return its value (as a string).
172 const char* GetCacheDefinition(const char*) const;
175 * Execute commands during the build process. Supports options such
176 * as echo, remove file etc.
178 static int CMakeCommand(std::vector
<std::string
>&);
181 * Add a command to this cmake instance
183 void AddCommand(cmCommand
* );
186 * Get a command by its name
188 cmCommand
*GetCommand(const char *name
);
190 /** Check if a command exists. */
191 bool CommandExists(const char* name
) const;
194 * Is cmake in the process of a local cmake invocation. If so, we know the
195 * cache is already configured and ready to go.
197 bool GetLocal() { return m_Local
; }
199 ///! Display command line useage
200 void Usage(const char *program
);
202 ///! Parse command line arguments
203 void SetArgs(const std::vector
<std::string
>&);
205 ///! Is this cmake running as a result of a TRY_COMPILE command
206 bool GetIsInTryCompile() { return m_InTryCompile
; }
208 ///! Is this cmake running as a result of a TRY_COMPILE command
209 void SetIsInTryCompile(bool i
) { m_InTryCompile
= i
; }
211 ///! Parse command line arguments that might set cache values
212 void SetCacheArgs(const std::vector
<std::string
>&);
214 typedef void (*ProgressCallback
)(const char*msg
, float progress
, void *);
216 * Set the function used by GUI's to receive progress updates
217 * Function gets passed: message as a const char*, a progress
218 * amount ranging from 0 to 1.0 and client data. The progress
219 * number provided may be negative in cases where a message is
220 * to be displayed without any progress percentage.
222 void SetProgressCallback(ProgressCallback f
, void* clientData
=0);
224 ///! this is called by generators to update the progress
225 void UpdateProgress(const char *msg
, float prog
);
228 typedef std::map
<cmStdString
, cmCommand
*> RegisteredCommandsMap
;
229 RegisteredCommandsMap m_Commands
;
230 void AddDefaultCommands();
232 cmGlobalGenerator
*m_GlobalGenerator
;
233 cmCacheManager
*m_CacheManager
;
234 std::string m_cmHomeDirectory
;
235 std::string m_HomeOutputDirectory
;
236 std::string m_cmStartDirectory
;
237 std::string m_StartOutputDirectory
;
239 ///! read in a cmake list file to initialize the cache
240 void ReadListFile(const char *path
);
246 * Generate CMAKE_ROOT and CMAKE_COMMAND cache entries
248 int AddCMakePaths(const char *arg0
);
251 ProgressCallback m_ProgressCallback
;
252 void* m_ProgressCallbackClientData
;
256 std::string m_CMakeCommand
;