cmState.cxx 52.1 KB
Newer Older
Stephen Kelly's avatar
Stephen Kelly committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2015 Stephen Kelly <steveire@gmail.com>

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

  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.
============================================================================*/
#include "cmState.h"

#include "cmake.h"
15
#include "cmCacheManager.h"
16
17
#include "cmCommand.h"
#include "cmAlgorithms.h"
18
#include "cmDefinitions.h"
19
20

#include <assert.h>
Stephen Kelly's avatar
Stephen Kelly committed
21

22
23
struct cmState::SnapshotDataType
{
24
  cmState::PositionType ScopeParent;
25
  cmState::PositionType DirectoryParent;
26
27
28
  cmLinkedTree<cmState::PolicyStackEntry>::iterator Policies;
  cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyRoot;
  cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyScope;
29
  cmState::SnapshotType SnapshotType;
30
  bool Keep;
31
  cmLinkedTree<std::string>::iterator ExecutionListFile;
32
33
  cmLinkedTree<cmState::BuildsystemDirectoryStateType>::iterator
                                                          BuildSystemDirectory;
34
35
36
  cmLinkedTree<cmDefinitions>::iterator Vars;
  cmLinkedTree<cmDefinitions>::iterator Root;
  cmLinkedTree<cmDefinitions>::iterator Parent;
37
38
  std::string EntryPointCommand;
  long EntryPointLine;
39
40
41
  std::vector<std::string>::size_type IncludeDirectoryPosition;
  std::vector<std::string>::size_type CompileDefinitionsPosition;
  std::vector<std::string>::size_type CompileOptionsPosition;
42
43
};

44
45
46
47
48
49
50
51
52
struct cmState::PolicyStackEntry: public cmPolicies::PolicyMap
{
  typedef cmPolicies::PolicyMap derived;
  PolicyStackEntry(bool w = false): derived(), Weak(w) {}
  PolicyStackEntry(derived const& d, bool w): derived(d), Weak(w) {}
  PolicyStackEntry(PolicyStackEntry const& r): derived(r), Weak(r.Weak) {}
  bool Weak;
};

53
54
struct cmState::BuildsystemDirectoryStateType
{
55
56
  cmState::PositionType DirectoryEnd;

57
58
59
60
61
62
63
64
65
66
67
68
  std::string Location;
  std::string OutputLocation;

  std::vector<std::string> CurrentSourceDirectoryComponents;
  std::vector<std::string> CurrentBinaryDirectoryComponents;
  // The top-most directories for relative path conversion.  Both the
  // source and destination location of a relative path conversion
  // must be underneath one of these directories (both under source or
  // both under binary) in order for the relative path to be evaluated
  // safely by the build tools.
  std::string RelativePathTopSource;
  std::string RelativePathTopBinary;
69
70
71
72
73
74
75
76
77

  std::vector<std::string> IncludeDirectories;
  std::vector<cmListFileBacktrace> IncludeDirectoryBacktraces;

  std::vector<std::string> CompileDefinitions;
  std::vector<cmListFileBacktrace> CompileDefinitionsBacktraces;

  std::vector<std::string> CompileOptions;
  std::vector<cmListFileBacktrace> CompileOptionsBacktraces;
78

79
80
  std::string ProjectName;

81
  cmPropertyMap Properties;
82
83

  std::vector<cmState::Snapshot> Children;
84
85
};

Stephen Kelly's avatar
Stephen Kelly committed
86
cmState::cmState(cmake* cm)
87
  : CMakeInstance(cm),
88
89
90
91
92
93
94
    IsInTryCompile(false),
    WindowsShell(false),
    WindowsVSIDE(false),
    WatcomWMake(false),
    MinGWMake(false),
    NMake(false),
    MSYSShell(false)
Stephen Kelly's avatar
Stephen Kelly committed
95
96
{
}
97

98
99
100
101
102
cmState::~cmState()
{
  cmDeleteAll(this->Commands);
}

103
104
105
106
107
108
109
110
111
112
113
114
115
const char* cmCacheEntryTypes[] =
{ "BOOL",
  "PATH",
  "FILEPATH",
  "STRING",
  "INTERNAL",
  "STATIC",
  "UNINITIALIZED",
  0
};

const char*
cmState::CacheEntryTypeToString(cmState::CacheEntryType type)
Stephen Kelly's avatar
Stephen Kelly committed
116
{
117
118
119
120
121
  if ( type > 6 )
    {
    return cmCacheEntryTypes[6];
    }
  return cmCacheEntryTypes[type];
Stephen Kelly's avatar
Stephen Kelly committed
122
123
}

124
125
cmState::CacheEntryType
cmState::StringToCacheEntryType(const char* s)
Stephen Kelly's avatar
Stephen Kelly committed
126
{
127
128
129
130
131
132
133
134
135
136
  int i = 0;
  while(cmCacheEntryTypes[i])
    {
    if(strcmp(s, cmCacheEntryTypes[i]) == 0)
      {
      return static_cast<cmState::CacheEntryType>(i);
      }
    ++i;
    }
  return STRING;
Stephen Kelly's avatar
Stephen Kelly committed
137
138
139
140
}

bool cmState::IsCacheEntryType(std::string const& key)
{
141
142
143
144
145
146
147
148
  for(int i=0; cmCacheEntryTypes[i]; ++i)
    {
    if(strcmp(key.c_str(), cmCacheEntryTypes[i]) == 0)
      {
      return true;
      }
    }
  return false;
Stephen Kelly's avatar
Stephen Kelly committed
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
}

std::vector<std::string> cmState::GetCacheEntryKeys() const
{
  std::vector<std::string> definitions;
  definitions.reserve(this->CMakeInstance->GetCacheManager()->GetSize());
  cmCacheManager::CacheIterator cit =
    this->CMakeInstance->GetCacheManager()->GetCacheIterator();
  for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
    {
    definitions.push_back(cit.GetName());
    }
  return definitions;
}

const char* cmState::GetCacheEntryValue(std::string const& key) const
{
  cmCacheManager::CacheEntry* e = this->CMakeInstance->GetCacheManager()
             ->GetCacheEntry(key);
  if (!e)
    {
    return 0;
    }
  return e->Value.c_str();
}

const char*
cmState::GetInitializedCacheValue(std::string const& key) const
{
  return this->CMakeInstance->GetCacheManager()->GetInitializedCacheValue(key);
}

181
cmState::CacheEntryType
Stephen Kelly's avatar
Stephen Kelly committed
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
cmState::GetCacheEntryType(std::string const& key) const
{
  cmCacheManager::CacheIterator it =
      this->CMakeInstance->GetCacheManager()->GetCacheIterator(key.c_str());
  return it.GetType();
}

void cmState::SetCacheEntryValue(std::string const& key,
                                         std::string const& value)
{
  this->CMakeInstance->GetCacheManager()->SetCacheEntryValue(key, value);
}

void cmState::SetCacheEntryProperty(std::string const& key,
                            std::string const& propertyName,
                            std::string const& value)
{
  cmCacheManager::CacheIterator it =
      this->CMakeInstance->GetCacheManager()->GetCacheIterator(key.c_str());
  it.SetProperty(propertyName, value.c_str());
}

void cmState::SetCacheEntryBoolProperty(std::string const& key,
                            std::string const& propertyName,
                            bool value)
{
  cmCacheManager::CacheIterator it =
      this->CMakeInstance->GetCacheManager()->GetCacheIterator(key.c_str());
  it.SetProperty(propertyName, value);
}

const char* cmState::GetCacheEntryProperty(std::string const& key,
                                              std::string const& propertyName)
{
  cmCacheManager::CacheIterator it = this->CMakeInstance->GetCacheManager()
             ->GetCacheIterator(key.c_str());
  if (!it.PropertyExists(propertyName))
    {
    return 0;
    }
  return it.GetProperty(propertyName);
}

bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,
                                              std::string const& propertyName)
{
  return this->CMakeInstance->GetCacheManager()
             ->GetCacheIterator(key.c_str()).GetPropertyAsBool(propertyName);
}

void cmState::AddCacheEntry(const std::string& key, const char* value,
                                    const char* helpString,
234
                                    cmState::CacheEntryType type)
Stephen Kelly's avatar
Stephen Kelly committed
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
{
  this->CMakeInstance->GetCacheManager()->AddCacheEntry(key, value,
                                                        helpString, type);
}

void cmState::RemoveCacheEntry(std::string const& key)
{
  this->CMakeInstance->GetCacheManager()->RemoveCacheEntry(key);
}

void cmState::AppendCacheEntryProperty(const std::string& key,
                                               const std::string& property,
                                               const std::string& value,
                                               bool asString)
{
  this->CMakeInstance->GetCacheManager()
       ->GetCacheIterator(key.c_str()).AppendProperty(property,
                                                       value.c_str(),
                                                       asString);
}

void cmState::RemoveCacheEntryProperty(std::string const& key,
                                              std::string const& propertyName)
{
  this->CMakeInstance->GetCacheManager()
       ->GetCacheIterator(key.c_str()).SetProperty(propertyName, (void*)0);
}
262

263
cmState::Snapshot cmState::Reset()
264
{
265
  this->GlobalProperties.clear();
266
  this->PropertyDefinitions.clear();
267

268
269
270
  PositionType pos = this->SnapshotData.Truncate();
  this->ExecutionListFiles.Truncate();

271
272
273
274
275
276
277
278
279
  {
  cmLinkedTree<BuildsystemDirectoryStateType>::iterator it =
      this->BuildsystemDirectory.Truncate();
  it->IncludeDirectories.clear();
  it->IncludeDirectoryBacktraces.clear();
  it->CompileDefinitions.clear();
  it->CompileDefinitionsBacktraces.clear();
  it->CompileOptions.clear();
  it->CompileOptionsBacktraces.clear();
280
  it->DirectoryEnd = pos;
281
  it->Properties.clear();
282
  it->Children.clear();
283
  }
284

285
286
287
288
289
290
  this->PolicyStack.Clear();
  pos->Policies = this->PolicyStack.Root();
  pos->PolicyRoot = this->PolicyStack.Root();
  pos->PolicyScope = this->PolicyStack.Root();
  assert(pos->Policies.IsValid());
  assert(pos->PolicyRoot.IsValid());
291
  this->VarTree.Clear();
292
  pos->Vars = this->VarTree.Push(this->VarTree.Root());
293
294
  pos->Parent = this->VarTree.Root();
  pos->Root = this->VarTree.Root();
295

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
  this->DefineProperty
    ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY,
     "", "", true);
  this->DefineProperty
    ("RULE_LAUNCH_LINK", cmProperty::DIRECTORY,
     "", "", true);
  this->DefineProperty
    ("RULE_LAUNCH_CUSTOM", cmProperty::DIRECTORY,
     "", "", true);

  this->DefineProperty
    ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
     "", "", true);
  this->DefineProperty
    ("RULE_LAUNCH_LINK", cmProperty::TARGET,
     "", "", true);
  this->DefineProperty
    ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
     "", "", true);
315
316

  return Snapshot(this, pos);
317
318
319
320
321
322
323
324
325
326
327
328
329
}

void cmState::DefineProperty(const std::string& name,
                           cmProperty::ScopeType scope,
                           const char *ShortDescription,
                           const char *FullDescription,
                           bool chained)
{
  this->PropertyDefinitions[scope].DefineProperty(name,scope,ShortDescription,
                                                  FullDescription,
                                                  chained);
}

330
cmPropertyDefinition const* cmState
331
::GetPropertyDefinition(const std::string& name,
332
                        cmProperty::ScopeType scope) const
333
334
335
{
  if (this->IsPropertyDefined(name,scope))
    {
336
337
338
    cmPropertyDefinitionMap const& defs =
        this->PropertyDefinitions.find(scope)->second;
    return &defs.find(name)->second;
339
340
341
342
343
    }
  return 0;
}

bool cmState::IsPropertyDefined(const std::string& name,
344
                                cmProperty::ScopeType scope) const
345
{
346
347
348
349
350
351
352
  std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it
      = this->PropertyDefinitions.find(scope);
  if (it == this->PropertyDefinitions.end())
    {
    return false;
    }
  return it->second.IsPropertyDefined(name);
353
354
355
}

bool cmState::IsPropertyChained(const std::string& name,
356
                                cmProperty::ScopeType scope) const
357
{
358
359
360
361
362
363
364
  std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it
      = this->PropertyDefinitions.find(scope);
  if (it == this->PropertyDefinitions.end())
    {
    return false;
    }
  return it->second.IsPropertyChained(name);
365
}
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388

void cmState::SetLanguageEnabled(std::string const& l)
{
  std::vector<std::string>::iterator it =
      std::lower_bound(this->EnabledLanguages.begin(),
                       this->EnabledLanguages.end(), l);
  if (it == this->EnabledLanguages.end() || *it != l)
    {
    this->EnabledLanguages.insert(it, l);
    }
}

bool cmState::GetLanguageEnabled(std::string const& l) const
{
  return std::binary_search(this->EnabledLanguages.begin(),
                            this->EnabledLanguages.end(), l);
}

std::vector<std::string> cmState::GetEnabledLanguages() const
{
  return this->EnabledLanguages;
}

389
390
391
392
393
void cmState::SetEnabledLanguages(std::vector<std::string> const& langs)
{
  this->EnabledLanguages = langs;
}

394
395
396
397
void cmState::ClearEnabledLanguages()
{
  this->EnabledLanguages.clear();
}
398
399
400
401
402
403
404
405
406
407

bool cmState::GetIsInTryCompile() const
{
  return this->IsInTryCompile;
}

void cmState::SetIsInTryCompile(bool b)
{
  this->IsInTryCompile = b;
}
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493

void cmState::RenameCommand(std::string const& oldName,
                            std::string const& newName)
{
  // if the command already exists, free the old one
  std::string sOldName = cmSystemTools::LowerCase(oldName);
  std::string sNewName = cmSystemTools::LowerCase(newName);
  std::map<std::string, cmCommand*>::iterator pos =
      this->Commands.find(sOldName);
  if ( pos == this->Commands.end() )
    {
    return;
    }
  cmCommand* cmd = pos->second;

  pos = this->Commands.find(sNewName);
  if (pos != this->Commands.end())
    {
    delete pos->second;
    this->Commands.erase(pos);
    }
  this->Commands.insert(std::make_pair(sNewName, cmd));
  pos = this->Commands.find(sOldName);
  this->Commands.erase(pos);
}

void cmState::AddCommand(cmCommand* command)
{
  std::string name = cmSystemTools::LowerCase(command->GetName());
  // if the command already exists, free the old one
  std::map<std::string, cmCommand*>::iterator pos = this->Commands.find(name);
  if (pos != this->Commands.end())
    {
    delete pos->second;
    this->Commands.erase(pos);
    }
  this->Commands.insert(std::make_pair(name, command));
}

void cmState::RemoveUnscriptableCommands()
{
  std::vector<std::string> unscriptableCommands;
  for (std::map<std::string, cmCommand*>::iterator
       pos = this->Commands.begin();
       pos != this->Commands.end(); )
    {
    if (!pos->second->IsScriptable())
      {
      delete pos->second;
      this->Commands.erase(pos++);
      }
    else
      {
      ++pos;
      }
    }
}

cmCommand* cmState::GetCommand(std::string const& name) const
{
  cmCommand* command = 0;
  std::string sName = cmSystemTools::LowerCase(name);
  std::map<std::string, cmCommand*>::const_iterator pos =
      this->Commands.find(sName);
  if (pos != this->Commands.end())
    {
    command = (*pos).second;
    }
  return command;
}

std::vector<std::string> cmState::GetCommandNames() const
{
  std::vector<std::string> commandNames;
  commandNames.reserve(this->Commands.size());
  std::map<std::string, cmCommand*>::const_iterator cmds
      = this->Commands.begin();
  for ( ; cmds != this->Commands.end(); ++ cmds )
    {
    commandNames.push_back(cmds->first);
    }
  return commandNames;
}

void cmState::RemoveUserDefinedCommands()
{
494
  std::vector<cmCommand*> renamedCommands;
495
496
497
498
499
500
501
502
503
  for(std::map<std::string, cmCommand*>::iterator j = this->Commands.begin();
      j != this->Commands.end(); )
    {
    if (j->second->IsA("cmMacroHelperCommand") ||
        j->second->IsA("cmFunctionHelperCommand"))
      {
      delete j->second;
      this->Commands.erase(j++);
      }
504
505
506
507
508
    else if (j->first != j->second->GetName())
      {
      renamedCommands.push_back(j->second);
      this->Commands.erase(j++);
      }
509
510
511
512
513
    else
      {
      ++j;
      }
    }
514
515
516
517
518
  for (std::vector<cmCommand*>::const_iterator it = renamedCommands.begin();
       it != renamedCommands.end(); ++it)
    {
    this->Commands[cmSystemTools::LowerCase((*it)->GetName())] = *it;
    }
519
}
520
521
522

void cmState::SetGlobalProperty(const std::string& prop, const char* value)
{
523
  this->GlobalProperties.SetProperty(prop, value);
524
525
526
527
528
}

void cmState::AppendGlobalProperty(const std::string& prop,
                                   const char* value, bool asString)
{
529
  this->GlobalProperties.AppendProperty(prop, value, asString);
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
}

const char *cmState::GetGlobalProperty(const std::string& prop)
{
  if ( prop == "CACHE_VARIABLES" )
    {
    std::vector<std::string> cacheKeys = this->GetCacheEntryKeys();
    this->SetGlobalProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str());
    }
  else if ( prop == "COMMANDS" )
    {
    std::vector<std::string> commands = this->GetCommandNames();
    this->SetGlobalProperty("COMMANDS", cmJoin(commands, ";").c_str());
    }
  else if ( prop == "IN_TRY_COMPILE" )
    {
    this->SetGlobalProperty("IN_TRY_COMPILE",
                      this->IsInTryCompile ? "1" : "0");
    }
  else if ( prop == "ENABLED_LANGUAGES" )
    {
    std::string langs;
    langs = cmJoin(this->EnabledLanguages, ";");
    this->SetGlobalProperty("ENABLED_LANGUAGES", langs.c_str());
    }
#define STRING_LIST_ELEMENT(F) ";" #F
  if (prop == "CMAKE_C_KNOWN_FEATURES")
    {
    return FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT) + 1;
    }
  if (prop == "CMAKE_CXX_KNOWN_FEATURES")
    {
    return FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT) + 1;
    }
#undef STRING_LIST_ELEMENT
565
  return this->GlobalProperties.GetPropertyValue(prop);
566
567
568
569
570
571
}

bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
{
  return cmSystemTools::IsOn(this->GetGlobalProperty(prop));
}
572
573
574
575
576

void cmState::SetSourceDirectory(std::string const& sourceDirectory)
{
  this->SourceDirectory = sourceDirectory;
  cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
577
578
579
580

  cmSystemTools::SplitPath(
      cmSystemTools::CollapseFullPath(this->SourceDirectory),
        this->SourceDirectoryComponents);
581
582
583
584
585
586
587
}

const char* cmState::GetSourceDirectory() const
{
  return this->SourceDirectory.c_str();
}

588
589
590
591
592
std::vector<std::string> const& cmState::GetSourceDirectoryComponents() const
{
  return this->SourceDirectoryComponents;
}

593
594
595
596
void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
{
  this->BinaryDirectory = binaryDirectory;
  cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
597
598
599
600

  cmSystemTools::SplitPath(
      cmSystemTools::CollapseFullPath(this->BinaryDirectory),
        this->BinaryDirectoryComponents);
601
602
}

603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
void cmState::SetWindowsShell(bool windowsShell)
{
  this->WindowsShell = windowsShell;
}

bool cmState::UseWindowsShell() const
{
  return this->WindowsShell;
}

void cmState::SetWindowsVSIDE(bool windowsVSIDE)
{
  this->WindowsVSIDE = windowsVSIDE;
}

bool cmState::UseWindowsVSIDE() const
{
  return this->WindowsVSIDE;
}

void cmState::SetWatcomWMake(bool watcomWMake)
{
  this->WatcomWMake = watcomWMake;
}

bool cmState::UseWatcomWMake() const
{
  return this->WatcomWMake;
}

void cmState::SetMinGWMake(bool minGWMake)
{
  this->MinGWMake = minGWMake;
}

bool cmState::UseMinGWMake() const
{
  return this->MinGWMake;
}

void cmState::SetNMake(bool nMake)
{
  this->NMake = nMake;
}

bool cmState::UseNMake() const
{
  return this->NMake;
}

void cmState::SetMSYSShell(bool mSYSShell)
{
  this->MSYSShell = mSYSShell;
}

bool cmState::UseMSYSShell() const
{
  return this->MSYSShell;
}

663
664
665
666
const char* cmState::GetBinaryDirectory() const
{
  return this->BinaryDirectory.c_str();
}
Stephen Kelly's avatar
Stephen Kelly committed
667

668
669
670
671
672
std::vector<std::string> const& cmState::GetBinaryDirectoryComponents() const
{
  return this->BinaryDirectoryComponents;
}

673
void cmState::Directory::ComputeRelativePathTopSource()
674
675
676
677
678
{
  // Relative path conversion inside the source tree is not used to
  // construct relative paths passed to build tools so it is safe to use
  // even when the source is a network path.

679
  cmState::Snapshot snapshot = this->Snapshot_;
680
681
682
683
  std::vector<cmState::Snapshot> snapshots;
  snapshots.push_back(snapshot);
  while (true)
    {
684
    snapshot = snapshot.GetBuildsystemDirectoryParent();
685
686
687
688
689
690
691
692
693
694
    if (snapshot.IsValid())
      {
      snapshots.push_back(snapshot);
      }
    else
      {
      break;
      }
    }

695
  std::string result = snapshots.front().GetDirectory().GetCurrentSource();
696
697
698
699

  for (std::vector<cmState::Snapshot>::const_iterator it =
       snapshots.begin() + 1; it != snapshots.end(); ++it)
    {
700
    std::string currentSource = it->GetDirectory().GetCurrentSource();
701
702
703
704
705
    if(cmSystemTools::IsSubDirectory(result, currentSource))
      {
      result = currentSource;
      }
    }
706
  this->DirectoryState->RelativePathTopSource = result;
707
708
}

709
void cmState::Directory::ComputeRelativePathTopBinary()
710
{
711
  cmState::Snapshot snapshot = this->Snapshot_;
712
713
714
715
  std::vector<cmState::Snapshot> snapshots;
  snapshots.push_back(snapshot);
  while (true)
    {
716
    snapshot = snapshot.GetBuildsystemDirectoryParent();
717
718
719
720
721
722
723
724
725
726
727
    if (snapshot.IsValid())
      {
      snapshots.push_back(snapshot);
      }
    else
      {
      break;
      }
    }

  std::string result =
728
      snapshots.front().GetDirectory().GetCurrentBinary();
729
730
731
732

  for (std::vector<cmState::Snapshot>::const_iterator it =
       snapshots.begin() + 1; it != snapshots.end(); ++it)
    {
733
    std::string currentBinary = it->GetDirectory().GetCurrentBinary();
734
735
736
737
738
739
740
741
742
743
744
    if(cmSystemTools::IsSubDirectory(result, currentBinary))
      {
      result = currentBinary;
      }
    }

  // The current working directory on Windows cannot be a network
  // path.  Therefore relative paths cannot work when the binary tree
  // is a network path.
  if(result.size() < 2 || result.substr(0, 2) != "//")
    {
745
    this->DirectoryState->RelativePathTopBinary = result;
746
747
748
    }
  else
    {
749
    this->DirectoryState->RelativePathTopBinary = "";
750
751
752
    }
}

753
754
cmState::Snapshot cmState::CreateBaseSnapshot()
{
755
  PositionType pos = this->SnapshotData.Push(this->SnapshotData.Root());
756
  pos->DirectoryParent = this->SnapshotData.Root();
757
  pos->ScopeParent = this->SnapshotData.Root();
758
  pos->SnapshotType = BaseType;
759
  pos->Keep = true;
760
  pos->BuildSystemDirectory =
761
      this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root());
762
  pos->ExecutionListFile =
763
      this->ExecutionListFiles.Push(this->ExecutionListFiles.Root());
764
765
766
  pos->IncludeDirectoryPosition = 0;
  pos->CompileDefinitionsPosition = 0;
  pos->CompileOptionsPosition = 0;
767
  pos->BuildSystemDirectory->DirectoryEnd = pos;
768
769
770
771
772
  pos->Policies = this->PolicyStack.Root();
  pos->PolicyRoot = this->PolicyStack.Root();
  pos->PolicyScope = this->PolicyStack.Root();
  assert(pos->Policies.IsValid());
  assert(pos->PolicyRoot.IsValid());
773
  pos->Vars = this->VarTree.Push(this->VarTree.Root());
774
775
776
  assert(pos->Vars.IsValid());
  pos->Parent = this->VarTree.Root();
  pos->Root = this->VarTree.Root();
777
778
779
  return cmState::Snapshot(this, pos);
}

780
cmState::Snapshot
781
782
783
cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
                                    std::string const& entryPointCommand,
                                    long entryPointLine)
Stephen Kelly's avatar
Stephen Kelly committed
784
{
785
  assert(originSnapshot.IsValid());
786
  PositionType pos = this->SnapshotData.Push(originSnapshot.Position);
787
788
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
789
  pos->DirectoryParent = originSnapshot.Position;
790
  pos->ScopeParent = originSnapshot.Position;
791
  pos->SnapshotType = BuildsystemDirectoryType;
792
  pos->Keep = true;
793
  pos->BuildSystemDirectory =
794
      this->BuildsystemDirectory.Push(
795
        originSnapshot.Position->BuildSystemDirectory);
796
  pos->ExecutionListFile =
797
      this->ExecutionListFiles.Push(
798
        originSnapshot.Position->ExecutionListFile);
799
  pos->BuildSystemDirectory->DirectoryEnd = pos;
800
801
802
803
804
  pos->Policies = originSnapshot.Position->Policies;
  pos->PolicyRoot = originSnapshot.Position->Policies;
  pos->PolicyScope = originSnapshot.Position->Policies;
  assert(pos->Policies.IsValid());
  assert(pos->PolicyRoot.IsValid());
805
806
807
808
809

  cmLinkedTree<cmDefinitions>::iterator origin =
      originSnapshot.Position->Vars;
  pos->Parent = origin;
  pos->Root = origin;
810
  pos->Vars = this->VarTree.Push(origin);
811
812
813
  cmState::Snapshot snapshot = cmState::Snapshot(this, pos);
  originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
  return snapshot;
Stephen Kelly's avatar
Stephen Kelly committed
814
815
}

816
cmState::Snapshot
817
818
819
820
cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot,
                                    std::string const& entryPointCommand,
                                    long entryPointLine,
                                    std::string const& fileName)
821
{
822
823
  PositionType pos = this->SnapshotData.Push(originSnapshot.Position,
                                             *originSnapshot.Position);
824
  pos->ScopeParent = originSnapshot.Position;
825
826
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
827
  pos->SnapshotType = FunctionCallType;
828
  pos->Keep = false;
829
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
830
        originSnapshot.Position->ExecutionListFile, fileName);
831
  pos->BuildSystemDirectory->DirectoryEnd = pos;
832
  pos->PolicyScope = originSnapshot.Position->Policies;
833
834
835
836
  assert(originSnapshot.Position->Vars.IsValid());
  cmLinkedTree<cmDefinitions>::iterator origin =
      originSnapshot.Position->Vars;
  pos->Parent = origin;
837
  pos->Vars = this->VarTree.Push(origin);
838
839
840
841
842
  return cmState::Snapshot(this, pos);
}


cmState::Snapshot
843
844
845
846
cmState::CreateMacroCallSnapshot(cmState::Snapshot originSnapshot,
                                    std::string const& entryPointCommand,
                                    long entryPointLine,
                                    std::string const& fileName)
847
{
848
849
  PositionType pos = this->SnapshotData.Push(originSnapshot.Position,
                                             *originSnapshot.Position);
850
851
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
852
  pos->SnapshotType = MacroCallType;
853
  pos->Keep = false;
854
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
855
        originSnapshot.Position->ExecutionListFile, fileName);
856
  assert(originSnapshot.Position->Vars.IsValid());
857
  pos->BuildSystemDirectory->DirectoryEnd = pos;
858
  pos->PolicyScope = originSnapshot.Position->Policies;
859
860
861
862
  return cmState::Snapshot(this, pos);
}

cmState::Snapshot
863
864
865
866
cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot,
                                 const std::string& entryPointCommand,
                                 long entryPointLine,
                                 const std::string& fileName)
867
{
868
869
  PositionType pos = this->SnapshotData.Push(originSnapshot.Position,
                                             *originSnapshot.Position);
870
871
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
872
  pos->SnapshotType = CallStackType;
873
  pos->Keep = true;
874
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
875
        originSnapshot.Position->ExecutionListFile, fileName);
876
  assert(originSnapshot.Position->Vars.IsValid());
877
  pos->BuildSystemDirectory->DirectoryEnd = pos;
878
  pos->PolicyScope = originSnapshot.Position->Policies;
879
880
881
  return cmState::Snapshot(this, pos);
}

882
883
884
885
886
cmState::Snapshot
cmState::CreateVariableScopeSnapshot(cmState::Snapshot originSnapshot,
                                     std::string const& entryPointCommand,
                                     long entryPointLine)
{
887
888
  PositionType pos = this->SnapshotData.Push(originSnapshot.Position,
                                             *originSnapshot.Position);
889
890
891
892
  pos->ScopeParent = originSnapshot.Position;
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
  pos->SnapshotType = VariableScopeType;
893
  pos->Keep = false;
894
  pos->PolicyScope = originSnapshot.Position->Policies;
895
  assert(originSnapshot.Position->Vars.IsValid());
896

897
898
899
  cmLinkedTree<cmDefinitions>::iterator origin =
      originSnapshot.Position->Vars;
  pos->Parent = origin;
900
  pos->Vars = this->VarTree.Push(origin);
901
  assert(pos->Vars.IsValid());
902
903
904
  return cmState::Snapshot(this, pos);
}

905
cmState::Snapshot
906
907
908
909
cmState::CreateInlineListFileSnapshot(cmState::Snapshot originSnapshot,
                                      const std::string& entryPointCommand,
                                      long entryPointLine,
                                      const std::string& fileName)
910
{
911
912
  PositionType pos = this->SnapshotData.Push(originSnapshot.Position,
                                             *originSnapshot.Position);
913
914
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
915
  pos->SnapshotType = InlineListFileType;
916
  pos->Keep = true;
917
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
918
        originSnapshot.Position->ExecutionListFile, fileName);
919
  pos->BuildSystemDirectory->DirectoryEnd = pos;
920
  pos->PolicyScope = originSnapshot.Position->Policies;
921
922
923
  return cmState::Snapshot(this, pos);
}

924
925
926
cmState::Snapshot
cmState::CreatePolicyScopeSnapshot(cmState::Snapshot originSnapshot)
{
927
928
  PositionType pos = this->SnapshotData.Push(originSnapshot.Position,
                                             *originSnapshot.Position);
929
  pos->SnapshotType = PolicyScopeType;
930
  pos->Keep = false;
931
  pos->BuildSystemDirectory->DirectoryEnd = pos;
932
  pos->PolicyScope = originSnapshot.Position->Policies;
933
934
935
  return cmState::Snapshot(this, pos);
}

936
937
938
939
940
cmState::Snapshot cmState::Pop(cmState::Snapshot originSnapshot)
{
  PositionType pos = originSnapshot.Position;
  PositionType prevPos = pos;
  ++prevPos;
941
942
943
944
945
946
  prevPos->IncludeDirectoryPosition =
      prevPos->BuildSystemDirectory->IncludeDirectories.size();
  prevPos->CompileDefinitionsPosition =
      prevPos->BuildSystemDirectory->CompileDefinitions.size();
  prevPos->CompileOptionsPosition =
      prevPos->BuildSystemDirectory->CompileOptions.size();
947
  prevPos->BuildSystemDirectory->DirectoryEnd = prevPos;
948

949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
  if (!pos->Keep && this->SnapshotData.IsLast(pos))
    {
    if (pos->Vars != prevPos->Vars)
      {
      assert(this->VarTree.IsLast(pos->Vars));
      this->VarTree.Pop(pos->Vars);
      }
    if (pos->ExecutionListFile != prevPos->ExecutionListFile)
      {
      assert(this->ExecutionListFiles.IsLast(pos->ExecutionListFile));
      this->ExecutionListFiles.Pop(pos->ExecutionListFile);
      }
    this->SnapshotData.Pop(pos);
    }

964
  return Snapshot(this, prevPos);
965
966
}

967
968
969
970
971
972
cmState::Snapshot::Snapshot(cmState* state)
  : State(state)
  , Position()
{
}

973
974
975
976
977
std::vector<cmState::Snapshot> cmState::Snapshot::GetChildren()
{
  return this->Position->BuildSystemDirectory->Children;
}

Stephen Kelly's avatar
Stephen Kelly committed
978
979
980
981
982
983
cmState::Snapshot::Snapshot(cmState* state, PositionType position)
  : State(state),
  Position(position)
{

}
984

985
986
987
988
989
cmState::SnapshotType cmState::Snapshot::GetType() const
{
  return this->Position->SnapshotType;
}

990
const char* cmState::Directory::GetCurrentSource() const
991
{
992
  return this->DirectoryState->Location.c_str();
993
994
}

995
void cmState::Directory::SetCurrentSource(std::string const& dir)
996
{
997
  std::string& loc = this->DirectoryState->Location;
998
999
1000
  loc = dir;
  cmSystemTools::ConvertToUnixSlashes(loc);
  loc = cmSystemTools::CollapseFullPath(loc);
1001
1002

  cmSystemTools::SplitPath(
1003
      loc,
1004
      this->DirectoryState->CurrentSourceDirectoryComponents);
1005
  this->ComputeRelativePathTopSource();
1006
1007
}

1008
const char* cmState::Directory::GetCurrentBinary() const
1009
{
1010
  return this->DirectoryState->OutputLocation.c_str();
1011
1012
}

1013
void cmState::Directory::SetCurrentBinary(std::string const& dir)
1014
{
1015
  std::string& loc = this->DirectoryState->OutputLocation;
1016
1017
1018
  loc = dir;
  cmSystemTools::ConvertToUnixSlashes(loc);
  loc = cmSystemTools::CollapseFullPath(loc);
1019
1020

  cmSystemTools::SplitPath(
1021
      loc,
1022
      this->DirectoryState->CurrentBinaryDirectoryComponents);
1023
  this->ComputeRelativePathTopBinary();
1024
1025
}

1026
1027
1028
1029
1030
void cmState::Snapshot::Keep()
{
  this->Position->Keep = true;
}

1031
1032
1033
1034
1035
void cmState::Snapshot::SetListFile(const std::string& listfile)
{
  *this->Position->ExecutionListFile = listfile;
}

1036
std::vector<std::string> const&
1037
cmState::Directory::GetCurrentSourceComponents() const
1038
{
1039
  return this->DirectoryState->CurrentSourceDirectoryComponents;
1040
1041
1042
}

std::vector<std::string> const&
1043
cmState::Directory::GetCurrentBinaryComponents() const
1044
{
1045
  return this->DirectoryState->CurrentBinaryDirectoryComponents;
1046
}
1047

1048
const char* cmState::Directory::GetRelativePathTopSource() const
1049
{
1050
  return this->DirectoryState->RelativePathTopSource.c_str();
1051
1052
}

1053
const char* cmState::Directory::GetRelativePathTopBinary() const
1054
{
1055
  return this->DirectoryState->RelativePathTopBinary.c_str();
1056
1057
}

1058
void cmState::Directory::SetRelativePathTopSource(const char* dir)
1059
{
1060
  this->DirectoryState->RelativePathTopSource = dir;
1061
1062
}

1063
void cmState::Directory::SetRelativePathTopBinary(const char* dir)
1064
{
1065
  this->DirectoryState->RelativePathTopBinary = dir;
1066
1067
}

1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
std::string cmState::Snapshot::GetExecutionListFile() const
{
  return *this->Position->ExecutionListFile;
}

std::string cmState::Snapshot::GetEntryPointCommand() const
{
  return this->Position->EntryPointCommand;
}

long cmState::Snapshot::GetEntryPointLine() const
{
  return this->Position->EntryPointLine;
}

1083
1084
bool cmState::Snapshot::IsValid() const
{
1085
1086
1087
  return this->State && this->Position.IsValid()
      ? this->Position != this->State->SnapshotData.Root()
      : false;
1088
1089
}

1090
cmState::Snapshot cmState::Snapshot::GetBuildsystemDirectoryParent() const
1091
1092
{
  Snapshot snapshot;
1093
  if (!this->State || this->Position == this->State->SnapshotData.Root())
1094
1095
1096
    {
    return snapshot;
    }
1097
1098
1099
  PositionType parentPos = this->Position->DirectoryParent;
  if (parentPos != this->State->SnapshotData.Root())
    {
1100
1101
    snapshot = Snapshot(this->State,
                        parentPos->BuildSystemDirectory->DirectoryEnd);
1102
    }
1103
1104
1105

  return snapshot;
}
1106

1107
1108
1109
1110
1111
1112
cmState::Snapshot cmState::Snapshot::GetCallStackParent() const
{
  assert(this->State);
  assert(this->Position != this->State->SnapshotData.Root());

  Snapshot snapshot;
1113
  PositionType parentPos = this->Position;
1114
1115
  while (parentPos->SnapshotType == cmState::PolicyScopeType ||
         parentPos->SnapshotType == cmState::VariableScopeType)
1116
1117
1118
    {
    ++parentPos;
    }
1119
1120
  if (parentPos->SnapshotType == cmState::BuildsystemDirectoryType
      || parentPos->SnapshotType == cmState::BaseType)
1121
1122
1123
1124
1125
    {
    return snapshot;
    }

  ++parentPos;
1126
1127
  while (parentPos->SnapshotType == cmState::PolicyScopeType ||
         parentPos->SnapshotType == cmState::VariableScopeType)
1128
1129
1130
1131
    {
    ++parentPos;
    }

1132
1133
1134
1135
1136
1137
1138
1139
1140
  if (parentPos == this->State->SnapshotData.Root())
    {
    return snapshot;
    }

  snapshot = Snapshot(this->State, parentPos);
  return snapshot;
}

1141
1142
1143
1144
void cmState::Snapshot::PushPolicy(cmPolicies::PolicyMap entry, bool weak)
{
  PositionType pos = this->Position;
  pos->Policies =
1145
1146
    this->State->PolicyStack.Push(pos->Policies,
                                  PolicyStackEntry(entry, weak));
1147
1148
1149
1150
1151
1152
1153
1154
1155
}

bool cmState::Snapshot::PopPolicy()
{
  PositionType pos = this->Position;
  if (pos->Policies == pos->PolicyScope)
    {
    return false;
    }
1156
  pos->Policies = this->State->PolicyStack.Pop(pos->Policies);
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
  return true;
}

bool cmState::Snapshot::CanPopPolicyScope()
{
  return this->Position->Policies == this->Position->PolicyScope;
}

void cmState::Snapshot::SetPolicy(cmPolicies::PolicyID id,
                                  cmPolicies::PolicyStatus status)
{
  // Update the policy stack from the top to the top-most strong entry.
  bool previous_was_weak = true;
  for(cmLinkedTree<PolicyStackEntry>::iterator psi = this->Position->Policies;
      previous_was_weak && psi != this->Position->PolicyRoot; ++psi)
    {
    psi->Set(id, status);
    previous_was_weak = psi->Weak;
    }
}

cmPolicies::PolicyStatus
cmState::Snapshot::GetPolicy(cmPolicies::PolicyID id) const
{
  cmPolicies::PolicyStatus status = cmPolicies::GetPolicyStatus(id);

  if(status == cmPolicies::REQUIRED_ALWAYS ||
     status == cmPolicies::REQUIRED_IF_USED)
    {
    return status;
    }

  cmLinkedTree<BuildsystemDirectoryStateType>::iterator dir =
      this->Position->BuildSystemDirectory;

  while (true)
    {
    assert(dir.IsValid());
    cmLinkedTree<PolicyStackEntry>::iterator leaf =
        dir->DirectoryEnd->Policies;
    cmLinkedTree<PolicyStackEntry>::iterator root =
        dir->DirectoryEnd->PolicyRoot;
    for( ; leaf != root; ++leaf)
      {
      if(leaf->IsDefined(id))
        {
        status = leaf->Get(id);
        return status;
        }
      }
    cmState::PositionType e = dir->DirectoryEnd;
    cmState::PositionType p = e->DirectoryParent;
    if (p == this->State->SnapshotData.Root())
      {
      break;
      }
    dir = p->BuildSystemDirectory;
    }
  return status;
}

bool cmState::Snapshot::HasDefinedPolicyCMP0011()
{
  return !this->Position->Policies->IsEmpty();
}

1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
const char* cmState::Snapshot::GetDefinition(std::string const& name) const
{
  assert(this->Position->Vars.IsValid());
  return cmDefinitions::Get(name, this->Position->Vars,
                    this->Position->Root);
}

bool cmState::Snapshot::IsInitialized(std::string const& name) const
{
  return cmDefinitions::HasKey(name, this->Position->Vars,
                               this->Position->Root);
}

void cmState::Snapshot::SetDefinition(std::string const& name,
                                      std::string const& value)
{
  this->Position->Vars->Set(name, value.c_str());
}

void cmState::Snapshot::RemoveDefinition(std::string const& name)
{
  this->Position->Vars->Set(name, 0);
}

std::vector<std::string> cmState::Snapshot::UnusedKeys() const
{
  return this->Position->Vars->UnusedKeys();
}

std::vector<std::string> cmState::Snapshot::ClosureKeys() const
{
  return cmDefinitions::ClosureKeys(this->Position->Vars,
                                    this->Position->Root);
}

bool cmState::Snapshot::RaiseScope(std::string const& var, const char* varDef)
{
  if(this->Position->ScopeParent == this->Position->DirectoryParent)
    {
    Snapshot parentDir = this->GetBuildsystemDirectoryParent();
    if(!parentDir.IsValid())
      {
      return false;
      }
    // Update the definition in the parent directory top scope.  This
    // directory's scope was initialized by the closure of the parent
    // scope, so we do not need to localize the definition first.
    if (varDef)
      {
      parentDir.SetDefinition(var, varDef);
      }
    else
      {
      parentDir.RemoveDefinition(var);
      }
    return true;
    }
  // First localize the definition in the current scope.
  cmDefinitions::Raise(var, this->Position->Vars,
                       this->Position->Root);

  // Now update the definition in the parent scope.
  this->Position->Parent->Set(var, varDef);
  return true;
}

1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
static const std::string cmPropertySentinal = std::string();

template<typename T, typename U, typename V>
void InitializeContentFromParent(T& parentContent,
                          T& thisContent,
                          U& parentBacktraces,
                          U& thisBacktraces,
                          V& contentEndPosition)
{
  std::vector<std::string>::const_iterator parentBegin =
      parentContent.begin();
  std::vector<std::string>::const_iterator parentEnd =
      parentContent.end();

  std::vector<std::string>::const_reverse_iterator parentRbegin =
      cmMakeReverseIterator(parentEnd);
  std::vector<std::string>::const_reverse_iterator parentRend =
      parentContent.rend();
  parentRbegin = std::find(parentRbegin, parentRend, cmPropertySentinal);
  std::vector<std::string>::const_iterator parentIt = parentRbegin.base();

  thisContent = std::vector<std::string>(parentIt, parentEnd);

  std::vector<cmListFileBacktrace>::const_iterator btIt =
      parentBacktraces.begin() + std::distance(parentBegin, parentIt);
  std::vector<cmListFileBacktrace>::const_iterator btEnd =
      parentBacktraces.end();

  thisBacktraces = std::vector<cmListFileBacktrace>(btIt, btEnd);

  contentEndPosition = thisContent.size();
}

void cmState::Snapshot::InitializeFromParent()
{
  PositionType parent = this->Position->DirectoryParent;
1325
1326
1327
1328
1329
  assert(this->Position->Vars.IsValid());
  assert(parent->Vars.IsValid());

  *this->Position->Vars =
      cmDefinitions::MakeClosure(parent->Vars, parent->Root);
Stephen Kelly's avatar