Coverage Report

Created: 2026-06-15 07:03

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