Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmMakefile.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmMakefile_h
13 #define cmMakefile_h
14
15 #include "cmCacheManager.h"
16 #include "cmExecutionStatus.h"
17 #include "cmListFileCache.h"
18 #include "cmPolicies.h"
19 #include "cmPropertyMap.h"
20 #include "cmSystemTools.h"
21 #include "cmTarget.h"
22 #include "cmNewLineStyle.h"
23 #include "cmake.h"
24
25 #if defined(CMAKE_BUILD_WITH_CMAKE)
26 #include "cmSourceGroup.h"
27 #endif
28
29 #include <cmsys/auto_ptr.hxx>
30 #include <cmsys/RegularExpression.hxx>
31
32 class cmFunctionBlocker;
33 class cmCommand;
34 class cmInstallGenerator;
35 class cmLocalGenerator;
36 class cmMakeDepend;
37 class cmSourceFile;
38 class cmTest;
39 class cmTestGenerator;
40 class cmVariableWatch;
41 class cmake;
42 class cmMakefileCall;
43 class cmCMakePolicyCommand;
44
45 /** \class cmMakefile
46  * \brief Process the input CMakeLists.txt file.
47  *
48  * Process and store into memory the input CMakeLists.txt file.
49  * Each CMakeLists.txt file is parsed and the commands found there
50  * are added into the build process.
51  */
52 class cmMakefile
53 {
54   class Internals;
55   cmsys::auto_ptr<Internals> Internal;
56 public:
57   /**
58    * Return the major and minor version of the cmake that
59    * was used to write the currently loaded cache, note
60    * this method will not work before the cache is loaded.
61    */
62   unsigned int GetCacheMajorVersion();
63   unsigned int GetCacheMinorVersion();
64
65   /* Check for unused variables in this scope */
66   void CheckForUnusedVariables() const;
67   /* Mark a variable as used */
68   void MarkVariableAsUsed(const char* var);
69   /* return true if a variable has been initialized */
70   bool VariableInitialized(const char* ) const;
71   /* return true if a variable has been used */
72   bool VariableUsed(const char* ) const;
73   /** Return whether compatibility features needed for a version of
74       the cache or lower should be enabled.  */
75   bool NeedCacheCompatibility(int major, int minor);
76
77   /**
78    * Construct an empty makefile.
79    */
80   cmMakefile();
81   cmMakefile(const cmMakefile& mf);
82
83   /**
84    * Destructor.
85    */
86   ~cmMakefile();
87
88   /**
89    * Read and parse a CMakeLists.txt file.
90    */
91   bool ReadListFile(const char* listfile,
92                     const char* external= 0,
93                     std::string* fullPath= 0,
94                     bool noPolicyScope = true);
95
96   /**
97    * Add a function blocker to this makefile
98    */
99   void AddFunctionBlocker(cmFunctionBlocker* fb);
100
101   /**
102    * Remove the function blocker whose scope ends with the given command.
103    * This returns ownership of the function blocker object.
104    */
105   cmsys::auto_ptr<cmFunctionBlocker>
106   RemoveFunctionBlocker(cmFunctionBlocker* fb, const cmListFileFunction& lff);
107
108   /** Push/pop a lexical (function blocker) barrier automatically.  */
109   class LexicalPushPop
110   {
111   public:
112     LexicalPushPop(cmMakefile* mf);
113     ~LexicalPushPop();
114     void Quiet() { this->ReportError = false; }
115   private:
116     cmMakefile* Makefile;
117     bool ReportError;
118   };
119   friend class LexicalPushPop;
120
121   /**
122    * Try running cmake and building a file. This is used for dynalically
123    * loaded commands, not as part of the usual build process.
124    */
125   int TryCompile(const char *srcdir, const char *bindir,
126                  const char *projectName, const char *targetName,
127                  bool fast,
128                  const std::vector<std::string> *cmakeArgs,
129                  std::string *output);
130
131   /**
132    * Specify the makefile generator. This is platform/compiler
133    * dependent, although the interface is through a generic
134    * superclass.
135    */
136   void SetLocalGenerator(cmLocalGenerator*);
137
138   ///! Get the current makefile generator.
139   cmLocalGenerator* GetLocalGenerator()
140     { return this->LocalGenerator;}
141
142   /**
143    * Test whether compatibility is set to a given version or lower.
144    */
145   bool NeedBackwardsCompatibility(unsigned int major,
146                                   unsigned int minor,
147                                   unsigned int patch = 0xFFu);
148
149   /**
150    * Help enforce global target name uniqueness.
151    */
152   bool EnforceUniqueName(std::string const& name, std::string& msg,
153                          bool isCustom = false);
154
155   /**
156    * Perform FinalPass, Library dependency analysis etc before output of the
157    * makefile.
158    */
159   void ConfigureFinalPass();
160
161   /**
162    * run the final pass on all commands.
163    */
164   void FinalPass();
165
166   /**
167    * Print the object state to std::cout.
168    */
169   void Print();
170
171   /** Add a custom command to the build.  */
172   void AddCustomCommandToTarget(const char* target,
173                                 const std::vector<std::string>& depends,
174                                 const cmCustomCommandLines& commandLines,
175                                 cmTarget::CustomCommandType type,
176                                 const char* comment, const char* workingDir,
177                                 bool escapeOldStyle = true);
178   cmSourceFile* AddCustomCommandToOutput(
179     const std::vector<std::string>& outputs,
180     const std::vector<std::string>& depends,
181     const char* main_dependency,
182     const cmCustomCommandLines& commandLines,
183     const char* comment, const char* workingDir,
184     bool replace = false,
185     bool escapeOldStyle = true);
186   cmSourceFile* AddCustomCommandToOutput(
187     const char* output,
188     const std::vector<std::string>& depends,
189     const char* main_dependency,
190     const cmCustomCommandLines& commandLines,
191     const char* comment, const char* workingDir,
192     bool replace = false,
193     bool escapeOldStyle = true);
194   void AddCustomCommandOldStyle(const char* target,
195                                 const std::vector<std::string>& outputs,
196                                 const std::vector<std::string>& depends,
197                                 const char* source,
198                                 const cmCustomCommandLines& commandLines,
199                                 const char* comment);
200
201   /**
202    * Add a define flag to the build.
203    */
204   void AddDefineFlag(const char* definition);
205   void RemoveDefineFlag(const char* definition);
206
207   /** Create a new imported target with the name and type given.  */
208   cmTarget* AddImportedTarget(const char* name, cmTarget::TargetType type,
209                               bool global);
210
211   cmTarget* AddNewTarget(cmTarget::TargetType type, const char* name);
212
213   /**
214    * Add an executable to the build.
215    */
216   cmTarget* AddExecutable(const char *exename,
217                           const std::vector<std::string> &srcs,
218                           bool excludeFromAll = false);
219
220   /**
221    * Add a utility to the build.  A utiltity target is a command that
222    * is run every time the target is built.
223    */
224   void AddUtilityCommand(const char* utilityName, bool excludeFromAll,
225                          const std::vector<std::string>& depends,
226                          const char* workingDirectory,
227                          const char* command,
228                          const char* arg1=0,
229                          const char* arg2=0,
230                          const char* arg3=0,
231                          const char* arg4=0);
232   cmTarget* AddUtilityCommand(const char* utilityName, bool excludeFromAll,
233                               const char* workingDirectory,
234                               const std::vector<std::string>& depends,
235                               const cmCustomCommandLines& commandLines,
236                               bool escapeOldStyle = true,
237                               const char* comment = 0);
238
239   /**
240    * Add a link library to the build.
241    */
242   void AddLinkLibrary(const char*);
243   void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type);
244   void AddLinkLibraryForTarget(const char *tgt, const char*,
245                                cmTarget::LinkLibraryType type);
246   void AddLinkDirectoryForTarget(const char *tgt, const char* d);
247
248   /**
249    * Add a link directory to the build.
250    */
251   void AddLinkDirectory(const char*);
252
253   /**
254    * Get the list of link directories
255    */
256   std::vector<std::string>& GetLinkDirectories()
257     {
258       return this->LinkDirectories;
259     }
260   const std::vector<std::string>& GetLinkDirectories() const
261     {
262       return this->LinkDirectories;
263     }
264   void SetLinkDirectories(const std::vector<std::string>& vec)
265     {
266       this->LinkDirectories = vec;
267     }
268
269   /**
270    * Add a subdirectory to the build.
271    */
272   void AddSubDirectory(const char*, bool excludeFromAll=false,
273                        bool preorder = false);
274   void AddSubDirectory(const char* fullSrcDir,const char *fullBinDir,
275                        bool excludeFromAll, bool preorder,
276                        bool immediate);
277
278   /**
279    * Configure a subdirectory
280    */
281   void ConfigureSubDirectory(cmLocalGenerator *);
282
283   /**
284    * Add an include directory to the build.
285    */
286   void AddIncludeDirectory(const char*, bool before = false);
287
288   /**
289    * Add a variable definition to the build. This variable
290    * can be used in CMake to refer to lists, directories, etc.
291    */
292   void AddDefinition(const char* name, const char* value);
293   ///! Add a definition to this makefile and the global cmake cache.
294   void AddCacheDefinition(const char* name, const char* value,
295                           const char* doc,
296                           cmCacheManager::CacheEntryType type,
297                           bool force = false);
298
299   /**
300    * Add bool variable definition to the build.
301    */
302   void AddDefinition(const char* name, bool);
303
304   /**
305    * Remove a variable definition from the build.  This is not valid
306    * for cache entries, and will only affect the current makefile.
307    */
308   void RemoveDefinition(const char* name);
309   ///! Remove a definition from the cache.
310   void RemoveCacheDefinition(const char* name);
311
312   /**
313    * Specify the name of the project for this build.
314    */
315   void SetProjectName(const char*);
316
317   /**
318    * Get the name of the project for this build.
319    */
320   const char* GetProjectName() const
321     {
322       return this->ProjectName.c_str();
323     }
324
325   /** Get the configurations to be generated.  */
326   const char* GetConfigurations(std::vector<std::string>& configs,
327                                 bool single = true) const;
328
329   /**
330    * Set the name of the library.
331    */
332   cmTarget* AddLibrary(const char *libname, cmTarget::TargetType type,
333                   const std::vector<std::string> &srcs,
334                   bool excludeFromAll = false);
335
336 #if defined(CMAKE_BUILD_WITH_CMAKE)
337   /**
338    * Add a root source group for consideration when adding a new source.
339    */
340   void AddSourceGroup(const char* name, const char* regex=0);
341
342   /**
343    * Add a source group for consideration when adding a new source.
344    * name is tokenized.
345    */
346   void AddSourceGroup(const std::vector<std::string>& name,
347                       const char* regex=0);
348
349 #endif
350
351   //@{
352   /**
353      * Set, Push, Pop policy values for CMake.
354      */
355   bool SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
356   bool SetPolicy(const char *id, cmPolicies::PolicyStatus status);
357   cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
358   bool SetPolicyVersion(const char *version);
359   void RecordPolicies(cmPolicies::PolicyMap& pm);
360   //@}
361
362   /** Helper class to push and pop policies automatically.  */
363   class PolicyPushPop
364   {
365   public:
366     PolicyPushPop(cmMakefile* m,
367                   bool weak = false,
368                   cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
369     ~PolicyPushPop();
370     void Quiet() { this->ReportError = false; }
371   private:
372     cmMakefile* Makefile;
373     bool ReportError;
374   };
375   friend class PolicyPushPop;
376
377   /**
378     * Get the Policies Instance
379     */
380  cmPolicies *GetPolicies();
381
382   /**
383    * Add an auxiliary directory to the build.
384    */
385   void AddExtraDirectory(const char* dir);
386
387
388   /**
389    * Add an auxiliary directory to the build.
390    */
391   void MakeStartDirectoriesCurrent()
392     {
393       this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
394                           this->cmStartDirectory.c_str());
395       this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
396                           this->StartOutputDirectory.c_str());
397     }
398
399   //@{
400   /**
401    * Set/Get the home directory (or output directory) in the project. The
402    * home directory is the top directory of the project. It is where
403    * CMakeSetup or configure was run. Remember that CMake processes
404    * CMakeLists files by recursing up the tree starting at the StartDirectory
405    * and going up until it reaches the HomeDirectory.
406    */
407   void SetHomeDirectory(const char* dir);
408   const char* GetHomeDirectory() const
409     {
410       return this->cmHomeDirectory.c_str();
411     }
412   void SetHomeOutputDirectory(const char* lib);
413   const char* GetHomeOutputDirectory() const
414     {
415       return this->HomeOutputDirectory.c_str();
416     }
417   //@}
418
419   /**
420    * Set CMAKE_SCRIPT_MODE_FILE variable when running a -P script.
421    */
422   void SetScriptModeFile(const char* scriptfile);
423
424   /**
425    * Set CMAKE_ARGC, CMAKE_ARGV0 ... variables.
426    */
427   void SetArgcArgv(const std::vector<std::string>& args);
428
429   //@{
430   /**
431    * Set/Get the start directory (or output directory). The start directory
432    * is the directory of the CMakeLists.txt file that started the current
433    * round of processing. Remember that CMake processes CMakeLists files by
434    * recursing up the tree starting at the StartDirectory and going up until
435    * it reaches the HomeDirectory.
436    */
437   void SetStartDirectory(const char* dir)
438     {
439       this->cmStartDirectory = dir;
440       cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory);
441       this->cmStartDirectory =
442         cmSystemTools::CollapseFullPath(this->cmStartDirectory.c_str());
443       this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
444                           this->cmStartDirectory.c_str());
445     }
446   const char* GetStartDirectory() const
447     {
448       return this->cmStartDirectory.c_str();
449     }
450   void SetStartOutputDirectory(const char* lib)
451     {
452       this->StartOutputDirectory = lib;
453       cmSystemTools::ConvertToUnixSlashes(this->StartOutputDirectory);
454       this->StartOutputDirectory =
455         cmSystemTools::CollapseFullPath(this->StartOutputDirectory.c_str());
456       cmSystemTools::MakeDirectory(this->StartOutputDirectory.c_str());
457       this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
458                           this->StartOutputDirectory.c_str());
459     }
460   const char* GetStartOutputDirectory() const
461     {
462       return this->StartOutputDirectory.c_str();
463     }
464   //@}
465
466   const char* GetCurrentDirectory() const
467     {
468       return this->cmStartDirectory.c_str();
469     }
470   const char* GetCurrentOutputDirectory() const
471     {
472       return this->StartOutputDirectory.c_str();
473     }
474
475   /* Get the current CMakeLists.txt file that is being processed.  This
476    * is just used in order to be able to 'branch' from one file to a second
477    * transparently */
478   const char* GetCurrentListFile() const
479     {
480       return this->cmCurrentListFile.c_str();
481     }
482
483   //@}
484
485   /**
486    * Set a regular expression that include files must match
487    * in order to be considered as part of the depend information.
488    */
489   void SetIncludeRegularExpression(const char* regex)
490     {
491       this->IncludeFileRegularExpression = regex;
492     }
493   const char* GetIncludeRegularExpression()
494     {
495       return this->IncludeFileRegularExpression.c_str();
496     }
497
498   /**
499    * Set a regular expression that include files that are not found
500    * must match in order to be considered a problem.
501    */
502   void SetComplainRegularExpression(const char* regex)
503     {
504       this->ComplainFileRegularExpression = regex;
505     }
506   const char* GetComplainRegularExpression()
507     {
508       return this->ComplainFileRegularExpression.c_str();
509     }
510
511   /**
512    * Get the list of targets
513    */
514   cmTargets &GetTargets() { return this->Targets; }
515   /**
516    * Get the list of targets, const version
517    */
518   const cmTargets &GetTargets() const { return this->Targets; }
519
520   cmTarget* FindTarget(const char* name);
521
522   /** Find a target to use in place of the given name.  The target
523       returned may be imported or built within the project.  */
524   cmTarget* FindTargetToUse(const char* name);
525
526   /**
527    * Mark include directories as system directories.
528    */
529   void AddSystemIncludeDirectory(const char* dir);
530   bool IsSystemIncludeDirectory(const char* dir);
531
532   /** Expand out any arguements in the vector that have ; separated
533    *  strings into multiple arguements.  A new vector is created
534    *  containing the expanded versions of all arguments in argsIn.
535    * This method differes from the one in cmSystemTools in that if
536    * the CmakeLists file is version 1.2 or earlier it will check for
537    * source lists being used without ${} around them
538    */
539   void ExpandSourceListArguments(std::vector<std::string> const& argsIn,
540                                  std::vector<std::string>& argsOut,
541                                  unsigned int startArgumentIndex);
542
543   /** Get a cmSourceFile pointer for a given source name, if the name is
544    *  not found, then a null pointer is returned.
545    */
546   cmSourceFile* GetSource(const char* sourceName);
547
548   /** Get a cmSourceFile pointer for a given source name, if the name is
549    *  not found, then create the source file and return it. generated
550    * indicates if it is a generated file, this is used in determining
551    * how to create the source file instance e.g. name
552    */
553   cmSourceFile* GetOrCreateSource(const char* sourceName,
554                                   bool generated = false);
555
556   /**
557    * Obtain a list of auxiliary source directories.
558    */
559   std::vector<std::string>& GetAuxSourceDirectories()
560     {return this->AuxSourceDirectories;}
561
562   //@{
563   /**
564    * Return a list of extensions associated with source and header
565    * files
566    */
567   const std::vector<std::string>& GetSourceExtensions() const
568     {return this->SourceFileExtensions;}
569   const std::vector<std::string>& GetHeaderExtensions() const
570     {return this->HeaderFileExtensions;}
571   //@}
572
573   /**
574    * Given a variable name, return its value (as a string).
575    * If the variable is not found in this makefile instance, the
576    * cache is then queried.
577    */
578   const char* GetDefinition(const char*) const;
579   const char* GetSafeDefinition(const char*) const;
580   const char* GetRequiredDefinition(const char* name) const;
581   bool IsDefinitionSet(const char*) const;
582   /**
583    * Get the list of all variables in the current space. If argument
584    * cacheonly is specified and is greater than 0, then only cache
585    * variables will be listed.
586    */
587   std::vector<std::string> GetDefinitions(int cacheonly=0) const;
588
589   /** Test a boolean cache entry to see if it is true or false,
590    *  returns false if no entry defined.
591    */
592   bool IsOn(const char* name) const;
593   bool IsSet(const char* name) const;
594
595   /** Return whether the target platform is 64-bit.  */
596   bool PlatformIs64Bit() const;
597
598   /** Retrieve soname flag for the specified language if supported */
599   const char* GetSONameFlag(const char* language) const;
600
601   /**
602    * Get a list of preprocessor define flags.
603    */
604   const char* GetDefineFlags()
605     {return this->DefineFlags.c_str();}
606
607   /**
608    * Make sure CMake can write this file
609    */
610   bool CanIWriteThisFile(const char* fileName);
611
612 #if defined(CMAKE_BUILD_WITH_CMAKE)
613   /**
614    * Get the vector source groups.
615    */
616   const std::vector<cmSourceGroup>& GetSourceGroups() const
617     { return this->SourceGroups; }
618
619   /**
620    * Get the source group
621    */
622   cmSourceGroup* GetSourceGroup(const std::vector<std::string>&name);
623 #endif
624
625   /**
626    * Get the vector of list files on which this makefile depends
627    */
628   const std::vector<std::string>& GetListFiles() const
629     { return this->ListFiles; }
630   ///! When the file changes cmake will be re-run from the build system.
631   void AddCMakeDependFile(const char* file)
632     { this->ListFiles.push_back(file);}
633
634     /**
635      * Get the list file stack as a string
636      */
637     std::string GetListFileStack();
638
639   /**
640    * Get the current context backtrace.
641    */
642   bool GetBacktrace(cmListFileBacktrace& backtrace) const;
643
644   /**
645    * Get the vector of  files created by this makefile
646    */
647   const std::vector<std::string>& GetOutputFiles() const
648     { return this->OutputFiles; }
649   void AddCMakeOutputFile(const char* file)
650     { this->OutputFiles.push_back(file);}
651
652   /**
653    * Expand all defined variables in the string.
654    * Defined variables come from the this->Definitions map.
655    * They are expanded with ${var} where var is the
656    * entry in the this->Definitions map.  Also \@var\@ is
657    * expanded to match autoconf style expansions.
658    */
659   const char *ExpandVariablesInString(std::string& source);
660   const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
661                                       bool noEscapes,
662                                       bool atOnly = false,
663                                       const char* filename = 0,
664                                       long line = -1,
665                                       bool removeEmpty = false,
666                                       bool replaceAt = true);
667
668   /**
669    * Remove any remaining variables in the string. Anything with ${var} or
670    * \@var\@ will be removed.
671    */
672   void RemoveVariablesInString(std::string& source,
673                                bool atOnly = false) const;
674
675   /**
676    * Expand variables in the makefiles ivars such as link directories etc
677    */
678   void ExpandVariables();
679
680   /**
681    * Replace variables and #cmakedefine lines in the given string.
682    * See cmConfigureFileCommand for details.
683    */
684   void ConfigureString(const std::string& input, std::string& output,
685                        bool atOnly, bool escapeQuotes);
686
687   /**
688    * Copy file but change lines acording to ConfigureString
689    */
690   int ConfigureFile(const char* infile, const char* outfile,
691                     bool copyonly, bool atOnly, bool escapeQuotes,
692                     const cmNewLineStyle& = cmNewLineStyle());
693
694
695 #if defined(CMAKE_BUILD_WITH_CMAKE)
696   /**
697    * find what source group this source is in
698    */
699   cmSourceGroup& FindSourceGroup(const char* source,
700                                  std::vector<cmSourceGroup> &groups);
701 #endif
702
703   /**
704    * Print a command's invocation
705    */
706   void PrintCommandTrace(const cmListFileFunction& lff);
707
708   /**
709    * Execute a single CMake command.  Returns true if the command
710    * succeeded or false if it failed.
711    */
712   bool ExecuteCommand(const cmListFileFunction& lff,
713                       cmExecutionStatus &status);
714
715   /** Check if a command exists. */
716   bool CommandExists(const char* name) const;
717
718   /**
719    * Add a command to this cmake instance
720    */
721   void AddCommand(cmCommand* );
722
723   ///! Enable support for named language, if nil then all languages are
724   ///enabled.
725   void EnableLanguage(std::vector<std::string>const& languages, bool optional);
726
727   /**
728    * Set/Get the name of the parent directories CMakeLists file
729    * given a current CMakeLists file name
730    */
731   cmCacheManager *GetCacheManager() const;
732
733   /**
734    * Get the variable watch. This is used to determine when certain variables
735    * are accessed.
736    */
737 #ifdef CMAKE_BUILD_WITH_CMAKE
738   cmVariableWatch* GetVariableWatch() const;
739 #endif
740
741   ///! Display progress or status message.
742   void DisplayStatus(const char*, float);
743
744   /**
745    * Expand the given list file arguments into the full set after
746    * variable replacement and list expansion.
747    */
748   bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
749                        std::vector<std::string>& outArgs);
750   /**
751    * Get the instance
752    */
753   cmake *GetCMakeInstance() const;
754
755   /**
756    * Get all the source files this makefile knows about
757    */
758   const std::vector<cmSourceFile*> &GetSourceFiles() const
759     {return this->SourceFiles;}
760   std::vector<cmSourceFile*> &GetSourceFiles() {return this->SourceFiles;}
761
762   /**
763    * Is there a source file that has the provided source file as an output?
764    * if so then return it
765    */
766   cmSourceFile *GetSourceFileWithOutput(const char *outName);
767
768   /**
769    * Add a macro to the list of macros. The arguments should be name of the
770    * macro and a documentation signature of it
771    */
772   void AddMacro(const char* name, const char* signature);
773
774   ///! Add a new cmTest to the list of tests for this makefile.
775   cmTest* CreateTest(const char* testName);
776
777   /** Get a cmTest pointer for a given test name, if the name is
778    *  not found, then a null pointer is returned.
779    */
780   cmTest* GetTest(const char* testName) const;
781
782   /**
783    * Get a list of macros as a ; separated string
784    */
785   void GetListOfMacros(std::string& macros);
786
787   /**
788    * Return a location of a file in cmake or custom modules directory
789    */
790   std::string GetModulesFile(const char* name);
791
792   ///! Set/Get a property of this directory
793   void SetProperty(const char *prop, const char *value);
794   void AppendProperty(const char *prop, const char *value,bool asString=false);
795   const char *GetProperty(const char *prop);
796   const char *GetPropertyOrDefinition(const char *prop);
797   const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
798   bool GetPropertyAsBool(const char *prop);
799
800   const char* GetFeature(const char* feature, const char* config);
801
802   // Get the properties
803   cmPropertyMap &GetProperties() { return this->Properties; };
804
805   ///! Initialize a makefile from its parent
806   void InitializeFromParent();
807
808   ///! Set/Get the preorder flag
809   void SetPreOrder(bool p) { this->PreOrder = p; }
810   bool GetPreOrder() const { return this->PreOrder; }
811
812   void AddInstallGenerator(cmInstallGenerator* g)
813     { if(g) this->InstallGenerators.push_back(g); }
814   std::vector<cmInstallGenerator*>& GetInstallGenerators()
815     { return this->InstallGenerators; }
816
817   void AddTestGenerator(cmTestGenerator* g)
818     { if(g) this->TestGenerators.push_back(g); }
819   std::vector<cmTestGenerator*>& GetTestGenerators()
820     { return this->TestGenerators; }
821
822   // Define the properties
823   static void DefineProperties(cmake *cm);
824
825   // push and pop variable scopes
826   void PushScope();
827   void PopScope();
828   void RaiseScope(const char *var, const char *value);
829
830   /** Helper class to push and pop scopes automatically.  */
831   class ScopePushPop
832   {
833   public:
834     ScopePushPop(cmMakefile* m): Makefile(m) { this->Makefile->PushScope(); }
835     ~ScopePushPop() { this->Makefile->PopScope(); }
836   private:
837     cmMakefile* Makefile;
838   };
839
840   void IssueMessage(cmake::MessageType t,
841                     std::string const& text) const;
842
843   /** Set whether or not to report a CMP0000 violation.  */
844   void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }
845
846 protected:
847   // add link libraries and directories to the target
848   void AddGlobalLinkInformation(const char* name, cmTarget& target);
849
850   // Check for a an unused variable
851   void CheckForUnused(const char* reason, const char* name) const;
852
853   std::string Prefix;
854   std::vector<std::string> AuxSourceDirectories; //
855
856   std::string cmStartDirectory;
857   std::string StartOutputDirectory;
858   std::string cmHomeDirectory;
859   std::string HomeOutputDirectory;
860   std::string cmCurrentListFile;
861
862   std::string ProjectName;    // project name
863
864   // libraries, classes, and executables
865   cmTargets Targets;
866   std::vector<cmSourceFile*> SourceFiles;
867
868   // Tests
869   std::map<cmStdString, cmTest*> Tests;
870
871   // The link-library paths.  Order matters, use std::vector (not std::set).
872   std::vector<std::string> LinkDirectories;
873
874   // The set of include directories that are marked as system include
875   // directories.
876   std::set<cmStdString> SystemIncludeDirectories;
877
878   std::vector<std::string> ListFiles; // list of command files loaded
879   std::vector<std::string> OutputFiles; // list of command files loaded
880
881
882   cmTarget::LinkLibraryVectorType LinkLibraries;
883
884   std::vector<cmInstallGenerator*> InstallGenerators;
885   std::vector<cmTestGenerator*> TestGenerators;
886
887   std::string IncludeFileRegularExpression;
888   std::string ComplainFileRegularExpression;
889   std::vector<std::string> SourceFileExtensions;
890   std::vector<std::string> HeaderFileExtensions;
891   std::string DefineFlags;
892
893   // Track the value of the computed DEFINITIONS property.
894   void AddDefineFlag(const char*, std::string&);
895   void RemoveDefineFlag(const char*, std::string::size_type, std::string&);
896   std::string DefineFlagsOrig;
897
898 #if defined(CMAKE_BUILD_WITH_CMAKE)
899   std::vector<cmSourceGroup> SourceGroups;
900 #endif
901
902   std::vector<cmCommand*> FinalPassCommands;
903   cmLocalGenerator* LocalGenerator;
904   bool IsFunctionBlocked(const cmListFileFunction& lff,
905                          cmExecutionStatus &status);
906
907 private:
908   void Initialize();
909
910   bool ParseDefineFlag(std::string const& definition, bool remove);
911
912   bool EnforceUniqueDir(const char* srcPath, const char* binPath);
913
914   void ReadSources(std::ifstream& fin, bool t);
915   friend class cmMakeDepend;    // make depend needs direct access
916                                 // to the Sources array
917   void PrintStringVector(const char* s, const
918                          std::vector<std::pair<cmStdString, bool> >& v) const;
919   void PrintStringVector(const char* s,
920                          const std::vector<std::string>& v) const;
921
922   void AddDefaultDefinitions();
923   typedef std::vector<cmFunctionBlocker*> FunctionBlockersType;
924   FunctionBlockersType FunctionBlockers;
925   std::vector<FunctionBlockersType::size_type> FunctionBlockerBarriers;
926   void PushFunctionBlockerBarrier();
927   void PopFunctionBlockerBarrier(bool reportError = true);
928
929   typedef std::map<cmStdString, cmStdString> StringStringMap;
930   StringStringMap MacrosMap;
931
932   std::map<cmStdString, bool> SubDirectoryOrder;
933
934   cmsys::RegularExpression cmDefineRegex;
935   cmsys::RegularExpression cmDefine01Regex;
936   cmsys::RegularExpression cmAtVarRegex;
937
938   cmPropertyMap Properties;
939
940   // should this makefile be processed before or after processing the parent
941   bool PreOrder;
942
943   // Unused variable flags
944   bool WarnUnused;
945   bool CheckSystemVars;
946
947   // stack of list files being read
948   std::deque<cmStdString> ListFileStack;
949
950   // stack of commands being invoked.
951   struct CallStackEntry
952   {
953     cmListFileContext const* Context;
954     cmExecutionStatus* Status;
955   };
956   typedef std::deque<CallStackEntry> CallStackType;
957   CallStackType CallStack;
958   friend class cmMakefileCall;
959
960   cmTarget* FindBasicTarget(const char* name);
961   std::vector<cmTarget*> ImportedTargetsOwned;
962   std::map<cmStdString, cmTarget*> ImportedTargets;
963
964   // Internal policy stack management.
965   void PushPolicy(bool weak = false,
966                   cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
967   void PopPolicy();
968   void PushPolicyBarrier();
969   void PopPolicyBarrier(bool reportError = true);
970   friend class cmCMakePolicyCommand;
971   class IncludeScope;
972   friend class IncludeScope;
973
974   // stack of policy settings
975   struct PolicyStackEntry: public cmPolicies::PolicyMap
976   {
977     typedef cmPolicies::PolicyMap derived;
978     PolicyStackEntry(bool w = false): derived(), Weak(w) {}
979     PolicyStackEntry(derived const& d, bool w = false): derived(d), Weak(w) {}
980     PolicyStackEntry(PolicyStackEntry const& r): derived(r), Weak(r.Weak) {}
981     bool Weak;
982   };
983   typedef std::vector<PolicyStackEntry> PolicyStackType;
984   PolicyStackType PolicyStack;
985   std::vector<PolicyStackType::size_type> PolicyBarriers;
986   cmPolicies::PolicyStatus GetPolicyStatusInternal(cmPolicies::PolicyID id);
987
988   bool CheckCMP0000;
989
990   // Enforce rules about CMakeLists.txt files.
991   void EnforceDirectoryLevelRules();
992 };
993
994 //----------------------------------------------------------------------------
995 // Helper class to make sure the call stack is valid.
996 class cmMakefileCall
997 {
998 public:
999   cmMakefileCall(cmMakefile* mf,
1000                  cmListFileContext const& lfc,
1001                  cmExecutionStatus& status): Makefile(mf)
1002     {
1003     cmMakefile::CallStackEntry entry = {&lfc, &status};
1004     this->Makefile->CallStack.push_back(entry);
1005     }
1006   ~cmMakefileCall()
1007     {
1008     this->Makefile->CallStack.pop_back();
1009     }
1010 private:
1011   cmMakefile* Makefile;
1012 };
1013
1014 #endif