Coverage Report

Created: 2026-04-29 07:01

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::SetEnabledLanguages(std::vector<std::string> const& langs)
394
0
{
395
0
  this->EnabledLanguages = langs;
396
0
}
397
398
void cmState::ClearEnabledLanguages()
399
0
{
400
0
  this->EnabledLanguages.clear();
401
0
}
402
403
bool cmState::GetIsGeneratorMultiConfig() const
404
0
{
405
0
  return this->IsGeneratorMultiConfig;
406
0
}
407
408
void cmState::SetIsGeneratorMultiConfig(bool b)
409
1
{
410
1
  this->IsGeneratorMultiConfig = b;
411
1
}
412
413
void cmState::AddBuiltinCommand(std::string const& name, Command command)
414
2.11k
{
415
2.11k
  assert(name == cmSystemTools::LowerCase(name));
416
2.11k
  assert(this->BuiltinCommands.find(name) == this->BuiltinCommands.end());
417
2.11k
  this->BuiltinCommands.emplace(name, std::move(command));
418
2.11k
}
419
420
static bool InvokeBuiltinCommand(cmState::BuiltinCommand command,
421
                                 std::vector<cmListFileArgument> const& args,
422
                                 cmExecutionStatus& status)
423
0
{
424
0
  cmMakefile& mf = status.GetMakefile();
425
0
  std::vector<std::string> expandedArguments;
426
0
  if (!mf.ExpandArguments(args, expandedArguments)) {
427
    // There was an error expanding arguments.  It was already
428
    // reported, so we can skip this command without error.
429
0
    return true;
430
0
  }
431
0
  return command(expandedArguments, status);
432
0
}
433
434
void cmState::AddBuiltinCommand(std::string const& name,
435
                                BuiltinCommand command)
436
1.57k
{
437
1.57k
  this->AddBuiltinCommand(
438
1.57k
    name,
439
1.57k
    [command](std::vector<cmListFileArgument> const& args,
440
1.57k
              cmExecutionStatus& status) -> bool {
441
0
      return InvokeBuiltinCommand(command, args, status);
442
0
    });
443
1.57k
}
444
445
void cmState::AddFlowControlCommand(std::string const& name, Command command)
446
70
{
447
70
  this->FlowControlCommands.insert(name);
448
70
  this->AddBuiltinCommand(name, std::move(command));
449
70
}
450
451
void cmState::AddFlowControlCommand(std::string const& name,
452
                                    BuiltinCommand command)
453
245
{
454
245
  this->FlowControlCommands.insert(name);
455
245
  this->AddBuiltinCommand(name, command);
456
245
}
457
458
void cmState::AddDisallowedCommand(std::string const& name,
459
                                   BuiltinCommand command,
460
                                   cmPolicies::PolicyID policy,
461
                                   char const* message,
462
                                   char const* additionalWarning)
463
35
{
464
35
  this->AddBuiltinCommand(
465
35
    name,
466
35
    [command, policy, message,
467
35
     additionalWarning](std::vector<cmListFileArgument> const& args,
468
35
                        cmExecutionStatus& status) -> bool {
469
0
      cmMakefile& mf = status.GetMakefile();
470
0
      switch (mf.GetPolicyStatus(policy)) {
471
0
        case cmPolicies::WARN: {
472
0
          std::string warning = cmPolicies::GetPolicyWarning(policy);
473
0
          if (additionalWarning) {
474
0
            warning = cmStrCat(warning, '\n', additionalWarning);
475
0
          }
476
0
          mf.IssueDiagnostic(cmDiagnostics::CMD_AUTHOR, warning);
477
0
        }
478
0
          CM_FALLTHROUGH;
479
0
        case cmPolicies::OLD:
480
0
          break;
481
0
        case cmPolicies::NEW:
482
0
          mf.IssueMessage(MessageType::FATAL_ERROR, message);
483
0
          return true;
484
0
      }
485
0
      return InvokeBuiltinCommand(command, args, status);
486
0
    });
487
35
}
488
489
void cmState::AddRemovedCommand(std::string const& name,
490
                                std::string const& message)
491
70
{
492
70
  this->AddBuiltinCommand(name,
493
70
                          [message](std::vector<cmListFileArgument> const&,
494
70
                                    cmExecutionStatus& status) -> bool {
495
0
                            status.GetMakefile().IssueMessage(
496
0
                              MessageType::FATAL_ERROR, message);
497
0
                            return true;
498
0
                          });
499
70
}
500
501
void cmState::AddUnexpectedCommand(std::string const& name, char const* error)
502
329
{
503
329
  this->AddBuiltinCommand(
504
329
    name,
505
329
    [name, error](std::vector<cmListFileArgument> const&,
506
329
                  cmExecutionStatus& status) -> bool {
507
0
      cmValue versionValue =
508
0
        status.GetMakefile().GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
509
0
      if (name == "endif" &&
510
0
          (!versionValue || atof(versionValue->c_str()) <= 1.4)) {
511
0
        return true;
512
0
      }
513
0
      status.SetError(error);
514
0
      return false;
515
0
    });
516
329
}
517
518
void cmState::AddUnexpectedFlowControlCommand(std::string const& name,
519
                                              char const* error)
520
280
{
521
280
  this->FlowControlCommands.insert(name);
522
280
  this->AddUnexpectedCommand(name, error);
523
280
}
524
525
bool cmState::AddScriptedCommand(std::string const& name, BT<Command> command,
526
                                 cmMakefile& mf)
527
0
{
528
0
  std::string sName = cmSystemTools::LowerCase(name);
529
530
0
  if (this->FlowControlCommands.count(sName)) {
531
0
    mf.GetCMakeInstance()->IssueMessage(
532
0
      MessageType::FATAL_ERROR,
533
0
      cmStrCat("Built-in flow control command \"", sName,
534
0
               "\" cannot be overridden."),
535
0
      command.Backtrace);
536
0
    cmSystemTools::SetFatalErrorOccurred();
537
0
    return false;
538
0
  }
539
540
  // if the command already exists, give a new name to the old command.
541
0
  if (Command oldCmd = this->GetCommandByExactName(sName)) {
542
0
    this->ScriptedCommands["_" + sName] = oldCmd;
543
0
  }
544
545
0
  this->ScriptedCommands[sName] = std::move(command.Value);
546
0
  return true;
547
0
}
548
549
cmState::Command cmState::GetCommand(std::string const& name) const
550
0
{
551
0
  return this->GetCommandByExactName(cmSystemTools::LowerCase(name));
552
0
}
553
554
cmState::Command cmState::GetCommandByExactName(std::string const& name) const
555
0
{
556
0
  auto pos = this->ScriptedCommands.find(name);
557
0
  if (pos != this->ScriptedCommands.end()) {
558
0
    return pos->second;
559
0
  }
560
0
  pos = this->BuiltinCommands.find(name);
561
0
  if (pos != this->BuiltinCommands.end()) {
562
0
    return pos->second;
563
0
  }
564
0
  return nullptr;
565
0
}
566
567
std::vector<std::string> cmState::GetCommandNames() const
568
0
{
569
0
  std::vector<std::string> commandNames;
570
0
  commandNames.reserve(this->BuiltinCommands.size() +
571
0
                       this->ScriptedCommands.size());
572
0
  for (auto const& bc : this->BuiltinCommands) {
573
0
    commandNames.push_back(bc.first);
574
0
  }
575
0
  for (auto const& sc : this->ScriptedCommands) {
576
0
    commandNames.push_back(sc.first);
577
0
  }
578
0
  std::sort(commandNames.begin(), commandNames.end());
579
0
  commandNames.erase(std::unique(commandNames.begin(), commandNames.end()),
580
0
                     commandNames.end());
581
0
  return commandNames;
582
0
}
583
584
void cmState::RemoveBuiltinCommand(std::string const& name)
585
0
{
586
0
  assert(name == cmSystemTools::LowerCase(name));
587
0
  this->BuiltinCommands.erase(name);
588
0
}
589
590
void cmState::RemoveUserDefinedCommands()
591
0
{
592
0
  this->ScriptedCommands.clear();
593
0
}
594
595
void cmState::SetGlobalProperty(std::string const& prop,
596
                                std::string const& value)
597
0
{
598
0
  this->GlobalProperties.SetProperty(prop, value);
599
0
}
600
void cmState::SetGlobalProperty(std::string const& prop, cmValue value)
601
0
{
602
0
  this->GlobalProperties.SetProperty(prop, value);
603
0
}
604
605
void cmState::AppendGlobalProperty(std::string const& prop,
606
                                   std::string const& value, bool asString)
607
0
{
608
0
  this->GlobalProperties.AppendProperty(prop, value, asString);
609
0
}
610
611
cmValue cmState::GetGlobalProperty(std::string const& prop)
612
0
{
613
0
  if (prop == "CACHE_VARIABLES") {
614
0
    std::vector<std::string> cacheKeys = this->GetCacheEntryKeys();
615
0
    this->SetGlobalProperty("CACHE_VARIABLES", cmList::to_string(cacheKeys));
616
0
  } else if (prop == "COMMANDS") {
617
0
    std::vector<std::string> commands = this->GetCommandNames();
618
0
    this->SetGlobalProperty("COMMANDS", cmList::to_string(commands));
619
0
  } else if (prop == "IN_TRY_COMPILE") {
620
0
    this->SetGlobalProperty("IN_TRY_COMPILE",
621
0
                            this->IsTryCompile == TryCompile::Yes ? "1" : "0");
622
0
  } else if (prop == "GENERATOR_IS_MULTI_CONFIG") {
623
0
    this->SetGlobalProperty("GENERATOR_IS_MULTI_CONFIG",
624
0
                            this->IsGeneratorMultiConfig ? "1" : "0");
625
0
  } else if (prop == "ENABLED_LANGUAGES") {
626
0
    auto langs = cmList::to_string(this->EnabledLanguages);
627
0
    this->SetGlobalProperty("ENABLED_LANGUAGES", langs);
628
0
  } else if (prop == "CMAKE_ROLE") {
629
0
    this->SetGlobalProperty("CMAKE_ROLE", this->GetRoleString());
630
0
  }
631
0
#define STRING_LIST_ELEMENT(F) ";" #F
632
0
  if (prop == "CMAKE_C_KNOWN_FEATURES") {
633
0
    static std::string const s_out(
634
0
      &FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT)[1]);
635
0
    return cmValue(s_out);
636
0
  }
637
0
  if (prop == "CMAKE_C90_KNOWN_FEATURES") {
638
0
    static std::string const s_out(
639
0
      &FOR_EACH_C90_FEATURE(STRING_LIST_ELEMENT)[1]);
640
0
    return cmValue(s_out);
641
0
  }
642
0
  if (prop == "CMAKE_C99_KNOWN_FEATURES") {
643
0
    static std::string const s_out(
644
0
      &FOR_EACH_C99_FEATURE(STRING_LIST_ELEMENT)[1]);
645
0
    return cmValue(s_out);
646
0
  }
647
0
  if (prop == "CMAKE_C11_KNOWN_FEATURES") {
648
0
    static std::string const s_out(
649
0
      &FOR_EACH_C11_FEATURE(STRING_LIST_ELEMENT)[1]);
650
0
    return cmValue(s_out);
651
0
  }
652
0
  if (prop == "CMAKE_CXX_KNOWN_FEATURES") {
653
0
    static std::string const s_out(
654
0
      &FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT)[1]);
655
0
    return cmValue(s_out);
656
0
  }
657
0
  if (prop == "CMAKE_CXX98_KNOWN_FEATURES") {
658
0
    static std::string const s_out(
659
0
      &FOR_EACH_CXX98_FEATURE(STRING_LIST_ELEMENT)[1]);
660
0
    return cmValue(s_out);
661
0
  }
662
0
  if (prop == "CMAKE_CXX11_KNOWN_FEATURES") {
663
0
    static std::string const s_out(
664
0
      &FOR_EACH_CXX11_FEATURE(STRING_LIST_ELEMENT)[1]);
665
0
    return cmValue(s_out);
666
0
  }
667
0
  if (prop == "CMAKE_CXX14_KNOWN_FEATURES") {
668
0
    static std::string const s_out(
669
0
      &FOR_EACH_CXX14_FEATURE(STRING_LIST_ELEMENT)[1]);
670
0
    return cmValue(s_out);
671
0
  }
672
0
  if (prop == "CMAKE_CUDA_KNOWN_FEATURES") {
673
0
    static std::string const s_out(
674
0
      &FOR_EACH_CUDA_FEATURE(STRING_LIST_ELEMENT)[1]);
675
0
    return cmValue(s_out);
676
0
  }
677
0
  if (prop == "CMAKE_HIP_KNOWN_FEATURES") {
678
0
    static std::string const s_out(
679
0
      &FOR_EACH_HIP_FEATURE(STRING_LIST_ELEMENT)[1]);
680
0
    return cmValue(s_out);
681
0
  }
682
683
0
#undef STRING_LIST_ELEMENT
684
0
  return this->GlobalProperties.GetPropertyValue(prop);
685
0
}
686
687
bool cmState::GetGlobalPropertyAsBool(std::string const& prop)
688
0
{
689
0
  return this->GetGlobalProperty(prop).IsOn();
690
0
}
691
692
void cmState::SetSourceDirectory(std::string const& sourceDirectory)
693
36
{
694
36
  this->SourceDirectory = sourceDirectory;
695
36
  cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
696
36
}
697
698
std::string const& cmState::GetSourceDirectory() const
699
72
{
700
72
  return this->SourceDirectory;
701
72
}
702
703
void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
704
36
{
705
36
  this->BinaryDirectory = binaryDirectory;
706
36
  cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
707
36
}
708
709
void cmState::SetWindowsShell(bool windowsShell)
710
1
{
711
1
  this->WindowsShell = windowsShell;
712
1
}
713
714
bool cmState::UseWindowsShell() const
715
0
{
716
0
  return this->WindowsShell;
717
0
}
718
719
void cmState::SetWindowsVSIDE(bool windowsVSIDE)
720
1
{
721
1
  this->WindowsVSIDE = windowsVSIDE;
722
1
}
723
724
bool cmState::UseWindowsVSIDE() const
725
0
{
726
0
  return this->WindowsVSIDE;
727
0
}
728
729
void cmState::SetGhsMultiIDE(bool ghsMultiIDE)
730
0
{
731
0
  this->GhsMultiIDE = ghsMultiIDE;
732
0
}
733
734
bool cmState::UseGhsMultiIDE() const
735
0
{
736
0
  return this->GhsMultiIDE;
737
0
}
738
739
void cmState::SetBorlandMake(bool borlandMake)
740
0
{
741
0
  this->BorlandMake = borlandMake;
742
0
}
743
744
bool cmState::UseBorlandMake() const
745
0
{
746
0
  return this->BorlandMake;
747
0
}
748
749
void cmState::SetWatcomWMake(bool watcomWMake)
750
1
{
751
1
  this->WatcomWMake = watcomWMake;
752
1
}
753
754
bool cmState::UseWatcomWMake() const
755
0
{
756
0
  return this->WatcomWMake;
757
0
}
758
759
void cmState::SetMinGWMake(bool minGWMake)
760
1
{
761
1
  this->MinGWMake = minGWMake;
762
1
}
763
764
bool cmState::UseMinGWMake() const
765
0
{
766
0
  return this->MinGWMake;
767
0
}
768
769
void cmState::SetNMake(bool nMake)
770
1
{
771
1
  this->NMake = nMake;
772
1
}
773
774
bool cmState::UseNMake() const
775
0
{
776
0
  return this->NMake;
777
0
}
778
779
void cmState::SetMSYSShell(bool mSYSShell)
780
1
{
781
1
  this->MSYSShell = mSYSShell;
782
1
}
783
784
bool cmState::UseMSYSShell() const
785
0
{
786
0
  return this->MSYSShell;
787
0
}
788
789
void cmState::SetNinja(bool ninja)
790
0
{
791
0
  this->Ninja = ninja;
792
0
}
793
794
bool cmState::UseNinja() const
795
0
{
796
0
  return this->Ninja;
797
0
}
798
799
void cmState::SetNinjaMulti(bool ninjaMulti)
800
0
{
801
0
  this->NinjaMulti = ninjaMulti;
802
0
}
803
804
bool cmState::UseNinjaMulti() const
805
0
{
806
0
  return this->NinjaMulti;
807
0
}
808
809
void cmState::SetFastbuildMake(bool fastbuildMake)
810
1
{
811
1
  this->FastbuildMake = fastbuildMake;
812
1
}
813
814
bool cmState::UseFastbuildMake() const
815
0
{
816
0
  return this->FastbuildMake;
817
0
}
818
819
unsigned int cmState::GetCacheMajorVersion() const
820
0
{
821
0
  return this->CacheManager->GetCacheMajorVersion();
822
0
}
823
824
unsigned int cmState::GetCacheMinorVersion() const
825
0
{
826
0
  return this->CacheManager->GetCacheMinorVersion();
827
0
}
828
829
void cmState::SetRoleToProjectForCMakeBuildVsReconfigure()
830
0
{
831
0
  this->StateRole = Role::Project;
832
0
}
833
834
void cmState::SetRoleToHelpForListPresets()
835
0
{
836
0
  this->StateRole = Role::Help;
837
0
}
838
839
cmState::Role cmState::GetRole() const
840
76
{
841
76
  return this->StateRole;
842
76
}
843
844
std::string cmState::GetRoleString() const
845
0
{
846
0
  return RoleToString(this->StateRole);
847
0
}
848
849
std::string cmState::RoleToString(cmState::Role mode)
850
0
{
851
0
  switch (mode) {
852
0
    case Role::Project:
853
0
      return "PROJECT";
854
0
    case Role::Script:
855
0
      return "SCRIPT";
856
0
    case Role::FindPackage:
857
0
      return "FIND_PACKAGE";
858
0
    case Role::CTest:
859
0
      return "CTEST";
860
0
    case Role::CPack:
861
0
      return "CPACK";
862
0
    case Role::Help:
863
0
      return "HELP";
864
0
    case Role::Internal:
865
0
      return "INTERNAL";
866
0
  }
867
0
  return "UNKNOWN";
868
0
}
869
870
cmState::TryCompile cmState::GetIsTryCompile() const
871
36
{
872
36
  return this->IsTryCompile;
873
36
}
874
875
std::string const& cmState::GetBinaryDirectory() const
876
36
{
877
36
  return this->BinaryDirectory;
878
36
}
879
880
cmStateSnapshot cmState::CreateBaseSnapshot()
881
35
{
882
35
  cmStateDetail::PositionType pos =
883
35
    this->SnapshotData.Push(this->SnapshotData.Root());
884
35
  pos->DirectoryParent = this->SnapshotData.Root();
885
35
  pos->ScopeParent = this->SnapshotData.Root();
886
35
  pos->SnapshotType = cmStateEnums::BaseType;
887
35
  pos->Keep = true;
888
35
  pos->BuildSystemDirectory =
889
35
    this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root());
890
35
  pos->ExecutionListFile =
891
35
    this->ExecutionListFiles.Push(this->ExecutionListFiles.Root());
892
35
  pos->IncludeDirectoryPosition = 0;
893
35
  pos->CompileDefinitionsPosition = 0;
894
35
  pos->CompileOptionsPosition = 0;
895
35
  pos->LinkOptionsPosition = 0;
896
35
  pos->LinkDirectoriesPosition = 0;
897
35
  pos->BuildSystemDirectory->CurrentScope = pos;
898
35
  pos->Policies = this->PolicyStack.Root();
899
35
  pos->PolicyRoot = this->PolicyStack.Root();
900
35
  pos->PolicyScope = this->PolicyStack.Root();
901
35
  assert(pos->Policies.IsValid());
902
35
  assert(pos->PolicyRoot.IsValid());
903
35
  pos->Diagnostics =
904
35
    this->DiagnosticStack.Push(this->DiagnosticStack.Root(), { {}, false });
905
35
  pos->DiagnosticRoot = this->DiagnosticStack.Root();
906
35
  pos->DiagnosticScope = this->DiagnosticStack.Root();
907
35
  assert(pos->Diagnostics.IsValid());
908
35
  assert(pos->DiagnosticRoot.IsValid());
909
35
  assert(pos->Diagnostics != pos->DiagnosticRoot);
910
35
  pos->Vars = this->VarTree.Push(this->VarTree.Root());
911
35
  assert(pos->Vars.IsValid());
912
35
  pos->Parent = this->VarTree.Root();
913
35
  pos->Root = this->VarTree.Root();
914
35
  return { this, pos };
915
35
}
916
917
cmStateSnapshot cmState::CreateBuildsystemDirectorySnapshot(
918
  cmStateSnapshot const& originSnapshot)
919
0
{
920
0
  assert(originSnapshot.IsValid());
921
0
  cmStateDetail::PositionType pos =
922
0
    this->SnapshotData.Push(originSnapshot.Position);
923
0
  pos->DirectoryParent = originSnapshot.Position;
924
0
  pos->ScopeParent = originSnapshot.Position;
925
0
  pos->SnapshotType = cmStateEnums::BuildsystemDirectoryType;
926
0
  pos->Keep = true;
927
0
  pos->BuildSystemDirectory = this->BuildsystemDirectory.Push(
928
0
    originSnapshot.Position->BuildSystemDirectory);
929
0
  pos->ExecutionListFile =
930
0
    this->ExecutionListFiles.Push(originSnapshot.Position->ExecutionListFile);
931
0
  pos->BuildSystemDirectory->CurrentScope = pos;
932
0
  pos->Policies = originSnapshot.Position->Policies;
933
0
  pos->PolicyRoot = originSnapshot.Position->Policies;
934
0
  pos->PolicyScope = originSnapshot.Position->Policies;
935
0
  assert(pos->Policies.IsValid());
936
0
  assert(pos->PolicyRoot.IsValid());
937
0
  pos->Diagnostics = originSnapshot.Position->Diagnostics;
938
0
  pos->DiagnosticRoot = originSnapshot.Position->Diagnostics;
939
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
940
0
  assert(pos->Diagnostics.IsValid());
941
0
  assert(pos->DiagnosticRoot.IsValid());
942
943
0
  cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
944
0
  pos->Parent = origin;
945
0
  pos->Root = origin;
946
0
  pos->Vars = this->VarTree.Push(origin);
947
948
0
  cmStateSnapshot snapshot = cmStateSnapshot(this, pos);
949
0
  originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
950
0
  snapshot.SetDefaultDefinitions();
951
0
  snapshot.InitializeFromParent();
952
0
  snapshot.SetDirectoryDefinitions();
953
0
  return snapshot;
954
0
}
955
956
cmStateSnapshot cmState::CreateDeferCallSnapshot(
957
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
958
0
{
959
0
  cmStateDetail::PositionType pos =
960
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
961
0
  pos->SnapshotType = cmStateEnums::DeferCallType;
962
0
  pos->Keep = false;
963
0
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
964
0
    originSnapshot.Position->ExecutionListFile, fileName);
965
0
  assert(originSnapshot.Position->Vars.IsValid());
966
0
  pos->BuildSystemDirectory->CurrentScope = pos;
967
0
  pos->PolicyScope = originSnapshot.Position->Policies;
968
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
969
0
  return { this, pos };
970
0
}
971
972
cmStateSnapshot cmState::CreateFunctionCallSnapshot(
973
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
974
0
{
975
0
  cmStateDetail::PositionType pos =
976
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
977
0
  pos->ScopeParent = originSnapshot.Position;
978
0
  pos->SnapshotType = cmStateEnums::FunctionCallType;
979
0
  pos->Keep = false;
980
0
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
981
0
    originSnapshot.Position->ExecutionListFile, fileName);
982
0
  pos->BuildSystemDirectory->CurrentScope = pos;
983
0
  pos->PolicyScope = originSnapshot.Position->Policies;
984
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
985
0
  assert(originSnapshot.Position->Vars.IsValid());
986
0
  cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
987
0
  pos->Parent = origin;
988
0
  pos->Vars = this->VarTree.Push(origin);
989
0
  return { this, pos };
990
0
}
991
992
cmStateSnapshot cmState::CreateMacroCallSnapshot(
993
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
994
0
{
995
0
  cmStateDetail::PositionType pos =
996
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
997
0
  pos->SnapshotType = cmStateEnums::MacroCallType;
998
0
  pos->Keep = false;
999
0
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1000
0
    originSnapshot.Position->ExecutionListFile, fileName);
1001
0
  assert(originSnapshot.Position->Vars.IsValid());
1002
0
  pos->BuildSystemDirectory->CurrentScope = pos;
1003
0
  pos->PolicyScope = originSnapshot.Position->Policies;
1004
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1005
0
  return { this, pos };
1006
0
}
1007
1008
cmStateSnapshot cmState::CreateIncludeFileSnapshot(
1009
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
1010
0
{
1011
0
  cmStateDetail::PositionType pos =
1012
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1013
0
  pos->SnapshotType = cmStateEnums::IncludeFileType;
1014
0
  pos->Keep = true;
1015
0
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1016
0
    originSnapshot.Position->ExecutionListFile, fileName);
1017
0
  assert(originSnapshot.Position->Vars.IsValid());
1018
0
  pos->BuildSystemDirectory->CurrentScope = pos;
1019
0
  pos->PolicyScope = originSnapshot.Position->Policies;
1020
0
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1021
0
  return { this, pos };
1022
0
}
1023
1024
cmStateSnapshot cmState::CreateVariableScopeSnapshot(
1025
  cmStateSnapshot const& originSnapshot)
1026
0
{
1027
0
  cmStateDetail::PositionType pos =
1028
0
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1029
0
  pos->ScopeParent = originSnapshot.Position;
1030
0
  pos->SnapshotType = cmStateEnums::VariableScopeType;
1031
0
  pos->Keep = false;
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
1037
0
  cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
1038
0
  pos->Parent = origin;
1039
0
  pos->Vars = this->VarTree.Push(origin);
1040
0
  assert(pos->Vars.IsValid());
1041
0
  return { this, pos };
1042
0
}
1043
1044
cmStateSnapshot cmState::CreateInlineListFileSnapshot(
1045
  cmStateSnapshot const& originSnapshot, std::string const& fileName)
1046
1
{
1047
1
  cmStateDetail::PositionType pos =
1048
1
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1049
1
  pos->SnapshotType = cmStateEnums::InlineListFileType;
1050
1
  pos->Keep = true;
1051
1
  pos->ExecutionListFile = this->ExecutionListFiles.Push(
1052
1
    originSnapshot.Position->ExecutionListFile, fileName);
1053
1
  pos->BuildSystemDirectory->CurrentScope = pos;
1054
1
  pos->PolicyScope = originSnapshot.Position->Policies;
1055
1
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1056
1
  return { this, pos };
1057
1
}
1058
1059
cmStateSnapshot cmState::CreatePolicyScopeSnapshot(
1060
  cmStateSnapshot const& originSnapshot)
1061
1
{
1062
1
  cmStateDetail::PositionType pos =
1063
1
    this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
1064
1
  pos->SnapshotType = cmStateEnums::PolicyScopeType;
1065
1
  pos->Keep = false;
1066
1
  pos->BuildSystemDirectory->CurrentScope = pos;
1067
1
  pos->PolicyScope = originSnapshot.Position->Policies;
1068
1
  pos->DiagnosticScope = originSnapshot.Position->Diagnostics;
1069
1
  return { this, pos };
1070
1
}
1071
1072
cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot)
1073
1
{
1074
1
  cmStateDetail::PositionType pos = originSnapshot.Position;
1075
1
  cmStateDetail::PositionType prevPos = pos;
1076
1
  ++prevPos;
1077
1
  prevPos->IncludeDirectoryPosition =
1078
1
    prevPos->BuildSystemDirectory->IncludeDirectories.size();
1079
1
  prevPos->CompileDefinitionsPosition =
1080
1
    prevPos->BuildSystemDirectory->CompileDefinitions.size();
1081
1
  prevPos->CompileOptionsPosition =
1082
1
    prevPos->BuildSystemDirectory->CompileOptions.size();
1083
1
  prevPos->LinkOptionsPosition =
1084
1
    prevPos->BuildSystemDirectory->LinkOptions.size();
1085
1
  prevPos->LinkDirectoriesPosition =
1086
1
    prevPos->BuildSystemDirectory->LinkDirectories.size();
1087
1
  prevPos->BuildSystemDirectory->CurrentScope = prevPos;
1088
1
  prevPos->UnwindState = pos->UnwindState;
1089
1090
1
  if (!pos->Keep && this->SnapshotData.IsLast(pos)) {
1091
0
    if (pos->Vars != prevPos->Vars) {
1092
0
      assert(this->VarTree.IsLast(pos->Vars));
1093
0
      this->VarTree.Pop(pos->Vars);
1094
0
    }
1095
0
    if (pos->ExecutionListFile != prevPos->ExecutionListFile) {
1096
0
      assert(this->ExecutionListFiles.IsLast(pos->ExecutionListFile));
1097
0
      this->ExecutionListFiles.Pop(pos->ExecutionListFile);
1098
0
    }
1099
0
    this->SnapshotData.Pop(pos);
1100
0
  }
1101
1102
1
  return { this, prevPos };
1103
1
}
1104
1105
static bool ParseEntryWithoutType(std::string const& entry, std::string& var,
1106
                                  std::string& value)
1107
0
{
1108
  // input line is:         key=value
1109
0
  static cmsys::RegularExpression reg(
1110
0
    "^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
1111
  // input line is:         "key"=value
1112
0
  static cmsys::RegularExpression regQuoted(
1113
0
    "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
1114
0
  bool flag = false;
1115
0
  if (regQuoted.find(entry)) {
1116
0
    var = regQuoted.match(1);
1117
0
    value = regQuoted.match(2);
1118
0
    flag = true;
1119
0
  } else if (reg.find(entry)) {
1120
0
    var = reg.match(1);
1121
0
    value = reg.match(2);
1122
0
    flag = true;
1123
0
  }
1124
1125
  // if value is enclosed in single quotes ('foo') then remove them
1126
  // it is used to enclose trailing space or tab
1127
0
  if (flag && value.size() >= 2 && value.front() == '\'' &&
1128
0
      value.back() == '\'') {
1129
0
    value = value.substr(1, value.size() - 2);
1130
0
  }
1131
1132
0
  return flag;
1133
0
}
1134
1135
bool cmState::ParseCacheEntry(std::string const& entry, std::string& var,
1136
                              std::string& value,
1137
                              cmStateEnums::CacheEntryType& type)
1138
0
{
1139
  // input line is:         key:type=value
1140
0
  static cmsys::RegularExpression reg(
1141
0
    "^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
1142
  // input line is:         "key":type=value
1143
0
  static cmsys::RegularExpression regQuoted(
1144
0
    "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
1145
0
  bool flag = false;
1146
0
  if (regQuoted.find(entry)) {
1147
0
    var = regQuoted.match(1);
1148
0
    type = cmState::StringToCacheEntryType(regQuoted.match(2));
1149
0
    value = regQuoted.match(3);
1150
0
    flag = true;
1151
0
  } else if (reg.find(entry)) {
1152
0
    var = reg.match(1);
1153
0
    type = cmState::StringToCacheEntryType(reg.match(2));
1154
0
    value = reg.match(3);
1155
0
    flag = true;
1156
0
  }
1157
1158
  // if value is enclosed in single quotes ('foo') then remove them
1159
  // it is used to enclose trailing space or tab
1160
0
  if (flag && value.size() >= 2 && value.front() == '\'' &&
1161
0
      value.back() == '\'') {
1162
0
    value = value.substr(1, value.size() - 2);
1163
0
  }
1164
1165
0
  if (!flag) {
1166
0
    return ParseEntryWithoutType(entry, var, value);
1167
0
  }
1168
1169
0
  return flag;
1170
0
}
1171
1172
cmState::Command cmState::GetDependencyProviderCommand(
1173
  cmDependencyProvider::Method method) const
1174
0
{
1175
0
  return (this->DependencyProvider &&
1176
0
          this->DependencyProvider->SupportsMethod(method))
1177
0
    ? this->GetCommand(this->DependencyProvider->GetCommand())
1178
0
    : Command{};
1179
0
}