Coverage Report

Created: 2026-10-28 06:38

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
19.9k
  : StateRole(role)
39
19.9k
  , IsTryCompile(isTryCompile)
40
19.9k
{
41
19.9k
  this->CacheManager = cm::make_unique<cmCacheManager>();
42
19.9k
  this->GlobVerificationManager = cm::make_unique<cmGlobVerificationManager>();
43
19.9k
}
44
45
19.9k
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
207k
{
158
207k
  return this->CacheManager->GetCacheEntryValue(key);
159
207k
}
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
5.95M
{
171
5.95M
  return this->CacheManager->GetInitializedCacheValue(key);
172
5.95M
}
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
23.7k
{
263
23.7k
  this->CacheManager->RemoveCacheEntry(key);
264
23.7k
}
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
346k
{
362
346k
  return this->PropertyDefinitions.GetPropertyDefinition(name, scope);
363
346k
}
364
365
bool cmState::IsPropertyChained(std::string const& name,
366
                                cmProperty::ScopeType scope) const
367
346k
{
368
346k
  if (auto const* def = this->GetPropertyDefinition(name, scope)) {
369
0
    return def->IsChained();
370
0
  }
371
346k
  return false;
372
346k
}
373
374
void cmState::SetLanguageEnabled(std::string const& l)
375
11.8k
{
376
11.8k
  auto it = std::lower_bound(this->EnabledLanguages.begin(),
377
11.8k
                             this->EnabledLanguages.end(), l);
378
11.8k
  if (it == this->EnabledLanguages.end() || *it != l) {
379
11.8k
    this->EnabledLanguages.insert(it, l);
380
11.8k
  }
381
11.8k
}
382
383
bool cmState::GetLanguageEnabled(std::string const& l) const
384
1
{
385
1
  return std::binary_search(this->EnabledLanguages.begin(),
386
1
                            this->EnabledLanguages.end(), l);
387
1
}
388
389
std::vector<std::string> cmState::GetEnabledLanguages() const
390
5.92k
{
391
5.92k
  return this->EnabledLanguages;
392
5.92k
}
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
19.8k
{
406
19.8k
  this->IsGeneratorMultiConfig = b;
407
19.8k
}
408
409
void cmState::AddBuiltinCommand(std::string const& name, Command command)
410
2.38M
{
411
2.38M
  assert(name == cmSystemTools::LowerCase(name));
412
2.38M
  assert(this->BuiltinCommands.find(name) == this->BuiltinCommands.end());
413
2.38M
  this->BuiltinCommands.emplace(
414
2.38M
    name,
415
2.38M
    CommandDescriptor{ cmStateEnums::CommandType::Function,
416
2.38M
                       std::move(command) });
417
2.38M
}
418
419
static bool InvokeBuiltinCommand(cmState::BuiltinCommand command,
420
                                 std::vector<cmListFileArgument> const& args,
421
                                 cmExecutionStatus& status)
422
403k
{
423
403k
  cmMakefile& mf = status.GetMakefile();
424
403k
  std::vector<std::string> expandedArguments;
425
403k
  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
403k
  return command(expandedArguments, status);
431
403k
}
432
433
void cmState::AddBuiltinCommand(std::string const& name,
434
                                BuiltinCommand command)
435
1.99M
{
436
1.99M
  this->AddBuiltinCommand(
437
1.99M
    name,
438
1.99M
    [command](std::vector<cmListFileArgument> const& args,
439
1.99M
              cmExecutionStatus& status) -> bool {
440
403k
      return InvokeBuiltinCommand(command, args, status);
441
403k
    });
442
1.99M
}
443
444
void cmState::AddFlowControlCommand(std::string const& name, Command command)
445
39.8k
{
446
39.8k
  this->FlowControlCommands.insert(name);
447
39.8k
  this->AddBuiltinCommand(name, std::move(command));
448
39.8k
}
449
450
void cmState::AddFlowControlCommand(std::string const& name,
451
                                    BuiltinCommand command)
452
139k
{
453
139k
  this->FlowControlCommands.insert(name);
454
139k
  this->AddBuiltinCommand(name, command);
455
139k
}
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
19.9k
{
463
19.9k
  this->AddBuiltinCommand(
464
19.9k
    name,
465
19.9k
    [command, policy, message,
466
19.9k
     additionalWarning](std::vector<cmListFileArgument> const& args,
467
19.9k
                        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
19.9k
}
482
483
void cmState::AddRemovedCommand(std::string const& name,
484
                                std::string const& message)
485
159k
{
486
159k
  this->AddBuiltinCommand(name,
487
159k
                          [message](std::vector<cmListFileArgument> const&,
488
159k
                                    cmExecutionStatus& status) -> bool {
489
0
                            status.GetMakefile().IssueMessage(
490
0
                              MessageType::FATAL_ERROR, message);
491
0
                            return true;
492
0
                          });
493
159k
}
494
495
void cmState::AddUnexpectedCommand(std::string const& name, char const* error)
496
159k
{
497
159k
  this->AddBuiltinCommand(
498
159k
    name,
499
159k
    [name, error](std::vector<cmListFileArgument> const&,
500
159k
                  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
159k
}
511
512
void cmState::AddUnexpectedFlowControlCommand(std::string const& name,
513
                                              char const* error)
514
159k
{
515
159k
  this->FlowControlCommands.insert(name);
516
159k
  this->AddUnexpectedCommand(name, error);
517
159k
}
518
519
cmState::CommandDescriptor::CommandDescriptor(CommandType type,
520
                                              Command command)
521
2.38M
  : Type(type)
522
2.38M
  , Script(std::move(command))
523
2.38M
{
524
2.38M
}
525
cmState::CommandDescriptor::CommandDescriptor(
526
  CommandDescriptor&& descriptor) noexcept
527
2.38M
  : Type(descriptor.Type)
528
2.38M
  , Script(std::move(descriptor.Script))
529
2.38M
{
530
2.38M
}
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
403k
{
571
403k
  auto pos = this->ScriptedCommands.find(name);
572
403k
  if (pos != this->ScriptedCommands.end()) {
573
0
    return &pos->second;
574
0
  }
575
403k
  pos = this->BuiltinCommands.find(name);
576
403k
  if (pos != this->BuiltinCommands.end()) {
577
403k
    return &pos->second;
578
403k
  }
579
0
  return nullptr;
580
403k
}
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
403k
{
594
403k
  CommandDescriptor const* descriptor =
595
403k
    this->GetCommandDescriptorByExactName(name);
596
403k
  if (!descriptor) {
597
0
    return nullptr;
598
0
  }
599
600
403k
  return descriptor->Script;
601
403k
}
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
11.8k
{
649
11.8k
  this->GlobalProperties.SetProperty(prop, value);
650
11.8k
}
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
14.6k
{
660
14.6k
  if (prop == "CACHE_VARIABLES") {
661
0
    std::vector<std::string> cacheKeys = this->GetCacheEntryKeys();
662
0
    this->SetGlobalProperty("CACHE_VARIABLES", cmList::to_string(cacheKeys));
663
14.6k
  } else if (prop == "COMMANDS") {
664
0
    std::vector<std::string> commands = this->GetCommandNames();
665
0
    this->SetGlobalProperty("COMMANDS", cmList::to_string(commands));
666
14.6k
  } else if (prop == "IN_TRY_COMPILE") {
667
0
    this->SetGlobalProperty("IN_TRY_COMPILE",
668
0
                            this->IsTryCompile == TryCompile::Yes ? "1" : "0");
669
14.6k
  } else if (prop == "GENERATOR_IS_MULTI_CONFIG") {
670
0
    this->SetGlobalProperty("GENERATOR_IS_MULTI_CONFIG",
671
0
                            this->IsGeneratorMultiConfig ? "1" : "0");
672
14.6k
  } else if (prop == "ENABLED_LANGUAGES") {
673
0
    auto langs = cmList::to_string(this->EnabledLanguages);
674
0
    this->SetGlobalProperty("ENABLED_LANGUAGES", langs);
675
14.6k
  } else if (prop == "CMAKE_ROLE") {
676
0
    this->SetGlobalProperty("CMAKE_ROLE", this->GetRoleString());
677
14.6k
  } 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
14.6k
#define STRING_LIST_ELEMENT(F) ";" #F
682
14.6k
  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
14.6k
  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
14.6k
  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
14.6k
  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
14.6k
  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
14.6k
  if (prop == "CMAKE_SYCL_KNOWN_FEATURES") {
708
0
    static std::string const s_out(
709
0
      &FOR_EACH_SYCL_FEATURE(STRING_LIST_ELEMENT)[1]);
710
0
    return cmValue(s_out);
711
0
  }
712
14.6k
  if (prop == "CMAKE_CXX98_KNOWN_FEATURES") {
713
0
    static std::string const s_out(
714
0
      &FOR_EACH_CXX98_FEATURE(STRING_LIST_ELEMENT)[1]);
715
0
    return cmValue(s_out);
716
0
  }
717
14.6k
  if (prop == "CMAKE_CXX11_KNOWN_FEATURES") {
718
0
    static std::string const s_out(
719
0
      &FOR_EACH_CXX11_FEATURE(STRING_LIST_ELEMENT)[1]);
720
0
    return cmValue(s_out);
721
0
  }
722
14.6k
  if (prop == "CMAKE_CXX14_KNOWN_FEATURES") {
723
0
    static std::string const s_out(
724
0
      &FOR_EACH_CXX14_FEATURE(STRING_LIST_ELEMENT)[1]);
725
0
    return cmValue(s_out);
726
0
  }
727
14.6k
  if (prop == "CMAKE_CUDA_KNOWN_FEATURES") {
728
0
    static std::string const s_out(
729
0
      &FOR_EACH_CUDA_FEATURE(STRING_LIST_ELEMENT)[1]);
730
0
    return cmValue(s_out);
731
0
  }
732
14.6k
  if (prop == "CMAKE_HIP_KNOWN_FEATURES") {
733
2
    static std::string const s_out(
734
4
      &FOR_EACH_HIP_FEATURE(STRING_LIST_ELEMENT)[1]);
735
2
    return cmValue(s_out);
736
2
  }
737
738
14.6k
#undef STRING_LIST_ELEMENT
739
14.6k
  return this->GlobalProperties.GetPropertyValue(prop);
740
14.6k
}
741
742
bool cmState::GetGlobalPropertyAsBool(std::string const& prop)
743
5.92k
{
744
5.92k
  return this->GetGlobalProperty(prop).IsOn();
745
5.92k
}
746
747
void cmState::SetSourceDirectory(std::string const& sourceDirectory)
748
19.9k
{
749
19.9k
  this->SourceDirectory = sourceDirectory;
750
19.9k
  cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
751
19.9k
}
752
753
std::string const& cmState::GetSourceDirectory() const
754
19.9k
{
755
19.9k
  return this->SourceDirectory;
756
19.9k
}
757
758
void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
759
19.9k
{
760
19.9k
  this->BinaryDirectory = binaryDirectory;
761
19.9k
  cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
762
19.9k
}
763
764
void cmState::SetWindowsShell(bool windowsShell)
765
19.8k
{
766
19.8k
  this->WindowsShell = windowsShell;
767
19.8k
}
768
769
bool cmState::UseWindowsShell() const
770
273
{
771
273
  return this->WindowsShell;
772
273
}
773
774
void cmState::SetWindowsVSIDE(bool windowsVSIDE)
775
19.8k
{
776
19.8k
  this->WindowsVSIDE = windowsVSIDE;
777
19.8k
}
778
779
bool cmState::UseWindowsVSIDE() const
780
0
{
781
0
  return this->WindowsVSIDE;
782
0
}
783
784
void cmState::SetGhsMultiIDE(bool ghsMultiIDE)
785
0
{
786
0
  this->GhsMultiIDE = ghsMultiIDE;
787
0
}
788
789
bool cmState::UseGhsMultiIDE() const
790
0
{
791
0
  return this->GhsMultiIDE;
792
0
}
793
794
void cmState::SetBorlandMake(bool borlandMake)
795
0
{
796
0
  this->BorlandMake = borlandMake;
797
0
}
798
799
bool cmState::UseBorlandMake() const
800
5.92k
{
801
5.92k
  return this->BorlandMake;
802
5.92k
}
803
804
void cmState::SetWatcomWMake(bool watcomWMake)
805
19.8k
{
806
19.8k
  this->WatcomWMake = watcomWMake;
807
19.8k
}
808
809
bool cmState::UseWatcomWMake() const
810
0
{
811
0
  return this->WatcomWMake;
812
0
}
813
814
void cmState::SetMinGWMake(bool minGWMake)
815
19.8k
{
816
19.8k
  this->MinGWMake = minGWMake;
817
19.8k
}
818
819
bool cmState::UseMinGWMake() const
820
0
{
821
0
  return this->MinGWMake;
822
0
}
823
824
void cmState::SetNMake(bool nMake)
825
19.8k
{
826
19.8k
  this->NMake = nMake;
827
19.8k
}
828
829
bool cmState::UseNMake() const
830
0
{
831
0
  return this->NMake;
832
0
}
833
834
void cmState::SetMSYSShell(bool mSYSShell)
835
19.8k
{
836
19.8k
  this->MSYSShell = mSYSShell;
837
19.8k
}
838
839
bool cmState::UseMSYSShell() const
840
219
{
841
219
  return this->MSYSShell;
842
219
}
843
844
void cmState::SetNinja(bool ninja)
845
0
{
846
0
  this->Ninja = ninja;
847
0
}
848
849
bool cmState::UseNinja() const
850
0
{
851
0
  return this->Ninja;
852
0
}
853
854
void cmState::SetNinjaMulti(bool ninjaMulti)
855
0
{
856
0
  this->NinjaMulti = ninjaMulti;
857
0
}
858
859
bool cmState::UseNinjaMulti() const
860
0
{
861
0
  return this->NinjaMulti;
862
0
}
863
864
void cmState::SetFastbuildMake(bool fastbuildMake)
865
19.8k
{
866
19.8k
  this->FastbuildMake = fastbuildMake;
867
19.8k
}
868
869
bool cmState::UseFastbuildMake() const
870
0
{
871
0
  return this->FastbuildMake;
872
0
}
873
874
unsigned int cmState::GetCacheMajorVersion() const
875
0
{
876
0
  return this->CacheManager->GetCacheMajorVersion();
877
0
}
878
879
unsigned int cmState::GetCacheMinorVersion() const
880
0
{
881
0
  return this->CacheManager->GetCacheMinorVersion();
882
0
}
883
884
void cmState::SetRoleToProjectForCMakeBuildVsReconfigure()
885
0
{
886
0
  this->StateRole = Role::Project;
887
0
}
888
889
void cmState::SetRoleToHelpForListPresets()
890
0
{
891
0
  this->StateRole = Role::Help;
892
0
}
893
894
cmState::Role cmState::GetRole() const
895
11.9k
{
896
11.9k
  return this->StateRole;
897
11.9k
}
898
899
std::string cmState::GetRoleString() const
900
0
{
901
0
  return RoleToString(this->StateRole);
902
0
}
903
904
std::string cmState::RoleToString(cmState::Role mode)
905
0
{
906
0
  switch (mode) {
907
0
    case Role::Project:
908
0
      return "PROJECT";
909
0
    case Role::Script:
910
0
      return "SCRIPT";
911
0
    case Role::FindPackage:
912
0
      return "FIND_PACKAGE";
913
0
    case Role::CTest:
914
0
      return "CTEST";
915
0
    case Role::CPack:
916
0
      return "CPACK";
917
0
    case Role::Help:
918
0
      return "HELP";
919
0
    case Role::Internal:
920
0
      return "INTERNAL";
921
0
  }
922
0
  return "UNKNOWN";
923
0
}
924
925
cmState::TryCompile cmState::GetIsTryCompile() const
926
19.9k
{
927
19.9k
  return this->IsTryCompile;
928
19.9k
}
929
930
std::string const& cmState::GetBinaryDirectory() const
931
36
{
932
36
  return this->BinaryDirectory;
933
36
}
934
935
cmStateSnapshot cmState::CreateBaseSnapshot()
936
19.9k
{
937
19.9k
  cmStateDetail::PositionType pos =
938
19.9k
    this->SnapshotData.Push(this->SnapshotData.Root());
939
19.9k
  pos->DirectoryParent = this->SnapshotData.Root();
940
19.9k
  pos->ScopeParent = this->SnapshotData.Root();
941
19.9k
  pos->SnapshotType = cmStateEnums::BaseType;
942
19.9k
  pos->Keep = true;
943
19.9k
  pos->BuildSystemDirectory =
944
19.9k
    this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root());
945
19.9k
  pos->ExecutionListFile =
946
19.9k
    this->ExecutionListFiles.Push(this->ExecutionListFiles.Root());
947
19.9k
  pos->IncludeDirectoryPosition = 0;
948
19.9k
  pos->CompileDefinitionsPosition = 0;
949
19.9k
  pos->CompileOptionsPosition = 0;
950
19.9k
  pos->LinkOptionsPosition = 0;
951
19.9k
  pos->LinkDirectoriesPosition = 0;
952
19.9k
  pos->BuildSystemDirectory->CurrentScope = pos;
953
19.9k
  pos->Policies = this->PolicyStack.Root();
954
19.9k
  pos->PolicyRoot = this->PolicyStack.Root();
955
19.9k
  pos->PolicyScope = this->PolicyStack.Root();
956
19.9k
  assert(pos->Policies.IsValid());
957
19.9k
  assert(pos->PolicyRoot.IsValid());
958
19.9k
  pos->Diagnostics =
959
19.9k
    this->DiagnosticStack.Push(this->DiagnosticStack.Root(), { {}, false });
960
19.9k
  pos->DiagnosticRoot = this->DiagnosticStack.Root();
961
19.9k
  pos->DiagnosticScope = this->DiagnosticStack.Root();
962
19.9k
  assert(pos->Diagnostics.IsValid());
963
19.9k
  assert(pos->DiagnosticRoot.IsValid());
964
19.9k
  assert(pos->Diagnostics != pos->DiagnosticRoot);
965
19.9k
  pos->Vars = this->VarTree.Push(this->VarTree.Root());
966
19.9k
  assert(pos->Vars.IsValid());
967
19.9k
  pos->Parent = this->VarTree.Root();
968
19.9k
  pos->Root = this->VarTree.Root();
969
19.9k
  return { this, pos };
970
19.9k
}
971
972
cmStateSnapshot cmState::CreateBuildsystemDirectorySnapshot(
973
  cmStateSnapshot const& originSnapshot)
974
0
{
975
0
  assert(originSnapshot.IsValid());
976
0
  cmStateDetail::PositionType pos =
977
0
    this->SnapshotData.Push(originSnapshot.Position);
978
0
  pos->DirectoryParent = originSnapshot.Position;
979
0
  pos->ScopeParent = originSnapshot.Position;
980
0
  pos->SnapshotType = cmStateEnums::BuildsystemDirectoryType;
981
0
  pos->Keep = true;
982
0
  pos->BuildSystemDirectory = this->BuildsystemDirectory.Push(
983
0
    originSnapshot.Position->BuildSystemDirectory);
984
0
  pos->ExecutionListFile =
985
0
    this->ExecutionListFiles.Push(originSnapshot.Position->ExecutionListFile);
986
0
  pos->BuildSystemDirectory->CurrentScope = pos;
987
0
  pos->Policies = originSnapshot.Position->Policies;
988
0
  pos->PolicyRoot = originSnapshot.Position->Policies;
989
0
  pos->PolicyScope = originSnapshot.Position->Policies;
990
0
  assert(pos->Policies.IsValid());
991
0
  assert(pos->PolicyRoot.IsValid());
992
0
  pos->Diagnostics = originSnapshot.Position->Diagnostics;
993
0
  pos->DiagnosticRoot = originSnapshot.Position->Diagnostics;
994
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
995
0
  assert(pos->Diagnostics.IsValid());
996
0
  assert(pos->DiagnosticRoot.IsValid());
997
998
0
  cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
999
0
  pos->Parent = origin;
1000
0
  pos->Root = origin;
1001
0
  pos->Vars = this->VarTree.Push(origin);
1002
1003
0
  cmStateSnapshot snapshot = cmStateSnapshot(this, pos);
1004
0
  originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
1005
0
  snapshot.SetDefaultDefinitions();
1006
0
  snapshot.InitializeFromParent();
1007
0
  snapshot.SetDirectoryDefinitions();
1008
0
  return snapshot;
1009
0
}
1010
1011
cmStateSnapshot cmState::CreateDeferCallSnapshot(
1012
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
1013
0
{
1014
0
  cmStateDetail::PositionType pos =
1015
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1016
0
  pos->SnapshotType = cmStateEnums::DeferCallType;
1017
0
  pos->Keep = false;
1018
0
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1019
0
    originSnapshot.Position->ExecutionListFile, fileName);
1020
0
  assert(originSnapshot.Position->Vars.IsValid());
1021
0
  pos->BuildSystemDirectory->CurrentScope = pos;
1022
0
  pos->PolicyScope = originSnapshot.Position->Policies;
1023
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1024
0
  return { this, pos };
1025
0
}
1026
1027
cmStateSnapshot cmState::CreateFunctionCallSnapshot(
1028
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
1029
0
{
1030
0
  cmStateDetail::PositionType pos =
1031
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1032
0
  pos->ScopeParent = originSnapshot.Position;
1033
0
  pos->SnapshotType = cmStateEnums::FunctionCallType;
1034
0
  pos->Keep = false;
1035
0
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1036
0
    originSnapshot.Position->ExecutionListFile, fileName);
1037
0
  pos->BuildSystemDirectory->CurrentScope = pos;
1038
0
  pos->PolicyScope = originSnapshot.Position->Policies;
1039
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1040
0
  assert(originSnapshot.Position->Vars.IsValid());
1041
0
  cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
1042
0
  pos->Parent = origin;
1043
0
  pos->Vars = this->VarTree.Push(origin);
1044
0
  return { this, pos };
1045
0
}
1046
1047
cmStateSnapshot cmState::CreateMacroCallSnapshot(
1048
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
1049
0
{
1050
0
  cmStateDetail::PositionType pos =
1051
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1052
0
  pos->SnapshotType = cmStateEnums::MacroCallType;
1053
0
  pos->Keep = false;
1054
0
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1055
0
    originSnapshot.Position->ExecutionListFile, fileName);
1056
0
  assert(originSnapshot.Position->Vars.IsValid());
1057
0
  pos->BuildSystemDirectory->CurrentScope = pos;
1058
0
  pos->PolicyScope = originSnapshot.Position->Policies;
1059
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1060
0
  return { this, pos };
1061
0
}
1062
1063
cmStateSnapshot cmState::CreateIncludeFileSnapshot(
1064
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
1065
0
{
1066
0
  cmStateDetail::PositionType pos =
1067
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1068
0
  pos->SnapshotType = cmStateEnums::IncludeFileType;
1069
0
  pos->Keep = true;
1070
0
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1071
0
    originSnapshot.Position->ExecutionListFile, fileName);
1072
0
  assert(originSnapshot.Position->Vars.IsValid());
1073
0
  pos->BuildSystemDirectory->CurrentScope = pos;
1074
0
  pos->PolicyScope = originSnapshot.Position->Policies;
1075
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1076
0
  return { this, pos };
1077
0
}
1078
1079
cmStateSnapshot cmState::CreateVariableScopeSnapshot(
1080
  cmStateSnapshot const& originSnapshot)
1081
0
{
1082
0
  cmStateDetail::PositionType pos =
1083
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1084
0
  pos->ScopeParent = originSnapshot.Position;
1085
0
  pos->SnapshotType = cmStateEnums::VariableScopeType;
1086
0
  pos->Keep = false;
1087
0
  pos->BuildSystemDirectory->CurrentScope = pos;
1088
0
  pos->PolicyScope = originSnapshot.Position->Policies;
1089
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1090
0
  assert(originSnapshot.Position->Vars.IsValid());
1091
1092
0
  cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
1093
0
  pos->Parent = origin;
1094
0
  pos->Vars = this->VarTree.Push(origin);
1095
0
  assert(pos->Vars.IsValid());
1096
0
  return { this, pos };
1097
0
}
1098
1099
cmStateSnapshot cmState::CreateInlineListFileSnapshot(
1100
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
1101
11.8k
{
1102
11.8k
  cmStateDetail::PositionType pos =
1103
11.8k
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1104
11.8k
  pos->SnapshotType = cmStateEnums::InlineListFileType;
1105
11.8k
  pos->Keep = true;
1106
11.8k
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1107
11.8k
    originSnapshot.Position->ExecutionListFile, fileName);
1108
11.8k
  pos->BuildSystemDirectory->CurrentScope = pos;
1109
11.8k
  pos->PolicyScope = originSnapshot.Position->Policies;
1110
11.8k
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1111
11.8k
  return { this, pos };
1112
11.8k
}
1113
1114
cmStateSnapshot cmState::CreatePolicyScopeSnapshot(
1115
  cmStateSnapshot const& originSnapshot)
1116
19.8k
{
1117
19.8k
  cmStateDetail::PositionType pos =
1118
19.8k
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1119
19.8k
  pos->SnapshotType = cmStateEnums::PolicyScopeType;
1120
19.8k
  pos->Keep = false;
1121
19.8k
  pos->BuildSystemDirectory->CurrentScope = pos;
1122
19.8k
  pos->PolicyScope = originSnapshot.Position->Policies;
1123
19.8k
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1124
19.8k
  return { this, pos };
1125
19.8k
}
1126
1127
cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot)
1128
11.8k
{
1129
11.8k
  cmStateDetail::PositionType pos = originSnapshot.Position;
1130
11.8k
  cmStateDetail::PositionType prevPos = pos;
1131
11.8k
  ++prevPos;
1132
11.8k
  prevPos->IncludeDirectoryPosition =
1133
11.8k
    prevPos->BuildSystemDirectory->IncludeDirectories.size();
1134
11.8k
  prevPos->CompileDefinitionsPosition =
1135
11.8k
    prevPos->BuildSystemDirectory->CompileDefinitions.size();
1136
11.8k
  prevPos->CompileOptionsPosition =
1137
11.8k
    prevPos->BuildSystemDirectory->CompileOptions.size();
1138
11.8k
  prevPos->LinkOptionsPosition =
1139
11.8k
    prevPos->BuildSystemDirectory->LinkOptions.size();
1140
11.8k
  prevPos->LinkDirectoriesPosition =
1141
11.8k
    prevPos->BuildSystemDirectory->LinkDirectories.size();
1142
11.8k
  prevPos->BuildSystemDirectory->CurrentScope = prevPos;
1143
11.8k
  prevPos->UnwindState = pos->UnwindState;
1144
1145
11.8k
  if (!pos->Keep && this->SnapshotData.IsLast(pos)) {
1146
0
    if (pos->Vars != prevPos->Vars) {
1147
0
      assert(this->VarTree.IsLast(pos->Vars));
1148
0
      this->VarTree.Pop(pos->Vars);
1149
0
    }
1150
0
    if (pos->ExecutionListFile != prevPos->ExecutionListFile) {
1151
0
      assert(this->ExecutionListFiles.IsLast(pos->ExecutionListFile));
1152
0
      this->ExecutionListFiles.Pop(pos->ExecutionListFile);
1153
0
    }
1154
0
    this->SnapshotData.Pop(pos);
1155
0
  }
1156
1157
11.8k
  return { this, prevPos };
1158
11.8k
}
1159
1160
static bool ParseEntryWithoutType(std::string const& entry, std::string& var,
1161
                                  std::string& value)
1162
0
{
1163
  // input line is:         key=value
1164
0
  static cmsys::RegularExpression reg(
1165
0
    "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
1166
  // input line is:         "key"=value
1167
0
  static cmsys::RegularExpression regQuoted(
1168
0
    "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
1169
0
  bool flag = false;
1170
0
  if (regQuoted.find(entry)) {
1171
0
    var = regQuoted.match(1);
1172
0
    value = regQuoted.match(2);
1173
0
    flag = true;
1174
0
  } else if (reg.find(entry)) {
1175
0
    var = reg.match(1);
1176
0
    value = reg.match(2);
1177
0
    flag = true;
1178
0
  }
1179
1180
  // if value is enclosed in single quotes ('foo') then remove them
1181
  // it is used to enclose trailing space or tab
1182
0
  if (flag && value.size() >= 2 && value.front() == '\'' &&
1183
0
      value.back() == '\'') {
1184
0
    value = value.substr(1, value.size() - 2);
1185
0
  }
1186
1187
0
  return flag;
1188
0
}
1189
1190
bool cmState::ParseCacheEntry(std::string const& entry, std::string& var,
1191
                              std::string& value,
1192
                              cmStateEnums::CacheEntryType& type)
1193
0
{
1194
  // input line is:         key:type=value
1195
0
  static cmsys::RegularExpression reg(
1196
0
    "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
1197
  // input line is:         "key":type=value
1198
0
  static cmsys::RegularExpression regQuoted(
1199
0
    "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
1200
0
  bool flag = false;
1201
0
  if (regQuoted.find(entry)) {
1202
0
    var = regQuoted.match(1);
1203
0
    type = cmState::StringToCacheEntryType(regQuoted.match(2));
1204
0
    value = regQuoted.match(3);
1205
0
    flag = true;
1206
0
  } else if (reg.find(entry)) {
1207
0
    var = reg.match(1);
1208
0
    type = cmState::StringToCacheEntryType(reg.match(2));
1209
0
    value = reg.match(3);
1210
0
    flag = true;
1211
0
  }
1212
1213
  // if value is enclosed in single quotes ('foo') then remove them
1214
  // it is used to enclose trailing space or tab
1215
0
  if (flag && value.size() >= 2 && value.front() == '\'' &&
1216
0
      value.back() == '\'') {
1217
0
    value = value.substr(1, value.size() - 2);
1218
0
  }
1219
1220
0
  if (!flag) {
1221
0
    return ParseEntryWithoutType(entry, var, value);
1222
0
  }
1223
1224
0
  return flag;
1225
0
}
1226
1227
cmState::Command cmState::GetDependencyProviderCommand(
1228
  cmDependencyProvider::Method method) const
1229
0
{
1230
0
  return (this->DependencyProvider &&
1231
0
          this->DependencyProvider->SupportsMethod(method))
1232
0
    ? this->GetCommand(this->DependencyProvider->GetCommand())
1233
0
    : Command{};
1234
0
}