Coverage Report

Created: 2026-09-14 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmState.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
#include "cmState.h"
4
5
#include <algorithm>
6
#include <array>
7
#include <cassert>
8
#include <cstdlib>
9
#include <utility>
10
11
#include <cm/memory>
12
13
#include "cmsys/RegularExpression.hxx"
14
15
#include "cmCacheManager.h"
16
#include "cmDefinitions.h"
17
#include "cmDiagnostics.h"
18
#include "cmExecutionStatus.h"
19
#include "cmGlobCacheEntry.h" // IWYU pragma: keep
20
#include "cmGlobVerificationManager.h"
21
#include "cmList.h"
22
#include "cmListFileCache.h"
23
#include "cmMakefile.h"
24
#include "cmMessageType.h"
25
#include "cmStatePrivate.h"
26
#include "cmStateSnapshot.h"
27
#include "cmStringAlgorithms.h"
28
#include "cmSystemTools.h"
29
#include "cmTargetTypes.h"
30
#include "cmUnreachable.h"
31
#include "cmake.h"
32
33
namespace cmStateDetail {
34
std::string const PropertySentinel = std::string{};
35
} // namespace cmStateDetail
36
37
cmState::cmState(Role role, TryCompile isTryCompile)
38
35
  : StateRole(role)
39
35
  , IsTryCompile(isTryCompile)
40
35
{
41
35
  this->CacheManager = cm::make_unique<cmCacheManager>();
42
35
  this->GlobVerificationManager = cm::make_unique<cmGlobVerificationManager>();
43
35
}
44
45
35
cmState::~cmState() = default;
46
47
std::string const& cmState::GetTargetTypeName(cm::TargetType targetType)
48
0
{
49
0
#define MAKE_STATIC_PROP(PROP) static const std::string prop##PROP = #PROP
50
0
  MAKE_STATIC_PROP(STATIC_LIBRARY);
51
0
  MAKE_STATIC_PROP(MODULE_LIBRARY);
52
0
  MAKE_STATIC_PROP(SHARED_LIBRARY);
53
0
  MAKE_STATIC_PROP(OBJECT_LIBRARY);
54
0
  MAKE_STATIC_PROP(EXECUTABLE);
55
0
  MAKE_STATIC_PROP(UTILITY);
56
0
  MAKE_STATIC_PROP(GLOBAL_TARGET);
57
0
  MAKE_STATIC_PROP(INTERFACE_LIBRARY);
58
0
  MAKE_STATIC_PROP(UNKNOWN_LIBRARY);
59
0
  static std::string const propEmpty;
60
0
#undef MAKE_STATIC_PROP
61
62
0
  switch (targetType) {
63
0
    case cm::TargetType::STATIC_LIBRARY:
64
0
      return propSTATIC_LIBRARY;
65
0
    case cm::TargetType::MODULE_LIBRARY:
66
0
      return propMODULE_LIBRARY;
67
0
    case cm::TargetType::SHARED_LIBRARY:
68
0
      return propSHARED_LIBRARY;
69
0
    case cm::TargetType::OBJECT_LIBRARY:
70
0
      return propOBJECT_LIBRARY;
71
0
    case cm::TargetType::EXECUTABLE:
72
0
      return propEXECUTABLE;
73
0
    case cm::TargetType::UTILITY:
74
0
      return propUTILITY;
75
0
    case cm::TargetType::GLOBAL_TARGET:
76
0
      return propGLOBAL_TARGET;
77
0
    case cm::TargetType::INTERFACE_LIBRARY:
78
0
      return propINTERFACE_LIBRARY;
79
0
    case cm::TargetType::UNKNOWN_LIBRARY:
80
0
      return propUNKNOWN_LIBRARY;
81
0
  }
82
0
  CM_UNREACHABLE;
83
0
  return propEmpty;
84
0
}
85
86
static std::array<std::string, 7> const cmCacheEntryTypes = {
87
  { "BOOL", "PATH", "FILEPATH", "STRING", "INTERNAL", "STATIC",
88
    "UNINITIALIZED" }
89
};
90
91
std::string const& cmState::CacheEntryTypeToString(
92
  cmStateEnums::CacheEntryType type)
93
0
{
94
0
  if (type < cmStateEnums::BOOL || type > cmStateEnums::UNINITIALIZED) {
95
0
    type = cmStateEnums::UNINITIALIZED;
96
0
  }
97
0
  return cmCacheEntryTypes[type];
98
0
}
99
100
cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(
101
  std::string const& s)
102
0
{
103
0
  cmStateEnums::CacheEntryType type = cmStateEnums::STRING;
104
0
  StringToCacheEntryType(s, type);
105
0
  return type;
106
0
}
107
108
bool cmState::StringToCacheEntryType(std::string const& s,
109
                                     cmStateEnums::CacheEntryType& type)
110
0
{
111
  // NOLINTNEXTLINE(readability-qualified-auto)
112
0
  auto const entry =
113
0
    std::find(cmCacheEntryTypes.begin(), cmCacheEntryTypes.end(), s);
114
0
  if (entry != cmCacheEntryTypes.end()) {
115
0
    type = static_cast<cmStateEnums::CacheEntryType>(
116
0
      entry - cmCacheEntryTypes.begin());
117
0
    return true;
118
0
  }
119
0
  return false;
120
0
}
121
122
bool cmState::IsCacheEntryType(std::string const& key)
123
0
{
124
0
  return std::any_of(
125
0
    cmCacheEntryTypes.begin(), cmCacheEntryTypes.end(),
126
0
    [&key](std::string const& i) -> bool { return key == i; });
127
0
}
128
129
bool cmState::LoadCache(std::string const& path, bool internal,
130
                        std::set<std::string>& excludes,
131
                        std::set<std::string>& includes)
132
0
{
133
0
  return this->CacheManager->LoadCache(path, internal, excludes, includes);
134
0
}
135
136
bool cmState::SaveCache(std::string const& path, cmMessenger* messenger)
137
0
{
138
0
  return this->CacheManager->SaveCache(path, messenger);
139
0
}
140
141
bool cmState::DeleteCache(std::string const& path)
142
0
{
143
0
  return this->CacheManager->DeleteCache(path);
144
0
}
145
146
bool cmState::IsCacheLoaded() const
147
0
{
148
0
  return this->CacheManager->IsCacheLoaded();
149
0
}
150
151
std::vector<std::string> cmState::GetCacheEntryKeys() const
152
0
{
153
0
  return this->CacheManager->GetCacheEntryKeys();
154
0
}
155
156
cmValue cmState::GetCacheEntryValue(std::string const& key) const
157
0
{
158
0
  return this->CacheManager->GetCacheEntryValue(key);
159
0
}
160
161
std::string cmState::GetSafeCacheEntryValue(std::string const& key) const
162
0
{
163
0
  if (cmValue val = this->GetCacheEntryValue(key)) {
164
0
    return *val;
165
0
  }
166
0
  return std::string();
167
0
}
168
169
cmValue cmState::GetInitializedCacheValue(std::string const& key) const
170
3
{
171
3
  return this->CacheManager->GetInitializedCacheValue(key);
172
3
}
173
174
cmStateEnums::CacheEntryType cmState::GetCacheEntryType(
175
  std::string const& key) const
176
0
{
177
0
  return this->CacheManager->GetCacheEntryType(key);
178
0
}
179
180
void cmState::SetCacheEntryValue(std::string const& key,
181
                                 std::string const& value)
182
0
{
183
0
  this->CacheManager->SetCacheEntryValue(key, value);
184
0
}
185
186
void cmState::SetCacheEntryProperty(std::string const& key,
187
                                    std::string const& propertyName,
188
                                    std::string const& value)
189
0
{
190
0
  this->CacheManager->SetCacheEntryProperty(key, propertyName, value);
191
0
}
192
193
void cmState::SetCacheEntryBoolProperty(std::string const& key,
194
                                        std::string const& propertyName,
195
                                        bool value)
196
0
{
197
0
  this->CacheManager->SetCacheEntryBoolProperty(key, propertyName, value);
198
0
}
199
200
std::vector<std::string> cmState::GetCacheEntryPropertyList(
201
  std::string const& key)
202
0
{
203
0
  return this->CacheManager->GetCacheEntryPropertyList(key);
204
0
}
205
206
cmValue cmState::GetCacheEntryProperty(std::string const& key,
207
                                       std::string const& propertyName)
208
0
{
209
0
  return this->CacheManager->GetCacheEntryProperty(key, propertyName);
210
0
}
211
212
bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,
213
                                          std::string const& propertyName)
214
0
{
215
0
  return this->CacheManager->GetCacheEntryPropertyAsBool(key, propertyName);
216
0
}
217
218
void cmState::AddCacheEntry(std::string const& key, cmValue value,
219
                            std::string const& helpString,
220
                            cmStateEnums::CacheEntryType type)
221
3
{
222
3
  this->CacheManager->AddCacheEntry(key, value, helpString, type);
223
3
}
224
225
bool cmState::DoWriteGlobVerifyTarget() const
226
0
{
227
0
  return this->GlobVerificationManager->DoWriteVerifyTarget();
228
0
}
229
230
std::string const& cmState::GetGlobVerifyScript() const
231
0
{
232
0
  return this->GlobVerificationManager->GetVerifyScript();
233
0
}
234
235
std::string const& cmState::GetGlobVerifyStamp() const
236
0
{
237
0
  return this->GlobVerificationManager->GetVerifyStamp();
238
0
}
239
240
bool cmState::SaveVerificationScript(std::string const& path,
241
                                     cmMessenger* messenger)
242
0
{
243
0
  return this->GlobVerificationManager->SaveVerificationScript(path,
244
0
                                                               messenger);
245
0
}
246
247
void cmState::AddGlobCacheEntry(cmGlobCacheEntry const& entry,
248
                                std::string const& variable,
249
                                cmListFileBacktrace const& backtrace,
250
                                cmMessenger* messenger)
251
0
{
252
0
  this->GlobVerificationManager->AddCacheEntry(entry, variable, backtrace,
253
0
                                               messenger);
254
0
}
255
256
std::vector<cmGlobCacheEntry> cmState::GetGlobCacheEntries() const
257
0
{
258
0
  return this->GlobVerificationManager->GetCacheEntries();
259
0
}
260
261
void cmState::RemoveCacheEntry(std::string const& key)
262
0
{
263
0
  this->CacheManager->RemoveCacheEntry(key);
264
0
}
265
266
void cmState::AppendCacheEntryProperty(std::string const& key,
267
                                       std::string const& property,
268
                                       std::string const& value, bool asString)
269
0
{
270
0
  this->CacheManager->AppendCacheEntryProperty(key, property, value, asString);
271
0
}
272
273
void cmState::RemoveCacheEntryProperty(std::string const& key,
274
                                       std::string const& propertyName)
275
0
{
276
0
  this->CacheManager->RemoveCacheEntryProperty(key, propertyName);
277
0
}
278
279
cmStateSnapshot cmState::Reset(cmStateSnapshot const& diagnosticState)
280
1
{
281
1
  assert(diagnosticState.CanPopDiagnosticScope());
282
1
  cmDiagnostics::DiagnosticMap diagnostics =
283
1
    *diagnosticState.Position->Diagnostics;
284
285
1
  this->GlobalProperties.Clear();
286
1
  this->PropertyDefinitions = {};
287
1
  this->GlobVerificationManager->Reset();
288
289
1
  cmStateDetail::PositionType pos = this->SnapshotData.Truncate();
290
1
  this->ExecutionListFiles.Truncate();
291
292
1
  {
293
1
    cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator it =
294
1
      this->BuildsystemDirectory.Truncate();
295
296
1
    cmStateDetail::BuildsystemDirectoryStateType newState;
297
1
    newState.Location = std::move(it->Location);
298
1
    newState.OutputLocation = std::move(it->OutputLocation);
299
1
    newState.CurrentScope = pos;
300
1
    *it = std::move(newState);
301
1
  }
302
303
1
  this->PolicyStack.Clear();
304
1
  pos->Policies = this->PolicyStack.Root();
305
1
  pos->PolicyRoot = this->PolicyStack.Root();
306
1
  pos->PolicyScope = this->PolicyStack.Root();
307
1
  assert(pos->Policies.IsValid());
308
1
  assert(pos->PolicyRoot.IsValid());
309
310
1
  this->DiagnosticStack.Clear();
311
1
  pos->Diagnostics = this->DiagnosticStack.Push(this->DiagnosticStack.Root(),
312
1
                                                { diagnostics, false });
313
1
  pos->DiagnosticRoot = this->DiagnosticStack.Root();
314
1
  pos->DiagnosticScope = this->DiagnosticStack.Root();
315
1
  assert(pos->Diagnostics.IsValid());
316
1
  assert(pos->DiagnosticRoot.IsValid());
317
1
  assert(pos->Diagnostics != pos->DiagnosticRoot);
318
319
1
  {
320
1
    std::string srcDir =
321
1
      *cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
322
1
    std::string binDir =
323
1
      *cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
324
1
    this->VarTree.Clear();
325
1
    pos->Vars = this->VarTree.Push(this->VarTree.Root());
326
1
    pos->Parent = this->VarTree.Root();
327
1
    pos->Root = this->VarTree.Root();
328
329
1
    pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir);
330
1
    pos->Vars->Set("CMAKE_BINARY_DIR", binDir);
331
1
  }
332
333
1
  this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, "", "",
334
1
                       true);
335
1
  this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::DIRECTORY, "", "",
336
1
                       true);
337
1
  this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::DIRECTORY, "", "",
338
1
                       true);
339
340
1
  this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::TARGET, "", "",
341
1
                       true);
342
1
  this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::TARGET, "", "", true);
343
1
  this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::TARGET, "", "", true);
344
345
1
  return { this, pos };
346
1
}
347
348
void cmState::DefineProperty(std::string const& name,
349
                             cmProperty::ScopeType scope,
350
                             std::string const& ShortDescription,
351
                             std::string const& FullDescription, bool chained,
352
                             std::string const& initializeFromVariable)
353
6
{
354
6
  this->PropertyDefinitions.DefineProperty(name, scope, ShortDescription,
355
6
                                           FullDescription, chained,
356
6
                                           initializeFromVariable);
357
6
}
358
359
cmPropertyDefinition const* cmState::GetPropertyDefinition(
360
  std::string const& name, cmProperty::ScopeType scope) const
361
0
{
362
0
  return this->PropertyDefinitions.GetPropertyDefinition(name, scope);
363
0
}
364
365
bool cmState::IsPropertyChained(std::string const& name,
366
                                cmProperty::ScopeType scope) const
367
0
{
368
0
  if (auto const* def = this->GetPropertyDefinition(name, scope)) {
369
0
    return def->IsChained();
370
0
  }
371
0
  return false;
372
0
}
373
374
void cmState::SetLanguageEnabled(std::string const& l)
375
0
{
376
0
  auto it = std::lower_bound(this->EnabledLanguages.begin(),
377
0
                             this->EnabledLanguages.end(), l);
378
0
  if (it == this->EnabledLanguages.end() || *it != l) {
379
0
    this->EnabledLanguages.insert(it, l);
380
0
  }
381
0
}
382
383
bool cmState::GetLanguageEnabled(std::string const& l) const
384
0
{
385
0
  return std::binary_search(this->EnabledLanguages.begin(),
386
0
                            this->EnabledLanguages.end(), l);
387
0
}
388
389
std::vector<std::string> cmState::GetEnabledLanguages() const
390
0
{
391
0
  return this->EnabledLanguages;
392
0
}
393
394
void cmState::ClearEnabledLanguages()
395
0
{
396
0
  this->EnabledLanguages.clear();
397
0
}
398
399
bool cmState::GetIsGeneratorMultiConfig() const
400
0
{
401
0
  return this->IsGeneratorMultiConfig;
402
0
}
403
404
void cmState::SetIsGeneratorMultiConfig(bool b)
405
1
{
406
1
  this->IsGeneratorMultiConfig = b;
407
1
}
408
409
void cmState::AddBuiltinCommand(std::string const& name, Command command)
410
2.11k
{
411
2.11k
  assert(name == cmSystemTools::LowerCase(name));
412
2.11k
  assert(this->BuiltinCommands.find(name) == this->BuiltinCommands.end());
413
2.11k
  this->BuiltinCommands.emplace(
414
2.11k
    name,
415
2.11k
    CommandDescriptor{ cmStateEnums::CommandType::Function,
416
2.11k
                       std::move(command) });
417
2.11k
}
418
419
static bool InvokeBuiltinCommand(cmState::BuiltinCommand command,
420
                                 std::vector<cmListFileArgument> const& args,
421
                                 cmExecutionStatus& status)
422
0
{
423
0
  cmMakefile& mf = status.GetMakefile();
424
0
  std::vector<std::string> expandedArguments;
425
0
  if (!mf.ExpandArguments(args, expandedArguments)) {
426
    // There was an error expanding arguments.  It was already
427
    // reported, so we can skip this command without error.
428
0
    return true;
429
0
  }
430
0
  return command(expandedArguments, status);
431
0
}
432
433
void cmState::AddBuiltinCommand(std::string const& name,
434
                                BuiltinCommand command)
435
1.57k
{
436
1.57k
  this->AddBuiltinCommand(
437
1.57k
    name,
438
1.57k
    [command](std::vector<cmListFileArgument> const& args,
439
1.57k
              cmExecutionStatus& status) -> bool {
440
0
      return InvokeBuiltinCommand(command, args, status);
441
0
    });
442
1.57k
}
443
444
void cmState::AddFlowControlCommand(std::string const& name, Command command)
445
70
{
446
70
  this->FlowControlCommands.insert(name);
447
70
  this->AddBuiltinCommand(name, std::move(command));
448
70
}
449
450
void cmState::AddFlowControlCommand(std::string const& name,
451
                                    BuiltinCommand command)
452
245
{
453
245
  this->FlowControlCommands.insert(name);
454
245
  this->AddBuiltinCommand(name, command);
455
245
}
456
457
void cmState::AddDisallowedCommand(std::string const& name,
458
                                   BuiltinCommand command,
459
                                   cmPolicies::PolicyID policy,
460
                                   char const* message,
461
                                   char const* additionalWarning)
462
35
{
463
35
  this->AddBuiltinCommand(
464
35
    name,
465
35
    [command, policy, message,
466
35
     additionalWarning](std::vector<cmListFileArgument> const& args,
467
35
                        cmExecutionStatus& status) -> bool {
468
0
      cmMakefile& mf = status.GetMakefile();
469
0
      switch (mf.GetPolicyStatus(policy)) {
470
0
        case cmPolicies::WARN:
471
0
          mf.IssuePolicyWarning(policy, {}, additionalWarning);
472
0
          CM_FALLTHROUGH;
473
0
        case cmPolicies::OLD:
474
0
          break;
475
0
        case cmPolicies::NEW:
476
0
          mf.IssueMessage(MessageType::FATAL_ERROR, message);
477
0
          return true;
478
0
      }
479
0
      return InvokeBuiltinCommand(command, args, status);
480
0
    });
481
35
}
482
483
void cmState::AddRemovedCommand(std::string const& name,
484
                                std::string const& message)
485
70
{
486
70
  this->AddBuiltinCommand(name,
487
70
                          [message](std::vector<cmListFileArgument> const&,
488
70
                                    cmExecutionStatus& status) -> bool {
489
0
                            status.GetMakefile().IssueMessage(
490
0
                              MessageType::FATAL_ERROR, message);
491
0
                            return true;
492
0
                          });
493
70
}
494
495
void cmState::AddUnexpectedCommand(std::string const& name, char const* error)
496
329
{
497
329
  this->AddBuiltinCommand(
498
329
    name,
499
329
    [name, error](std::vector<cmListFileArgument> const&,
500
329
                  cmExecutionStatus& status) -> bool {
501
0
      cmValue versionValue =
502
0
        status.GetMakefile().GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
503
0
      if (name == "endif" &&
504
0
          (!versionValue || atof(versionValue->c_str()) <= 1.4)) {
505
0
        return true;
506
0
      }
507
0
      status.SetError(error);
508
0
      return false;
509
0
    });
510
329
}
511
512
void cmState::AddUnexpectedFlowControlCommand(std::string const& name,
513
                                              char const* error)
514
280
{
515
280
  this->FlowControlCommands.insert(name);
516
280
  this->AddUnexpectedCommand(name, error);
517
280
}
518
519
cmState::CommandDescriptor::CommandDescriptor(CommandType type,
520
                                              Command command)
521
2.11k
  : Type(type)
522
2.11k
  , Script(std::move(command))
523
2.11k
{
524
2.11k
}
525
cmState::CommandDescriptor::CommandDescriptor(
526
  CommandDescriptor&& descriptor) noexcept
527
2.11k
  : Type(descriptor.Type)
528
2.11k
  , Script(std::move(descriptor.Script))
529
2.11k
{
530
2.11k
}
531
532
cmState::CommandDescriptor& cmState::CommandDescriptor::operator=(
533
  CommandDescriptor&& descriptor) noexcept
534
0
{
535
0
  this->Type = descriptor.Type;
536
0
  this->Script = std::move(descriptor.Script);
537
538
0
  return *this;
539
0
}
540
541
bool cmState::AddScriptedCommand(std::string const& name,
542
                                 cmStateEnums::CommandType type,
543
                                 BT<Command> command, cmMakefile& mf)
544
0
{
545
0
  std::string sName = cmSystemTools::LowerCase(name);
546
547
0
  if (this->FlowControlCommands.count(sName)) {
548
0
    mf.GetCMakeInstance()->IssueMessage(
549
0
      MessageType::FATAL_ERROR,
550
0
      cmStrCat("Built-in flow control command \"", sName,
551
0
               "\" cannot be overridden."),
552
0
      command.Backtrace);
553
0
    cmSystemTools::SetFatalErrorOccurred();
554
0
    return false;
555
0
  }
556
557
  // if the command already exists, give a new name to the old command.
558
0
  if (CommandDescriptor const* oldCmd =
559
0
        this->GetCommandDescriptorByExactName(sName)) {
560
0
    this->ScriptedCommands["_" + sName] = *oldCmd;
561
0
  }
562
563
0
  this->ScriptedCommands[sName] =
564
0
    CommandDescriptor{ type, std::move(command.Value) };
565
0
  return true;
566
0
}
567
568
cmState::CommandDescriptor const* cmState::GetCommandDescriptorByExactName(
569
  std::string const& name) const
570
0
{
571
0
  auto pos = this->ScriptedCommands.find(name);
572
0
  if (pos != this->ScriptedCommands.end()) {
573
0
    return &pos->second;
574
0
  }
575
0
  pos = this->BuiltinCommands.find(name);
576
0
  if (pos != this->BuiltinCommands.end()) {
577
0
    return &pos->second;
578
0
  }
579
0
  return nullptr;
580
0
}
581
582
cmState::Command cmState::GetCommand(std::string const& name) const
583
0
{
584
0
  return this->GetCommandByExactName(cmSystemTools::LowerCase(name));
585
0
}
586
cm::optional<cmStateEnums::CommandType> cmState::GetCommandType(
587
  std::string const& name) const
588
0
{
589
0
  return this->GetCommandTypeByExactName(cmSystemTools::LowerCase(name));
590
0
}
591
592
cmState::Command cmState::GetCommandByExactName(std::string const& name) const
593
0
{
594
0
  CommandDescriptor const* descriptor =
595
0
    this->GetCommandDescriptorByExactName(name);
596
0
  if (!descriptor) {
597
0
    return nullptr;
598
0
  }
599
600
0
  return descriptor->Script;
601
0
}
602
cm::optional<cmStateEnums::CommandType> cmState::GetCommandTypeByExactName(
603
  std::string const& name) const
604
0
{
605
0
  CommandDescriptor const* descriptor =
606
0
    this->GetCommandDescriptorByExactName(name);
607
0
  if (!descriptor) {
608
0
    return cm::nullopt;
609
0
  }
610
611
0
  return descriptor->Type;
612
0
}
613
614
std::vector<std::string> cmState::GetCommandNames() const
615
0
{
616
0
  std::vector<std::string> commandNames;
617
0
  commandNames.reserve(this->BuiltinCommands.size() +
618
0
                       this->ScriptedCommands.size());
619
0
  for (auto const& bc : this->BuiltinCommands) {
620
0
    commandNames.push_back(bc.first);
621
0
  }
622
0
  for (auto const& sc : this->ScriptedCommands) {
623
0
    commandNames.push_back(sc.first);
624
0
  }
625
0
  std::sort(commandNames.begin(), commandNames.end());
626
0
  commandNames.erase(std::unique(commandNames.begin(), commandNames.end()),
627
0
                     commandNames.end());
628
0
  return commandNames;
629
0
}
630
631
void cmState::RemoveBuiltinCommand(std::string const& name)
632
0
{
633
0
  assert(name == cmSystemTools::LowerCase(name));
634
0
  this->BuiltinCommands.erase(name);
635
0
}
636
637
void cmState::RemoveUserDefinedCommands()
638
0
{
639
0
  this->ScriptedCommands.clear();
640
0
}
641
642
void cmState::SetGlobalProperty(std::string const& prop,
643
                                std::string const& value)
644
0
{
645
0
  this->GlobalProperties.SetProperty(prop, value);
646
0
}
647
void cmState::SetGlobalProperty(std::string const& prop, cmValue value)
648
0
{
649
0
  this->GlobalProperties.SetProperty(prop, value);
650
0
}
651
652
void cmState::AppendGlobalProperty(std::string const& prop,
653
                                   std::string const& value, bool asString)
654
0
{
655
0
  this->GlobalProperties.AppendProperty(prop, value, asString);
656
0
}
657
658
cmValue cmState::GetGlobalProperty(std::string const& prop)
659
0
{
660
0
  if (prop == "CACHE_VARIABLES") {
661
0
    std::vector<std::string> cacheKeys = this->GetCacheEntryKeys();
662
0
    this->SetGlobalProperty("CACHE_VARIABLES", cmList::to_string(cacheKeys));
663
0
  } else if (prop == "COMMANDS") {
664
0
    std::vector<std::string> commands = this->GetCommandNames();
665
0
    this->SetGlobalProperty("COMMANDS", cmList::to_string(commands));
666
0
  } else if (prop == "IN_TRY_COMPILE") {
667
0
    this->SetGlobalProperty("IN_TRY_COMPILE",
668
0
                            this->IsTryCompile == TryCompile::Yes ? "1" : "0");
669
0
  } else if (prop == "GENERATOR_IS_MULTI_CONFIG") {
670
0
    this->SetGlobalProperty("GENERATOR_IS_MULTI_CONFIG",
671
0
                            this->IsGeneratorMultiConfig ? "1" : "0");
672
0
  } else if (prop == "ENABLED_LANGUAGES") {
673
0
    auto langs = cmList::to_string(this->EnabledLanguages);
674
0
    this->SetGlobalProperty("ENABLED_LANGUAGES", langs);
675
0
  } else if (prop == "CMAKE_ROLE") {
676
0
    this->SetGlobalProperty("CMAKE_ROLE", this->GetRoleString());
677
0
  } else if (prop == "_CMAKE_RUNNING_IN_BUILD_TREE") {
678
0
    this->SetGlobalProperty("_CMAKE_RUNNING_IN_BUILD_TREE",
679
0
                            cmSystemTools::GetCMakeInBuildTree() ? "1" : "0");
680
0
  }
681
0
#define STRING_LIST_ELEMENT(F) ";" #F
682
0
  if (prop == "CMAKE_C_KNOWN_FEATURES") {
683
0
    static std::string const s_out(
684
0
      &FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT)[1]);
685
0
    return cmValue(s_out);
686
0
  }
687
0
  if (prop == "CMAKE_C90_KNOWN_FEATURES") {
688
0
    static std::string const s_out(
689
0
      &FOR_EACH_C90_FEATURE(STRING_LIST_ELEMENT)[1]);
690
0
    return cmValue(s_out);
691
0
  }
692
0
  if (prop == "CMAKE_C99_KNOWN_FEATURES") {
693
0
    static std::string const s_out(
694
0
      &FOR_EACH_C99_FEATURE(STRING_LIST_ELEMENT)[1]);
695
0
    return cmValue(s_out);
696
0
  }
697
0
  if (prop == "CMAKE_C11_KNOWN_FEATURES") {
698
0
    static std::string const s_out(
699
0
      &FOR_EACH_C11_FEATURE(STRING_LIST_ELEMENT)[1]);
700
0
    return cmValue(s_out);
701
0
  }
702
0
  if (prop == "CMAKE_CXX_KNOWN_FEATURES") {
703
0
    static std::string const s_out(
704
0
      &FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT)[1]);
705
0
    return cmValue(s_out);
706
0
  }
707
0
  if (prop == "CMAKE_CXX98_KNOWN_FEATURES") {
708
0
    static std::string const s_out(
709
0
      &FOR_EACH_CXX98_FEATURE(STRING_LIST_ELEMENT)[1]);
710
0
    return cmValue(s_out);
711
0
  }
712
0
  if (prop == "CMAKE_CXX11_KNOWN_FEATURES") {
713
0
    static std::string const s_out(
714
0
      &FOR_EACH_CXX11_FEATURE(STRING_LIST_ELEMENT)[1]);
715
0
    return cmValue(s_out);
716
0
  }
717
0
  if (prop == "CMAKE_CXX14_KNOWN_FEATURES") {
718
0
    static std::string const s_out(
719
0
      &FOR_EACH_CXX14_FEATURE(STRING_LIST_ELEMENT)[1]);
720
0
    return cmValue(s_out);
721
0
  }
722
0
  if (prop == "CMAKE_CUDA_KNOWN_FEATURES") {
723
0
    static std::string const s_out(
724
0
      &FOR_EACH_CUDA_FEATURE(STRING_LIST_ELEMENT)[1]);
725
0
    return cmValue(s_out);
726
0
  }
727
0
  if (prop == "CMAKE_HIP_KNOWN_FEATURES") {
728
0
    static std::string const s_out(
729
0
      &FOR_EACH_HIP_FEATURE(STRING_LIST_ELEMENT)[1]);
730
0
    return cmValue(s_out);
731
0
  }
732
733
0
#undef STRING_LIST_ELEMENT
734
0
  return this->GlobalProperties.GetPropertyValue(prop);
735
0
}
736
737
bool cmState::GetGlobalPropertyAsBool(std::string const& prop)
738
0
{
739
0
  return this->GetGlobalProperty(prop).IsOn();
740
0
}
741
742
void cmState::SetSourceDirectory(std::string const& sourceDirectory)
743
36
{
744
36
  this->SourceDirectory = sourceDirectory;
745
36
  cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
746
36
}
747
748
std::string const& cmState::GetSourceDirectory() const
749
72
{
750
72
  return this->SourceDirectory;
751
72
}
752
753
void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
754
36
{
755
36
  this->BinaryDirectory = binaryDirectory;
756
36
  cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
757
36
}
758
759
void cmState::SetWindowsShell(bool windowsShell)
760
1
{
761
1
  this->WindowsShell = windowsShell;
762
1
}
763
764
bool cmState::UseWindowsShell() const
765
0
{
766
0
  return this->WindowsShell;
767
0
}
768
769
void cmState::SetWindowsVSIDE(bool windowsVSIDE)
770
1
{
771
1
  this->WindowsVSIDE = windowsVSIDE;
772
1
}
773
774
bool cmState::UseWindowsVSIDE() const
775
0
{
776
0
  return this->WindowsVSIDE;
777
0
}
778
779
void cmState::SetGhsMultiIDE(bool ghsMultiIDE)
780
0
{
781
0
  this->GhsMultiIDE = ghsMultiIDE;
782
0
}
783
784
bool cmState::UseGhsMultiIDE() const
785
0
{
786
0
  return this->GhsMultiIDE;
787
0
}
788
789
void cmState::SetBorlandMake(bool borlandMake)
790
0
{
791
0
  this->BorlandMake = borlandMake;
792
0
}
793
794
bool cmState::UseBorlandMake() const
795
0
{
796
0
  return this->BorlandMake;
797
0
}
798
799
void cmState::SetWatcomWMake(bool watcomWMake)
800
1
{
801
1
  this->WatcomWMake = watcomWMake;
802
1
}
803
804
bool cmState::UseWatcomWMake() const
805
0
{
806
0
  return this->WatcomWMake;
807
0
}
808
809
void cmState::SetMinGWMake(bool minGWMake)
810
1
{
811
1
  this->MinGWMake = minGWMake;
812
1
}
813
814
bool cmState::UseMinGWMake() const
815
0
{
816
0
  return this->MinGWMake;
817
0
}
818
819
void cmState::SetNMake(bool nMake)
820
1
{
821
1
  this->NMake = nMake;
822
1
}
823
824
bool cmState::UseNMake() const
825
0
{
826
0
  return this->NMake;
827
0
}
828
829
void cmState::SetMSYSShell(bool mSYSShell)
830
1
{
831
1
  this->MSYSShell = mSYSShell;
832
1
}
833
834
bool cmState::UseMSYSShell() const
835
0
{
836
0
  return this->MSYSShell;
837
0
}
838
839
void cmState::SetNinja(bool ninja)
840
0
{
841
0
  this->Ninja = ninja;
842
0
}
843
844
bool cmState::UseNinja() const
845
0
{
846
0
  return this->Ninja;
847
0
}
848
849
void cmState::SetNinjaMulti(bool ninjaMulti)
850
0
{
851
0
  this->NinjaMulti = ninjaMulti;
852
0
}
853
854
bool cmState::UseNinjaMulti() const
855
0
{
856
0
  return this->NinjaMulti;
857
0
}
858
859
void cmState::SetFastbuildMake(bool fastbuildMake)
860
1
{
861
1
  this->FastbuildMake = fastbuildMake;
862
1
}
863
864
bool cmState::UseFastbuildMake() const
865
0
{
866
0
  return this->FastbuildMake;
867
0
}
868
869
unsigned int cmState::GetCacheMajorVersion() const
870
0
{
871
0
  return this->CacheManager->GetCacheMajorVersion();
872
0
}
873
874
unsigned int cmState::GetCacheMinorVersion() const
875
0
{
876
0
  return this->CacheManager->GetCacheMinorVersion();
877
0
}
878
879
void cmState::SetRoleToProjectForCMakeBuildVsReconfigure()
880
0
{
881
0
  this->StateRole = Role::Project;
882
0
}
883
884
void cmState::SetRoleToHelpForListPresets()
885
0
{
886
0
  this->StateRole = Role::Help;
887
0
}
888
889
cmState::Role cmState::GetRole() const
890
111
{
891
111
  return this->StateRole;
892
111
}
893
894
std::string cmState::GetRoleString() const
895
0
{
896
0
  return RoleToString(this->StateRole);
897
0
}
898
899
std::string cmState::RoleToString(cmState::Role mode)
900
0
{
901
0
  switch (mode) {
902
0
    case Role::Project:
903
0
      return "PROJECT";
904
0
    case Role::Script:
905
0
      return "SCRIPT";
906
0
    case Role::FindPackage:
907
0
      return "FIND_PACKAGE";
908
0
    case Role::CTest:
909
0
      return "CTEST";
910
0
    case Role::CPack:
911
0
      return "CPACK";
912
0
    case Role::Help:
913
0
      return "HELP";
914
0
    case Role::Internal:
915
0
      return "INTERNAL";
916
0
  }
917
0
  return "UNKNOWN";
918
0
}
919
920
cmState::TryCompile cmState::GetIsTryCompile() const
921
36
{
922
36
  return this->IsTryCompile;
923
36
}
924
925
std::string const& cmState::GetBinaryDirectory() const
926
36
{
927
36
  return this->BinaryDirectory;
928
36
}
929
930
cmStateSnapshot cmState::CreateBaseSnapshot()
931
35
{
932
35
  cmStateDetail::PositionType pos =
933
35
    this->SnapshotData.Push(this->SnapshotData.Root());
934
35
  pos->DirectoryParent = this->SnapshotData.Root();
935
35
  pos->ScopeParent = this->SnapshotData.Root();
936
35
  pos->SnapshotType = cmStateEnums::BaseType;
937
35
  pos->Keep = true;
938
35
  pos->BuildSystemDirectory =
939
35
    this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root());
940
35
  pos->ExecutionListFile =
941
35
    this->ExecutionListFiles.Push(this->ExecutionListFiles.Root());
942
35
  pos->IncludeDirectoryPosition = 0;
943
35
  pos->CompileDefinitionsPosition = 0;
944
35
  pos->CompileOptionsPosition = 0;
945
35
  pos->LinkOptionsPosition = 0;
946
35
  pos->LinkDirectoriesPosition = 0;
947
35
  pos->BuildSystemDirectory->CurrentScope = pos;
948
35
  pos->Policies = this->PolicyStack.Root();
949
35
  pos->PolicyRoot = this->PolicyStack.Root();
950
35
  pos->PolicyScope = this->PolicyStack.Root();
951
35
  assert(pos->Policies.IsValid());
952
35
  assert(pos->PolicyRoot.IsValid());
953
35
  pos->Diagnostics =
954
35
    this->DiagnosticStack.Push(this->DiagnosticStack.Root(), { {}, false });
955
35
  pos->DiagnosticRoot = this->DiagnosticStack.Root();
956
35
  pos->DiagnosticScope = this->DiagnosticStack.Root();
957
35
  assert(pos->Diagnostics.IsValid());
958
35
  assert(pos->DiagnosticRoot.IsValid());
959
35
  assert(pos->Diagnostics != pos->DiagnosticRoot);
960
35
  pos->Vars = this->VarTree.Push(this->VarTree.Root());
961
35
  assert(pos->Vars.IsValid());
962
35
  pos->Parent = this->VarTree.Root();
963
35
  pos->Root = this->VarTree.Root();
964
35
  return { this, pos };
965
35
}
966
967
cmStateSnapshot cmState::CreateBuildsystemDirectorySnapshot(
968
  cmStateSnapshot const& originSnapshot)
969
0
{
970
0
  assert(originSnapshot.IsValid());
971
0
  cmStateDetail::PositionType pos =
972
0
    this->SnapshotData.Push(originSnapshot.Position);
973
0
  pos->DirectoryParent = originSnapshot.Position;
974
0
  pos->ScopeParent = originSnapshot.Position;
975
0
  pos->SnapshotType = cmStateEnums::BuildsystemDirectoryType;
976
0
  pos->Keep = true;
977
0
  pos->BuildSystemDirectory = this->BuildsystemDirectory.Push(
978
0
    originSnapshot.Position->BuildSystemDirectory);
979
0
  pos->ExecutionListFile =
980
0
    this->ExecutionListFiles.Push(originSnapshot.Position->ExecutionListFile);
981
0
  pos->BuildSystemDirectory->CurrentScope = pos;
982
0
  pos->Policies = originSnapshot.Position->Policies;
983
0
  pos->PolicyRoot = originSnapshot.Position->Policies;
984
0
  pos->PolicyScope = originSnapshot.Position->Policies;
985
0
  assert(pos->Policies.IsValid());
986
0
  assert(pos->PolicyRoot.IsValid());
987
0
  pos->Diagnostics = originSnapshot.Position->Diagnostics;
988
0
  pos->DiagnosticRoot = originSnapshot.Position->Diagnostics;
989
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
990
0
  assert(pos->Diagnostics.IsValid());
991
0
  assert(pos->DiagnosticRoot.IsValid());
992
993
0
  cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
994
0
  pos->Parent = origin;
995
0
  pos->Root = origin;
996
0
  pos->Vars = this->VarTree.Push(origin);
997
998
0
  cmStateSnapshot snapshot = cmStateSnapshot(this, pos);
999
0
  originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
1000
0
  snapshot.SetDefaultDefinitions();
1001
0
  snapshot.InitializeFromParent();
1002
0
  snapshot.SetDirectoryDefinitions();
1003
0
  return snapshot;
1004
0
}
1005
1006
cmStateSnapshot cmState::CreateDeferCallSnapshot(
1007
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
1008
0
{
1009
0
  cmStateDetail::PositionType pos =
1010
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1011
0
  pos->SnapshotType = cmStateEnums::DeferCallType;
1012
0
  pos->Keep = false;
1013
0
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1014
0
    originSnapshot.Position->ExecutionListFile, fileName);
1015
0
  assert(originSnapshot.Position->Vars.IsValid());
1016
0
  pos->BuildSystemDirectory->CurrentScope = pos;
1017
0
  pos->PolicyScope = originSnapshot.Position->Policies;
1018
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1019
0
  return { this, pos };
1020
0
}
1021
1022
cmStateSnapshot cmState::CreateFunctionCallSnapshot(
1023
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
1024
0
{
1025
0
  cmStateDetail::PositionType pos =
1026
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1027
0
  pos->ScopeParent = originSnapshot.Position;
1028
0
  pos->SnapshotType = cmStateEnums::FunctionCallType;
1029
0
  pos->Keep = false;
1030
0
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1031
0
    originSnapshot.Position->ExecutionListFile, fileName);
1032
0
  pos->BuildSystemDirectory->CurrentScope = pos;
1033
0
  pos->PolicyScope = originSnapshot.Position->Policies;
1034
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1035
0
  assert(originSnapshot.Position->Vars.IsValid());
1036
0
  cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
1037
0
  pos->Parent = origin;
1038
0
  pos->Vars = this->VarTree.Push(origin);
1039
0
  return { this, pos };
1040
0
}
1041
1042
cmStateSnapshot cmState::CreateMacroCallSnapshot(
1043
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
1044
0
{
1045
0
  cmStateDetail::PositionType pos =
1046
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1047
0
  pos->SnapshotType = cmStateEnums::MacroCallType;
1048
0
  pos->Keep = false;
1049
0
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1050
0
    originSnapshot.Position->ExecutionListFile, fileName);
1051
0
  assert(originSnapshot.Position->Vars.IsValid());
1052
0
  pos->BuildSystemDirectory->CurrentScope = pos;
1053
0
  pos->PolicyScope = originSnapshot.Position->Policies;
1054
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1055
0
  return { this, pos };
1056
0
}
1057
1058
cmStateSnapshot cmState::CreateIncludeFileSnapshot(
1059
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
1060
0
{
1061
0
  cmStateDetail::PositionType pos =
1062
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1063
0
  pos->SnapshotType = cmStateEnums::IncludeFileType;
1064
0
  pos->Keep = true;
1065
0
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1066
0
    originSnapshot.Position->ExecutionListFile, fileName);
1067
0
  assert(originSnapshot.Position->Vars.IsValid());
1068
0
  pos->BuildSystemDirectory->CurrentScope = pos;
1069
0
  pos->PolicyScope = originSnapshot.Position->Policies;
1070
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1071
0
  return { this, pos };
1072
0
}
1073
1074
cmStateSnapshot cmState::CreateVariableScopeSnapshot(
1075
  cmStateSnapshot const& originSnapshot)
1076
0
{
1077
0
  cmStateDetail::PositionType pos =
1078
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1079
0
  pos->ScopeParent = originSnapshot.Position;
1080
0
  pos->SnapshotType = cmStateEnums::VariableScopeType;
1081
0
  pos->Keep = false;
1082
0
  pos->BuildSystemDirectory->CurrentScope = pos;
1083
0
  pos->PolicyScope = originSnapshot.Position->Policies;
1084
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1085
0
  assert(originSnapshot.Position->Vars.IsValid());
1086
1087
0
  cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
1088
0
  pos->Parent = origin;
1089
0
  pos->Vars = this->VarTree.Push(origin);
1090
0
  assert(pos->Vars.IsValid());
1091
0
  return { this, pos };
1092
0
}
1093
1094
cmStateSnapshot cmState::CreateInlineListFileSnapshot(
1095
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
1096
1
{
1097
1
  cmStateDetail::PositionType pos =
1098
1
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1099
1
  pos->SnapshotType = cmStateEnums::InlineListFileType;
1100
1
  pos->Keep = true;
1101
1
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1102
1
    originSnapshot.Position->ExecutionListFile, fileName);
1103
1
  pos->BuildSystemDirectory->CurrentScope = pos;
1104
1
  pos->PolicyScope = originSnapshot.Position->Policies;
1105
1
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1106
1
  return { this, pos };
1107
1
}
1108
1109
cmStateSnapshot cmState::CreatePolicyScopeSnapshot(
1110
  cmStateSnapshot const& originSnapshot)
1111
1
{
1112
1
  cmStateDetail::PositionType pos =
1113
1
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1114
1
  pos->SnapshotType = cmStateEnums::PolicyScopeType;
1115
1
  pos->Keep = false;
1116
1
  pos->BuildSystemDirectory->CurrentScope = pos;
1117
1
  pos->PolicyScope = originSnapshot.Position->Policies;
1118
1
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1119
1
  return { this, pos };
1120
1
}
1121
1122
cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot)
1123
1
{
1124
1
  cmStateDetail::PositionType pos = originSnapshot.Position;
1125
1
  cmStateDetail::PositionType prevPos = pos;
1126
1
  ++prevPos;
1127
1
  prevPos->IncludeDirectoryPosition =
1128
1
    prevPos->BuildSystemDirectory->IncludeDirectories.size();
1129
1
  prevPos->CompileDefinitionsPosition =
1130
1
    prevPos->BuildSystemDirectory->CompileDefinitions.size();
1131
1
  prevPos->CompileOptionsPosition =
1132
1
    prevPos->BuildSystemDirectory->CompileOptions.size();
1133
1
  prevPos->LinkOptionsPosition =
1134
1
    prevPos->BuildSystemDirectory->LinkOptions.size();
1135
1
  prevPos->LinkDirectoriesPosition =
1136
1
    prevPos->BuildSystemDirectory->LinkDirectories.size();
1137
1
  prevPos->BuildSystemDirectory->CurrentScope = prevPos;
1138
1
  prevPos->UnwindState = pos->UnwindState;
1139
1140
1
  if (!pos->Keep && this->SnapshotData.IsLast(pos)) {
1141
0
    if (pos->Vars != prevPos->Vars) {
1142
0
      assert(this->VarTree.IsLast(pos->Vars));
1143
0
      this->VarTree.Pop(pos->Vars);
1144
0
    }
1145
0
    if (pos->ExecutionListFile != prevPos->ExecutionListFile) {
1146
0
      assert(this->ExecutionListFiles.IsLast(pos->ExecutionListFile));
1147
0
      this->ExecutionListFiles.Pop(pos->ExecutionListFile);
1148
0
    }
1149
0
    this->SnapshotData.Pop(pos);
1150
0
  }
1151
1152
1
  return { this, prevPos };
1153
1
}
1154
1155
static bool ParseEntryWithoutType(std::string const& entry, std::string& var,
1156
                                  std::string& value)
1157
0
{
1158
  // input line is:         key=value
1159
0
  static cmsys::RegularExpression reg(
1160
0
    "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
1161
  // input line is:         "key"=value
1162
0
  static cmsys::RegularExpression regQuoted(
1163
0
    "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
1164
0
  bool flag = false;
1165
0
  if (regQuoted.find(entry)) {
1166
0
    var = regQuoted.match(1);
1167
0
    value = regQuoted.match(2);
1168
0
    flag = true;
1169
0
  } else if (reg.find(entry)) {
1170
0
    var = reg.match(1);
1171
0
    value = reg.match(2);
1172
0
    flag = true;
1173
0
  }
1174
1175
  // if value is enclosed in single quotes ('foo') then remove them
1176
  // it is used to enclose trailing space or tab
1177
0
  if (flag && value.size() >= 2 && value.front() == '\'' &&
1178
0
      value.back() == '\'') {
1179
0
    value = value.substr(1, value.size() - 2);
1180
0
  }
1181
1182
0
  return flag;
1183
0
}
1184
1185
bool cmState::ParseCacheEntry(std::string const& entry, std::string& var,
1186
                              std::string& value,
1187
                              cmStateEnums::CacheEntryType& type)
1188
0
{
1189
  // input line is:         key:type=value
1190
0
  static cmsys::RegularExpression reg(
1191
0
    "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
1192
  // input line is:         "key":type=value
1193
0
  static cmsys::RegularExpression regQuoted(
1194
0
    "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
1195
0
  bool flag = false;
1196
0
  if (regQuoted.find(entry)) {
1197
0
    var = regQuoted.match(1);
1198
0
    type = cmState::StringToCacheEntryType(regQuoted.match(2));
1199
0
    value = regQuoted.match(3);
1200
0
    flag = true;
1201
0
  } else if (reg.find(entry)) {
1202
0
    var = reg.match(1);
1203
0
    type = cmState::StringToCacheEntryType(reg.match(2));
1204
0
    value = reg.match(3);
1205
0
    flag = true;
1206
0
  }
1207
1208
  // if value is enclosed in single quotes ('foo') then remove them
1209
  // it is used to enclose trailing space or tab
1210
0
  if (flag && value.size() >= 2 && value.front() == '\'' &&
1211
0
      value.back() == '\'') {
1212
0
    value = value.substr(1, value.size() - 2);
1213
0
  }
1214
1215
0
  if (!flag) {
1216
0
    return ParseEntryWithoutType(entry, var, value);
1217
0
  }
1218
1219
0
  return flag;
1220
0
}
1221
1222
cmState::Command cmState::GetDependencyProviderCommand(
1223
  cmDependencyProvider::Method method) const
1224
0
{
1225
0
  return (this->DependencyProvider &&
1226
0
          this->DependencyProvider->SupportsMethod(method))
1227
0
    ? this->GetCommand(this->DependencyProvider->GetCommand())
1228
0
    : Command{};
1229
0
}