Coverage Report

Created: 2026-09-14 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmStateSnapshot.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
4
#include "cmStateSnapshot.h"
5
6
#include <algorithm>
7
#include <array>
8
#include <cassert>
9
#include <set>
10
#include <string>
11
#include <unordered_map>
12
13
#include <cm/iterator>
14
#include <cmext/algorithm>
15
16
#include "cmDefinitions.h"
17
#include "cmLinkedTree.h"
18
#include "cmListFileCache.h"
19
#include "cmPackageState.h"
20
#include "cmPropertyMap.h"
21
#include "cmState.h"
22
#include "cmStateDirectory.h"
23
#include "cmStatePrivate.h"
24
#include "cmSystemTools.h"
25
#include "cmValue.h"
26
#include "cmVersion.h"
27
28
#if defined(__CYGWIN__)
29
#  include "cmStringAlgorithms.h"
30
#endif
31
32
cmStateSnapshot::cmStateSnapshot(cmState* state)
33
35
  : State(state)
34
35
{
35
35
}
36
37
std::vector<cmStateSnapshot> cmStateSnapshot::GetChildren()
38
0
{
39
0
  return this->Position->BuildSystemDirectory->Children;
40
0
}
41
42
cmStateSnapshot::cmStateSnapshot(cmState* state,
43
                                 cmStateDetail::PositionType position)
44
39
  : State(state)
45
39
  , Position(position)
46
39
{
47
39
}
48
49
cmStateEnums::SnapshotType cmStateSnapshot::GetType() const
50
0
{
51
0
  return this->Position->SnapshotType;
52
0
}
53
54
cmStateEnums::SnapshotUnwindType cmStateSnapshot::GetUnwindType() const
55
0
{
56
0
  return this->Position->UnwindType;
57
0
}
58
59
void cmStateSnapshot::SetUnwindType(cmStateEnums::SnapshotUnwindType type)
60
0
{
61
0
  this->Position->UnwindType = type;
62
0
}
63
64
cmStateEnums::SnapshotUnwindState cmStateSnapshot::GetUnwindState() const
65
0
{
66
0
  return this->Position->UnwindState;
67
0
}
68
69
void cmStateSnapshot::SetUnwindState(cmStateEnums::SnapshotUnwindState state)
70
0
{
71
0
  this->Position->UnwindState = state;
72
0
}
73
74
void cmStateSnapshot::SetListFile(std::string const& listfile)
75
0
{
76
0
  *this->Position->ExecutionListFile = listfile;
77
0
}
78
79
std::string const& cmStateSnapshot::GetExecutionListFile() const
80
0
{
81
0
  return *this->Position->ExecutionListFile;
82
0
}
83
84
bool cmStateSnapshot::IsValid() const
85
72
{
86
72
  return this->State && this->Position.IsValid()
87
72
    ? this->Position != this->State->SnapshotData.Root()
88
72
    : false;
89
72
}
90
91
cmStateSnapshot cmStateSnapshot::GetBuildsystemDirectory() const
92
0
{
93
0
  return { this->State, this->Position->BuildSystemDirectory->CurrentScope };
94
0
}
95
96
cmStateSnapshot cmStateSnapshot::GetBuildsystemDirectoryParent() const
97
0
{
98
0
  cmStateSnapshot snapshot;
99
0
  if (!this->State || this->Position == this->State->SnapshotData.Root()) {
100
0
    return snapshot;
101
0
  }
102
0
  cmStateDetail::PositionType parentPos = this->Position->DirectoryParent;
103
0
  if (parentPos != this->State->SnapshotData.Root()) {
104
0
    snapshot = cmStateSnapshot(this->State,
105
0
                               parentPos->BuildSystemDirectory->CurrentScope);
106
0
  }
107
108
0
  return snapshot;
109
0
}
110
111
cmStateSnapshot cmStateSnapshot::GetCallStackParent() const
112
0
{
113
0
  assert(this->State);
114
0
  assert(this->Position != this->State->SnapshotData.Root());
115
116
0
  cmStateSnapshot snapshot;
117
0
  cmStateDetail::PositionType parentPos = this->Position;
118
0
  while (parentPos->SnapshotType == cmStateEnums::PolicyScopeType ||
119
0
         parentPos->SnapshotType == cmStateEnums::VariableScopeType) {
120
0
    ++parentPos;
121
0
  }
122
0
  if (parentPos->SnapshotType == cmStateEnums::BuildsystemDirectoryType ||
123
0
      parentPos->SnapshotType == cmStateEnums::BaseType) {
124
0
    return snapshot;
125
0
  }
126
127
0
  ++parentPos;
128
0
  while (parentPos->SnapshotType == cmStateEnums::PolicyScopeType ||
129
0
         parentPos->SnapshotType == cmStateEnums::VariableScopeType) {
130
0
    ++parentPos;
131
0
  }
132
133
0
  if (parentPos == this->State->SnapshotData.Root()) {
134
0
    return snapshot;
135
0
  }
136
137
0
  snapshot = cmStateSnapshot(this->State, parentPos);
138
0
  return snapshot;
139
0
}
140
141
cmStateSnapshot cmStateSnapshot::GetCallStackBottom() const
142
0
{
143
0
  assert(this->State);
144
0
  assert(this->Position != this->State->SnapshotData.Root());
145
146
0
  cmStateDetail::PositionType pos = this->Position;
147
0
  while (pos->SnapshotType != cmStateEnums::BaseType &&
148
0
         pos->SnapshotType != cmStateEnums::BuildsystemDirectoryType &&
149
0
         pos != this->State->SnapshotData.Root()) {
150
0
    ++pos;
151
0
  }
152
0
  return { this->State, pos };
153
0
}
154
155
void cmStateSnapshot::PushPolicy(cmPolicies::PolicyMap const& entry, bool weak)
156
1
{
157
1
  cmStateDetail::PositionType pos = this->Position;
158
1
  pos->Policies = this->State->PolicyStack.Push(
159
1
    pos->Policies, cmStateDetail::PolicyStackEntry(entry, weak));
160
1
}
161
162
bool cmStateSnapshot::PopPolicy()
163
0
{
164
0
  cmStateDetail::PositionType pos = this->Position;
165
0
  if (pos->Policies == pos->PolicyScope) {
166
0
    return false;
167
0
  }
168
0
  pos->Policies = this->State->PolicyStack.Pop(pos->Policies);
169
0
  return true;
170
0
}
171
172
bool cmStateSnapshot::CanPopPolicyScope() const
173
1
{
174
1
  return this->Position->Policies != this->Position->PolicyScope;
175
1
}
176
177
void cmStateSnapshot::SetPolicy(cmPolicies::PolicyID id,
178
                                cmPolicies::PolicyStatus status)
179
0
{
180
  // Update the policy stack from the top to the top-most strong entry.
181
0
  bool previous_was_weak = true;
182
0
  for (cmLinkedTree<cmStateDetail::PolicyStackEntry>::iterator psi =
183
0
         this->Position->Policies;
184
0
       previous_was_weak && psi != this->Position->PolicyRoot; ++psi) {
185
0
    psi->Set(id, status);
186
0
    previous_was_weak = psi->Weak;
187
0
  }
188
0
}
189
190
cmPolicies::PolicyStatus cmStateSnapshot::GetPolicy(cmPolicies::PolicyID id,
191
                                                    bool parent_scope) const
192
0
{
193
0
  if (cmPolicies::IsRemoved(id)) {
194
0
    return cmPolicies::NEW;
195
0
  }
196
197
0
  cmPolicies::PolicyStatus status = cmPolicies::WARN;
198
199
0
  cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator dir =
200
0
    this->Position->BuildSystemDirectory;
201
202
0
  while (true) {
203
0
    assert(dir.IsValid());
204
0
    cmLinkedTree<cmStateDetail::PolicyStackEntry>::iterator leaf =
205
0
      dir->CurrentScope->Policies;
206
0
    cmLinkedTree<cmStateDetail::PolicyStackEntry>::iterator root =
207
0
      dir->CurrentScope->PolicyRoot;
208
0
    for (; leaf != root; ++leaf) {
209
0
      if (parent_scope) {
210
0
        parent_scope = false;
211
0
        continue;
212
0
      }
213
0
      if (leaf->IsDefined(id)) {
214
0
        status = leaf->Get(id);
215
0
        return status;
216
0
      }
217
0
    }
218
0
    cmStateDetail::PositionType e = dir->CurrentScope;
219
0
    cmStateDetail::PositionType p = e->DirectoryParent;
220
0
    if (p == this->State->SnapshotData.Root()) {
221
0
      break;
222
0
    }
223
0
    dir = p->BuildSystemDirectory;
224
0
  }
225
0
  return status;
226
0
}
227
228
cmPolicies::PolicyStatus cmStateSnapshot::GetScopePolicy(
229
  cmPolicies::PolicyID id) const
230
0
{
231
0
  if (cmPolicies::IsRemoved(id)) {
232
0
    return cmPolicies::NEW;
233
0
  }
234
235
0
  cmPolicies::PolicyStatus status = cmPolicies::WARN;
236
237
0
  cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator dir =
238
0
    this->Position->BuildSystemDirectory;
239
240
  // Logic mirrors GetPolicy(), except that the search starts at this
241
  // snapshot's exact scope rather than the directory's current top scope.
242
0
  cmLinkedTree<cmStateDetail::PolicyStackEntry>::iterator leaf =
243
0
    this->Position->Policies;
244
0
  cmLinkedTree<cmStateDetail::PolicyStackEntry>::iterator root =
245
0
    this->Position->PolicyRoot;
246
0
  while (true) {
247
0
    assert(dir.IsValid());
248
0
    for (; leaf != root; ++leaf) {
249
0
      if (leaf->IsDefined(id)) {
250
0
        return leaf->Get(id);
251
0
      }
252
0
    }
253
0
    cmStateDetail::PositionType e = dir->CurrentScope;
254
0
    cmStateDetail::PositionType p = e->DirectoryParent;
255
0
    if (p == this->State->SnapshotData.Root()) {
256
0
      break;
257
0
    }
258
0
    dir = p->BuildSystemDirectory;
259
0
    leaf = dir->CurrentScope->Policies;
260
0
    root = dir->CurrentScope->PolicyRoot;
261
0
  }
262
0
  return status;
263
0
}
264
265
void cmStateSnapshot::PushDiagnostic(cmDiagnostics::DiagnosticMap entry,
266
                                     bool weak)
267
1
{
268
1
  cmStateDetail::PositionType pos = this->Position;
269
1
  pos->Diagnostics = this->State->DiagnosticStack.Push(
270
1
    pos->Diagnostics, cmStateDetail::DiagnosticStackEntry(entry, weak));
271
1
}
272
273
bool cmStateSnapshot::PopDiagnostic()
274
0
{
275
0
  cmStateDetail::PositionType pos = this->Position;
276
0
  if (pos->Diagnostics == pos->DiagnosticScope) {
277
0
    return false;
278
0
  }
279
0
  pos->Diagnostics = this->State->DiagnosticStack.Pop(pos->Diagnostics);
280
0
  return true;
281
0
}
282
283
bool cmStateSnapshot::CanPopDiagnosticScope() const
284
1
{
285
1
  return this->Position->Diagnostics != this->Position->DiagnosticScope;
286
1
}
287
288
void cmStateSnapshot::SetDiagnostic(cmDiagnosticCategory category,
289
                                    cmDiagnosticAction action, bool recursive)
290
0
{
291
0
  assert(action != cmDiagnostics::Undefined);
292
293
0
  auto function = [](cmDiagnosticAction, cmDiagnosticAction) -> bool {
294
0
    return true;
295
0
  };
296
297
0
  this->AlterDiagnostic(category, action, function, recursive);
298
0
}
299
300
void cmStateSnapshot::PromoteDiagnostic(cmDiagnosticCategory category,
301
                                        cmDiagnosticAction action,
302
                                        bool recursive)
303
0
{
304
0
  assert(action != cmDiagnostics::Undefined);
305
306
0
  auto function = [](cmDiagnosticAction current,
307
0
                     cmDiagnosticAction desired) -> bool {
308
0
    return (current < desired);
309
0
  };
310
311
0
  this->AlterDiagnostic(category, action, function, recursive);
312
0
}
313
314
void cmStateSnapshot::DemoteDiagnostic(cmDiagnosticCategory category,
315
                                       cmDiagnosticAction action,
316
                                       bool recursive)
317
0
{
318
0
  assert(action != cmDiagnostics::Undefined);
319
320
0
  auto function = [](cmDiagnosticAction current,
321
0
                     cmDiagnosticAction desired) -> bool {
322
0
    return (current > desired);
323
0
  };
324
325
0
  this->AlterDiagnostic(category, action, function, recursive);
326
0
}
327
328
void cmStateSnapshot::AlterDiagnostic(cmDiagnosticCategory category,
329
                                      cmDiagnosticAction action,
330
                                      AlterDiagnosticFunction function,
331
                                      bool recursive)
332
0
{
333
0
  if (recursive) {
334
0
    unsigned i = category;
335
0
    for (;;) {
336
0
      this->AlterDiagnostic(static_cast<cmDiagnosticCategory>(i), action,
337
0
                            function, false);
338
0
      if (++i >= cmDiagnostics::CategoryCount) {
339
0
        break;
340
0
      }
341
0
      if (cmDiagnostics::CategoryInfo[i].Parent < category) {
342
0
        break;
343
0
      }
344
0
    }
345
0
  } else {
346
0
    cmDiagnosticAction const oldAction = this->GetDiagnostic(category);
347
0
    if (function(oldAction, action)) {
348
      // Update the policy stack from the top to the top-most strong entry.
349
0
      bool previous_was_weak = true;
350
0
      for (cmLinkedTree<cmStateDetail::DiagnosticStackEntry>::iterator dsi =
351
0
             this->Position->Diagnostics;
352
0
           previous_was_weak && dsi != this->Position->DiagnosticRoot; ++dsi) {
353
0
        (*dsi)[category] = action;
354
0
        previous_was_weak = dsi->Weak;
355
0
      }
356
0
    }
357
0
  }
358
0
}
359
360
cmDiagnosticAction cmStateSnapshot::GetDiagnostic(
361
  cmDiagnosticCategory category, cmDiagnosticAction defaultAction) const
362
0
{
363
0
  cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator dir =
364
0
    this->Position->BuildSystemDirectory;
365
366
0
  while (true) {
367
0
    assert(dir.IsValid());
368
0
    cmLinkedTree<cmStateDetail::DiagnosticStackEntry>::iterator leaf =
369
0
      dir->CurrentScope->Diagnostics;
370
0
    cmLinkedTree<cmStateDetail::DiagnosticStackEntry>::iterator root =
371
0
      dir->CurrentScope->DiagnosticRoot;
372
0
    for (; leaf != root; ++leaf) {
373
0
      cmDiagnosticAction const action = (*leaf)[category];
374
0
      if (action != cmDiagnostics::Undefined) {
375
0
        return action;
376
0
      }
377
0
    }
378
0
    cmStateDetail::PositionType e = dir->CurrentScope;
379
0
    cmStateDetail::PositionType p = e->DirectoryParent;
380
0
    if (p == this->State->SnapshotData.Root()) {
381
0
      break;
382
0
    }
383
0
    dir = p->BuildSystemDirectory;
384
0
  }
385
0
  return defaultAction;
386
0
}
387
388
cmValue cmStateSnapshot::GetDefinition(std::string const& name) const
389
6
{
390
6
  assert(this->Position->Vars.IsValid());
391
6
  return cmDefinitions::Get(name, this->Position->Vars, this->Position->Root);
392
6
}
393
394
bool cmStateSnapshot::IsInitialized(std::string const& name) const
395
0
{
396
0
  return cmDefinitions::HasKey(name, this->Position->Vars,
397
0
                               this->Position->Root);
398
0
}
399
400
void cmStateSnapshot::SetDefinition(std::string const& name,
401
                                    cm::string_view value)
402
95
{
403
95
  this->Position->Vars->Set(name, value);
404
95
}
405
406
void cmStateSnapshot::RemoveDefinition(std::string const& name)
407
1
{
408
1
  this->Position->Vars->Unset(name);
409
1
}
410
411
std::vector<std::string> cmStateSnapshot::ClosureKeys() const
412
0
{
413
0
  return cmDefinitions::ClosureKeys(this->Position->Vars,
414
0
                                    this->Position->Root);
415
0
}
416
417
std::vector<std::string> cmStateSnapshot::LocalKeys() const
418
0
{
419
0
  std::vector<std::string> keys = cmDefinitions::ClosureKeys(
420
0
    this->Position->Vars, this->Position->ScopeParent->Vars);
421
422
  // Remove keys that are the same in the parent scope to avoid propagating
423
  // logic meant to restore variables back to their original value.
424
0
  keys.erase(std::remove_if(
425
0
               keys.begin(), keys.end(),
426
0
               [this](std::string const& key) {
427
0
                 return cmDefinitions::Get(key, this->Position->Vars,
428
0
                                           this->Position->Root) ==
429
0
                   cmDefinitions::Get(key, this->Position->ScopeParent->Vars,
430
0
                                      this->Position->ScopeParent->Root);
431
0
               }),
432
0
             keys.end());
433
0
  std::sort(keys.begin(), keys.end());
434
435
0
  return keys;
436
0
}
437
438
bool cmStateSnapshot::RaiseScope(std::string const& var, char const* varDef)
439
0
{
440
0
  if (this->Position->ScopeParent == this->Position->DirectoryParent) {
441
0
    cmStateSnapshot parentDir = this->GetBuildsystemDirectoryParent();
442
0
    if (!parentDir.IsValid()) {
443
0
      return false;
444
0
    }
445
    // Update the definition in the parent directory top scope.  This
446
    // directory's scope was initialized by the closure of the parent
447
    // scope, so we do not need to localize the definition first.
448
0
    if (varDef) {
449
0
      parentDir.SetDefinition(var, varDef);
450
0
    } else {
451
0
      parentDir.RemoveDefinition(var);
452
0
    }
453
0
    return true;
454
0
  }
455
  // First localize the definition in the current scope.
456
0
  cmDefinitions::Raise(var, this->Position->Vars, this->Position->Root);
457
458
  // Now update the definition in the parent scope.
459
0
  if (varDef) {
460
0
    this->Position->Parent->Set(var, varDef);
461
0
  } else {
462
0
    this->Position->Parent->Unset(var);
463
0
  }
464
0
  return true;
465
0
}
466
467
cmStateSnapshot::WarnCMP0220 cmStateSnapshot::RaiseToRoot(
468
  std::string const& var, char const* varDef, CheckCMP0220 checkCMP0220)
469
0
{
470
  // If we are at the top of a directory, propagate to the parent directory (if
471
  // any).
472
0
  cmStateSnapshot parentScope =
473
0
    this->Position->ScopeParent == this->Position->DirectoryParent
474
0
    ? this->GetBuildsystemDirectoryParent()
475
0
    : cmStateSnapshot(this->State, this->Position->ScopeParent);
476
477
0
  if (!parentScope.IsValid()) {
478
0
    return WarnCMP0220::No;
479
0
  }
480
481
  // First raise always occurs to propagate out of capturing variable scope.
482
0
  if (checkCMP0220 == CheckCMP0220::Yes) {
483
0
    switch (parentScope.GetScopePolicy(cmPolicies::CMP0220)) {
484
0
      case cmPolicies::NEW:
485
0
        break;
486
0
      case cmPolicies::OLD:
487
0
        return WarnCMP0220::No;
488
0
      case cmPolicies::WARN:
489
0
        return WarnCMP0220::Yes;
490
0
    }
491
0
  }
492
493
0
  if (varDef) {
494
0
    parentScope.SetDefinition(var, varDef);
495
0
  } else {
496
0
    parentScope.RemoveDefinition(var);
497
0
  }
498
0
  return parentScope.RaiseToRoot(var, varDef, CheckCMP0220::Yes);
499
0
}
500
501
template <typename T, typename U>
502
void InitializeContentFromParent(T& parentContent, T& thisContent,
503
                                 U& contentEndPosition)
504
0
{
505
0
  auto parentEnd = parentContent.end();
506
507
0
  auto parentRbegin = cm::make_reverse_iterator(parentEnd);
508
0
  auto parentRend = parentContent.rend();
509
0
  parentRbegin =
510
0
    std::find(parentRbegin, parentRend, cmStateDetail::PropertySentinel);
511
0
  auto parentIt = parentRbegin.base();
512
513
0
  thisContent = std::vector<BT<std::string>>(parentIt, parentEnd);
514
515
0
  contentEndPosition = thisContent.size();
516
0
}
517
518
void cmStateSnapshot::SetDefaultDefinitions()
519
1
{
520
  /* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
521
    With CMake must separate between target and host platform. In most cases
522
    the tests for WIN32, UNIX and APPLE will be for the target system, so an
523
    additional set of variables for the host system is required ->
524
    CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
525
    WIN32, UNIX and APPLE are now set in the platform files in
526
    Modules/Platforms/.
527
    To keep cmake scripts (-P) and custom language and compiler modules
528
    working, these variables are still also set here in this place, but they
529
    will be reset in CMakeSystemSpecificInformation.cmake before the platform
530
    files are executed. */
531
1
  cm::string_view hostSystemName = cmSystemTools::GetSystemName();
532
1
  this->SetDefinition("CMAKE_HOST_SYSTEM_NAME", hostSystemName);
533
1
  if (hostSystemName == "Windows") {
534
0
    this->SetDefinition("WIN32", "1");
535
0
    this->SetDefinition("CMAKE_HOST_WIN32", "1");
536
0
    this->SetDefinition("CMAKE_HOST_EXECUTABLE_SUFFIX", ".exe");
537
1
  } else {
538
1
    this->SetDefinition("UNIX", "1");
539
1
    this->SetDefinition("CMAKE_HOST_UNIX", "1");
540
1
    this->SetDefinition("CMAKE_HOST_EXECUTABLE_SUFFIX", "");
541
1
  }
542
#if defined(__APPLE__)
543
  this->SetDefinition("APPLE", "1");
544
  this->SetDefinition("CMAKE_HOST_APPLE", "1");
545
#endif
546
#if defined(__sun__)
547
  this->SetDefinition("CMAKE_HOST_SOLARIS", "1");
548
#endif
549
550
#if defined(__OpenBSD__)
551
  this->SetDefinition("BSD", "OpenBSD");
552
  this->SetDefinition("CMAKE_HOST_BSD", "OpenBSD");
553
#elif defined(__FreeBSD__)
554
  this->SetDefinition("BSD", "FreeBSD");
555
  this->SetDefinition("CMAKE_HOST_BSD", "FreeBSD");
556
#elif defined(__NetBSD__)
557
  this->SetDefinition("BSD", "NetBSD");
558
  this->SetDefinition("CMAKE_HOST_BSD", "NetBSD");
559
#elif defined(__DragonFly__)
560
  this->SetDefinition("BSD", "DragonFlyBSD");
561
  this->SetDefinition("CMAKE_HOST_BSD", "DragonFlyBSD");
562
#endif
563
564
1
#if defined(__linux__)
565
1
  this->SetDefinition("LINUX", "1");
566
1
  this->SetDefinition("CMAKE_HOST_LINUX", "1");
567
1
#endif
568
569
#if defined(_AIX)
570
  this->SetDefinition("AIX", "1");
571
  this->SetDefinition("CMAKE_HOST_AIX", "1");
572
#endif
573
574
1
  this->SetDefinition("CMAKE_MAJOR_VERSION",
575
1
                      std::to_string(cmVersion::GetMajorVersion()));
576
1
  this->SetDefinition("CMAKE_MINOR_VERSION",
577
1
                      std::to_string(cmVersion::GetMinorVersion()));
578
1
  this->SetDefinition("CMAKE_PATCH_VERSION",
579
1
                      std::to_string(cmVersion::GetPatchVersion()));
580
1
  this->SetDefinition("CMAKE_TWEAK_VERSION",
581
1
                      std::to_string(cmVersion::GetTweakVersion()));
582
1
  this->SetDefinition("CMAKE_VERSION", cmVersion::GetCMakeVersion());
583
584
1
  this->SetDefinition("CMAKE_FILES_DIRECTORY", "/CMakeFiles");
585
586
  // Setup the default include file regular expression (match everything).
587
1
  this->Position->BuildSystemDirectory->Properties.SetProperty(
588
1
    "INCLUDE_REGULAR_EXPRESSION", "^.*$");
589
1
}
590
591
void cmStateSnapshot::SetDirectoryDefinitions()
592
0
{
593
0
  this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory());
594
0
  this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR",
595
0
                      this->State->GetSourceDirectory());
596
0
  this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory());
597
0
  this->SetDefinition("CMAKE_CURRENT_BINARY_DIR",
598
0
                      this->State->GetBinaryDirectory());
599
0
}
600
601
void cmStateSnapshot::InitializeFromParent()
602
0
{
603
0
  cmStateDetail::PositionType parent = this->Position->DirectoryParent;
604
0
  assert(this->Position->Vars.IsValid());
605
0
  assert(parent->Vars.IsValid());
606
607
0
  *this->Position->Vars =
608
0
    cmDefinitions::MakeClosure(parent->Vars, parent->Root);
609
610
0
  InitializeContentFromParent(
611
0
    parent->BuildSystemDirectory->IncludeDirectories,
612
0
    this->Position->BuildSystemDirectory->IncludeDirectories,
613
0
    this->Position->IncludeDirectoryPosition);
614
615
0
  InitializeContentFromParent(
616
0
    parent->BuildSystemDirectory->CompileDefinitions,
617
0
    this->Position->BuildSystemDirectory->CompileDefinitions,
618
0
    this->Position->CompileDefinitionsPosition);
619
620
0
  InitializeContentFromParent(
621
0
    parent->BuildSystemDirectory->CompileOptions,
622
0
    this->Position->BuildSystemDirectory->CompileOptions,
623
0
    this->Position->CompileOptionsPosition);
624
625
0
  InitializeContentFromParent(
626
0
    parent->BuildSystemDirectory->LinkOptions,
627
0
    this->Position->BuildSystemDirectory->LinkOptions,
628
0
    this->Position->LinkOptionsPosition);
629
630
0
  InitializeContentFromParent(
631
0
    parent->BuildSystemDirectory->LinkDirectories,
632
0
    this->Position->BuildSystemDirectory->LinkDirectories,
633
0
    this->Position->LinkDirectoriesPosition);
634
635
0
  cmValue include_regex =
636
0
    parent->BuildSystemDirectory->Properties.GetPropertyValue(
637
0
      "INCLUDE_REGULAR_EXPRESSION");
638
0
  this->Position->BuildSystemDirectory->Properties.SetProperty(
639
0
    "INCLUDE_REGULAR_EXPRESSION", include_regex);
640
0
}
641
642
cmState* cmStateSnapshot::GetState() const
643
1
{
644
1
  return this->State;
645
1
}
646
647
cmStateDirectory cmStateSnapshot::GetDirectory() const
648
3
{
649
3
  return { this->Position->BuildSystemDirectory, *this };
650
3
}
651
652
void cmStateSnapshot::SetProjectName(std::string const& name)
653
0
{
654
0
  this->Position->BuildSystemDirectory->ProjectName = name;
655
0
  this->Position->BuildSystemDirectory->Projects.insert(name);
656
0
}
657
658
std::string cmStateSnapshot::GetProjectName() const
659
0
{
660
0
  return this->Position->BuildSystemDirectory->ProjectName;
661
0
}
662
663
bool cmStateSnapshot::CheckProjectName(std::string const& name) const
664
0
{
665
0
  return cm::contains(this->Position->BuildSystemDirectory->Projects, name);
666
0
}
667
668
cmPackageState& cmStateSnapshot::GetPackageState(
669
  std::string const& packagePath)
670
0
{
671
0
  return this->Position->BuildSystemDirectory->Packages[packagePath];
672
0
}
673
674
void cmStateSnapshot::InitializeFromParent_ForSubdirsCommand()
675
0
{
676
0
  std::string currentSrcDir = *this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR");
677
0
  std::string currentBinDir = *this->GetDefinition("CMAKE_CURRENT_BINARY_DIR");
678
0
  this->InitializeFromParent();
679
0
  this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory());
680
0
  this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory());
681
682
0
  this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR", currentSrcDir);
683
0
  this->SetDefinition("CMAKE_CURRENT_BINARY_DIR", currentBinDir);
684
0
}
685
686
bool cmStateSnapshot::StrictWeakOrder::operator()(
687
  cmStateSnapshot const& lhs, cmStateSnapshot const& rhs) const
688
0
{
689
0
  return lhs.Position.StrictWeakOrdered(rhs.Position);
690
0
}
691
692
bool operator==(cmStateSnapshot const& lhs, cmStateSnapshot const& rhs)
693
0
{
694
0
  return lhs.Position == rhs.Position;
695
0
}
696
697
bool operator!=(cmStateSnapshot const& lhs, cmStateSnapshot const& rhs)
698
0
{
699
0
  return lhs.Position != rhs.Position;
700
0
}