1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmState.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdlib>
#include <utility>
#include <cm/memory>
#include "cmsys/RegularExpression.hxx"
#include "cmCacheManager.h"
#include "cmCommand.h"
#include "cmDefinitions.h"
#include "cmExecutionStatus.h"
#include "cmGlobVerificationManager.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmStatePrivate.h"
#include "cmStateSnapshot.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
#include "cmake.h"
cmState::cmState()
{
this->CacheManager = cm::make_unique<cmCacheManager>();
this->GlobVerificationManager = cm::make_unique<cmGlobVerificationManager>();
}
cmState::~cmState() = default;
const char* cmState::GetTargetTypeName(cmStateEnums::TargetType targetType)
{
switch (targetType) {
case cmStateEnums::STATIC_LIBRARY:
return "STATIC_LIBRARY";
case cmStateEnums::MODULE_LIBRARY:
return "MODULE_LIBRARY";
case cmStateEnums::SHARED_LIBRARY:
return "SHARED_LIBRARY";
case cmStateEnums::OBJECT_LIBRARY:
return "OBJECT_LIBRARY";
case cmStateEnums::EXECUTABLE:
return "EXECUTABLE";
case cmStateEnums::UTILITY:
return "UTILITY";
case cmStateEnums::GLOBAL_TARGET:
return "GLOBAL_TARGET";
case cmStateEnums::INTERFACE_LIBRARY:
return "INTERFACE_LIBRARY";
case cmStateEnums::UNKNOWN_LIBRARY:
return "UNKNOWN_LIBRARY";
}
assert(false && "Unexpected target type");
return nullptr;
}
static const std::array<std::string, 7> cmCacheEntryTypes = {
{ "BOOL", "PATH", "FILEPATH", "STRING", "INTERNAL", "STATIC",
"UNINITIALIZED" }
};
const std::string& cmState::CacheEntryTypeToString(
cmStateEnums::CacheEntryType type)
{
if (type < cmStateEnums::BOOL || type > cmStateEnums::UNINITIALIZED) {
type = cmStateEnums::UNINITIALIZED;
}
return cmCacheEntryTypes[type];
}
cmStateEnums::CacheEntryType cmState::StringToCacheEntryType(
const std::string& s)
{
cmStateEnums::CacheEntryType type = cmStateEnums::STRING;
StringToCacheEntryType(s, type);
return type;
}
bool cmState::StringToCacheEntryType(const std::string& s,
cmStateEnums::CacheEntryType& type)
{
for (size_t i = 0; i < cmCacheEntryTypes.size(); ++i) {
if (s == cmCacheEntryTypes[i]) {
type = static_cast<cmStateEnums::CacheEntryType>(i);
return true;
}
}
return false;
}
bool cmState::IsCacheEntryType(std::string const& key)
{
for (const std::string& i : cmCacheEntryTypes) {
if (key == i) {
return true;
}
}
return false;
}
bool cmState::LoadCache(const std::string& path, bool internal,
std::set<std::string>& excludes,
std::set<std::string>& includes)
{
return this->CacheManager->LoadCache(path, internal, excludes, includes);
}
bool cmState::SaveCache(const std::string& path, cmMessenger* messenger)
{
return this->CacheManager->SaveCache(path, messenger);
}
bool cmState::DeleteCache(const std::string& path)
{
return this->CacheManager->DeleteCache(path);
}
std::vector<std::string> cmState::GetCacheEntryKeys() const
{
std::vector<std::string> definitions;
definitions.reserve(this->CacheManager->GetSize());
cmCacheManager::CacheIterator cit = this->CacheManager->GetCacheIterator();
for (cit.Begin(); !cit.IsAtEnd(); cit.Next()) {
definitions.push_back(cit.GetName());
}
return definitions;
}
const char* cmState::GetCacheEntryValue(std::string const& key) const
{
cmCacheManager::CacheEntry* e = this->CacheManager->GetCacheEntry(key);
if (!e) {
return nullptr;
}
return e->Value.c_str();
}
std::string cmState::GetSafeCacheEntryValue(std::string const& key) const
{
std::string retval;
auto val = this->GetCacheEntryValue(key);
if (val) {
retval = val;
}
return retval;
}
const std::string* cmState::GetInitializedCacheValue(
std::string const& key) const
{
return this->CacheManager->GetInitializedCacheValue(key);
}
cmStateEnums::CacheEntryType cmState::GetCacheEntryType(
std::string const& key) const
{
cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key);
return it.GetType();
}
void cmState::SetCacheEntryValue(std::string const& key,
std::string const& value)
{
this->CacheManager->SetCacheEntryValue(key, value);
}
void cmState::SetCacheEntryProperty(std::string const& key,
std::string const& propertyName,
std::string const& value)
{
cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key);
it.SetProperty(propertyName, value.c_str());
}
void cmState::SetCacheEntryBoolProperty(std::string const& key,
std::string const& propertyName,
bool value)
{
cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key);
it.SetProperty(propertyName, value);
}
std::vector<std::string> cmState::GetCacheEntryPropertyList(
const std::string& key)
{
cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key);
return it.GetPropertyList();
}
const char* cmState::GetCacheEntryProperty(std::string const& key,
std::string const& propertyName)
{
cmCacheManager::CacheIterator it = this->CacheManager->GetCacheIterator(key);
if (!it.PropertyExists(propertyName)) {
return nullptr;
}
return it.GetProperty(propertyName);
}
bool cmState::GetCacheEntryPropertyAsBool(std::string const& key,
std::string const& propertyName)
{
return this->CacheManager->GetCacheIterator(key).GetPropertyAsBool(
propertyName);
}
void cmState::AddCacheEntry(const std::string& key, const char* value,
const char* helpString,
cmStateEnums::CacheEntryType type)
{
this->CacheManager->AddCacheEntry(key, value, helpString, type);
}
bool cmState::DoWriteGlobVerifyTarget() const
{
return this->GlobVerificationManager->DoWriteVerifyTarget();
}
std::string const& cmState::GetGlobVerifyScript() const
{
return this->GlobVerificationManager->GetVerifyScript();
}
std::string const& cmState::GetGlobVerifyStamp() const
{
return this->GlobVerificationManager->GetVerifyStamp();
}
bool cmState::SaveVerificationScript(const std::string& path)
{
return this->GlobVerificationManager->SaveVerificationScript(path);
}
void cmState::AddGlobCacheEntry(bool recurse, bool listDirectories,
bool followSymlinks,
const std::string& relative,
const std::string& expression,
const std::vector<std::string>& files,
const std::string& variable,
cmListFileBacktrace const& backtrace)
{
this->GlobVerificationManager->AddCacheEntry(
recurse, listDirectories, followSymlinks, relative, expression, files,
variable, backtrace);
}
void cmState::RemoveCacheEntry(std::string const& key)
{
this->CacheManager->RemoveCacheEntry(key);
}
void cmState::AppendCacheEntryProperty(const std::string& key,
const std::string& property,
const std::string& value, bool asString)
{
this->CacheManager->GetCacheIterator(key).AppendProperty(property, value,
asString);
}
void cmState::RemoveCacheEntryProperty(std::string const& key,
std::string const& propertyName)
{
this->CacheManager->GetCacheIterator(key).SetProperty(propertyName, nullptr);
}
cmStateSnapshot cmState::Reset()
{
this->GlobalProperties.Clear();
this->PropertyDefinitions.clear();
this->GlobVerificationManager->Reset();
cmStateDetail::PositionType pos = this->SnapshotData.Truncate();
this->ExecutionListFiles.Truncate();
{
cmLinkedTree<cmStateDetail::BuildsystemDirectoryStateType>::iterator it =
this->BuildsystemDirectory.Truncate();
it->IncludeDirectories.clear();
it->IncludeDirectoryBacktraces.clear();
it->CompileDefinitions.clear();
it->CompileDefinitionsBacktraces.clear();
it->CompileOptions.clear();
it->CompileOptionsBacktraces.clear();
it->LinkOptions.clear();
it->LinkOptionsBacktraces.clear();
it->LinkDirectories.clear();
it->LinkDirectoriesBacktraces.clear();
it->DirectoryEnd = pos;
it->NormalTargetNames.clear();
it->Properties.Clear();
it->Children.clear();
}
this->PolicyStack.Clear();
pos->Policies = this->PolicyStack.Root();
pos->PolicyRoot = this->PolicyStack.Root();
pos->PolicyScope = this->PolicyStack.Root();
assert(pos->Policies.IsValid());
assert(pos->PolicyRoot.IsValid());
{
std::string srcDir =
*cmDefinitions::Get("CMAKE_SOURCE_DIR", pos->Vars, pos->Root);
std::string binDir =
*cmDefinitions::Get("CMAKE_BINARY_DIR", pos->Vars, pos->Root);
this->VarTree.Clear();
pos->Vars = this->VarTree.Push(this->VarTree.Root());
pos->Parent = this->VarTree.Root();
pos->Root = this->VarTree.Root();
pos->Vars->Set("CMAKE_SOURCE_DIR", srcDir);
pos->Vars->Set("CMAKE_BINARY_DIR", binDir);
}
this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, "", "",
true);
this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::DIRECTORY, "", "",
true);
this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::DIRECTORY, "", "",
true);
this->DefineProperty("RULE_LAUNCH_COMPILE", cmProperty::TARGET, "", "",
true);
this->DefineProperty("RULE_LAUNCH_LINK", cmProperty::TARGET, "", "", true);
this->DefineProperty("RULE_LAUNCH_CUSTOM", cmProperty::TARGET, "", "", true);
return { this, pos };
}
void cmState::DefineProperty(const std::string& name,
cmProperty::ScopeType scope,
const char* ShortDescription,
const char* FullDescription, bool chained)
{
this->PropertyDefinitions[scope].DefineProperty(
name, scope, ShortDescription, FullDescription, chained);
}
cmPropertyDefinition const* cmState::GetPropertyDefinition(
const std::string& name, cmProperty::ScopeType scope) const
{
if (this->IsPropertyDefined(name, scope)) {
cmPropertyDefinitionMap const& defs =
this->PropertyDefinitions.find(scope)->second;
return &defs.find(name)->second;
}
return nullptr;
}
bool cmState::IsPropertyDefined(const std::string& name,
cmProperty::ScopeType scope) const
{
auto it = this->PropertyDefinitions.find(scope);
if (it == this->PropertyDefinitions.end()) {
return false;
}
return it->second.IsPropertyDefined(name);
}
bool cmState::IsPropertyChained(const std::string& name,
cmProperty::ScopeType scope) const
{
auto it = this->PropertyDefinitions.find(scope);
if (it == this->PropertyDefinitions.end()) {
return false;
}
return it->second.IsPropertyChained(name);
}
void cmState::SetLanguageEnabled(std::string const& l)
{
auto it = std::lower_bound(this->EnabledLanguages.begin(),
this->EnabledLanguages.end(), l);
if (it == this->EnabledLanguages.end() || *it != l) {
this->EnabledLanguages.insert(it, l);
}
}
bool cmState::GetLanguageEnabled(std::string const& l) const
{
return std::binary_search(this->EnabledLanguages.begin(),
this->EnabledLanguages.end(), l);
}
std::vector<std::string> cmState::GetEnabledLanguages() const
{
return this->EnabledLanguages;
}
void cmState::SetEnabledLanguages(std::vector<std::string> const& langs)
{
this->EnabledLanguages = langs;
}
void cmState::ClearEnabledLanguages()
{
this->EnabledLanguages.clear();
}
bool cmState::GetIsInTryCompile() const
{
return this->IsInTryCompile;
}
void cmState::SetIsInTryCompile(bool b)
{
this->IsInTryCompile = b;
}
bool cmState::GetIsGeneratorMultiConfig() const
{
return this->IsGeneratorMultiConfig;
}
void cmState::SetIsGeneratorMultiConfig(bool b)
{
this->IsGeneratorMultiConfig = b;
}
void cmState::AddBuiltinCommand(std::string const& name,
std::unique_ptr<cmCommand> command)
{
this->AddBuiltinCommand(name, cmLegacyCommandWrapper(std::move(command)));
}
void cmState::AddBuiltinCommand(std::string const& name, Command command)
{
assert(name == cmSystemTools::LowerCase(name));
assert(this->BuiltinCommands.find(name) == this->BuiltinCommands.end());
this->BuiltinCommands.emplace(name, std::move(command));
}
static bool InvokeBuiltinCommand(cmState::BuiltinCommand command,
std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status)
{
cmMakefile& mf = status.GetMakefile();
std::vector<std::string> expandedArguments;
if (!mf.ExpandArguments(args, expandedArguments)) {
// There was an error expanding arguments. It was already
// reported, so we can skip this command without error.
return true;
}
return command(expandedArguments, status);
}
void cmState::AddBuiltinCommand(std::string const& name,
BuiltinCommand command)
{
this->AddBuiltinCommand(
name,
[command](const std::vector<cmListFileArgument>& args,
cmExecutionStatus& status) -> bool {
return InvokeBuiltinCommand(command, args, status);
});
}
void cmState::AddDisallowedCommand(std::string const& name,
BuiltinCommand command,
cmPolicies::PolicyID policy,
const char* message)
{
this->AddBuiltinCommand(
name,
[command, policy, message](const std::vector<cmListFileArgument>& args,
cmExecutionStatus& status) -> bool {
cmMakefile& mf = status.GetMakefile();
switch (mf.GetPolicyStatus(policy)) {
case cmPolicies::WARN:
mf.IssueMessage(MessageType::AUTHOR_WARNING,
cmPolicies::GetPolicyWarning(policy));
break;
case cmPolicies::OLD:
break;
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::NEW:
mf.IssueMessage(MessageType::FATAL_ERROR, message);
return true;
}
return InvokeBuiltinCommand(command, args, status);
});
}
void cmState::AddUnexpectedCommand(std::string const& name, const char* error)
{
this->AddBuiltinCommand(
name,
[name, error](std::vector<cmListFileArgument> const&,
cmExecutionStatus& status) -> bool {
const char* versionValue =
status.GetMakefile().GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION");
if (name == "endif" && (!versionValue || atof(versionValue) <= 1.4)) {
return true;
}
status.SetError(error);
return false;
});
}
void cmState::AddScriptedCommand(std::string const& name, Command command)
{
std::string sName = cmSystemTools::LowerCase(name);
// if the command already exists, give a new name to the old command.
if (Command oldCmd = this->GetCommandByExactName(sName)) {
this->ScriptedCommands["_" + sName] = oldCmd;
}
this->ScriptedCommands[sName] = std::move(command);
}
cmState::Command cmState::GetCommand(std::string const& name) const
{
return GetCommandByExactName(cmSystemTools::LowerCase(name));
}
cmState::Command cmState::GetCommandByExactName(std::string const& name) const
{
auto pos = this->ScriptedCommands.find(name);
if (pos != this->ScriptedCommands.end()) {
return pos->second;
}
pos = this->BuiltinCommands.find(name);
if (pos != this->BuiltinCommands.end()) {
return pos->second;
}
return nullptr;
}
std::vector<std::string> cmState::GetCommandNames() const
{
std::vector<std::string> commandNames;
commandNames.reserve(this->BuiltinCommands.size() +
this->ScriptedCommands.size());
for (auto const& bc : this->BuiltinCommands) {
commandNames.push_back(bc.first);
}
for (auto const& sc : this->ScriptedCommands) {
commandNames.push_back(sc.first);
}
std::sort(commandNames.begin(), commandNames.end());
commandNames.erase(std::unique(commandNames.begin(), commandNames.end()),
commandNames.end());
return commandNames;
}
void cmState::RemoveBuiltinCommand(std::string const& name)
{
assert(name == cmSystemTools::LowerCase(name));
this->BuiltinCommands.erase(name);
}
void cmState::RemoveUserDefinedCommands()
{
this->ScriptedCommands.clear();
}
void cmState::SetGlobalProperty(const std::string& prop, const char* value)
{
this->GlobalProperties.SetProperty(prop, value);
}
void cmState::AppendGlobalProperty(const std::string& prop,
const std::string& value, bool asString)
{
this->GlobalProperties.AppendProperty(prop, value, asString);
}
const char* cmState::GetGlobalProperty(const std::string& prop)
{
if (prop == "CACHE_VARIABLES") {
std::vector<std::string> cacheKeys = this->GetCacheEntryKeys();
this->SetGlobalProperty("CACHE_VARIABLES", cmJoin(cacheKeys, ";").c_str());
} else if (prop == "COMMANDS") {
std::vector<std::string> commands = this->GetCommandNames();
this->SetGlobalProperty("COMMANDS", cmJoin(commands, ";").c_str());
} else if (prop == "IN_TRY_COMPILE") {
this->SetGlobalProperty("IN_TRY_COMPILE",
this->IsInTryCompile ? "1" : "0");
} else if (prop == "GENERATOR_IS_MULTI_CONFIG") {
this->SetGlobalProperty("GENERATOR_IS_MULTI_CONFIG",
this->IsGeneratorMultiConfig ? "1" : "0");
} else if (prop == "ENABLED_LANGUAGES") {
std::string langs;
langs = cmJoin(this->EnabledLanguages, ";");
this->SetGlobalProperty("ENABLED_LANGUAGES", langs.c_str());
} else if (prop == "CMAKE_ROLE") {
std::string mode = this->GetModeString();
this->SetGlobalProperty("CMAKE_ROLE", mode.c_str());
}
#define STRING_LIST_ELEMENT(F) ";" #F
if (prop == "CMAKE_C_KNOWN_FEATURES") {
return &FOR_EACH_C_FEATURE(STRING_LIST_ELEMENT)[1];
}
if (prop == "CMAKE_C90_KNOWN_FEATURES") {
return &FOR_EACH_C90_FEATURE(STRING_LIST_ELEMENT)[1];
}
if (prop == "CMAKE_C99_KNOWN_FEATURES") {
return &FOR_EACH_C99_FEATURE(STRING_LIST_ELEMENT)[1];
}
if (prop == "CMAKE_C11_KNOWN_FEATURES") {
return &FOR_EACH_C11_FEATURE(STRING_LIST_ELEMENT)[1];
}
if (prop == "CMAKE_CXX_KNOWN_FEATURES") {
return &FOR_EACH_CXX_FEATURE(STRING_LIST_ELEMENT)[1];
}
if (prop == "CMAKE_CXX98_KNOWN_FEATURES") {
return &FOR_EACH_CXX98_FEATURE(STRING_LIST_ELEMENT)[1];
}
if (prop == "CMAKE_CXX11_KNOWN_FEATURES") {
return &FOR_EACH_CXX11_FEATURE(STRING_LIST_ELEMENT)[1];
}
if (prop == "CMAKE_CXX14_KNOWN_FEATURES") {
return &FOR_EACH_CXX14_FEATURE(STRING_LIST_ELEMENT)[1];
}
if (prop == "CMAKE_CUDA_KNOWN_FEATURES") {
return &FOR_EACH_CUDA_FEATURE(STRING_LIST_ELEMENT)[1];
}
#undef STRING_LIST_ELEMENT
return this->GlobalProperties.GetPropertyValue(prop);
}
bool cmState::GetGlobalPropertyAsBool(const std::string& prop)
{
return cmIsOn(this->GetGlobalProperty(prop));
}
void cmState::SetSourceDirectory(std::string const& sourceDirectory)
{
this->SourceDirectory = sourceDirectory;
cmSystemTools::ConvertToUnixSlashes(this->SourceDirectory);
}
std::string const& cmState::GetSourceDirectory() const
{
return this->SourceDirectory;
}
void cmState::SetBinaryDirectory(std::string const& binaryDirectory)
{
this->BinaryDirectory = binaryDirectory;
cmSystemTools::ConvertToUnixSlashes(this->BinaryDirectory);
}
void cmState::SetWindowsShell(bool windowsShell)
{
this->WindowsShell = windowsShell;
}
bool cmState::UseWindowsShell() const
{
return this->WindowsShell;
}
void cmState::SetWindowsVSIDE(bool windowsVSIDE)
{
this->WindowsVSIDE = windowsVSIDE;
}
bool cmState::UseWindowsVSIDE() const
{
return this->WindowsVSIDE;
}
void cmState::SetGhsMultiIDE(bool ghsMultiIDE)
{
this->GhsMultiIDE = ghsMultiIDE;
}
bool cmState::UseGhsMultiIDE() const
{
return this->GhsMultiIDE;
}
void cmState::SetWatcomWMake(bool watcomWMake)
{
this->WatcomWMake = watcomWMake;
}
bool cmState::UseWatcomWMake() const
{
return this->WatcomWMake;
}
void cmState::SetMinGWMake(bool minGWMake)
{
this->MinGWMake = minGWMake;
}
bool cmState::UseMinGWMake() const
{
return this->MinGWMake;
}
void cmState::SetNMake(bool nMake)
{
this->NMake = nMake;
}
bool cmState::UseNMake() const
{
return this->NMake;
}
void cmState::SetMSYSShell(bool mSYSShell)
{
this->MSYSShell = mSYSShell;
}
bool cmState::UseMSYSShell() const
{
return this->MSYSShell;
}
void cmState::SetNinjaMulti(bool ninjaMulti)
{
this->NinjaMulti = ninjaMulti;
}
bool cmState::UseNinjaMulti() const
{
return this->NinjaMulti;
}
unsigned int cmState::GetCacheMajorVersion() const
{
return this->CacheManager->GetCacheMajorVersion();
}
unsigned int cmState::GetCacheMinorVersion() const
{
return this->CacheManager->GetCacheMinorVersion();
}
cmState::Mode cmState::GetMode() const
{
return this->CurrentMode;
}
std::string cmState::GetModeString() const
{
return ModeToString(this->CurrentMode);
}
void cmState::SetMode(cmState::Mode mode)
{
this->CurrentMode = mode;
}
std::string cmState::ModeToString(cmState::Mode mode)
{
switch (mode) {
case Project:
return "PROJECT";
case Script:
return "SCRIPT";
case FindPackage:
return "FIND_PACKAGE";
case CTest:
return "CTEST";
case CPack:
return "CPACK";
case Unknown:
return "UNKNOWN";
}
return "UNKNOWN";
}
std::string const& cmState::GetBinaryDirectory() const
{
return this->BinaryDirectory;
}
cmStateSnapshot cmState::CreateBaseSnapshot()
{
cmStateDetail::PositionType pos =
this->SnapshotData.Push(this->SnapshotData.Root());
pos->DirectoryParent = this->SnapshotData.Root();
pos->ScopeParent = this->SnapshotData.Root();
pos->SnapshotType = cmStateEnums::BaseType;
pos->Keep = true;
pos->BuildSystemDirectory =
this->BuildsystemDirectory.Push(this->BuildsystemDirectory.Root());
pos->ExecutionListFile =
this->ExecutionListFiles.Push(this->ExecutionListFiles.Root());
pos->IncludeDirectoryPosition = 0;
pos->CompileDefinitionsPosition = 0;
pos->CompileOptionsPosition = 0;
pos->LinkOptionsPosition = 0;
pos->LinkDirectoriesPosition = 0;
pos->BuildSystemDirectory->DirectoryEnd = pos;
pos->Policies = this->PolicyStack.Root();
pos->PolicyRoot = this->PolicyStack.Root();
pos->PolicyScope = this->PolicyStack.Root();
assert(pos->Policies.IsValid());
assert(pos->PolicyRoot.IsValid());
pos->Vars = this->VarTree.Push(this->VarTree.Root());
assert(pos->Vars.IsValid());
pos->Parent = this->VarTree.Root();
pos->Root = this->VarTree.Root();
return { this, pos };
}
cmStateSnapshot cmState::CreateBuildsystemDirectorySnapshot(
cmStateSnapshot const& originSnapshot)
{
assert(originSnapshot.IsValid());
cmStateDetail::PositionType pos =
this->SnapshotData.Push(originSnapshot.Position);
pos->DirectoryParent = originSnapshot.Position;
pos->ScopeParent = originSnapshot.Position;
pos->SnapshotType = cmStateEnums::BuildsystemDirectoryType;
pos->Keep = true;
pos->BuildSystemDirectory = this->BuildsystemDirectory.Push(
originSnapshot.Position->BuildSystemDirectory);
pos->ExecutionListFile =
this->ExecutionListFiles.Push(originSnapshot.Position->ExecutionListFile);
pos->BuildSystemDirectory->DirectoryEnd = pos;
pos->Policies = originSnapshot.Position->Policies;
pos->PolicyRoot = originSnapshot.Position->Policies;
pos->PolicyScope = originSnapshot.Position->Policies;
assert(pos->Policies.IsValid());
assert(pos->PolicyRoot.IsValid());
cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
pos->Parent = origin;
pos->Root = origin;
pos->Vars = this->VarTree.Push(origin);
cmStateSnapshot snapshot = cmStateSnapshot(this, pos);
originSnapshot.Position->BuildSystemDirectory->Children.push_back(snapshot);
snapshot.SetDefaultDefinitions();
snapshot.InitializeFromParent();
snapshot.SetDirectoryDefinitions();
return snapshot;
}
cmStateSnapshot cmState::CreateFunctionCallSnapshot(
cmStateSnapshot const& originSnapshot, std::string const& fileName)
{
cmStateDetail::PositionType pos =
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
pos->ScopeParent = originSnapshot.Position;
pos->SnapshotType = cmStateEnums::FunctionCallType;
pos->Keep = false;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName);
pos->BuildSystemDirectory->DirectoryEnd = pos;
pos->PolicyScope = originSnapshot.Position->Policies;
assert(originSnapshot.Position->Vars.IsValid());
cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
pos->Parent = origin;
pos->Vars = this->VarTree.Push(origin);
return { this, pos };
}
cmStateSnapshot cmState::CreateMacroCallSnapshot(
cmStateSnapshot const& originSnapshot, std::string const& fileName)
{
cmStateDetail::PositionType pos =
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
pos->SnapshotType = cmStateEnums::MacroCallType;
pos->Keep = false;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName);
assert(originSnapshot.Position->Vars.IsValid());
pos->BuildSystemDirectory->DirectoryEnd = pos;
pos->PolicyScope = originSnapshot.Position->Policies;
return { this, pos };
}
cmStateSnapshot cmState::CreateIncludeFileSnapshot(
cmStateSnapshot const& originSnapshot, std::string const& fileName)
{
cmStateDetail::PositionType pos =
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
pos->SnapshotType = cmStateEnums::IncludeFileType;
pos->Keep = true;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName);
assert(originSnapshot.Position->Vars.IsValid());
pos->BuildSystemDirectory->DirectoryEnd = pos;
pos->PolicyScope = originSnapshot.Position->Policies;
return { this, pos };
}
cmStateSnapshot cmState::CreateVariableScopeSnapshot(
cmStateSnapshot const& originSnapshot)
{
cmStateDetail::PositionType pos =
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
pos->ScopeParent = originSnapshot.Position;
pos->SnapshotType = cmStateEnums::VariableScopeType;
pos->Keep = false;
pos->PolicyScope = originSnapshot.Position->Policies;
assert(originSnapshot.Position->Vars.IsValid());
cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
pos->Parent = origin;
pos->Vars = this->VarTree.Push(origin);
assert(pos->Vars.IsValid());
return { this, pos };
}
cmStateSnapshot cmState::CreateInlineListFileSnapshot(
cmStateSnapshot const& originSnapshot, std::string const& fileName)
{
cmStateDetail::PositionType pos =
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
pos->SnapshotType = cmStateEnums::InlineListFileType;
pos->Keep = true;
pos->ExecutionListFile = this->ExecutionListFiles.Push(
originSnapshot.Position->ExecutionListFile, fileName);
pos->BuildSystemDirectory->DirectoryEnd = pos;
pos->PolicyScope = originSnapshot.Position->Policies;
return { this, pos };
}
cmStateSnapshot cmState::CreatePolicyScopeSnapshot(
cmStateSnapshot const& originSnapshot)
{
cmStateDetail::PositionType pos =
this->SnapshotData.Push(originSnapshot.Position, *originSnapshot.Position);
pos->SnapshotType = cmStateEnums::PolicyScopeType;
pos->Keep = false;
pos->BuildSystemDirectory->DirectoryEnd = pos;
pos->PolicyScope = originSnapshot.Position->Policies;
return { this, pos };
}
cmStateSnapshot cmState::Pop(cmStateSnapshot const& originSnapshot)
{
cmStateDetail::PositionType pos = originSnapshot.Position;
cmStateDetail::PositionType prevPos = pos;
++prevPos;
prevPos->IncludeDirectoryPosition =
prevPos->BuildSystemDirectory->IncludeDirectories.size();
prevPos->CompileDefinitionsPosition =
prevPos->BuildSystemDirectory->CompileDefinitions.size();
prevPos->CompileOptionsPosition =
prevPos->BuildSystemDirectory->CompileOptions.size();
prevPos->LinkOptionsPosition =
prevPos->BuildSystemDirectory->LinkOptions.size();
prevPos->LinkDirectoriesPosition =
prevPos->BuildSystemDirectory->LinkDirectories.size();
prevPos->BuildSystemDirectory->DirectoryEnd = prevPos;
if (!pos->Keep && this->SnapshotData.IsLast(pos)) {
if (pos->Vars != prevPos->Vars) {
assert(this->VarTree.IsLast(pos->Vars));
this->VarTree.Pop(pos->Vars);
}
if (pos->ExecutionListFile != prevPos->ExecutionListFile) {
assert(this->ExecutionListFiles.IsLast(pos->ExecutionListFile));
this->ExecutionListFiles.Pop(pos->ExecutionListFile);
}
this->SnapshotData.Pop(pos);
}
return { this, prevPos };
}
static bool ParseEntryWithoutType(const std::string& entry, std::string& var,
std::string& value)
{
// input line is: key=value
static cmsys::RegularExpression reg(
"^([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
// input line is: "key"=value
static cmsys::RegularExpression regQuoted(
"^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
bool flag = false;
if (regQuoted.find(entry)) {
var = regQuoted.match(1);
value = regQuoted.match(2);
flag = true;
} else if (reg.find(entry)) {
var = reg.match(1);
value = reg.match(2);
flag = true;
}
// if value is enclosed in single quotes ('foo') then remove them
// it is used to enclose trailing space or tab
if (flag && value.size() >= 2 && value.front() == '\'' &&
value.back() == '\'') {
value = value.substr(1, value.size() - 2);
}
return flag;
}
bool cmState::ParseCacheEntry(const std::string& entry, std::string& var,
std::string& value,
cmStateEnums::CacheEntryType& type)
{
// input line is: key:type=value
static cmsys::RegularExpression reg(
"^([^=:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
// input line is: "key":type=value
static cmsys::RegularExpression regQuoted(
"^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
bool flag = false;
if (regQuoted.find(entry)) {
var = regQuoted.match(1);
type = cmState::StringToCacheEntryType(regQuoted.match(2));
value = regQuoted.match(3);
flag = true;
} else if (reg.find(entry)) {
var = reg.match(1);
type = cmState::StringToCacheEntryType(reg.match(2));
value = reg.match(3);
flag = true;
}
// if value is enclosed in single quotes ('foo') then remove them
// it is used to enclose trailing space or tab
if (flag && value.size() >= 2 && value.front() == '\'' &&
value.back() == '\'') {
value = value.substr(1, value.size() - 2);
}
if (!flag) {
return ParseEntryWithoutType(entry, var, value);
}
return flag;
}
|