cmState.cxx 57.7 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 "cmVersion.h"
16
#include "cmCacheManager.h"
17
18
#include "cmCommand.h"
#include "cmAlgorithms.h"
19
#include "cmDefinitions.h"
20
21

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

23
24
struct cmState::SnapshotDataType
{
25
  cmState::PositionType ScopeParent;
26
  cmState::PositionType DirectoryParent;
27
28
29
  cmLinkedTree<cmState::PolicyStackEntry>::iterator Policies;
  cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyRoot;
  cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyScope;
30
  cmState::SnapshotType SnapshotType;
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
};

86
87
cmState::cmState()
  : IsInTryCompile(false),
88
89
90
91
92
93
    WindowsShell(false),
    WindowsVSIDE(false),
    WatcomWMake(false),
    MinGWMake(false),
    NMake(false),
    MSYSShell(false)
Stephen Kelly's avatar
Stephen Kelly committed
94
{
95
  this->CacheManager = new cmCacheManager;
Stephen Kelly's avatar
Stephen Kelly committed
96
}
97

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

104
105
106
107
108
109
110
111
112
113
114
115
116
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
117
{
118
119
120
121
122
  if ( type > 6 )
    {
    return cmCacheEntryTypes[6];
    }
  return cmCacheEntryTypes[type];
Stephen Kelly's avatar
Stephen Kelly committed
123
124
}

125
126
cmState::CacheEntryType
cmState::StringToCacheEntryType(const char* s)
Stephen Kelly's avatar
Stephen Kelly committed
127
{
128
129
130
131
132
133
134
135
136
137
  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
138
139
140
141
}

bool cmState::IsCacheEntryType(std::string const& key)
{
142
143
144
145
146
147
148
149
  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
150
151
}

152
153
154
155
bool cmState::LoadCache(const std::string& path, bool internal,
                        std::set<std::string>& excludes,
                        std::set<std::string>& includes)
{
156
157
  return this->CacheManager->LoadCache(path, internal,
                                       excludes, includes);
158
159
160
161
}

bool cmState::SaveCache(const std::string& path)
{
162
  return this->CacheManager->SaveCache(path);
163
164
165
166
}

bool cmState::DeleteCache(const std::string& path)
{
167
  return this->CacheManager->DeleteCache(path);
168
169
}

Stephen Kelly's avatar
Stephen Kelly committed
170
171
172
std::vector<std::string> cmState::GetCacheEntryKeys() const
{
  std::vector<std::string> definitions;
173
  definitions.reserve(this->CacheManager->GetSize());
Stephen Kelly's avatar
Stephen Kelly committed
174
  cmCacheManager::CacheIterator cit =
175
    this->CacheManager->GetCacheIterator();
Stephen Kelly's avatar
Stephen Kelly committed
176
177
178
179
180
181
182
183
184
  for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
    {
    definitions.push_back(cit.GetName());
    }
  return definitions;
}

const char* cmState::GetCacheEntryValue(std::string const& key) const
{
185
  cmCacheManager::CacheEntry* e = this->CacheManager
Stephen Kelly's avatar
Stephen Kelly committed
186
187
188
189
190
191
192
193
194
195
196
             ->GetCacheEntry(key);
  if (!e)
    {
    return 0;
    }
  return e->Value.c_str();
}

const char*
cmState::GetInitializedCacheValue(std::string const& key) const
{
197
  return this->CacheManager->GetInitializedCacheValue(key);
Stephen Kelly's avatar
Stephen Kelly committed
198
199
}

200
cmState::CacheEntryType
Stephen Kelly's avatar
Stephen Kelly committed
201
202
203
cmState::GetCacheEntryType(std::string const& key) const
{
  cmCacheManager::CacheIterator it =
204
      this->CacheManager->GetCacheIterator(key.c_str());
Stephen Kelly's avatar
Stephen Kelly committed
205
206
207
208
209
210
  return it.GetType();
}

void cmState::SetCacheEntryValue(std::string const& key,
                                         std::string const& value)
{
211
  this->CacheManager->SetCacheEntryValue(key, value);
Stephen Kelly's avatar
Stephen Kelly committed
212
213
214
215
216
217
218
}

void cmState::SetCacheEntryProperty(std::string const& key,
                            std::string const& propertyName,
                            std::string const& value)
{
  cmCacheManager::CacheIterator it =
219
      this->CacheManager->GetCacheIterator(key.c_str());
Stephen Kelly's avatar
Stephen Kelly committed
220
221
222
223
224
225
226
227
  it.SetProperty(propertyName, value.c_str());
}

void cmState::SetCacheEntryBoolProperty(std::string const& key,
                            std::string const& propertyName,
                            bool value)
{
  cmCacheManager::CacheIterator it =
228
      this->CacheManager->GetCacheIterator(key.c_str());
Stephen Kelly's avatar
Stephen Kelly committed
229
230
231
232
233
234
  it.SetProperty(propertyName, value);
}

const char* cmState::GetCacheEntryProperty(std::string const& key,
                                              std::string const& propertyName)
{
235
  cmCacheManager::CacheIterator it = this->CacheManager
Stephen Kelly's avatar
Stephen Kelly committed
236
237
238
239
240
241
242
243
244
245
246
             ->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)
{
247
  return this->CacheManager
Stephen Kelly's avatar
Stephen Kelly committed
248
249
250
251
252
             ->GetCacheIterator(key.c_str()).GetPropertyAsBool(propertyName);
}

void cmState::AddCacheEntry(const std::string& key, const char* value,
                                    const char* helpString,
253
                                    cmState::CacheEntryType type)
Stephen Kelly's avatar
Stephen Kelly committed
254
{
255
  this->CacheManager->AddCacheEntry(key, value,
Stephen Kelly's avatar
Stephen Kelly committed
256
257
258
259
260
                                                        helpString, type);
}

void cmState::RemoveCacheEntry(std::string const& key)
{
261
  this->CacheManager->RemoveCacheEntry(key);
Stephen Kelly's avatar
Stephen Kelly committed
262
263
264
265
266
267
268
}

void cmState::AppendCacheEntryProperty(const std::string& key,
                                               const std::string& property,
                                               const std::string& value,
                                               bool asString)
{
269
  this->CacheManager
Stephen Kelly's avatar
Stephen Kelly committed
270
271
272
273
274
275
276
277
       ->GetCacheIterator(key.c_str()).AppendProperty(property,
                                                       value.c_str(),
                                                       asString);
}

void cmState::RemoveCacheEntryProperty(std::string const& key,
                                              std::string const& propertyName)
{
278
  this->CacheManager
Stephen Kelly's avatar
Stephen Kelly committed
279
280
       ->GetCacheIterator(key.c_str()).SetProperty(propertyName, (void*)0);
}
281

282
cmState::Snapshot cmState::Reset()
283
{
284
  this->GlobalProperties.clear();
285
  this->PropertyDefinitions.clear();
286

287
288
289
  PositionType pos = this->SnapshotData.Truncate();
  this->ExecutionListFiles.Truncate();

290
291
292
293
294
295
296
297
298
  {
  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();
299
  it->DirectoryEnd = pos;
300
  it->Properties.clear();
301
  it->Children.clear();
302
  }
303

304
305
306
307
308
309
  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());
310
311
312
313
314
315

  {
  std::string srcDir =
      cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
  std::string binDir =
      cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
316
317
318
319
  this->VarTree.Clear();
  pos->Vars = this->VarTree.Extend(this->VarTree.Root());
  pos->Parent = this->VarTree.Root();
  pos->Root = this->VarTree.Root();
320

321
322
323
324
  pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir.c_str());
  pos->Vars->Set("CMAKE_BINARY_DIR", binDir.c_str());
  }

325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
  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);
344
345

  return Snapshot(this, pos);
346
347
348
349
350
351
352
353
354
355
356
357
358
}

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);
}

359
cmPropertyDefinition const* cmState
360
::GetPropertyDefinition(const std::string& name,
361
                        cmProperty::ScopeType scope) const
362
363
364
{
  if (this->IsPropertyDefined(name,scope))
    {
365
366
367
    cmPropertyDefinitionMap const& defs =
        this->PropertyDefinitions.find(scope)->second;
    return &defs.find(name)->second;
368
369
370
371
372
    }
  return 0;
}

bool cmState::IsPropertyDefined(const std::string& name,
373
                                cmProperty::ScopeType scope) const
374
{
375
376
377
378
379
380
381
  std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it
      = this->PropertyDefinitions.find(scope);
  if (it == this->PropertyDefinitions.end())
    {
    return false;
    }
  return it->second.IsPropertyDefined(name);
382
383
384
}

bool cmState::IsPropertyChained(const std::string& name,
385
                                cmProperty::ScopeType scope) const
386
{
387
388
389
390
391
392
393
  std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it
      = this->PropertyDefinitions.find(scope);
  if (it == this->PropertyDefinitions.end())
    {
    return false;
    }
  return it->second.IsPropertyChained(name);
394
}
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417

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;
}

418
419
420
421
422
void cmState::SetEnabledLanguages(std::vector<std::string> const& langs)
{
  this->EnabledLanguages = langs;
}

423
424
425
426
void cmState::ClearEnabledLanguages()
{
  this->EnabledLanguages.clear();
}
427
428
429
430
431
432
433
434
435
436

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

void cmState::SetIsInTryCompile(bool b)
{
  this->IsInTryCompile = b;
}
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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522

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()
{
523
  std::vector<cmCommand*> renamedCommands;
524
525
526
527
528
529
530
531
532
  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++);
      }
533
534
535
536
537
    else if (j->first != j->second->GetName())
      {
      renamedCommands.push_back(j->second);
      this->Commands.erase(j++);
      }
538
539
540
541
542
    else
      {
      ++j;
      }
    }
543
544
545
546
547
  for (std::vector<cmCommand*>::const_iterator it = renamedCommands.begin();
       it != renamedCommands.end(); ++it)
    {
    this->Commands[cmSystemTools::LowerCase((*it)->GetName())] = *it;
    }
548
}
549
550
551

void cmState::SetGlobalProperty(const std::string& prop, const char* value)
{
552
  this->GlobalProperties.SetProperty(prop, value);
553
554
555
556
557
}

void cmState::AppendGlobalProperty(const std::string& prop,
                                   const char* value, bool asString)
{
558
  this->GlobalProperties.AppendProperty(prop, value, asString);
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
}

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
594
  return this->GlobalProperties.GetPropertyValue(prop);
595
596
597
598
599
600
}

bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
{
  return cmSystemTools::IsOn(this->GetGlobalProperty(prop));
}
601
602
603
604
605

void cmState::SetSourceDirectory(std::string const& sourceDirectory)
{
  this->SourceDirectory = sourceDirectory;
  cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
606
607
608
609

  cmSystemTools::SplitPath(
      cmSystemTools::CollapseFullPath(this->SourceDirectory),
        this->SourceDirectoryComponents);
610
611
612
613
614
615
616
}

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

617
618
619
620
621
std::vector<std::string> const& cmState::GetSourceDirectoryComponents() const
{
  return this->SourceDirectoryComponents;
}

622
623
624
625
void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
{
  this->BinaryDirectory = binaryDirectory;
  cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
626
627
628
629

  cmSystemTools::SplitPath(
      cmSystemTools::CollapseFullPath(this->BinaryDirectory),
        this->BinaryDirectoryComponents);
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
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
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;
}

692
693
unsigned int cmState::GetCacheMajorVersion() const
{
694
  return this->CacheManager->GetCacheMajorVersion();
695
696
697
698
}

unsigned int cmState::GetCacheMinorVersion() const
{
699
  return this->CacheManager->GetCacheMinorVersion();
700
701
}

702
703
704
705
const char* cmState::GetBinaryDirectory() const
{
  return this->BinaryDirectory.c_str();
}
Stephen Kelly's avatar
Stephen Kelly committed
706

707
708
709
710
711
std::vector<std::string> const& cmState::GetBinaryDirectoryComponents() const
{
  return this->BinaryDirectoryComponents;
}

712
void cmState::Directory::ComputeRelativePathTopSource()
713
714
715
716
717
{
  // 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.

718
  cmState::Snapshot snapshot = this->Snapshot_;
719
720
721
722
  std::vector<cmState::Snapshot> snapshots;
  snapshots.push_back(snapshot);
  while (true)
    {
723
    snapshot = snapshot.GetBuildsystemDirectoryParent();
724
725
726
727
728
729
730
731
732
733
    if (snapshot.IsValid())
      {
      snapshots.push_back(snapshot);
      }
    else
      {
      break;
      }
    }

734
  std::string result = snapshots.front().GetDirectory().GetCurrentSource();
735
736
737
738

  for (std::vector<cmState::Snapshot>::const_iterator it =
       snapshots.begin() + 1; it != snapshots.end(); ++it)
    {
739
    std::string currentSource = it->GetDirectory().GetCurrentSource();
740
741
742
743
744
    if(cmSystemTools::IsSubDirectory(result, currentSource))
      {
      result = currentSource;
      }
    }
745
  this->DirectoryState->RelativePathTopSource = result;
746
747
}

748
void cmState::Directory::ComputeRelativePathTopBinary()
749
{
750
  cmState::Snapshot snapshot = this->Snapshot_;
751
752
753
754
  std::vector<cmState::Snapshot> snapshots;
  snapshots.push_back(snapshot);
  while (true)
    {
755
    snapshot = snapshot.GetBuildsystemDirectoryParent();
756
757
758
759
760
761
762
763
764
765
766
    if (snapshot.IsValid())
      {
      snapshots.push_back(snapshot);
      }
    else
      {
      break;
      }
    }

  std::string result =
767
      snapshots.front().GetDirectory().GetCurrentBinary();
768
769
770
771

  for (std::vector<cmState::Snapshot>::const_iterator it =
       snapshots.begin() + 1; it != snapshots.end(); ++it)
    {
772
    std::string currentBinary = it->GetDirectory().GetCurrentBinary();
773
774
775
776
777
778
779
780
781
782
783
    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) != "//")
    {
784
    this->DirectoryState->RelativePathTopBinary = result;
785
786
787
    }
  else
    {
788
    this->DirectoryState->RelativePathTopBinary = "";
789
790
791
    }
}

792
793
cmState::Snapshot cmState::CreateBaseSnapshot()
{
794
795
  PositionType pos = this->SnapshotData.Extend(this->SnapshotData.Root());
  pos->DirectoryParent = this->SnapshotData.Root();
796
  pos->ScopeParent = this->SnapshotData.Root();
797
  pos->SnapshotType = BaseType;
798
799
  pos->BuildSystemDirectory =
      this->BuildsystemDirectory.Extend(this->BuildsystemDirectory.Root());
800
801
  pos->ExecutionListFile =
      this->ExecutionListFiles.Extend(this->ExecutionListFiles.Root());
802
803
804
  pos->IncludeDirectoryPosition = 0;
  pos->CompileDefinitionsPosition = 0;
  pos->CompileOptionsPosition = 0;
805
  pos->BuildSystemDirectory->DirectoryEnd = pos;
806
807
808
809
810
  pos->Policies = this->PolicyStack.Root();
  pos->PolicyRoot = this->PolicyStack.Root();
  pos->PolicyScope = this->PolicyStack.Root();
  assert(pos->Policies.IsValid());
  assert(pos->PolicyRoot.IsValid());
811
812
813
814
  pos->Vars = this->VarTree.Extend(this->VarTree.Root());
  assert(pos->Vars.IsValid());
  pos->Parent = this->VarTree.Root();
  pos->Root = this->VarTree.Root();
815
816
817
  return cmState::Snapshot(this, pos);
}

818
cmState::Snapshot
819
820
821
cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
                                    std::string const& entryPointCommand,
                                    long entryPointLine)
Stephen Kelly's avatar
Stephen Kelly committed
822
{
823
  assert(originSnapshot.IsValid());
824
  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position);
825
826
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
827
  pos->DirectoryParent = originSnapshot.Position;
828
  pos->ScopeParent = originSnapshot.Position;
829
830
831
832
  pos->SnapshotType = BuildsystemDirectoryType;
  pos->BuildSystemDirectory =
      this->BuildsystemDirectory.Extend(
        originSnapshot.Position->BuildSystemDirectory);
833
834
835
  pos->ExecutionListFile =
      this->ExecutionListFiles.Extend(
        originSnapshot.Position->ExecutionListFile);
836
  pos->BuildSystemDirectory->DirectoryEnd = pos;
837
838
839
840
841
  pos->Policies = originSnapshot.Position->Policies;
  pos->PolicyRoot = originSnapshot.Position->Policies;
  pos->PolicyScope = originSnapshot.Position->Policies;
  assert(pos->Policies.IsValid());
  assert(pos->PolicyRoot.IsValid());
842
843
844
845
846
847

  cmLinkedTree<cmDefinitions>::iterator origin =
      originSnapshot.Position->Vars;
  pos->Parent = origin;
  pos->Root = origin;
  pos->Vars = this->VarTree.Extend(origin);
848

849
850
  cmState::Snapshot snapshot = cmState::Snapshot(this, pos);
  originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
851
  snapshot.SetDefaultDefinitions();
852
  snapshot.InitializeFromParent();
853
  snapshot.SetDirectoryDefinitions();
854
  return snapshot;
Stephen Kelly's avatar
Stephen Kelly committed
855
856
}

857
cmState::Snapshot
858
859
860
861
cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot,
                                    std::string const& entryPointCommand,
                                    long entryPointLine,
                                    std::string const& fileName)
862
863
864
{
  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                               *originSnapshot.Position);
865
  pos->ScopeParent = originSnapshot.Position;
866
867
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
868
  pos->SnapshotType = FunctionCallType;
869
870
  pos->ExecutionListFile = this->ExecutionListFiles.Extend(
        originSnapshot.Position->ExecutionListFile, fileName);
871
  pos->BuildSystemDirectory->DirectoryEnd = pos;
872
  pos->PolicyScope = originSnapshot.Position->Policies;
873
874
875
876
877
  assert(originSnapshot.Position->Vars.IsValid());
  cmLinkedTree<cmDefinitions>::iterator origin =
      originSnapshot.Position->Vars;
  pos->Parent = origin;
  pos->Vars = this->VarTree.Extend(origin);
878
879
880
881
882
  return cmState::Snapshot(this, pos);
}


cmState::Snapshot
883
884
885
886
cmState::CreateMacroCallSnapshot(cmState::Snapshot originSnapshot,
                                    std::string const& entryPointCommand,
                                    long entryPointLine,
                                    std::string const& fileName)
887
888
889
{
  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                               *originSnapshot.Position);
890
891
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
892
  pos->SnapshotType = MacroCallType;
893
894
  pos->ExecutionListFile = this->ExecutionListFiles.Extend(
        originSnapshot.Position->ExecutionListFile, fileName);
895
  assert(originSnapshot.Position->Vars.IsValid());
896
  pos->BuildSystemDirectory->DirectoryEnd = pos;
897
  pos->PolicyScope = originSnapshot.Position->Policies;
898
899
900
901
  return cmState::Snapshot(this, pos);
}

cmState::Snapshot
902
903
904
905
cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot,
                                 const std::string& entryPointCommand,
                                 long entryPointLine,
                                 const std::string& fileName)
906
907
908
{
  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                               *originSnapshot.Position);
909
910
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
911
  pos->SnapshotType = CallStackType;
912
913
  pos->ExecutionListFile = this->ExecutionListFiles.Extend(
        originSnapshot.Position->ExecutionListFile, fileName);
914
  assert(originSnapshot.Position->Vars.IsValid());
915
  pos->BuildSystemDirectory->DirectoryEnd = pos;
916
  pos->PolicyScope = originSnapshot.Position->Policies;
917
918
919
  return cmState::Snapshot(this, pos);
}

920
921
922
923
924
925
926
927
928
929
930
cmState::Snapshot
cmState::CreateVariableScopeSnapshot(cmState::Snapshot originSnapshot,
                                     std::string const& entryPointCommand,
                                     long entryPointLine)
{
  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                               *originSnapshot.Position);
  pos->ScopeParent = originSnapshot.Position;
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
  pos->SnapshotType = VariableScopeType;
931
  assert(originSnapshot.Position->Vars.IsValid());
932

933
934
935
936
937
  cmLinkedTree<cmDefinitions>::iterator origin =
      originSnapshot.Position->Vars;
  pos->Parent = origin;
  pos->Vars = this->VarTree.Extend(origin);
  assert(pos->Vars.IsValid());
938
939
940
  return cmState::Snapshot(this, pos);
}

941
cmState::Snapshot
942
943
944
945
cmState::CreateInlineListFileSnapshot(cmState::Snapshot originSnapshot,
                                      const std::string& entryPointCommand,
                                      long entryPointLine,
                                      const std::string& fileName)
946
947
948
{
  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                               *originSnapshot.Position);
949
950
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
951
  pos->SnapshotType = InlineListFileType;
952
953
  pos->ExecutionListFile = this->ExecutionListFiles.Extend(
        originSnapshot.Position->ExecutionListFile, fileName);
954
  pos->BuildSystemDirectory->DirectoryEnd = pos;
955
  pos->PolicyScope = originSnapshot.Position->Policies;
956
957
958
  return cmState::Snapshot(this, pos);
}

959
960
961
962
963
964
cmState::Snapshot
cmState::CreatePolicyScopeSnapshot(cmState::Snapshot originSnapshot)
{
  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                               *originSnapshot.Position);
  pos->SnapshotType = PolicyScopeType;
965
  pos->BuildSystemDirectory->DirectoryEnd = pos;
966
  pos->PolicyScope = originSnapshot.Position->Policies;
967
968
969
  return cmState::Snapshot(this, pos);
}

970
971
972
973
974
cmState::Snapshot cmState::Pop(cmState::Snapshot originSnapshot)
{
  PositionType pos = originSnapshot.Position;
  PositionType prevPos = pos;
  ++prevPos;
975
976
977
978
979
980
  prevPos->IncludeDirectoryPosition =
      prevPos->BuildSystemDirectory->IncludeDirectories.size();
  prevPos->CompileDefinitionsPosition =
      prevPos->BuildSystemDirectory->CompileDefinitions.size();
  prevPos->CompileOptionsPosition =
      prevPos->BuildSystemDirectory->CompileOptions.size();
981
  prevPos->BuildSystemDirectory->DirectoryEnd = prevPos;
982

983
  return Snapshot(this, prevPos);
984
985
}

986
987
988
989
990
991
cmState::Snapshot::Snapshot(cmState* state)
  : State(state)
  , Position()
{
}

992
993
994
995
996
std::vector<cmState::Snapshot> cmState::Snapshot::GetChildren()
{
  return this->Position->BuildSystemDirectory->Children;
}

Stephen Kelly's avatar
Stephen Kelly committed
997
998
999
1000
1001
1002
cmState::Snapshot::Snapshot(cmState* state, PositionType position)
  : State(state),
  Position(position)
{

}
1003

1004
1005
1006
1007
1008
cmState::SnapshotType cmState::Snapshot::GetType() const
{
  return this->Position->SnapshotType;
}

1009
const char* cmState::Directory::GetCurrentSource() const
1010
{
1011
  return this->DirectoryState->Location.c_str();
1012
1013
}

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

  cmSystemTools::SplitPath(
1022
      loc,
1023
      this->DirectoryState->CurrentSourceDirectoryComponents);
1024
  this->ComputeRelativePathTopSource();
1025
1026

  this->Snapshot_.SetDefinition("CMAKE_CURRENT_SOURCE_DIR", loc.c_str());
1027
1028
}

1029
const char* cmState::Directory::GetCurrentBinary() const
1030
{
1031
  return this->DirectoryState->OutputLocation.c_str();
1032
1033
}

1034
void cmState::Directory::SetCurrentBinary(std::string const& dir)
1035
{
1036
  std::string& loc = this->DirectoryState->OutputLocation;
1037
1038
1039
  loc = dir;
  cmSystemTools::ConvertToUnixSlashes(loc);
  loc = cmSystemTools::CollapseFullPath(loc);
1040
1041

  cmSystemTools::SplitPath(
1042
      loc,
1043
      this->DirectoryState->CurrentBinaryDirectoryComponents);
1044
  this->ComputeRelativePathTopBinary();
1045
1046

  this->Snapshot_.SetDefinition("CMAKE_CURRENT_BINARY_DIR", loc.c_str());
1047
1048
}

1049
1050
1051
1052
1053
void cmState::Snapshot::SetListFile(const std::string& listfile)
{
  *this->Position->ExecutionListFile = listfile;
}

1054
std::vector<std::string> const&
1055
cmState::Directory::GetCurrentSourceComponents() const
1056
{
1057
  return this->DirectoryState->CurrentSourceDirectoryComponents;
1058
1059
1060
}

std::vector<std::string> const&
1061
cmState::Directory::GetCurrentBinaryComponents() const
1062
{
1063
  return this->DirectoryState->CurrentBinaryDirectoryComponents;
1064
}
1065

1066
const char* cmState::Directory::GetRelativePathTopSource() const
1067
{
1068
  return this->DirectoryState->RelativePathTopSource.c_str();
1069
1070
}

1071
const char* cmState::Directory::GetRelativePathTopBinary() const
1072
{
1073
  return this->DirectoryState->RelativePathTopBinary.c_str();
1074
1075
}

1076
void cmState::Directory::SetRelativePathTopSource(const char* dir)
1077
{
1078
  this->DirectoryState->RelativePathTopSource = dir;
1079
1080
}

1081
void cmState::Directory::SetRelativePathTopBinary(const char* dir)
1082
{
1083
  this->DirectoryState->RelativePathTopBinary = dir;
1084
1085
}

1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
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;
}

1101
1102
bool cmState::Snapshot::IsValid() const
{
1103
1104
1105
  return this->State && this->Position.IsValid()
      ? this->Position != this->State->SnapshotData.Root()
      : false;
1106
1107
}

1108
cmState::Snapshot cmState::Snapshot::GetBuildsystemDirectoryParent() const
1109
1110
{
  Snapshot snapshot;
1111
  if (!this->State || this->Position == this->State->SnapshotData.Root())
1112
1113
1114
    {
    return snapshot;
    }
1115
1116
1117
  PositionType parentPos = this->Position->DirectoryParent;
  if (parentPos != this->State->SnapshotData.Root())
    {
1118
1119
    snapshot = Snapshot(this->State,
                        parentPos->BuildSystemDirectory->DirectoryEnd);
1120
    }
1121
1122
1123

  return snapshot;
}
1124

1125
1126
1127
1128
1129
1130
cmState::Snapshot cmState::Snapshot::GetCallStackParent() const
{
  assert(this->State);
  assert(this->Position != this->State->SnapshotData.Root());

  Snapshot snapshot;
1131
1132
1133
1134
1135
  PositionType parentPos = this->Position;
  while(parentPos->SnapshotType == cmState::PolicyScopeType)
    {
    ++parentPos;
    }
1136
1137
  if (parentPos->SnapshotType == cmState::BuildsystemDirectoryType
      || parentPos->SnapshotType == cmState::BaseType)
1138
1139
1140
1141
1142
    {
    return snapshot;
    }

  ++parentPos;
1143
1144
1145
1146
1147
  while(parentPos->SnapshotType == cmState::PolicyScopeType)
    {
    ++parentPos;
    }

1148
1149
1150
1151
1152
1153
1154
1155
1156
  if (parentPos == this->State->SnapshotData.Root())
    {
    return snapshot;
    }

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

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
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
void cmState::Snapshot::PushPolicy(cmPolicies::PolicyMap entry, bool weak)
{
  PositionType pos = this->Position;
  pos->Policies =
      this->State->PolicyStack.Extend(pos->Policies,
                                      PolicyStackEntry(entry, weak));
}

bool cmState::Snapshot::PopPolicy()
{
  PositionType pos = this->Position;
  if (pos->Policies == pos->PolicyScope)
    {
    return false;
    }
  ++pos->Policies;
  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();
}

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
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
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;
}

1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
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