cmMakefile.h 32 KB
Newer Older
1
2
3
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4

5
6
  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.
7

8
9
10
11
  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
12
13
#ifndef cmMakefile_h
#define cmMakefile_h
14

15
16
#include "cmCacheManager.h"
#include "cmExecutionStatus.h"
17
#include "cmListFileCache.h"
18
#include "cmPolicies.h"
19
#include "cmPropertyMap.h"
20
21
#include "cmSystemTools.h"
#include "cmTarget.h"
22
#include "cmNewLineStyle.h"
Bill Hoffman's avatar
Bill Hoffman committed
23
#include "cmake.h"
24

25
26
27
28
#if defined(CMAKE_BUILD_WITH_CMAKE)
#include "cmSourceGroup.h"
#endif

29
#include <cmsys/auto_ptr.hxx>
30
31
#include <cmsys/RegularExpression.hxx>

32
class cmFunctionBlocker;
33
class cmCommand;
34
class cmInstallGenerator;
Ken Martin's avatar
Ken Martin committed
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
46
47
48
/** \class cmMakefile
 * \brief Process the input CMakeLists.txt file.
 *
 * Process and store into memory the input CMakeLists.txt file.
49
 * Each CMakeLists.txt file is parsed and the commands found there
50
51
 * are added into the build process.
 */
52
53
class cmMakefile
{
54
55
  class Internals;
  cmsys::auto_ptr<Internals> Internal;
56
public:
57
58
59
60
61
  /**
   * Return the major and minor version of the cmake that
   * was used to write the currently loaded cache, note
   * this method will not work before the cache is loaded.
   */
62
63
  unsigned int GetCacheMajorVersion();
  unsigned int GetCacheMinorVersion();
64

65
66
  /* Check for unused variables in this scope */
  void CheckForUnusedVariables() const;
67
68
  /* Mark a variable as used */
  void MarkVariableAsUsed(const char* var);
69
70
  /* return true if a variable has been initialized */
  bool VariableInitialized(const char* ) const;
Ben Boeckel's avatar
Ben Boeckel committed
71
72
  /* return true if a variable has been used */
  bool VariableUsed(const char* ) const;
73
74
75
  /** Return whether compatibility features needed for a version of
      the cache or lower should be enabled.  */
  bool NeedCacheCompatibility(int major, int minor);
76

77
78
79
  /**
   * Construct an empty makefile.
   */
Ken Martin's avatar
Ken Martin committed
80
  cmMakefile();
81
  cmMakefile(const cmMakefile& mf);
82
83
84
85

  /**
   * Destructor.
   */
Ken Martin's avatar
Ken Martin committed
86
  ~cmMakefile();
87
88
89
90

  /**
   * Read and parse a CMakeLists.txt file.
   */
91
92
  bool ReadListFile(const char* listfile,
                    const char* external= 0,
93
94
                    std::string* fullPath= 0,
                    bool noPolicyScope = true);
95

96
97
98
  /**
   * Add a function blocker to this makefile
   */
99
  void AddFunctionBlocker(cmFunctionBlocker* fb);
100
101
102
103
104
105

  /**
   * Remove the function blocker whose scope ends with the given command.
   * This returns ownership of the function blocker object.
   */
  cmsys::auto_ptr<cmFunctionBlocker>
106
  RemoveFunctionBlocker(cmFunctionBlocker* fb, const cmListFileFunction& lff);
107

108
109
110
111
112
113
114
115
116
117
118
119
120
  /** Push/pop a lexical (function blocker) barrier automatically.  */
  class LexicalPushPop
  {
  public:
    LexicalPushPop(cmMakefile* mf);
    ~LexicalPushPop();
    void Quiet() { this->ReportError = false; }
  private:
    cmMakefile* Makefile;
    bool ReportError;
  };
  friend class LexicalPushPop;

121
122
123
124
  /**
   * Try running cmake and building a file. This is used for dynalically
   * loaded commands, not as part of the usual build process.
   */
125
  int TryCompile(const char *srcdir, const char *bindir,
126
                 const char *projectName, const char *targetName,
127
                 bool fast,
128
129
                 const std::vector<std::string> *cmakeArgs,
                 std::string *output);
130

131
132
133
134
135
  /**
   * Specify the makefile generator. This is platform/compiler
   * dependent, although the interface is through a generic
   * superclass.
   */
Ken Martin's avatar
Ken Martin committed
136
  void SetLocalGenerator(cmLocalGenerator*);
137

138
  ///! Get the current makefile generator.
139
  cmLocalGenerator* GetLocalGenerator()
Ken Martin's avatar
Ken Martin committed
140
    { return this->LocalGenerator;}
141

142
143
144
145
146
147
148
  /**
   * Test whether compatibility is set to a given version or lower.
   */
  bool NeedBackwardsCompatibility(unsigned int major,
                                  unsigned int minor,
                                  unsigned int patch = 0xFFu);

149
150
151
  /**
   * Help enforce global target name uniqueness.
   */
152
153
  bool EnforceUniqueName(std::string const& name, std::string& msg,
                         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
163
164
  /**
   * run the final pass on all commands.
   */
  void FinalPass();
165

166
167
168
  /**
   * Print the object state to std::cout.
   */
169
  void Print();
170
171
172
173
174
175

  /** Add a custom command to the build.  */
  void AddCustomCommandToTarget(const char* target,
                                const std::vector<std::string>& depends,
                                const cmCustomCommandLines& commandLines,
                                cmTarget::CustomCommandType type,
176
177
                                const char* comment, const char* workingDir,
                                bool escapeOldStyle = true);
178
179
180
181
182
  void AddCustomCommandToOutput(const std::vector<std::string>& outputs,
                                const std::vector<std::string>& depends,
                                const char* main_dependency,
                                const cmCustomCommandLines& commandLines,
                                const char* comment, const char* workingDir,
183
184
                                bool replace = false,
                                bool escapeOldStyle = true);
185
186
  void AddCustomCommandToOutput(const char* output,
                                const std::vector<std::string>& depends,
187
188
                                const char* main_dependency,
                                const cmCustomCommandLines& commandLines,
189
                                const char* comment, const char* workingDir,
190
191
                                bool replace = false,
                                bool escapeOldStyle = true);
192
193
194
195
196
197
198
  void AddCustomCommandOldStyle(const char* target,
                                const std::vector<std::string>& outputs,
                                const std::vector<std::string>& depends,
                                const char* source,
                                const cmCustomCommandLines& commandLines,
                                const char* comment);

199
200
201
  /**
   * Add a define flag to the build.
   */
202
  void AddDefineFlag(const char* definition);
203
  void RemoveDefineFlag(const char* definition);
204

205
  /** Create a new imported target with the name and type given.  */
206
207
  cmTarget* AddImportedTarget(const char* name, cmTarget::TargetType type,
                              bool global);
208
209

  cmTarget* AddNewTarget(cmTarget::TargetType type, const char* name);
210

211
212
213
  /**
   * Add an executable to the build.
   */
214
  cmTarget* AddExecutable(const char *exename,
215
                          const std::vector<std::string> &srcs,
Ken Martin's avatar
Ken Martin committed
216
                          bool excludeFromAll = false);
217

218
  /**
219
220
   * Add a utility to the build.  A utiltity target is a command that
   * is run every time the target is built.
221
   */
Ken Martin's avatar
Ken Martin committed
222
  void AddUtilityCommand(const char* utilityName, bool excludeFromAll,
223
                         const std::vector<std::string>& depends,
224
                         const char* workingDirectory,
225
                         const char* command,
226
227
                         const char* arg1=0,
                         const char* arg2=0,
Andy Cedilnik's avatar
Andy Cedilnik committed
228
229
                         const char* arg3=0,
                         const char* arg4=0);
230
231
232
233
234
235
  cmTarget* AddUtilityCommand(const char* utilityName, bool excludeFromAll,
                              const char* workingDirectory,
                              const std::vector<std::string>& depends,
                              const cmCustomCommandLines& commandLines,
                              bool escapeOldStyle = true,
                              const char* comment = 0);
236

237
238
239
  /**
   * Add a link library to the build.
   */
240
  void AddLinkLibrary(const char*);
241
  void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type);
242
  void AddLinkLibraryForTarget(const char *tgt, const char*,
243
                               cmTarget::LinkLibraryType type);
244
  void AddLinkDirectoryForTarget(const char *tgt, const char* d);
245
246
247
248

  /**
   * Add a link directory to the build.
   */
249
  void AddLinkDirectory(const char*);
250

251
252
253
254
255
  /**
   * Get the list of link directories
   */
  std::vector<std::string>& GetLinkDirectories()
    {
Ken Martin's avatar
Ken Martin committed
256
      return this->LinkDirectories;
257
258
259
    }
  const std::vector<std::string>& GetLinkDirectories() const
    {
Ken Martin's avatar
Ken Martin committed
260
      return this->LinkDirectories;
261
262
263
    }
  void SetLinkDirectories(const std::vector<std::string>& vec)
    {
Ken Martin's avatar
Ken Martin committed
264
      this->LinkDirectories = vec;
265
266
    }

267
268
269
  /**
   * Add a subdirectory to the build.
   */
270
  void AddSubDirectory(const char*, bool excludeFromAll=false,
271
                       bool preorder = false);
272
  void AddSubDirectory(const char* fullSrcDir,const char *fullBinDir,
Ken Martin's avatar
Ken Martin committed
273
                       bool excludeFromAll, bool preorder,
274
                       bool immediate);
275

276
277
278
279
  /**
   * Configure a subdirectory
   */
  void ConfigureSubDirectory(cmLocalGenerator *);
280

281
282
283
  /**
   * Add an include directory to the build.
   */
284
  void AddIncludeDirectory(const char*, bool before = false);
285
286
287
288
289

  /**
   * Add a variable definition to the build. This variable
   * can be used in CMake to refer to lists, directories, etc.
   */
290
  void AddDefinition(const char* name, const char* value);
291
  ///! Add a definition to this makefile and the global cmake cache.
292
  void AddCacheDefinition(const char* name, const char* value,
293
                          const char* doc,
294
295
                          cmCacheManager::CacheEntryType type,
                          bool force = false);
296

297
  /**
298
   * Add bool variable definition to the build.
299
300
301
   */
  void AddDefinition(const char* name, bool);

302
303
304
305
306
  /**
   * Remove a variable definition from the build.  This is not valid
   * for cache entries, and will only affect the current makefile.
   */
  void RemoveDefinition(const char* name);
Brad King's avatar
Brad King committed
307
308
  ///! Remove a definition from the cache.
  void RemoveCacheDefinition(const char* name);
309

310
311
312
  /**
   * Specify the name of the project for this build.
   */
313
  void SetProjectName(const char*);
314
315
316
317

  /**
   * Get the name of the project for this build.
   */
Alexander Neundorf's avatar
   
Alexander Neundorf committed
318
  const char* GetProjectName() const
319
    {
Ken Martin's avatar
Ken Martin committed
320
      return this->ProjectName.c_str();
321
    }
322
323
324
325
326

  /** Get the configurations to be generated.  */
  const char* GetConfigurations(std::vector<std::string>& configs,
                                bool single = true) const;

327
328
329
  /**
   * Set the name of the library.
   */
330
  cmTarget* AddLibrary(const char *libname, cmTarget::TargetType type,
331
                  const std::vector<std::string> &srcs,
Ken Martin's avatar
Ken Martin committed
332
                  bool excludeFromAll = false);
333

334
#if defined(CMAKE_BUILD_WITH_CMAKE)
335
  /**
336
   * Add a root source group for consideration when adding a new source.
337
   */
Alexander Neundorf's avatar
   
Alexander Neundorf committed
338
  void AddSourceGroup(const char* name, const char* regex=0);
339
340
341
342
343

  /**
   * Add a source group for consideration when adding a new source.
   * name is tokenized.
   */
344
  void AddSourceGroup(const std::vector<std::string>& name,
Alexander Neundorf's avatar
   
Alexander Neundorf committed
345
                      const char* regex=0);
346

347
#endif
348
349
350

  //@{
  /**
351
     * Set, Push, Pop policy values for CMake.
352
353
354
355
356
     */
  bool SetPolicy(cmPolicies::PolicyID id, cmPolicies::PolicyStatus status);
  bool SetPolicy(const char *id, cmPolicies::PolicyStatus status);
  cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
  bool SetPolicyVersion(const char *version);
357
  void RecordPolicies(cmPolicies::PolicyMap& pm);
358
359
  //@}

360
361
362
363
  /** Helper class to push and pop policies automatically.  */
  class PolicyPushPop
  {
  public:
364
365
366
    PolicyPushPop(cmMakefile* m,
                  bool weak = false,
                  cmPolicies::PolicyMap const& pm = cmPolicies::PolicyMap());
367
    ~PolicyPushPop();
Brad King's avatar
Brad King committed
368
    void Quiet() { this->ReportError = false; }
369
370
  private:
    cmMakefile* Makefile;
Brad King's avatar
Brad King committed
371
    bool ReportError;
372
373
374
  };
  friend class PolicyPushPop;

375
376
377
378
  /**
    * Get the Policies Instance
    */
 cmPolicies *GetPolicies();
379

380
381
382
  /**
   * Add an auxiliary directory to the build.
   */
383
  void AddExtraDirectory(const char* dir);
384

Ken Martin's avatar
Ken Martin committed
385
386
387
388
389
390

  /**
   * Add an auxiliary directory to the build.
   */
  void MakeStartDirectoriesCurrent()
    {
391
      this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
Ken Martin's avatar
Ken Martin committed
392
                          this->cmStartDirectory.c_str());
393
      this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
Ken Martin's avatar
Ken Martin committed
394
                          this->StartOutputDirectory.c_str());
Ken Martin's avatar
Ken Martin committed
395
    }
396

Ken Martin's avatar
Ken Martin committed
397
  //@{
398
  /**
Ken Martin's avatar
Ken Martin committed
399
400
401
402
   * Set/Get the home directory (or output directory) in the project. The
   * home directory is the top directory of the project. It is where
   * CMakeSetup or configure was run. Remember that CMake processes
   * CMakeLists files by recursing up the tree starting at the StartDirectory
403
   * and going up until it reaches the HomeDirectory.
404
   */
405
  void SetHomeDirectory(const char* dir);
406
  const char* GetHomeDirectory() const
407
    {
Ken Martin's avatar
Ken Martin committed
408
      return this->cmHomeDirectory.c_str();
409
    }
410
  void SetHomeOutputDirectory(const char* lib);
411
  const char* GetHomeOutputDirectory() const
412
    {
Ken Martin's avatar
Ken Martin committed
413
      return this->HomeOutputDirectory.c_str();
414
    }
Ken Martin's avatar
Ken Martin committed
415
  //@}
416
417
418
419
420
421

  /**
   * Set CMAKE_SCRIPT_MODE_FILE variable when running a -P script.
   */
  void SetScriptModeFile(const char* scriptfile);

422
423
424
425
426
  /**
   * Set CMAKE_ARGC, CMAKE_ARGV0 ... variables.
   */
  void SetArgcArgv(const std::vector<std::string>& args);

Ken Martin's avatar
Ken Martin committed
427
  //@{
428
  /**
Ken Martin's avatar
Ken Martin committed
429
430
431
432
   * Set/Get the start directory (or output directory). The start directory
   * is the directory of the CMakeLists.txt file that started the current
   * round of processing. Remember that CMake processes CMakeLists files by
   * recursing up the tree starting at the StartDirectory and going up until
433
   * it reaches the HomeDirectory.
434
   */
435
  void SetStartDirectory(const char* dir)
436
    {
Ken Martin's avatar
Ken Martin committed
437
438
      this->cmStartDirectory = dir;
      cmSystemTools::ConvertToUnixSlashes(this->cmStartDirectory);
439
      this->cmStartDirectory =
440
        cmSystemTools::CollapseFullPath(this->cmStartDirectory.c_str());
441
      this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
Ken Martin's avatar
Ken Martin committed
442
                          this->cmStartDirectory.c_str());
443
    }
444
  const char* GetStartDirectory() const
445
    {
Ken Martin's avatar
Ken Martin committed
446
      return this->cmStartDirectory.c_str();
447
    }
Ken Martin's avatar
Ken Martin committed
448
449
  void SetStartOutputDirectory(const char* lib)
    {
Ken Martin's avatar
Ken Martin committed
450
451
      this->StartOutputDirectory = lib;
      cmSystemTools::ConvertToUnixSlashes(this->StartOutputDirectory);
452
      this->StartOutputDirectory =
453
        cmSystemTools::CollapseFullPath(this->StartOutputDirectory.c_str());
Ken Martin's avatar
Ken Martin committed
454
      cmSystemTools::MakeDirectory(this->StartOutputDirectory.c_str());
455
      this->AddDefinition("CMAKE_CURRENT_BINARY_DIR",
Ken Martin's avatar
Ken Martin committed
456
                          this->StartOutputDirectory.c_str());
Ken Martin's avatar
Ken Martin committed
457
    }
458
  const char* GetStartOutputDirectory() const
459
    {
Ken Martin's avatar
Ken Martin committed
460
      return this->StartOutputDirectory.c_str();
461
    }
Ken Martin's avatar
Ken Martin committed
462
  //@}
463

464
  const char* GetCurrentDirectory() const
Ken Martin's avatar
Ken Martin committed
465
    {
Ken Martin's avatar
Ken Martin committed
466
      return this->cmStartDirectory.c_str();
Ken Martin's avatar
Ken Martin committed
467
    }
468
  const char* GetCurrentOutputDirectory() const
Ken Martin's avatar
Ken Martin committed
469
    {
Ken Martin's avatar
Ken Martin committed
470
      return this->StartOutputDirectory.c_str();
Ken Martin's avatar
Ken Martin committed
471
    }
Anonymous's avatar
Anonymous committed
472
473
474
475
476
477

  /* Get the current CMakeLists.txt file that is being processed.  This
   * is just used in order to be able to 'branch' from one file to a second
   * transparently */
  const char* GetCurrentListFile() const
    {
Ken Martin's avatar
Ken Martin committed
478
      return this->cmCurrentListFile.c_str();
Anonymous's avatar
Anonymous committed
479
480
    }

Ken Martin's avatar
Ken Martin committed
481
  //@}
482

483
  /**
484
485
486
487
488
   * Set a regular expression that include files must match
   * in order to be considered as part of the depend information.
   */
  void SetIncludeRegularExpression(const char* regex)
    {
Ken Martin's avatar
Ken Martin committed
489
      this->IncludeFileRegularExpression = regex;
490
    }
491
  const char* GetIncludeRegularExpression()
492
    {
Ken Martin's avatar
Ken Martin committed
493
      return this->IncludeFileRegularExpression.c_str();
494
    }
495

496
  /**
497
498
499
500
501
   * Set a regular expression that include files that are not found
   * must match in order to be considered a problem.
   */
  void SetComplainRegularExpression(const char* regex)
    {
Ken Martin's avatar
Ken Martin committed
502
      this->ComplainFileRegularExpression = regex;
503
    }
504
505
  const char* GetComplainRegularExpression()
    {
Ken Martin's avatar
Ken Martin committed
506
      return this->ComplainFileRegularExpression.c_str();
507
    }
508

509
  /**
510
   * Get the list of targets
511
   */
Ken Martin's avatar
Ken Martin committed
512
  cmTargets &GetTargets() { return this->Targets; }
Alexander Neundorf's avatar
   
Alexander Neundorf committed
513
514
515
516
  /**
   * Get the list of targets, const version
   */
  const cmTargets &GetTargets() const { return this->Targets; }
517

518
  cmTarget* FindTarget(const char* name);
519

520
521
522
  /** Find a target to use in place of the given name.  The target
      returned may be imported or built within the project.  */
  cmTarget* FindTargetToUse(const char* name);
523

524
525
526
  /**
   * Get a list of include directories in the build.
   */
527
  std::vector<std::string>& GetIncludeDirectories()
528
    {
Ken Martin's avatar
Ken Martin committed
529
      return this->IncludeDirectories;
530
    }
531
  const std::vector<std::string>& GetIncludeDirectories() const
532
    {
Ken Martin's avatar
Ken Martin committed
533
      return this->IncludeDirectories;
534
    }
535
536
  void SetIncludeDirectories(const std::vector<std::string>& vec)
    {
Ken Martin's avatar
Ken Martin committed
537
      this->IncludeDirectories = vec;
538
    }
539

540
541
542
543
544
545
  /**
   * Mark include directories as system directories.
   */
  void AddSystemIncludeDirectory(const char* dir);
  bool IsSystemIncludeDirectory(const char* dir);

546
  /** Expand out any arguements in the vector that have ; separated
547
   *  strings into multiple arguements.  A new vector is created
548
549
550
551
   *  containing the expanded versions of all arguments in argsIn.
   * This method differes from the one in cmSystemTools in that if
   * the CmakeLists file is version 1.2 or earlier it will check for
   * source lists being used without ${} around them
552
   */
553
554
  void ExpandSourceListArguments(std::vector<std::string> const& argsIn,
                                 std::vector<std::string>& argsOut,
Ken Martin's avatar
Ken Martin committed
555
                                 unsigned int startArgumentIndex);
556

557
558
559
  /** Get a cmSourceFile pointer for a given source name, if the name is
   *  not found, then a null pointer is returned.
   */
560
  cmSourceFile* GetSource(const char* sourceName);
561
562

  /** Get a cmSourceFile pointer for a given source name, if the name is
563
   *  not found, then create the source file and return it. generated
564
565
566
   * indicates if it is a generated file, this is used in determining
   * how to create the source file instance e.g. name
   */
567
  cmSourceFile* GetOrCreateSource(const char* sourceName,
568
                                  bool generated = false);
569

570
571
572
  /**
   * Obtain a list of auxiliary source directories.
   */
573
  std::vector<std::string>& GetAuxSourceDirectories()
Ken Martin's avatar
Ken Martin committed
574
    {return this->AuxSourceDirectories;}
575

576
577
578
579
580
581
  //@{
  /**
   * Return a list of extensions associated with source and header
   * files
   */
  const std::vector<std::string>& GetSourceExtensions() const
Ken Martin's avatar
Ken Martin committed
582
    {return this->SourceFileExtensions;}
583
  const std::vector<std::string>& GetHeaderExtensions() const
Ken Martin's avatar
Ken Martin committed
584
    {return this->HeaderFileExtensions;}
585
586
  //@}

587
588
  /**
   * Given a variable name, return its value (as a string).
589
590
   * If the variable is not found in this makefile instance, the
   * cache is then queried.
591
   */
Ken Martin's avatar
Ken Martin committed
592
  const char* GetDefinition(const char*) const;
593
  const char* GetSafeDefinition(const char*) const;
Bill Hoffman's avatar
Bill Hoffman committed
594
  const char* GetRequiredDefinition(const char* name) const;
595
  bool IsDefinitionSet(const char*) const;
596
597
598
599
600
601
  /**
   * Get the list of all variables in the current space. If argument
   * cacheonly is specified and is greater than 0, then only cache
   * variables will be listed.
   */
  std::vector<std::string> GetDefinitions(int cacheonly=0) const;
602
603

  /** Test a boolean cache entry to see if it is true or false,
604
605
   *  returns false if no entry defined.
   */
606
  bool IsOn(const char* name) const;
607
  bool IsSet(const char* name) const;
608

609
610
611
  /** Return whether the target platform is 64-bit.  */
  bool PlatformIs64Bit() const;

612
  /**
613
   * Get a list of preprocessor define flags.
614
   */
615
  const char* GetDefineFlags()
Ken Martin's avatar
Ken Martin committed
616
    {return this->DefineFlags.c_str();}
617
618
619
620
621

  /**
   * Make sure CMake can write this file
   */
  bool CanIWriteThisFile(const char* fileName);
622

623
#if defined(CMAKE_BUILD_WITH_CMAKE)
624
625
626
627
  /**
   * Get the vector source groups.
   */
  const std::vector<cmSourceGroup>& GetSourceGroups() const
Ken Martin's avatar
Ken Martin committed
628
    { return this->SourceGroups; }
Anonymous's avatar
Anonymous committed
629

630
631
632
  /**
   * Get the source group
   */
633
  cmSourceGroup* GetSourceGroup(const std::vector<std::string>&name);
634
#endif
635

Anonymous's avatar
Anonymous committed
636
637
638
639
  /**
   * Get the vector of list files on which this makefile depends
   */
  const std::vector<std::string>& GetListFiles() const
Ken Martin's avatar
Ken Martin committed
640
    { return this->ListFiles; }
641
642
  ///! When the file changes cmake will be re-run from the build system.
  void AddCMakeDependFile(const char* file)
Ken Martin's avatar
Ken Martin committed
643
    { this->ListFiles.push_back(file);}
644
645
646
647
648
649

    /**
     * Get the list file stack as a string
     */
    std::string GetListFileStack();

650
651
652
653
654
  /**
   * Get the current context backtrace.
   */
  bool GetBacktrace(cmListFileBacktrace& backtrace) const;

655
656
657
658
659
660
  /**
   * Get the vector of  files created by this makefile
   */
  const std::vector<std::string>& GetOutputFiles() const
    { return this->OutputFiles; }
  void AddCMakeOutputFile(const char* file)
661
    { this->OutputFiles.push_back(file);}
662

663
  /**
664
   * Expand all defined variables in the string.
Ken Martin's avatar
Ken Martin committed
665
   * Defined variables come from the this->Definitions map.
666
   * They are expanded with ${var} where var is the
Nicolas Despres's avatar
Nicolas Despres committed
667
   * entry in the this->Definitions map.  Also \@var\@ is
668
   * expanded to match autoconf style expansions.
669
   */
670
  const char *ExpandVariablesInString(std::string& source);
671
  const char *ExpandVariablesInString(std::string& source, bool escapeQuotes,
672
                                      bool noEscapes,
673
674
                                      bool atOnly = false,
                                      const char* filename = 0,
Bill Hoffman's avatar
Bill Hoffman committed
675
                                      long line = -1,
676
                                      bool removeEmpty = false,
677
                                      bool replaceAt = true);
678

679
680
  /**
   * Remove any remaining variables in the string. Anything with ${var} or
Nicolas Despres's avatar
Nicolas Despres committed
681
   * \@var\@ will be removed.
682
   */
683
  void RemoveVariablesInString(std::string& source,
Ken Martin's avatar
Ken Martin committed
684
                               bool atOnly = false) const;
685

686
687
688
  /**
   * Expand variables in the makefiles ivars such as link directories etc
   */
689
  void ExpandVariables();
690
691
692
693
694
695
696
697

  /**
   * Replace variables and #cmakedefine lines in the given string.
   * See cmConfigureFileCommand for details.
   */
  void ConfigureString(const std::string& input, std::string& output,
                       bool atOnly, bool escapeQuotes);

Andy Cedilnik's avatar
Andy Cedilnik committed
698
699
700
  /**
   * Copy file but change lines acording to ConfigureString
   */
701
  int ConfigureFile(const char* infile, const char* outfile,
702
703
704
                    bool copyonly, bool atOnly, bool escapeQuotes,
                    const cmNewLineStyle& = cmNewLineStyle());

Andy Cedilnik's avatar
Andy Cedilnik committed
705

706
#if defined(CMAKE_BUILD_WITH_CMAKE)
707
708
709
710
711
  /**
   * find what source group this source is in
   */
  cmSourceGroup& FindSourceGroup(const char* source,
                                 std::vector<cmSourceGroup> &groups);
712
713
#endif

Ken Martin's avatar
Ken Martin committed
714
  /**
715
716
   * Execute a single CMake command.  Returns true if the command
   * succeeded or false if it failed.
Ken Martin's avatar
Ken Martin committed
717
   */
718
  bool ExecuteCommand(const cmListFileFunction& lff,
719
720
                      cmExecutionStatus &status);

721
722
  /** Check if a command exists. */
  bool CommandExists(const char* name) const;
723

724
725
726
727
728
  /**
   * Add a command to this cmake instance
   */
  void AddCommand(cmCommand* );

Ken Martin's avatar
Ken Martin committed
729
730
  ///! Enable support for named language, if nil then all languages are
  ///enabled.
Alexander Neundorf's avatar
   
Alexander Neundorf committed
731
  void EnableLanguage(std::vector<std::string>const& languages, bool optional);
732

733
734
735
736
  /**
   * Set/Get the name of the parent directories CMakeLists file
   * given a current CMakeLists file name
   */
Ken Martin's avatar
Ken Martin committed
737
  cmCacheManager *GetCacheManager() const;
738
739
740
741
742
743

  /**
   * Get the variable watch. This is used to determine when certain variables
   * are accessed.
   */
#ifdef CMAKE_BUILD_WITH_CMAKE
744
  cmVariableWatch* GetVariableWatch() const;
745
#endif
746

747
748
  ///! Display progress or status message.
  void DisplayStatus(const char*, float);
749

750
751
752
753
  /**
   * Expand the given list file arguments into the full set after
   * variable replacement and list expansion.
   */
754
  bool ExpandArguments(std::vector<cmListFileArgument> const& inArgs,
755
                       std::vector<std::string>& outArgs);
756
757
  /**
   * Get the instance
758
   */
759
760
  cmake *GetCMakeInstance() const;

761
762
763
  /**
   * Get all the source files this makefile knows about
   */
764
  const std::vector<cmSourceFile*> &GetSourceFiles() const
Ken Martin's avatar
Ken Martin committed
765
766
    {return this->SourceFiles;}
  std::vector<cmSourceFile*> &GetSourceFiles() {return this->SourceFiles;}
767
768
769
770
771
772

  /**
   * Is there a source file that has the provided source file as an output?
   * if so then return it
   */
  cmSourceFile *GetSourceFileWithOutput(const char *outName);
773
774
775

  /**
   * Add a macro to the list of macros. The arguments should be name of the
776
   * macro and a documentation signature of it
777
778
779
   */
  void AddMacro(const char* name, const char* signature);

780
781
782
783
784
785
786
787
  ///! Add a new cmTest to the list of tests for this makefile.
  cmTest* CreateTest(const char* testName);

  /** Get a cmTest pointer for a given test name, if the name is
   *  not found, then a null pointer is returned.
   */
  cmTest* GetTest(const char* testName) const;

788
789
790
791
  /**
   * Get a list of macros as a ; separated string
   */
  void GetListOfMacros(std::string& macros);
792
793
794
795
796

  /**
   * Return a location of a file in cmake or custom modules directory
   */
  std::string GetModulesFile(const char* name);
797

798
  ///! Set/Get a property of this directory
799
  void SetProperty(const char *prop, const char *value);
800
  void AppendProperty(const char *prop, const char *value,bool asString=false);
Ken Martin's avatar
Ken Martin committed
801
  const char *GetProperty(const char *prop);
802
803
804
805
  const char *GetPropertyOrDefinition(const char *prop);
  const char *GetProperty(const char *prop, cmProperty::ScopeType scope);
  bool GetPropertyAsBool(const char *prop);

806
807
  const char* GetFeature(const char* feature, const char* config);

808
809
  // Get the properties
  cmPropertyMap &GetProperties() { return this->Properties; };
810

811
812
  ///! Initialize a makefile from its parent
  void InitializeFromParent();
813

814
815
  ///! Set/Get the preorder flag
  void SetPreOrder(bool p) { this->PreOrder = p; }
Alexander Neundorf's avatar
   
Alexander Neundorf committed
816
  bool GetPreOrder() const { return this->PreOrder; }
817

818
  void AddInstallGenerator(cmInstallGenerator* g)
Alexander Neundorf's avatar
   
Alexander Neundorf committed
819
    { if(g) this->InstallGenerators.push_back(g); }
820
  std::vector<cmInstallGenerator*>& GetInstallGenerators()
Ken Martin's avatar
Ken Martin committed
821
    { return this->InstallGenerators; }
822

823
824
825
826
827
  void AddTestGenerator(cmTestGenerator* g)
    { if(g) this->TestGenerators.push_back(g); }
  std::vector<cmTestGenerator*>& GetTestGenerators()
    { return this->TestGenerators; }

828
829
830
  // Define the properties
  static void DefineProperties(cmake *cm);

831
832
833
  // push and pop variable scopes
  void PushScope();
  void PopScope();
834
  void RaiseScope(const char *var, const char *value);
835

836
837
838
839
840
841
842
843
844
845
  /** Helper class to push and pop scopes automatically.  */
  class ScopePushPop
  {
  public:
    ScopePushPop(cmMakefile* m): Makefile(m) { this->Makefile->PushScope(); }
    ~ScopePushPop() { this->Makefile->PopScope(); }
  private:
    cmMakefile* Makefile;
  };

Bill Hoffman's avatar
Bill Hoffman committed
846
847
  void IssueMessage(cmake::MessageType t,
                    std::string const& text) const;
848

849
850
851
  /** Set whether or not to report a CMP0000 violation.  */
  void SetCheckCMP0000(bool b) { this->CheckCMP0000 = b; }

852
protected:
853
854
  // add link libraries and directories to the target
  void AddGlobalLinkInformation(const char* name, cmTarget& target);
855
856

  // Check for a an unused variable
857
  void CheckForUnused(const char* reason, const char* name) const;
858

Ken Martin's avatar
Ken Martin committed
859
  std::string Prefix;
860
  std::vector<std::string> AuxSourceDirectories; //
Ken Martin's avatar
Ken Martin committed
861

862
863
864
  std::string cmStartDirectory;
  std::string StartOutputDirectory;
  std::string cmHomeDirectory;
Ken Martin's avatar
Ken Martin committed
865
866
  std::string HomeOutputDirectory;
  std::string cmCurrentListFile;
Ken Martin's avatar
Ken Martin committed
867

Ken Martin's avatar
Ken Martin committed
868
  std::string ProjectName;    // project name
869
870

  // libraries, classes, and executables
Ken Martin's avatar
Ken Martin committed
871
872
  cmTargets Targets;
  std::vector<cmSourceFile*> SourceFiles;
873

874
  // Tests
875
  std::map<cmStdString, cmTest*> Tests;
876

877
878
  // The include and link-library paths.  These may have order
  // dependency, so they must be vectors (not set).
Ken Martin's avatar
Ken Martin committed
879
880
  std::vector<std::string> IncludeDirectories;
  std::vector<std::string> LinkDirectories;
881
882
883
884
885

  // The set of include directories that are marked as system include
  // directories.
  std::set<cmStdString> SystemIncludeDirectories;

Ken Martin's avatar
Ken Martin committed
886
  std::vector<std::string> ListFiles; // list of command files loaded
Bill Hoffman's avatar