FIX: stupid pb fixed (close to being medieval'ed by The Ken)
[cmake.git] / Source / cmMakefile.h
blob1f2bea259b2b8be7d87d08d65f2e9ed10601ac08
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmMakefile.h,v $
5 Language: C++
6 Date: $Date: 2002-07-10 15:38:38 $
7 Version: $Revision: 1.105 $
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 #ifndef cmMakefile_h
18 #define cmMakefile_h
20 #include "cmStandardIncludes.h"
21 #include "cmData.h"
22 #include "cmSourceFile.h"
23 #include "cmSystemTools.h"
24 #include "cmSourceGroup.h"
25 #include "cmTarget.h"
26 #include "cmCacheManager.h"
28 class cmFunctionBlocker;
29 class cmCommand;
30 class cmMakefileGenerator;
31 class cmMakeDepend;
33 /** \class cmMakefile
34 * \brief Process the input CMakeLists.txt file.
36 * Process and store into memory the input CMakeLists.txt file.
37 * Each CMakeLists.txt file is parsed and the commands found there
38 * are added into the build process.
40 class cmMakefile
42 public:
43 /**
44 * Return major and minor version numbers for cmake.
46 static unsigned int GetMajorVersion() { return 1;}
47 static unsigned int GetMinorVersion() { return 5;}
48 static const char *GetReleaseVersion() { return "development";}
50 /**
51 * Return the major and minor version of the cmake that
52 * was used to write the currently loaded cache, note
53 * this method will not work before the cache is loaded.
55 static unsigned int GetCacheMajorVersion();
56 static unsigned int GetCacheMinorVersion();
58 /**
59 * Construct an empty makefile.
61 cmMakefile();
63 /**
64 * Destructor.
66 ~cmMakefile();
68 /**
69 * Read and parse a CMakeLists.txt file.
71 bool ReadListFile(const char* listfile, const char* external= 0);
73 /**
74 * Add a wrapper generator.
76 void AddCommand(cmCommand* );
78 /**
79 * Add a function blocker to this makefile
81 void AddFunctionBlocker(cmFunctionBlocker *fb)
82 { m_FunctionBlockers.push_back(fb);}
83 void RemoveFunctionBlocker(cmFunctionBlocker *fb)
84 { m_FunctionBlockers.remove(fb);}
85 void RemoveFunctionBlocker(const char *name, const std::vector<std::string> &args);
87 /**
88 * Specify the makefile generator. This is platform/compiler
89 * dependent, although the interface is through a generic
90 * superclass.
92 void SetMakefileGenerator(cmMakefileGenerator*);
94 ///! Get the current makefile generator.
95 cmMakefileGenerator* GetMakefileGenerator()
96 { return m_MakefileGenerator;}
98 /**
99 * Produce the output makefile.
101 void GenerateMakefile();
104 * run the final pass on all commands.
106 void FinalPass();
109 * Print the object state to std::cout.
111 void Print() const;
114 * Add a custom command to the build.
116 void AddCustomCommand(const char* source,
117 const char* command,
118 const std::vector<std::string>& commandArgs,
119 const std::vector<std::string>& depends,
120 const std::vector<std::string>& outputs,
121 const char *target);
123 void AddCustomCommand(const char* source,
124 const char* command,
125 const std::vector<std::string>& commandArgs,
126 const std::vector<std::string>& depends,
127 const char* output,
128 const char* target);
131 * Add a define flag to the build.
133 void AddDefineFlag(const char* definition);
136 * Add an executable to the build.
138 void AddExecutable(const char *exename,
139 const std::vector<std::string> &srcs);
140 void AddExecutable(const char *exename,
141 const std::vector<std::string> &srcs, bool win32);
144 * Add a utility to the build. A utiltity target is
145 * a command that is run every time a target is built.
147 void AddUtilityCommand(const char* utilityName,
148 const char* command,
149 const char* arguments,
150 bool all);
151 void AddUtilityCommand(const char* utilityName,
152 const char* command,
153 const char* arguments,
154 bool all,
155 const std::vector<std::string> &depends,
156 const std::vector<std::string> &outputs);
159 * Add a link library to the build.
161 void AddLinkLibrary(const char*);
162 void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type);
163 void AddLinkLibraryForTarget(const char *tgt, const char*,
164 cmTarget::LinkLibraryType type);
165 void AddLinkDirectoryForTarget(const char *tgt, const char* d);
168 * Add a link directory to the build.
170 void AddLinkDirectory(const char*);
173 * Add a subdirectory to the build.
175 void AddSubDirectory(const char*);
178 * Add an include directory to the build.
180 void AddIncludeDirectory(const char*, bool before = false);
183 * Add a variable definition to the build. This variable
184 * can be used in CMake to refer to lists, directories, etc.
186 void AddDefinition(const char* name, const char* value);
187 ///! Add a definition to this makefile and the global cmake cache.
188 void AddCacheDefinition(const char* name, const char* value,
189 const char* doc,
190 cmCacheManager::CacheEntryType type);
193 * Add bool variable definition to the build.
195 void AddDefinition(const char* name, bool);
196 ///! Add a definition to this makefile and the global cmake cache.
197 void AddCacheDefinition(const char* name, bool, const char* doc);
200 * Specify the name of the project for this build.
202 void SetProjectName(const char*);
205 * Get the name of the project for this build.
207 const char* GetProjectName()
209 return m_ProjectName.c_str();
213 * Set the name of the library.
215 void AddLibrary(const char *libname, int shared,
216 const std::vector<std::string> &srcs);
219 * Add a class/source file to the build.
221 //void AddSource(cmSourceFile& ,const char *srcListName);
224 * Remove a class/source file from the build.
226 //void RemoveSource(cmSourceFile& ,const char *srcListName);
229 * Add a source group for consideration when adding a new source.
231 void AddSourceGroup(const char* name, const char* regex);
234 * Add an auxiliary directory to the build.
236 void AddExtraDirectory(const char* dir);
240 * Add an auxiliary directory to the build.
242 void MakeStartDirectoriesCurrent()
244 m_cmCurrentDirectory = m_cmStartDirectory;
245 m_CurrentOutputDirectory = m_StartOutputDirectory;
248 //@{
250 * Set/Get the home directory (or output directory) in the project. The
251 * home directory is the top directory of the project. It is where
252 * CMakeSetup or configure was run. Remember that CMake processes
253 * CMakeLists files by recursing up the tree starting at the StartDirectory
254 * and going up until it reaches the HomeDirectory.
256 void SetHomeDirectory(const char* dir);
257 const char* GetHomeDirectory() const
259 return m_cmHomeDirectory.c_str();
261 void SetHomeOutputDirectory(const char* lib);
262 const char* GetHomeOutputDirectory() const
264 return m_HomeOutputDirectory.c_str();
266 //@}
268 //@{
270 * Set/Get the start directory (or output directory). The start directory
271 * is the directory of the CMakeLists.txt file that started the current
272 * round of processing. Remember that CMake processes CMakeLists files by
273 * recursing up the tree starting at the StartDirectory and going up until
274 * it reaches the HomeDirectory.
276 void SetStartDirectory(const char* dir)
278 m_cmStartDirectory = dir;
279 cmSystemTools::ConvertToUnixSlashes(m_cmStartDirectory);
281 const char* GetStartDirectory() const
283 return m_cmStartDirectory.c_str();
285 void SetStartOutputDirectory(const char* lib)
287 m_StartOutputDirectory = lib;
288 cmSystemTools::ConvertToUnixSlashes(m_StartOutputDirectory);
289 cmSystemTools::MakeDirectory(m_StartOutputDirectory.c_str());
291 const char* GetStartOutputDirectory() const
293 return m_StartOutputDirectory.c_str();
295 //@}
297 //@{
299 * Set/Get the current directory (or output directory) in the project. The
300 * current directory is the directory of the CMakeLists.txt file that is
301 * currently being processed. Remember that CMake processes CMakeLists
302 * files by recursing up the tree starting at the StartDirectory and going
303 * up until it reaches the HomeDirectory.
305 void SetCurrentDirectory(const char* dir)
307 m_cmCurrentDirectory = dir;
308 cmSystemTools::ConvertToUnixSlashes(m_cmCurrentDirectory);
310 const char* GetCurrentDirectory() const
312 return m_cmCurrentDirectory.c_str();
314 void SetCurrentOutputDirectory(const char* lib)
316 m_CurrentOutputDirectory = lib;
317 cmSystemTools::ConvertToUnixSlashes(m_CurrentOutputDirectory);
319 const char* GetCurrentOutputDirectory() const
321 return m_CurrentOutputDirectory.c_str();
324 /* Get the current CMakeLists.txt file that is being processed. This
325 * is just used in order to be able to 'branch' from one file to a second
326 * transparently */
327 const char* GetCurrentListFile() const
329 return m_cmCurrentListFile.c_str();
332 //@}
334 /**
335 * Set a regular expression that include files must match
336 * in order to be considered as part of the depend information.
338 void SetIncludeRegularExpression(const char* regex)
340 m_IncludeFileRegularExpression = regex;
343 /**
344 * Set a regular expression that include files that are not found
345 * must match in order to be considered a problem.
347 void SetComplainRegularExpression(const char* regex)
349 m_ComplainFileRegularExpression = regex;
353 * Get the list of targets
355 cmTargets &GetTargets() { return m_Targets; }
356 const cmTargets &GetTargets() const { return m_Targets; }
359 * Get a list of the build subdirectories.
361 const std::vector<std::string>& GetSubDirectories()
363 return m_SubDirectories;
367 * Get a list of include directories in the build.
369 std::vector<std::string>& GetIncludeDirectories()
371 return m_IncludeDirectories;
373 const std::vector<std::string>& GetIncludeDirectories() const
375 return m_IncludeDirectories;
378 /** Expand out any arguements in the vector that have ; separated
379 * strings into multiple arguements. A new vector is created
380 * containing the expanded versions of all arguments in argsIn.
381 * This method differes from the one in cmSystemTools in that if
382 * the CmakeLists file is version 1.2 or earlier it will check for
383 * source lists being used without ${} around them
385 void ExpandSourceListArguments(std::vector<std::string> const& argsIn,
386 std::vector<std::string>& argsOut,
387 unsigned int startArgumentIndex);
389 /** Get a cmSourceFile pointer for a given source name, if the name is
390 * not found, then a null pointer is returned.
392 cmSourceFile* GetSource(const char* sourceName) const;
393 ///! Add a new cmSourceFile to the list of sources for this makefile.
394 cmSourceFile* AddSource(cmSourceFile const&);
397 * Obtain a list of auxiliary source directories.
399 std::vector<std::string>& GetAuxSourceDirectories()
400 {return m_AuxSourceDirectories;}
402 //@{
404 * Return a list of extensions associated with source and header
405 * files
407 const std::vector<std::string>& GetSourceExtensions() const
408 {return m_SourceFileExtensions;}
409 const std::vector<std::string>& GetHeaderExtensions() const
410 {return m_HeaderFileExtensions;}
411 //@}
414 * Given a variable name, return its value (as a string).
415 * If the variable is not found in this makefile instance, the
416 * cache is then queried.
418 const char* GetDefinition(const char*) const;
420 /** Test a boolean cache entry to see if it is true or false,
421 * returns false if no entry defined.
423 bool IsOn(const char* name) const;
426 * Get a list of preprocessor define flags.
428 const char* GetDefineFlags()
429 {return m_DefineFlags.c_str();}
432 * Get the vector of used command instances.
434 const std::vector<cmCommand*>& GetUsedCommands() const
435 {return m_UsedCommands;}
438 * Get the vector source groups.
440 const std::vector<cmSourceGroup>& GetSourceGroups() const
441 { return m_SourceGroups; }
444 * Get the vector of list files on which this makefile depends
446 const std::vector<std::string>& GetListFiles() const
447 { return m_ListFiles; }
449 ///! When the file changes cmake will be re-run from the build system.
450 void AddCMakeDependFile(const char* file)
451 { m_ListFiles.push_back(file);}
454 * Dump documentation to a file. If 0 is returned, the
455 * operation failed.
457 int DumpDocumentationToFile(std::ostream&);
460 * Expand all defined varibles in the string.
461 * Defined varibles come from the m_Definitions map.
462 * They are expanded with ${var} where var is the
463 * entry in the m_Definitions map. Also @var@ is
464 * expanded to match autoconf style expansions.
466 const char *ExpandVariablesInString(std::string& source) const;
467 const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
468 bool atOnly = false) const;
471 * Remove any remaining variables in the string. Anything with ${var} or
472 * @var@ will be removed.
474 void RemoveVariablesInString(std::string& source, bool atOnly = false) const;
477 * Expand variables in the makefiles ivars such as link directories etc
479 void ExpandVariables();
481 /** Recursivly read and create a cmMakefile object for
482 * all CMakeLists.txt files in the GetSubDirectories list.
483 * Once the file is found, it ReadListFile is called on
484 * the cmMakefile created for it. CreateObject is called on
485 * the prototype to create a cmMakefileGenerator for each cmMakefile that
486 * is created.
488 void FindSubDirectoryCMakeListsFiles(std::vector<cmMakefile*>& makefiles);
491 * find what source group this source is in
493 cmSourceGroup& FindSourceGroup(const char* source,
494 std::vector<cmSourceGroup> &groups);
496 void RegisterData(cmData*);
497 void RegisterData(const char*, cmData*);
498 cmData* LookupData(const char*) const;
501 * execute a single CMake command
503 void ExecuteCommand(std::string &name, std::vector<std::string> const& args);
505 /** Check if a command exists. */
506 bool CommandExists(const char* name) const;
508 ///! Enable support for the named language, if null then all languages are enabled.
509 void EnableLanguage(const char* );
511 protected:
512 // add link libraries and directories to the target
513 void AddGlobalLinkInformation(const char* name, cmTarget& target);
515 std::string m_Prefix;
516 std::vector<std::string> m_AuxSourceDirectories; //
518 std::string m_cmCurrentDirectory;
519 std::string m_CurrentOutputDirectory;
520 std::string m_cmStartDirectory;
521 std::string m_StartOutputDirectory;
522 std::string m_cmHomeDirectory;
523 std::string m_HomeOutputDirectory;
524 std::string m_cmCurrentListFile;
526 std::string m_ProjectName; // project name
528 // libraries, classes, and executables
529 cmTargets m_Targets;
530 std::vector<cmSourceFile*> m_SourceFiles;
532 std::vector<std::string> m_SubDirectories; // list of sub directories
533 struct StringSet : public std::set<cmStdString>
537 // The include and link-library paths. These may have order
538 // dependency, so they must be vectors (not set).
539 std::vector<std::string> m_IncludeDirectories;
540 std::vector<std::string> m_LinkDirectories;
542 std::vector<std::string> m_ListFiles; // list of command files loaded
545 cmTarget::LinkLibraries m_LinkLibraries;
547 std::string m_IncludeFileRegularExpression;
548 std::string m_ComplainFileRegularExpression;
549 std::vector<std::string> m_SourceFileExtensions;
550 std::vector<std::string> m_HeaderFileExtensions;
551 std::string m_DefineFlags;
552 std::vector<cmSourceGroup> m_SourceGroups;
553 typedef std::map<cmStdString, cmCommand*> RegisteredCommandsMap;
554 typedef std::map<cmStdString, cmStdString> DefinitionMap;
555 DefinitionMap m_Definitions;
556 RegisteredCommandsMap m_Commands;
557 std::vector<cmCommand*> m_UsedCommands;
558 cmMakefileGenerator* m_MakefileGenerator;
559 bool IsFunctionBlocked(const char *name, std::vector<std::string> const& args);
561 private:
563 * Get the name of the parent directories CMakeLists file
564 * given a current CMakeLists file name
566 std::string GetParentListFileName(const char *listFileName);
568 void ReadSources(std::ifstream& fin, bool t);
569 friend class cmMakeDepend; // make depend needs direct access
570 // to the m_Sources array
571 void PrintStringVector(const char* s, const std::vector<std::string>& v) const;
572 void AddDefaultCommands();
573 void AddDefaultDefinitions();
574 std::list<cmFunctionBlocker *> m_FunctionBlockers;
576 typedef std::map<cmStdString, cmData*> DataMap;
577 DataMap m_DataMap;
578 bool m_Inheriting;
582 #endif