Coverage Report

Created: 2026-10-28 06:38

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
31.8k
  : State(state)
34
31.8k
{
35
31.8k
}
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
63.5k
  : State(state)
45
63.5k
  , Position(position)
46
63.5k
{
47
63.5k
}
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
403k
{
81
403k
  return *this->Position->ExecutionListFile;
82
403k
}
83
84
bool cmStateSnapshot::IsValid() const
85
51.8k
{
86
51.8k
  return this->State && this->Position.IsValid()
87
51.8k
    ? this->Position != this->State->SnapshotData.Root()
88
51.8k
    : false;
89
51.8k
}
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
11.9k
{
98
11.9k
  cmStateSnapshot snapshot;
99
11.9k
  if (!this->State || this->Position == this->State->SnapshotData.Root()) {
100
0
    return snapshot;
101
0
  }
102
11.9k
  cmStateDetail::PositionType parentPos = this->Position->DirectoryParent;
103
11.9k
  if (parentPos != this->State->SnapshotData.Root()) {
104
0
    snapshot = cmStateSnapshot(this->State,
105
0
                               parentPos->BuildSystemDirectory->CurrentScope);
106
0
  }
107
108
11.9k
  return snapshot;
109
11.9k
}
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
19.8k
{
157
19.8k
  cmStateDetail::PositionType pos = this->Position;
158
19.8k
  pos->Policies = this->State->PolicyStack.Push(
159
19.8k
    pos->Policies, cmStateDetail::PolicyStackEntry(entry, weak));
160
19.8k
}
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
11.8k
{
174
11.8k
  return this->Position->Policies != this->Position->PolicyScope;
175
11.8k
}
176
177
void cmStateSnapshot::SetPolicy(cmPolicies::PolicyID id,
178
                                cmPolicies::PolicyStatus status)
179
2.69M
{
180
  // Update the policy stack from the top to the top-most strong entry.
181
2.69M
  bool previous_was_weak = true;
182
2.69M
  for (cmLinkedTree<cmStateDetail::PolicyStackEntry>::iterator psi =
183
2.69M
         this->Position->Policies;
184
5.38M
       previous_was_weak && psi != this->Position->PolicyRoot; ++psi) {
185
2.69M
    psi->Set(id, status);
186
2.69M
    previous_was_weak = psi->Weak;
187
2.69M
  }
188
2.69M
}
189
190
cmPolicies::PolicyStatus cmStateSnapshot::GetPolicy(cmPolicies::PolicyID id,
191
                                                    bool parent_scope) const
192
19.6M
{
193
19.6M
  if (cmPolicies::IsRemoved(id)) {
194
5.60M
    return cmPolicies::NEW;
195
5.60M
  }
196
197
14.0M
  cmPolicies::PolicyStatus status = cmPolicies::WARN;
198
199
14.0M
  cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator dir =
200
14.0M
    this->Position->BuildSystemDirectory;
201
202
14.0M
  while (true) {
203
14.0M
    assert(dir.IsValid());
204
14.0M
    cmLinkedTree<cmStateDetail::PolicyStackEntry>::iterator leaf =
205
14.0M
      dir->CurrentScope->Policies;
206
14.0M
    cmLinkedTree<cmStateDetail::PolicyStackEntry>::iterator root =
207
14.0M
      dir->CurrentScope->PolicyRoot;
208
19.1M
    for (; leaf != root; ++leaf) {
209
14.0M
      if (parent_scope) {
210
0
        parent_scope = false;
211
0
        continue;
212
0
      }
213
14.0M
      if (leaf->IsDefined(id)) {
214
8.94M
        status = leaf->Get(id);
215
8.94M
        return status;
216
8.94M
      }
217
14.0M
    }
218
5.08M
    cmStateDetail::PositionType e = dir->CurrentScope;
219
5.08M
    cmStateDetail::PositionType p = e->DirectoryParent;
220
5.08M
    if (p == this->State->SnapshotData.Root()) {
221
5.08M
      break;
222
5.08M
    }
223
0
    dir = p->BuildSystemDirectory;
224
0
  }
225
5.08M
  return status;
226
14.0M
}
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
19.8k
{
268
19.8k
  cmStateDetail::PositionType pos = this->Position;
269
19.8k
  pos->Diagnostics = this->State->DiagnosticStack.Push(
270
19.8k
    pos->Diagnostics, cmStateDetail::DiagnosticStackEntry(entry, weak));
271
19.8k
}
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
11.8k
{
285
11.8k
  return this->Position->Diagnostics != this->Position->DiagnosticScope;
286
11.8k
}
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.45M
{
390
6.45M
  assert(this->Position->Vars.IsValid());
391
6.45M
  return cmDefinitions::Get(name, this->Position->Vars, this->Position->Root);
392
6.45M
}
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
447k
{
403
447k
  this->Position->Vars->Set(name, value);
404
447k
}
405
406
void cmStateSnapshot::RemoveDefinition(std::string const& name)
407
17.7k
{
408
17.7k
  this->Position->Vars->Unset(name);
409
17.7k
}
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
0
    cmDefinitions::UnsetKeys::Include);
422
423
  // Remove keys that are the same in the parent scope to avoid propagating
424
  // logic meant to restore variables back to their original value.
425
0
  keys.erase(std::remove_if(
426
0
               keys.begin(), keys.end(),
427
0
               [this](std::string const& key) {
428
0
                 return cmDefinitions::Get(key, this->Position->Vars,
429
0
                                           this->Position->Root) ==
430
0
                   cmDefinitions::Get(key, this->Position->ScopeParent->Vars,
431
0
                                      this->Position->ScopeParent->Root);
432
0
               }),
433
0
             keys.end());
434
0
  std::sort(keys.begin(), keys.end());
435
436
0
  return keys;
437
0
}
438
439
bool cmStateSnapshot::RaiseScope(std::string const& var, char const* varDef)
440
0
{
441
0
  if (this->Position->ScopeParent == this->Position->DirectoryParent) {
442
0
    cmStateSnapshot parentDir = this->GetBuildsystemDirectoryParent();
443
0
    if (!parentDir.IsValid()) {
444
0
      return false;
445
0
    }
446
    // Update the definition in the parent directory top scope.  This
447
    // directory's scope was initialized by the closure of the parent
448
    // scope, so we do not need to localize the definition first.
449
0
    if (varDef) {
450
0
      parentDir.SetDefinition(var, varDef);
451
0
    } else {
452
0
      parentDir.RemoveDefinition(var);
453
0
    }
454
0
    return true;
455
0
  }
456
  // First localize the definition in the current scope.
457
0
  cmDefinitions::Raise(var, this->Position->Vars, this->Position->Root);
458
459
  // Now update the definition in the parent scope.
460
0
  if (varDef) {
461
0
    this->Position->Parent->Set(var, varDef);
462
0
  } else {
463
0
    this->Position->Parent->Unset(var);
464
0
  }
465
0
  return true;
466
0
}
467
468
cmStateSnapshot::WarnCMP0220 cmStateSnapshot::RaiseToRoot(
469
  std::string const& var, char const* varDef, CheckCMP0220 checkCMP0220)
470
0
{
471
  // If we are at the top of a directory, propagate to the parent directory (if
472
  // any).
473
0
  cmStateSnapshot parentScope =
474
0
    this->Position->ScopeParent == this->Position->DirectoryParent
475
0
    ? this->GetBuildsystemDirectoryParent()
476
0
    : cmStateSnapshot(this->State, this->Position->ScopeParent);
477
478
0
  if (!parentScope.IsValid()) {
479
0
    return WarnCMP0220::No;
480
0
  }
481
482
  // First raise always occurs to propagate out of capturing variable scope.
483
0
  if (checkCMP0220 == CheckCMP0220::Yes) {
484
0
    switch (parentScope.GetScopePolicy(cmPolicies::CMP0220)) {
485
0
      case cmPolicies::NEW:
486
0
        break;
487
0
      case cmPolicies::OLD:
488
0
        return WarnCMP0220::No;
489
0
      case cmPolicies::WARN:
490
0
        return WarnCMP0220::Yes;
491
0
    }
492
0
  }
493
494
0
  if (varDef) {
495
0
    parentScope.SetDefinition(var, varDef);
496
0
  } else {
497
0
    parentScope.RemoveDefinition(var);
498
0
  }
499
0
  return parentScope.RaiseToRoot(var, varDef, CheckCMP0220::Yes);
500
0
}
501
502
template <typename T, typename U>
503
void InitializeContentFromParent(T& parentContent, T& thisContent,
504
                                 U& contentEndPosition)
505
0
{
506
0
  auto parentEnd = parentContent.end();
507
508
0
  auto parentRbegin = cm::make_reverse_iterator(parentEnd);
509
0
  auto parentRend = parentContent.rend();
510
0
  parentRbegin =
511
0
    std::find(parentRbegin, parentRend, cmStateDetail::PropertySentinel);
512
0
  auto parentIt = parentRbegin.base();
513
514
0
  thisContent = std::vector<BT<std::string>>(parentIt, parentEnd);
515
516
0
  contentEndPosition = thisContent.size();
517
0
}
518
519
void cmStateSnapshot::SetDefaultDefinitions()
520
5.92k
{
521
  /* Up to CMake 2.4 here only WIN32, UNIX and APPLE were set.
522
    With CMake must separate between target and host platform. In most cases
523
    the tests for WIN32, UNIX and APPLE will be for the target system, so an
524
    additional set of variables for the host system is required ->
525
    CMAKE_HOST_WIN32, CMAKE_HOST_UNIX, CMAKE_HOST_APPLE.
526
    WIN32, UNIX and APPLE are now set in the platform files in
527
    Modules/Platforms/.
528
    To keep cmake scripts (-P) and custom language and compiler modules
529
    working, these variables are still also set here in this place, but they
530
    will be reset in CMakeSystemSpecificInformation.cmake before the platform
531
    files are executed. */
532
5.92k
  cm::string_view hostSystemName = cmSystemTools::GetSystemName();
533
5.92k
  this->SetDefinition("CMAKE_HOST_SYSTEM_NAME", hostSystemName);
534
5.92k
  if (hostSystemName == "Windows") {
535
0
    this->SetDefinition("WIN32", "1");
536
0
    this->SetDefinition("CMAKE_HOST_WIN32", "1");
537
0
    this->SetDefinition("CMAKE_HOST_EXECUTABLE_SUFFIX", ".exe");
538
5.92k
  } else {
539
5.92k
    this->SetDefinition("UNIX", "1");
540
5.92k
    this->SetDefinition("CMAKE_HOST_UNIX", "1");
541
5.92k
    this->SetDefinition("CMAKE_HOST_EXECUTABLE_SUFFIX", "");
542
5.92k
  }
543
#if defined(__APPLE__)
544
  this->SetDefinition("APPLE", "1");
545
  this->SetDefinition("CMAKE_HOST_APPLE", "1");
546
#endif
547
#if defined(__sun__)
548
  this->SetDefinition("CMAKE_HOST_SOLARIS", "1");
549
#endif
550
551
#if defined(__OpenBSD__)
552
  this->SetDefinition("BSD", "OpenBSD");
553
  this->SetDefinition("CMAKE_HOST_BSD", "OpenBSD");
554
#elif defined(__FreeBSD__)
555
  this->SetDefinition("BSD", "FreeBSD");
556
  this->SetDefinition("CMAKE_HOST_BSD", "FreeBSD");
557
#elif defined(__NetBSD__)
558
  this->SetDefinition("BSD", "NetBSD");
559
  this->SetDefinition("CMAKE_HOST_BSD", "NetBSD");
560
#elif defined(__DragonFly__)
561
  this->SetDefinition("BSD", "DragonFlyBSD");
562
  this->SetDefinition("CMAKE_HOST_BSD", "DragonFlyBSD");
563
#endif
564
565
5.92k
#if defined(__linux__)
566
5.92k
  this->SetDefinition("LINUX", "1");
567
5.92k
  this->SetDefinition("CMAKE_HOST_LINUX", "1");
568
5.92k
#endif
569
570
#if defined(_AIX)
571
  this->SetDefinition("AIX", "1");
572
  this->SetDefinition("CMAKE_HOST_AIX", "1");
573
#endif
574
575
5.92k
  this->SetDefinition("CMAKE_MAJOR_VERSION",
576
5.92k
                      std::to_string(cmVersion::GetMajorVersion()));
577
5.92k
  this->SetDefinition("CMAKE_MINOR_VERSION",
578
5.92k
                      std::to_string(cmVersion::GetMinorVersion()));
579
5.92k
  this->SetDefinition("CMAKE_PATCH_VERSION",
580
5.92k
                      std::to_string(cmVersion::GetPatchVersion()));
581
5.92k
  this->SetDefinition("CMAKE_TWEAK_VERSION",
582
5.92k
                      std::to_string(cmVersion::GetTweakVersion()));
583
5.92k
  this->SetDefinition("CMAKE_VERSION", cmVersion::GetCMakeVersion());
584
585
5.92k
  this->SetDefinition("CMAKE_FILES_DIRECTORY", "/CMakeFiles");
586
587
  // Setup the default include file regular expression (match everything).
588
5.92k
  this->Position->BuildSystemDirectory->Properties.SetProperty(
589
5.92k
    "INCLUDE_REGULAR_EXPRESSION", "^.*$");
590
5.92k
}
591
592
void cmStateSnapshot::SetDirectoryDefinitions()
593
0
{
594
0
  this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory());
595
0
  this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR",
596
0
                      this->State->GetSourceDirectory());
597
0
  this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory());
598
0
  this->SetDefinition("CMAKE_CURRENT_BINARY_DIR",
599
0
                      this->State->GetBinaryDirectory());
600
0
}
601
602
void cmStateSnapshot::InitializeFromParent()
603
0
{
604
0
  cmStateDetail::PositionType parent = this->Position->DirectoryParent;
605
0
  assert(this->Position->Vars.IsValid());
606
0
  assert(parent->Vars.IsValid());
607
608
0
  *this->Position->Vars =
609
0
    cmDefinitions::MakeClosure(parent->Vars, parent->Root);
610
611
0
  InitializeContentFromParent(
612
0
    parent->BuildSystemDirectory->IncludeDirectories,
613
0
    this->Position->BuildSystemDirectory->IncludeDirectories,
614
0
    this->Position->IncludeDirectoryPosition);
615
616
0
  InitializeContentFromParent(
617
0
    parent->BuildSystemDirectory->CompileDefinitions,
618
0
    this->Position->BuildSystemDirectory->CompileDefinitions,
619
0
    this->Position->CompileDefinitionsPosition);
620
621
0
  InitializeContentFromParent(
622
0
    parent->BuildSystemDirectory->CompileOptions,
623
0
    this->Position->BuildSystemDirectory->CompileOptions,
624
0
    this->Position->CompileOptionsPosition);
625
626
0
  InitializeContentFromParent(
627
0
    parent->BuildSystemDirectory->LinkOptions,
628
0
    this->Position->BuildSystemDirectory->LinkOptions,
629
0
    this->Position->LinkOptionsPosition);
630
631
0
  InitializeContentFromParent(
632
0
    parent->BuildSystemDirectory->LinkDirectories,
633
0
    this->Position->BuildSystemDirectory->LinkDirectories,
634
0
    this->Position->LinkDirectoriesPosition);
635
636
0
  cmValue include_regex =
637
0
    parent->BuildSystemDirectory->Properties.GetPropertyValue(
638
0
      "INCLUDE_REGULAR_EXPRESSION");
639
0
  this->Position->BuildSystemDirectory->Properties.SetProperty(
640
0
    "INCLUDE_REGULAR_EXPRESSION", include_regex);
641
0
}
642
643
cmState* cmStateSnapshot::GetState() const
644
20.3k
{
645
20.3k
  return this->State;
646
20.3k
}
647
648
cmStateDirectory cmStateSnapshot::GetDirectory() const
649
392k
{
650
392k
  return { this->Position->BuildSystemDirectory, *this };
651
392k
}
652
653
void cmStateSnapshot::SetProjectName(std::string const& name)
654
0
{
655
0
  this->Position->BuildSystemDirectory->ProjectName = name;
656
0
  this->Position->BuildSystemDirectory->Projects.insert(name);
657
0
}
658
659
std::string cmStateSnapshot::GetProjectName() const
660
0
{
661
0
  return this->Position->BuildSystemDirectory->ProjectName;
662
0
}
663
664
bool cmStateSnapshot::CheckProjectName(std::string const& name) const
665
0
{
666
0
  return cm::contains(this->Position->BuildSystemDirectory->Projects, name);
667
0
}
668
669
cmPackageState& cmStateSnapshot::GetPackageState(
670
  std::string const& packagePath)
671
0
{
672
0
  return this->Position->BuildSystemDirectory->Packages[packagePath];
673
0
}
674
675
void cmStateSnapshot::InitializeFromParent_ForSubdirsCommand()
676
0
{
677
0
  std::string currentSrcDir = *this->GetDefinition("CMAKE_CURRENT_SOURCE_DIR");
678
0
  std::string currentBinDir = *this->GetDefinition("CMAKE_CURRENT_BINARY_DIR");
679
0
  this->InitializeFromParent();
680
0
  this->SetDefinition("CMAKE_SOURCE_DIR", this->State->GetSourceDirectory());
681
0
  this->SetDefinition("CMAKE_BINARY_DIR", this->State->GetBinaryDirectory());
682
683
0
  this->SetDefinition("CMAKE_CURRENT_SOURCE_DIR", currentSrcDir);
684
0
  this->SetDefinition("CMAKE_CURRENT_BINARY_DIR", currentBinDir);
685
0
}
686
687
bool cmStateSnapshot::StrictWeakOrder::operator()(
688
  cmStateSnapshot const& lhs, cmStateSnapshot const& rhs) const
689
0
{
690
0
  return lhs.Position.StrictWeakOrdered(rhs.Position);
691
0
}
692
693
bool operator==(cmStateSnapshot const& lhs, cmStateSnapshot const& rhs)
694
0
{
695
0
  return lhs.Position == rhs.Position;
696
0
}
697
698
bool operator!=(cmStateSnapshot const& lhs, cmStateSnapshot const& rhs)
699
0
{
700
0
  return lhs.Position != rhs.Position;
701
0
}