cmState.cxx 26.6 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
18
19
#include "cmCommand.h"
#include "cmAlgorithms.h"

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

21
22
struct cmState::SnapshotDataType
{
23
  cmState::PositionType CallStackParent;
24
25
  cmState::PositionType DirectoryParent;
  cmState::SnapshotType SnapshotType;
26
  cmLinkedTree<std::string>::iterator ExecutionListFile;
27
28
  cmLinkedTree<cmState::BuildsystemDirectoryStateType>::iterator
                                                          BuildSystemDirectory;
29
30
  std::string EntryPointCommand;
  long EntryPointLine;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
};

struct cmState::BuildsystemDirectoryStateType
{
  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;
47
48
};

Stephen Kelly's avatar
Stephen Kelly committed
49
cmState::cmState(cmake* cm)
50
  : CMakeInstance(cm),
51
52
53
54
55
56
57
    IsInTryCompile(false),
    WindowsShell(false),
    WindowsVSIDE(false),
    WatcomWMake(false),
    MinGWMake(false),
    NMake(false),
    MSYSShell(false)
Stephen Kelly's avatar
Stephen Kelly committed
58
59
{
}
60

61
62
63
64
65
cmState::~cmState()
{
  cmDeleteAll(this->Commands);
}

66
67
68
69
70
71
72
73
74
75
76
77
78
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
79
{
80
81
82
83
84
  if ( type > 6 )
    {
    return cmCacheEntryTypes[6];
    }
  return cmCacheEntryTypes[type];
Stephen Kelly's avatar
Stephen Kelly committed
85
86
}

87
88
cmState::CacheEntryType
cmState::StringToCacheEntryType(const char* s)
Stephen Kelly's avatar
Stephen Kelly committed
89
{
90
91
92
93
94
95
96
97
98
99
  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
100
101
102
103
}

bool cmState::IsCacheEntryType(std::string const& key)
{
104
105
106
107
108
109
110
111
  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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
}

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

144
cmState::CacheEntryType
Stephen Kelly's avatar
Stephen Kelly committed
145
146
147
148
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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,
197
                                    cmState::CacheEntryType type)
Stephen Kelly's avatar
Stephen Kelly committed
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
{
  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);
}
225

226
cmState::Snapshot cmState::Reset()
227
{
228
  this->GlobalProperties.clear();
229
  this->PropertyDefinitions.clear();
230

231
  this->BuildsystemDirectory.Truncate();
232
  PositionType pos = this->SnapshotData.Truncate();
233
  this->ExecutionListFiles.Truncate();
234

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
  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);
254
255

  return Snapshot(this, pos);
256
257
258
259
260
261
262
263
264
265
266
267
268
}

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

269
cmPropertyDefinition const* cmState
270
::GetPropertyDefinition(const std::string& name,
271
                        cmProperty::ScopeType scope) const
272
273
274
{
  if (this->IsPropertyDefined(name,scope))
    {
275
276
277
    cmPropertyDefinitionMap const& defs =
        this->PropertyDefinitions.find(scope)->second;
    return &defs.find(name)->second;
278
279
280
281
282
    }
  return 0;
}

bool cmState::IsPropertyDefined(const std::string& name,
283
                                cmProperty::ScopeType scope) const
284
{
285
286
287
288
289
290
291
  std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it
      = this->PropertyDefinitions.find(scope);
  if (it == this->PropertyDefinitions.end())
    {
    return false;
    }
  return it->second.IsPropertyDefined(name);
292
293
294
}

bool cmState::IsPropertyChained(const std::string& name,
295
                                cmProperty::ScopeType scope) const
296
{
297
298
299
300
301
302
303
  std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::const_iterator it
      = this->PropertyDefinitions.find(scope);
  if (it == this->PropertyDefinitions.end())
    {
    return false;
    }
  return it->second.IsPropertyChained(name);
304
}
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

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

328
329
330
331
332
void cmState::SetEnabledLanguages(std::vector<std::string> const& langs)
{
  this->EnabledLanguages = langs;
}

333
334
335
336
void cmState::ClearEnabledLanguages()
{
  this->EnabledLanguages.clear();
}
337
338
339
340
341
342
343
344
345
346

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

void cmState::SetIsInTryCompile(bool b)
{
  this->IsInTryCompile = b;
}
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
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

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()
{
433
  std::vector<cmCommand*> renamedCommands;
434
435
436
437
438
439
440
441
442
  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++);
      }
443
444
445
446
447
    else if (j->first != j->second->GetName())
      {
      renamedCommands.push_back(j->second);
      this->Commands.erase(j++);
      }
448
449
450
451
452
    else
      {
      ++j;
      }
    }
453
454
455
456
457
  for (std::vector<cmCommand*>::const_iterator it = renamedCommands.begin();
       it != renamedCommands.end(); ++it)
    {
    this->Commands[cmSystemTools::LowerCase((*it)->GetName())] = *it;
    }
458
}
459
460
461

void cmState::SetGlobalProperty(const std::string& prop, const char* value)
{
462
  this->GlobalProperties.SetProperty(prop, value);
463
464
465
466
467
}

void cmState::AppendGlobalProperty(const std::string& prop,
                                   const char* value, bool asString)
{
468
  this->GlobalProperties.AppendProperty(prop, value, asString);
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
}

const char *cmState::GetGlobalProperty(const std::string& prop)
{
  // watch for special properties
  std::string output = "";
  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
506
  return this->GlobalProperties.GetPropertyValue(prop);
507
508
509
510
511
512
}

bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
{
  return cmSystemTools::IsOn(this->GetGlobalProperty(prop));
}
513
514
515
516
517

void cmState::SetSourceDirectory(std::string const& sourceDirectory)
{
  this->SourceDirectory = sourceDirectory;
  cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
518
519
520
521

  cmSystemTools::SplitPath(
      cmSystemTools::CollapseFullPath(this->SourceDirectory),
        this->SourceDirectoryComponents);
522
523
524
525
526
527
528
}

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

529
530
531
532
533
std::vector<std::string> const& cmState::GetSourceDirectoryComponents() const
{
  return this->SourceDirectoryComponents;
}

534
535
536
537
void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
{
  this->BinaryDirectory = binaryDirectory;
  cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
538
539
540
541

  cmSystemTools::SplitPath(
      cmSystemTools::CollapseFullPath(this->BinaryDirectory),
        this->BinaryDirectoryComponents);
542
543
}

544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
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
594
595
596
597
598
599
600
601
602
603
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;
}

604
605
606
607
const char* cmState::GetBinaryDirectory() const
{
  return this->BinaryDirectory.c_str();
}
Stephen Kelly's avatar
Stephen Kelly committed
608

609
610
611
612
613
std::vector<std::string> const& cmState::GetBinaryDirectoryComponents() const
{
  return this->BinaryDirectoryComponents;
}

614
void cmState::Directory::ComputeRelativePathTopSource()
615
616
617
618
619
{
  // 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.

620
  cmState::Snapshot snapshot = this->Snapshot_;
621
622
623
624
  std::vector<cmState::Snapshot> snapshots;
  snapshots.push_back(snapshot);
  while (true)
    {
625
    snapshot = snapshot.GetBuildsystemDirectoryParent();
626
627
628
629
630
631
632
633
634
635
    if (snapshot.IsValid())
      {
      snapshots.push_back(snapshot);
      }
    else
      {
      break;
      }
    }

636
  std::string result = snapshots.front().GetDirectory().GetCurrentSource();
637
638
639
640

  for (std::vector<cmState::Snapshot>::const_iterator it =
       snapshots.begin() + 1; it != snapshots.end(); ++it)
    {
641
    std::string currentSource = it->GetDirectory().GetCurrentSource();
642
643
644
645
646
    if(cmSystemTools::IsSubDirectory(result, currentSource))
      {
      result = currentSource;
      }
    }
647
  this->DirectoryState->RelativePathTopSource = result;
648
649
}

650
void cmState::Directory::ComputeRelativePathTopBinary()
651
{
652
  cmState::Snapshot snapshot = this->Snapshot_;
653
654
655
656
  std::vector<cmState::Snapshot> snapshots;
  snapshots.push_back(snapshot);
  while (true)
    {
657
    snapshot = snapshot.GetBuildsystemDirectoryParent();
658
659
660
661
662
663
664
665
666
667
668
    if (snapshot.IsValid())
      {
      snapshots.push_back(snapshot);
      }
    else
      {
      break;
      }
    }

  std::string result =
669
      snapshots.front().GetDirectory().GetCurrentBinary();
670
671
672
673

  for (std::vector<cmState::Snapshot>::const_iterator it =
       snapshots.begin() + 1; it != snapshots.end(); ++it)
    {
674
    std::string currentBinary = it->GetDirectory().GetCurrentBinary();
675
676
677
678
679
680
681
682
683
684
685
    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) != "//")
    {
686
    this->DirectoryState->RelativePathTopBinary = result;
687
688
689
    }
  else
    {
690
    this->DirectoryState->RelativePathTopBinary = "";
691
692
693
    }
}

694
695
cmState::Snapshot cmState::CreateBaseSnapshot()
{
696
697
698
699
700
  PositionType pos = this->SnapshotData.Extend(this->SnapshotData.Root());
  pos->DirectoryParent = this->SnapshotData.Root();
  pos->SnapshotType = BuildsystemDirectoryType;
  pos->BuildSystemDirectory =
      this->BuildsystemDirectory.Extend(this->BuildsystemDirectory.Root());
701
702
  pos->ExecutionListFile =
      this->ExecutionListFiles.Extend(this->ExecutionListFiles.Root());
703
704
705
  return cmState::Snapshot(this, pos);
}

706
cmState::Snapshot
707
708
709
cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
                                    std::string const& entryPointCommand,
                                    long entryPointLine)
Stephen Kelly's avatar
Stephen Kelly committed
710
{
711
  assert(originSnapshot.IsValid());
712
  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position);
713
  pos->CallStackParent = originSnapshot.Position;
714
715
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
716
717
718
719
720
  pos->DirectoryParent = originSnapshot.Position;
  pos->SnapshotType = BuildsystemDirectoryType;
  pos->BuildSystemDirectory =
      this->BuildsystemDirectory.Extend(
        originSnapshot.Position->BuildSystemDirectory);
721
722
723
  pos->ExecutionListFile =
      this->ExecutionListFiles.Extend(
        originSnapshot.Position->ExecutionListFile);
Stephen Kelly's avatar
Stephen Kelly committed
724
725
726
  return cmState::Snapshot(this, pos);
}

727
cmState::Snapshot
728
729
730
731
cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot,
                                    std::string const& entryPointCommand,
                                    long entryPointLine,
                                    std::string const& fileName)
732
733
734
735
{
  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                               *originSnapshot.Position);
  pos->CallStackParent = originSnapshot.Position;
736
737
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
738
  pos->SnapshotType = FunctionCallType;
739
740
  pos->ExecutionListFile = this->ExecutionListFiles.Extend(
        originSnapshot.Position->ExecutionListFile, fileName);
741
742
743
744
745
  return cmState::Snapshot(this, pos);
}


cmState::Snapshot
746
747
748
749
cmState::CreateMacroCallSnapshot(cmState::Snapshot originSnapshot,
                                    std::string const& entryPointCommand,
                                    long entryPointLine,
                                    std::string const& fileName)
750
751
752
753
{
  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                               *originSnapshot.Position);
  pos->CallStackParent = originSnapshot.Position;
754
755
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
756
  pos->SnapshotType = MacroCallType;
757
758
  pos->ExecutionListFile = this->ExecutionListFiles.Extend(
        originSnapshot.Position->ExecutionListFile, fileName);
759
760
761
762
  return cmState::Snapshot(this, pos);
}

cmState::Snapshot
763
764
765
766
cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot,
                                 const std::string& entryPointCommand,
                                 long entryPointLine,
                                 const std::string& fileName)
767
768
769
770
{
  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                               *originSnapshot.Position);
  pos->CallStackParent = originSnapshot.Position;
771
772
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
773
  pos->SnapshotType = CallStackType;
774
775
  pos->ExecutionListFile = this->ExecutionListFiles.Extend(
        originSnapshot.Position->ExecutionListFile, fileName);
776
777
778
779
  return cmState::Snapshot(this, pos);
}

cmState::Snapshot
780
781
782
783
cmState::CreateInlineListFileSnapshot(cmState::Snapshot originSnapshot,
                                      const std::string& entryPointCommand,
                                      long entryPointLine,
                                      const std::string& fileName)
784
785
786
787
{
  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                               *originSnapshot.Position);
  pos->CallStackParent = originSnapshot.Position;
788
789
  pos->EntryPointLine = entryPointLine;
  pos->EntryPointCommand = entryPointCommand;
790
  pos->SnapshotType = InlineListFileType;
791
792
  pos->ExecutionListFile = this->ExecutionListFiles.Extend(
        originSnapshot.Position->ExecutionListFile, fileName);
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
  return cmState::Snapshot(this, pos);
}

cmState::Snapshot cmState::Pop(cmState::Snapshot originSnapshot)
{
  PositionType pos = originSnapshot.Position;
  PositionType prevPos = pos;
  ++prevPos;
  if (prevPos == this->SnapshotData.Root())
    {
    return Snapshot(this, prevPos);
    }
  return Snapshot(this, originSnapshot.Position->CallStackParent);
}

Stephen Kelly's avatar
Stephen Kelly committed
808
809
810
811
812
813
cmState::Snapshot::Snapshot(cmState* state, PositionType position)
  : State(state),
  Position(position)
{

}
814

815
const char* cmState::Directory::GetCurrentSource() const
816
{
817
  return this->DirectoryState->Location.c_str();
818
819
}

820
void cmState::Directory::SetCurrentSource(std::string const& dir)
821
{
822
  std::string& loc = this->DirectoryState->Location;
823
824
825
  loc = dir;
  cmSystemTools::ConvertToUnixSlashes(loc);
  loc = cmSystemTools::CollapseFullPath(loc);
826
827

  cmSystemTools::SplitPath(
828
      loc,
829
      this->DirectoryState->CurrentSourceDirectoryComponents);
830
  this->ComputeRelativePathTopSource();
831
832
}

833
const char* cmState::Directory::GetCurrentBinary() const
834
{
835
  return this->DirectoryState->OutputLocation.c_str();
836
837
}

838
void cmState::Directory::SetCurrentBinary(std::string const& dir)
839
{
840
  std::string& loc = this->DirectoryState->OutputLocation;
841
842
843
  loc = dir;
  cmSystemTools::ConvertToUnixSlashes(loc);
  loc = cmSystemTools::CollapseFullPath(loc);
844
845

  cmSystemTools::SplitPath(
846
      loc,
847
      this->DirectoryState->CurrentBinaryDirectoryComponents);
848
  this->ComputeRelativePathTopBinary();
849
850
}

851
852
853
854
855
void cmState::Snapshot::SetListFile(const std::string& listfile)
{
  *this->Position->ExecutionListFile = listfile;
}

856
std::vector<std::string> const&
857
cmState::Directory::GetCurrentSourceComponents() const
858
{
859
  return this->DirectoryState->CurrentSourceDirectoryComponents;
860
861
862
}

std::vector<std::string> const&
863
cmState::Directory::GetCurrentBinaryComponents() const
864
{
865
  return this->DirectoryState->CurrentBinaryDirectoryComponents;
866
}
867

868
const char* cmState::Directory::GetRelativePathTopSource() const
869
{
870
  return this->DirectoryState->RelativePathTopSource.c_str();
871
872
}

873
const char* cmState::Directory::GetRelativePathTopBinary() const
874
{
875
  return this->DirectoryState->RelativePathTopBinary.c_str();
876
877
}

878
void cmState::Directory::SetRelativePathTopSource(const char* dir)
879
{
880
  this->DirectoryState->RelativePathTopSource = dir;
881
882
}

883
void cmState::Directory::SetRelativePathTopBinary(const char* dir)
884
{
885
  this->DirectoryState->RelativePathTopBinary = dir;
886
887
}

888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
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;
}

903
904
bool cmState::Snapshot::IsValid() const
{
905
906
907
  return this->State && this->Position.IsValid()
      ? this->Position != this->State->SnapshotData.Root()
      : false;
908
909
}

910
cmState::Snapshot cmState::Snapshot::GetBuildsystemDirectoryParent() const
911
912
{
  Snapshot snapshot;
913
  if (!this->State || this->Position == this->State->SnapshotData.Root())
914
915
916
    {
    return snapshot;
    }
917
918
919
920
921
  PositionType parentPos = this->Position->DirectoryParent;
  if (parentPos != this->State->SnapshotData.Root())
    {
    snapshot = Snapshot(this->State, parentPos);
    }
922
923
924

  return snapshot;
}
925

926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
cmState::Snapshot cmState::Snapshot::GetCallStackParent() const
{
  assert(this->State);
  assert(this->Position != this->State->SnapshotData.Root());

  Snapshot snapshot;
  if (this->Position->SnapshotType == cmState::BuildsystemDirectoryType)
    {
    return snapshot;
    }

  PositionType parentPos = this->Position;
  ++parentPos;
  if (parentPos == this->State->SnapshotData.Root())
    {
    return snapshot;
    }

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

948
949
950
951
cmState* cmState::Snapshot::GetState() const
{
  return this->State;
}
952
953
954
955
956
957
958
959
960
961
962
963
964

cmState::Directory cmState::Snapshot::GetDirectory() const
{
  return Directory(this->Position->BuildSystemDirectory, *this);
}

cmState::Directory::Directory(
    cmLinkedTree<BuildsystemDirectoryStateType>::iterator iter,
    const cmState::Snapshot& snapshot)
  : DirectoryState(iter), Snapshot_(snapshot)
{

}