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