version num
[cmake.git] / Source / cmMakefile.h
blobcc85c44f14e4e7f14444d79eb4a0555f3d1e6694
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmMakefile.h,v $
5 Language: C++
6 Date: $Date: 2001-07-11 17:30:59 $
7 Version: $Revision: 1.51 $
9 Copyright (c) 2001 Insight Consortium
10 All rights reserved.
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.
40 =========================================================================*/
41 #ifndef cmMakefile_h
42 #define cmMakefile_h
44 #include "cmStandardIncludes.h"
45 #include "cmData.h"
46 #include "cmSourceFile.h"
47 #include "cmSystemTools.h"
48 #include "cmSourceGroup.h"
49 #include "cmTarget.h"
50 class cmFunctionBlocker;
51 class cmCommand;
52 class cmMakefileGenerator;
54 /** \class cmMakefile
55 * \brief Process the input CMakeLists.txt file.
57 * Process and store into memory the input CMakeLists.txt file.
58 * Each CMakeLists.txt file is parsed and the commands found there
59 * are added into the build process.
61 class cmMakefile
63 public:
64 /**
65 * Return major and minor version numbers for cmake.
67 static unsigned int GetMajorVersion() { return 0;}
68 static unsigned int GetMinorVersion() { return 4;}
69 /**
70 * Return the major and minor version of the cmake that
71 * was used to write the currently loaded cache, note
72 * this method will not work before the cache is loaded.
74 static unsigned int GetCacheMajorVersion();
75 static unsigned int GetCacheMinorVersion();
77 /**
78 * Construct an empty makefile.
80 cmMakefile();
82 /**
83 * Destructor.
85 ~cmMakefile();
87 /**
88 * Read and parse a CMakeLists.txt file.
90 bool ReadListFile(const char* listfile, const char* external= 0);
92 /**
93 * Add a wrapper generator.
95 void AddCommand(cmCommand* );
97 /**
98 * Add a function blocker to this makefile
100 void AddFunctionBlocker(cmFunctionBlocker *fb)
101 { m_FunctionBlockers.insert(fb);}
102 void RemoveFunctionBlocker(cmFunctionBlocker *fb)
103 { m_FunctionBlockers.erase(fb);}
104 void RemoveFunctionBlocker(const char *name, const std::vector<std::string> &args);
107 * Specify the makefile generator. This is platform/compiler
108 * dependent, although the interface is through a generic
109 * superclass.
111 void SetMakefileGenerator(cmMakefileGenerator*);
113 ///! Get the current makefile generator.
114 cmMakefileGenerator* GetMakefileGenerator()
115 { return m_MakefileGenerator;}
118 * Produce the output makefile.
120 void GenerateMakefile();
123 * Print the object state to std::cout.
125 void Print() const;
128 * Add a custom command to the build.
130 void AddCustomCommand(const char* source,
131 const char* command,
132 const char* commandArgs,
133 const std::vector<std::string>& depends,
134 const std::vector<std::string>& outputs,
135 const char *target);
137 void AddCustomCommand(const char* source,
138 const char* command,
139 const char* commandArgs,
140 const std::vector<std::string>& depends,
141 const char* output,
142 const char* target);
145 * Add a define flag to the build.
147 void AddDefineFlag(const char* definition);
150 * Add an executable to the build.
152 void AddExecutable(const char *exename,
153 const std::vector<std::string> &srcs);
154 void AddExecutable(const char *exename,
155 const std::vector<std::string> &srcs, bool win32);
158 * Add a utility to the build. A utiltity target is
159 * a command that is run every time a target is built.
161 void AddUtilityCommand(const char* utilityName,
162 const char* command,
163 bool all);
164 void AddUtilityCommand(const char* utilityName,
165 const char* command,
166 bool all,
167 const std::vector<std::string> &depends,
168 const std::vector<std::string> &outputs);
171 * Get a list of link libraries in the build.
173 cmTarget::LinkLibraries& GetLinkLibraries()
175 return m_LinkLibraries;
179 * Add a link library to the build.
181 void AddLinkLibrary(const char*);
182 void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type);
183 void AddLinkLibraryForTarget(const char *tgt, const char*,
184 cmTarget::LinkLibraryType type);
187 * Add a link directory to the build.
189 void AddLinkDirectory(const char*);
192 * Add a subdirectory to the build.
194 void AddSubDirectory(const char*);
197 * Add an include directory to the build.
199 void AddIncludeDirectory(const char*);
202 * Add a variable definition to the build. This variable
203 * can be used in CMake to refer to lists, directories, etc.
205 void AddDefinition(const char* name, const char* value);
208 * Add bool variable definition to the build.
210 void AddDefinition(const char* name, bool);
213 * Specify the name of the project for this build.
215 void SetProjectName(const char*);
218 * Get the name of the project for this build.
220 const char* GetProjectName()
222 return m_ProjectName.c_str();
226 * Set the name of the library.
228 void AddLibrary(const char *libname, bool shared,
229 const std::vector<std::string> &srcs);
232 * Add a class/source file to the build.
234 void AddSource(cmSourceFile& ,const char *srcListName);
237 * Remove a class/source file from the build.
239 void RemoveSource(cmSourceFile& ,const char *srcListName);
242 * Add a source group for consideration when adding a new source.
244 void AddSourceGroup(const char* name, const char* regex);
247 * Add an auxiliary directory to the build.
249 void AddExtraDirectory(const char* dir);
253 * Add an auxiliary directory to the build.
255 void MakeStartDirectoriesCurrent()
257 m_cmCurrentDirectory = m_cmStartDirectory;
258 m_CurrentOutputDirectory = m_StartOutputDirectory;
261 //@{
263 * Set/Get the home directory (or output directory) in the project. The
264 * home directory is the top directory of the project. It is where
265 * CMakeSetup or configure was run. Remember that CMake processes
266 * CMakeLists files by recursing up the tree starting at the StartDirectory
267 * and going up until it reaches the HomeDirectory.
269 void SetHomeDirectory(const char* dir);
270 const char* GetHomeDirectory() const
272 return m_cmHomeDirectory.c_str();
274 void SetHomeOutputDirectory(const char* lib);
275 const char* GetHomeOutputDirectory() const
277 return m_HomeOutputDirectory.c_str();
279 //@}
281 //@{
283 * Set/Get the start directory (or output directory). The start directory
284 * is the directory of the CMakeLists.txt file that started the current
285 * round of processing. Remember that CMake processes CMakeLists files by
286 * recursing up the tree starting at the StartDirectory and going up until
287 * it reaches the HomeDirectory.
289 void SetStartDirectory(const char* dir)
291 m_cmStartDirectory = dir;
292 cmSystemTools::ConvertToUnixSlashes(m_cmStartDirectory);
294 const char* GetStartDirectory() const
296 return m_cmStartDirectory.c_str();
298 void SetStartOutputDirectory(const char* lib)
300 m_StartOutputDirectory = lib;
301 cmSystemTools::ConvertToUnixSlashes(m_StartOutputDirectory);
303 const char* GetStartOutputDirectory() const
305 return m_StartOutputDirectory.c_str();
307 //@}
309 //@{
311 * Set/Get the current directory (or output directory) in the project. The
312 * current directory is the directory of the CMakeLists.txt file that is
313 * currently being processed. Remember that CMake processes CMakeLists
314 * files by recursing up the tree starting at the StartDirectory and going
315 * up until it reaches the HomeDirectory.
317 void SetCurrentDirectory(const char* dir)
319 m_cmCurrentDirectory = dir;
320 cmSystemTools::ConvertToUnixSlashes(m_cmCurrentDirectory);
322 const char* GetCurrentDirectory() const
324 return m_cmCurrentDirectory.c_str();
326 void SetCurrentOutputDirectory(const char* lib)
328 m_CurrentOutputDirectory = lib;
329 cmSystemTools::ConvertToUnixSlashes(m_CurrentOutputDirectory);
331 const char* GetCurrentOutputDirectory() const
333 return m_CurrentOutputDirectory.c_str();
336 /* Get the current CMakeLists.txt file that is being processed. This
337 * is just used in order to be able to 'branch' from one file to a second
338 * transparently */
339 const char* GetCurrentListFile() const
341 return m_cmCurrentListFile.c_str();
344 //@}
346 /**
347 * Set a regular expression that include files must match
348 * in order to be considered as part of the depend information.
350 void SetIncludeRegularExpression(const char* regex)
352 m_IncludeFileRegularExpression = regex;
355 /**
356 * Set a regular expression that include files that are not found
357 * must match in order to be considered a problem.
359 void SetComplainRegularExpression(const char* regex)
361 m_ComplainFileRegularExpression = regex;
365 * Get the list of targets
367 cmTargets &GetTargets() { return m_Targets; }
368 const cmTargets &GetTargets() const { return m_Targets; }
371 * Get a list of the build subdirectories.
373 const std::vector<std::string>& GetSubDirectories()
375 return m_SubDirectories;
379 * Get a list of include directories in the build.
381 std::vector<std::string>& GetIncludeDirectories()
383 return m_IncludeDirectories;
385 const std::vector<std::string>& GetIncludeDirectories() const
387 return m_IncludeDirectories;
391 * Get a list of link directories in the build.
393 std::vector<std::string>& GetLinkDirectories()
395 return m_LinkDirectories;
399 * Return a list of source files in this makefile.
401 typedef std::map<std::string,std::vector<cmSourceFile> > SourceMap;
402 const SourceMap &GetSources() const {return m_Sources;}
403 SourceMap &GetSources() {return m_Sources;}
404 cmSourceFile *GetSource(const char *srclist, const char *sourceName);
407 * Obtain a list of auxiliary source directories.
409 std::vector<std::string>& GetAuxSourceDirectories()
410 {return m_AuxSourceDirectories;}
413 * Given a variable name, return its value (as a string).
415 const char* GetDefinition(const char*);
418 * Get a list of preprocessor define flags.
420 const char* GetDefineFlags()
421 {return m_DefineFlags.c_str();}
424 * Get the vector of used command instances.
426 const std::vector<cmCommand*>& GetUsedCommands() const
427 {return m_UsedCommands;}
430 * Get the vector source groups.
432 const std::vector<cmSourceGroup>& GetSourceGroups() const
433 { return m_SourceGroups; }
436 * Get the vector of list files on which this makefile depends
438 const std::vector<std::string>& GetListFiles() const
439 { return m_ListFiles; }
442 * Dump documentation to a file. If 0 is returned, the
443 * operation failed.
445 int DumpDocumentationToFile(const char *fileName);
448 * Expand all defined varibles in the string.
449 * Defined varibles come from the m_Definitions map.
450 * They are expanded with ${var} where var is the
451 * entry in the m_Definitions map. Also @var@ is
452 * expanded to match autoconf style expansions.
454 void ExpandVariablesInString(std::string& source) const;
455 void ExpandVariablesInString(std::string& source, bool escapeQuotes) const;
458 * Remove any remaining variables in the string. Anything with ${var} or
459 * @var@ will be removed.
461 void RemoveVariablesInString(std::string& source) const;
464 * Expand variables in the makefiles ivars such as link directories etc
466 void ExpandVariables();
468 /** Recursivly read and create a cmMakefile object for
469 * all CMakeLists.txt files in the GetSubDirectories list.
470 * Once the file is found, it ReadListFile is called on
471 * the cmMakefile created for it.
473 void FindSubDirectoryCMakeListsFiles(std::vector<cmMakefile*>& makefiles);
476 * find what source group this source is in
478 cmSourceGroup& FindSourceGroup(const char* source,
479 std::vector<cmSourceGroup> &groups);
481 void RegisterData(cmData*);
482 void RegisterData(const char*, cmData*);
483 cmData* LookupData(const char*) const;
485 protected:
486 std::string m_Prefix;
487 std::vector<std::string> m_AuxSourceDirectories; //
489 std::string m_cmCurrentDirectory;
490 std::string m_CurrentOutputDirectory;
491 std::string m_cmStartDirectory;
492 std::string m_StartOutputDirectory;
493 std::string m_cmHomeDirectory;
494 std::string m_HomeOutputDirectory;
495 std::string m_cmCurrentListFile;
497 std::string m_ProjectName; // project name
499 // libraries, classes, and executables
500 cmTargets m_Targets;
501 SourceMap m_Sources;
503 std::vector<std::string> m_SubDirectories; // list of sub directories
504 std::vector<std::string> m_IncludeDirectories;
505 std::vector<std::string> m_LinkDirectories;
506 std::vector<std::string> m_ListFiles; // list of command files loaded
509 cmTarget::LinkLibraries m_LinkLibraries;
511 std::string m_IncludeFileRegularExpression;
512 std::string m_ComplainFileRegularExpression;
513 std::string m_DefineFlags;
514 std::vector<cmSourceGroup> m_SourceGroups;
515 typedef std::map<std::string, cmCommand*> RegisteredCommandsMap;
516 typedef std::map<std::string, std::string> DefinitionMap;
517 DefinitionMap m_Definitions;
518 RegisteredCommandsMap m_Commands;
519 std::vector<cmCommand*> m_UsedCommands;
520 cmMakefileGenerator* m_MakefileGenerator;
521 bool IsFunctionBlocked(const char *name, std::vector<std::string> &args) const;
523 private:
525 * Get the name of the parent directories CMakeLists file
526 * given a current CMakeLists file name
528 std::string GetParentListFileName(const char *listFileName);
530 void ReadSources(std::ifstream& fin, bool t);
531 friend class cmMakeDepend; // make depend needs direct access
532 // to the m_Sources array
533 void PrintStringVector(const char* s, const std::vector<std::string>& v) const;
534 void AddDefaultCommands();
535 void AddDefaultDefinitions();
536 std::set<cmFunctionBlocker *> m_FunctionBlockers;
538 typedef std::map<std::string, cmData*> DataMap;
539 DataMap m_DataMap;
543 #endif