/
cmTarget.cxx
3432 lines (3110 loc) · 113 KB
/
cmTarget.cxx
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
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmTarget.h"
#include <algorithm>
#include <cassert>
#include <iterator>
#include <map>
#include <set>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <cm/memory>
#include <cm/string_view>
#include <cmext/algorithm>
#include <cmext/string_view>
#include "cmsys/RegularExpression.hxx"
#include "cmAlgorithms.h"
#include "cmCustomCommand.h"
#include "cmFileSet.h"
#include "cmFindPackageStack.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalGenerator.h"
#include "cmList.h"
#include "cmListFileCache.h"
#include "cmMakefile.h"
#include "cmMessageType.h"
#include "cmProperty.h"
#include "cmPropertyDefinition.h"
#include "cmPropertyMap.h"
#include "cmRange.h"
#include "cmSourceFile.h"
#include "cmSourceFileLocation.h"
#include "cmSourceFileLocationKind.h"
#include "cmState.h"
#include "cmStateDirectory.h"
#include "cmStateSnapshot.h"
#include "cmSystemTools.h"
#include "cmTargetPropertyComputer.h"
#include "cmValue.h"
#include "cmXcFramework.h"
#include "cmake.h"
template <>
const std::string& cmTargetPropertyComputer::ComputeLocationForBuild<cmTarget>(
cmTarget const* tgt)
{
static std::string loc;
if (tgt->IsImported()) {
loc = tgt->ImportedGetFullPath("", cmStateEnums::RuntimeBinaryArtifact);
return loc;
}
cmGlobalGenerator* gg = tgt->GetGlobalGenerator();
if (!gg->GetConfigureDoneCMP0026()) {
gg->CreateGenerationObjects();
}
cmGeneratorTarget* gt = gg->FindGeneratorTarget(tgt->GetName());
loc = gt->GetLocationForBuild();
return loc;
}
template <>
const std::string& cmTargetPropertyComputer::ComputeLocation<cmTarget>(
cmTarget const* tgt, const std::string& config)
{
static std::string loc;
if (tgt->IsImported()) {
loc =
tgt->ImportedGetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
return loc;
}
cmGlobalGenerator* gg = tgt->GetGlobalGenerator();
if (!gg->GetConfigureDoneCMP0026()) {
gg->CreateGenerationObjects();
}
cmGeneratorTarget* gt = gg->FindGeneratorTarget(tgt->GetName());
loc = gt->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
return loc;
}
template <>
cmValue cmTargetPropertyComputer::GetSources<cmTarget>(cmTarget const* tgt,
cmMakefile const& mf)
{
cmBTStringRange entries = tgt->GetSourceEntries();
if (entries.empty()) {
return nullptr;
}
std::ostringstream ss;
const char* sep = "";
for (auto const& entry : entries) {
cmList files{ entry.Value };
for (std::string const& file : files) {
if (cmHasLiteralPrefix(file, "$<TARGET_OBJECTS:") &&
file.back() == '>') {
std::string objLibName = file.substr(17, file.size() - 18);
if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
ss << sep;
sep = ";";
ss << file;
continue;
}
bool addContent = false;
bool noMessage = true;
std::ostringstream e;
MessageType messageType = MessageType::AUTHOR_WARNING;
switch (mf.GetPolicyStatus(cmPolicies::CMP0051)) {
case cmPolicies::WARN:
e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0051) << "\n";
noMessage = false;
CM_FALLTHROUGH;
case cmPolicies::OLD:
break;
case cmPolicies::REQUIRED_ALWAYS:
case cmPolicies::REQUIRED_IF_USED:
case cmPolicies::NEW:
addContent = true;
break;
}
if (!noMessage) {
e << "Target \"" << tgt->GetName()
<< "\" contains $<TARGET_OBJECTS> generator expression in its "
"sources list. This content was not previously part of the "
"SOURCES property when that property was read at configure "
"time. Code reading that property needs to be adapted to "
"ignore the generator expression using the string(GENEX_STRIP) "
"command.";
mf.IssueMessage(messageType, e.str());
}
if (addContent) {
ss << sep;
sep = ";";
ss << file;
}
} else if (cmGeneratorExpression::Find(file) == std::string::npos) {
ss << sep;
sep = ";";
ss << file;
} else {
cmSourceFile* sf = tgt->GetMakefile()->GetOrCreateSource(file);
// Construct what is known about this source file location.
cmSourceFileLocation const& location = sf->GetLocation();
std::string sname = location.GetDirectory();
if (!sname.empty()) {
sname += "/";
}
sname += location.GetName();
ss << sep;
sep = ";";
// Append this list entry.
ss << sname;
}
}
}
static std::string srcs;
srcs = ss.str();
return cmValue(srcs);
}
namespace {
struct FileSetEntries
{
FileSetEntries(cm::static_string_view propertyName)
: PropertyName(propertyName)
{
}
cm::static_string_view const PropertyName;
std::vector<BT<std::string>> Entries;
};
struct FileSetType
{
FileSetType(cm::static_string_view typeName,
cm::static_string_view defaultDirectoryProperty,
cm::static_string_view defaultPathProperty,
cm::static_string_view directoryPrefix,
cm::static_string_view pathPrefix,
cm::static_string_view typeDescription,
cm::static_string_view defaultDescription,
cm::static_string_view arbitraryDescription,
FileSetEntries selfEntries, FileSetEntries interfaceEntries)
: TypeName(typeName)
, DefaultDirectoryProperty(defaultDirectoryProperty)
, DefaultPathProperty(defaultPathProperty)
, DirectoryPrefix(directoryPrefix)
, PathPrefix(pathPrefix)
, TypeDescription(typeDescription)
, DefaultDescription(defaultDescription)
, ArbitraryDescription(arbitraryDescription)
, SelfEntries(std::move(selfEntries))
, InterfaceEntries(std::move(interfaceEntries))
{
}
cm::static_string_view const TypeName;
cm::static_string_view const DefaultDirectoryProperty;
cm::static_string_view const DefaultPathProperty;
cm::static_string_view const DirectoryPrefix;
cm::static_string_view const PathPrefix;
cm::static_string_view const TypeDescription;
cm::static_string_view const DefaultDescription;
cm::static_string_view const ArbitraryDescription;
FileSetEntries SelfEntries;
FileSetEntries InterfaceEntries;
enum class Action
{
Set,
Append,
};
template <typename ValueType>
bool WriteProperties(cmTarget* tgt, cmTargetInternals* impl,
const std::string& prop, ValueType value,
Action action);
std::pair<bool, cmValue> ReadProperties(cmTarget const* tgt,
cmTargetInternals const* impl,
const std::string& prop) const;
void AddFileSet(const std::string& name, cmFileSetVisibility vis,
cmListFileBacktrace bt);
};
struct UsageRequirementProperty
{
enum class AppendEmpty
{
Yes,
No,
};
UsageRequirementProperty(cm::static_string_view name,
AppendEmpty appendEmpty = AppendEmpty::No)
: Name(name)
, AppendBehavior(appendEmpty)
{
}
void CopyFromEntries(cmBTStringRange entries)
{
return cm::append(this->Entries, entries);
}
enum class Action
{
Set,
Prepend,
Append,
};
template <typename ValueType>
bool Write(cmTargetInternals const* impl,
cm::optional<cmListFileBacktrace> const& bt,
const std::string& prop, ValueType value, Action action);
template <typename ValueType>
void WriteDirect(cmTargetInternals const* impl,
cm::optional<cmListFileBacktrace> const& bt,
ValueType value, Action action);
void WriteDirect(BT<std::string> value, Action action);
std::pair<bool, cmValue> Read(const std::string& prop) const;
cm::static_string_view const Name;
AppendEmpty const AppendBehavior;
std::vector<BT<std::string>> Entries;
};
struct TargetProperty
{
enum class InitCondition
{
// Always initialize the property.
Always,
// Never initialize the property.
Never,
// Only initialize if the target can compile sources.
CanCompileSources,
// Only apply to Xcode generators.
NeedsXcode,
// Only apply to Xcode generators on targets that can compile sources.
NeedsXcodeAndCanCompileSources,
// Needs to be a "normal" target (any non-global, non-utility target).
NormalTarget,
// Any non-imported target.
NonImportedTarget,
// Needs to be a "normal" target (any non-global, non-utility target) that
// is not `IMPORTED`.
NormalNonImportedTarget,
// Needs to be a "normal" target with an artifact (no `INTERFACE`
// libraries).
TargetWithArtifact,
// Needs to be a "normal" target with an artifact that is not an
// executable.
NonExecutableWithArtifact,
// Needs to be a linkable library target (no `OBJECT` or `MODULE`
// libraries).
LinkableLibraryTarget,
// Needs to be an executable.
ExecutableTarget,
// Needs to be a shared library (`SHARED`).
SharedLibraryTarget,
// Needs to be a target with meaningful symbol exports (`SHARED` or
// `EXECUTABLE`).
TargetWithSymbolExports,
// Targets with "commands" associated with them. Basically everything
// except global and `INTERFACE` targets.
TargetWithCommands,
};
enum class Repetition
{
Once,
PerConfig,
PerConfigPrefix,
};
TargetProperty(cm::static_string_view name)
: Name(name)
{
}
TargetProperty(cm::static_string_view name, cm::static_string_view dflt,
InitCondition init)
: Name(name)
, Default(dflt)
, InitConditional(init)
{
}
TargetProperty(cm::static_string_view name, InitCondition init)
: Name(name)
, InitConditional(init)
{
}
TargetProperty(cm::static_string_view name, InitCondition init,
Repetition repeat)
: Name(name)
, InitConditional(init)
, Repeat(repeat)
{
}
cm::static_string_view const Name;
cm::optional<cm::static_string_view> const Default = {};
InitCondition const InitConditional = InitCondition::Always;
Repetition const Repeat = Repetition::Once;
};
#define IC TargetProperty::InitCondition
#define R TargetProperty::Repetition
/* clang-format off */
#define COMMON_LANGUAGE_PROPERTIES(lang) \
{ #lang "_COMPILER_LAUNCHER"_s, IC::CanCompileSources }, \
{ #lang "_STANDARD"_s, IC::CanCompileSources }, \
{ #lang "_STANDARD_REQUIRED"_s, IC::CanCompileSources }, \
{ #lang "_EXTENSIONS"_s, IC::CanCompileSources }, \
{ #lang "_VISIBILITY_PRESET"_s, IC::CanCompileSources }
/* clang-format on */
TargetProperty const StaticTargetProperties[] = {
/* clang-format off */
// Compilation properties
{ "COMPILE_WARNING_AS_ERROR"_s, IC::CanCompileSources },
{ "INTERPROCEDURAL_OPTIMIZATION"_s, IC::CanCompileSources },
{ "INTERPROCEDURAL_OPTIMIZATION_"_s, IC::TargetWithArtifact, R::PerConfig },
{ "NO_SYSTEM_FROM_IMPORTED"_s, IC::CanCompileSources },
// Set to `True` for `SHARED` and `MODULE` targets.
{ "POSITION_INDEPENDENT_CODE"_s, IC::CanCompileSources },
{ "VISIBILITY_INLINES_HIDDEN"_s, IC::CanCompileSources },
// -- Features
// ---- PCH
{ "DISABLE_PRECOMPILE_HEADERS"_s, IC::CanCompileSources },
{ "PCH_WARN_INVALID"_s, "ON"_s, IC::CanCompileSources },
{ "PCH_INSTANTIATE_TEMPLATES"_s, "ON"_s, IC::CanCompileSources },
// -- Platforms
// ---- Android
{ "ANDROID_API"_s, IC::CanCompileSources },
{ "ANDROID_API_MIN"_s, IC::CanCompileSources },
{ "ANDROID_ARCH"_s, IC::CanCompileSources },
{ "ANDROID_ASSETS_DIRECTORIES"_s, IC::CanCompileSources },
{ "ANDROID_JAVA_SOURCE_DIR"_s, IC::CanCompileSources },
{ "ANDROID_STL_TYPE"_s, IC::CanCompileSources },
// ---- macOS
{ "OSX_ARCHITECTURES"_s, IC::CanCompileSources },
// ---- Windows
{ "MSVC_DEBUG_INFORMATION_FORMAT"_s, IC::CanCompileSources },
{ "MSVC_RUNTIME_LIBRARY"_s, IC::CanCompileSources },
{ "VS_JUST_MY_CODE_DEBUGGING"_s, IC::CanCompileSources },
{ "VS_DEBUGGER_COMMAND"_s, IC::ExecutableTarget },
{ "VS_DEBUGGER_COMMAND_ARGUMENTS"_s, IC::ExecutableTarget },
{ "VS_DEBUGGER_ENVIRONMENT"_s, IC::ExecutableTarget },
{ "VS_DEBUGGER_WORKING_DIRECTORY"_s, IC::ExecutableTarget },
{ "VS_USE_DEBUG_LIBRARIES"_s, IC::NonImportedTarget },
// ---- OpenWatcom
{ "WATCOM_RUNTIME_LIBRARY"_s, IC::CanCompileSources },
// -- Language
// ---- C
COMMON_LANGUAGE_PROPERTIES(C),
// ---- C++
COMMON_LANGUAGE_PROPERTIES(CXX),
{ "CXX_MODULE_STD"_s, IC::CanCompileSources },
// ---- CSharp
{ "DOTNET_SDK"_s, IC::NonImportedTarget },
{ "DOTNET_TARGET_FRAMEWORK"_s, IC::TargetWithCommands },
{ "DOTNET_TARGET_FRAMEWORK_VERSION"_s, IC::TargetWithCommands },
// ---- CUDA
COMMON_LANGUAGE_PROPERTIES(CUDA),
{ "CUDA_SEPARABLE_COMPILATION"_s, IC::CanCompileSources },
{ "CUDA_ARCHITECTURES"_s, IC::CanCompileSources },
// ---- Fortran
{ "Fortran_FORMAT"_s, IC::CanCompileSources },
{ "Fortran_MODULE_DIRECTORY"_s, IC::CanCompileSources },
{ "Fortran_COMPILER_LAUNCHER"_s, IC::CanCompileSources },
{ "Fortran_PREPROCESS"_s, IC::CanCompileSources },
{ "Fortran_VISIBILITY_PRESET"_s, IC::CanCompileSources },
// ---- HIP
COMMON_LANGUAGE_PROPERTIES(HIP),
{ "HIP_ARCHITECTURES"_s, IC::CanCompileSources },
// ---- ISPC
{ "ISPC_COMPILER_LAUNCHER"_s, IC::CanCompileSources },
{ "ISPC_HEADER_DIRECTORY"_s, IC::CanCompileSources },
{ "ISPC_HEADER_SUFFIX"_s, "_ispc.h"_s, IC::CanCompileSources },
{ "ISPC_INSTRUCTION_SETS"_s, IC::CanCompileSources },
// ---- Objective C
COMMON_LANGUAGE_PROPERTIES(OBJC),
// ---- Objective C++
COMMON_LANGUAGE_PROPERTIES(OBJCXX),
// ---- Swift
{ "Swift_LANGUAGE_VERSION"_s, IC::CanCompileSources },
{ "Swift_MODULE_DIRECTORY"_s, IC::CanCompileSources },
{ "Swift_COMPILATION_MODE"_s, IC::CanCompileSources },
// ---- moc
{ "AUTOMOC"_s, IC::CanCompileSources },
{ "AUTOMOC_COMPILER_PREDEFINES"_s, IC::CanCompileSources },
{ "AUTOMOC_MACRO_NAMES"_s, IC::CanCompileSources },
{ "AUTOMOC_MOC_OPTIONS"_s, IC::CanCompileSources },
{ "AUTOMOC_PATH_PREFIX"_s, IC::CanCompileSources },
{ "AUTOMOC_EXECUTABLE"_s, IC::CanCompileSources },
// ---- uic
{ "AUTOUIC"_s, IC::CanCompileSources },
{ "AUTOUIC_OPTIONS"_s, IC::CanCompileSources },
{ "AUTOUIC_SEARCH_PATHS"_s, IC::CanCompileSources },
{ "AUTOUIC_EXECUTABLE"_s, IC::CanCompileSources },
// ---- rcc
{ "AUTORCC"_s, IC::CanCompileSources },
{ "AUTORCC_OPTIONS"_s, IC::CanCompileSources },
{ "AUTORCC_EXECUTABLE"_s, IC::CanCompileSources },
// Linking properties
{ "LINKER_TYPE"_s, IC::CanCompileSources },
{ "ENABLE_EXPORTS"_s, IC::TargetWithSymbolExports },
{ "LINK_LIBRARIES_ONLY_TARGETS"_s, IC::NormalNonImportedTarget },
{ "LINK_SEARCH_START_STATIC"_s, IC::CanCompileSources },
{ "LINK_SEARCH_END_STATIC"_s, IC::CanCompileSources },
// Initialize per-configuration name postfix property from the variable only
// for non-executable targets. This preserves compatibility with previous
// CMake versions in which executables did not support this variable.
// Projects may still specify the property directly.
{ "_POSTFIX"_s, IC::NonExecutableWithArtifact, R::PerConfigPrefix },
// -- Dependent library lookup
{ "MACOSX_RPATH"_s, IC::CanCompileSources },
// ---- Build
{ "BUILD_RPATH"_s, IC::CanCompileSources },
{ "BUILD_RPATH_USE_ORIGIN"_s, IC::CanCompileSources },
{ "SKIP_BUILD_RPATH"_s, "OFF"_s, IC::CanCompileSources },
{ "BUILD_WITH_INSTALL_RPATH"_s, "OFF"_s, IC::CanCompileSources },
{ "BUILD_WITH_INSTALL_NAME_DIR"_s, IC::CanCompileSources },
// ---- Install
{ "INSTALL_NAME_DIR"_s, IC::CanCompileSources },
{ "INSTALL_REMOVE_ENVIRONMENT_RPATH"_s, IC::CanCompileSources },
{ "INSTALL_RPATH"_s, ""_s, IC::CanCompileSources },
{ "INSTALL_RPATH_USE_LINK_PATH"_s, "OFF"_s, IC::CanCompileSources },
// -- Platforms
// ---- AIX
{ "AIX_EXPORT_ALL_SYMBOLS"_s, IC::TargetWithSymbolExports },
// ---- Android
{ "ANDROID_GUI"_s, IC::ExecutableTarget },
{ "ANDROID_JAR_DIRECTORIES"_s, IC::CanCompileSources },
{ "ANDROID_JAR_DEPENDENCIES"_s, IC::CanCompileSources },
{ "ANDROID_NATIVE_LIB_DIRECTORIES"_s, IC::CanCompileSources },
{ "ANDROID_NATIVE_LIB_DEPENDENCIES"_s, IC::CanCompileSources },
{ "ANDROID_PROGUARD"_s, IC::CanCompileSources },
{ "ANDROID_PROGUARD_CONFIG_PATH"_s, IC::CanCompileSources },
{ "ANDROID_SECURE_PROPS_PATH"_s, IC::CanCompileSources },
// ---- iOS
{ "IOS_INSTALL_COMBINED"_s, IC::CanCompileSources },
// ---- macOS
{ "FRAMEWORK_MULTI_CONFIG_POSTFIX_"_s, IC::LinkableLibraryTarget, R::PerConfig },
// ---- Windows
{ "DLL_NAME_WITH_SOVERSION"_s, IC::SharedLibraryTarget },
{ "GNUtoMS"_s, IC::CanCompileSources },
{ "WIN32_EXECUTABLE"_s, IC::CanCompileSources },
{ "WINDOWS_EXPORT_ALL_SYMBOLS"_s, IC::TargetWithSymbolExports },
// -- Languages
// ---- C
{ "C_LINKER_LAUNCHER"_s, IC::CanCompileSources },
// ---- C++
{ "CXX_LINKER_LAUNCHER"_s, IC::CanCompileSources },
// ---- CUDA
{ "CUDA_RESOLVE_DEVICE_SYMBOLS"_s, IC::CanCompileSources },
{ "CUDA_RUNTIME_LIBRARY"_s, IC::CanCompileSources },
// ---- HIP
{ "HIP_RUNTIME_LIBRARY"_s, IC::CanCompileSources },
// ---- Objective C
{ "OBJC_LINKER_LAUNCHER"_s, IC::CanCompileSources },
// ---- Objective C++
{ "OBJCXX_LINKER_LAUNCHER"_s, IC::CanCompileSources },
// Static analysis
// -- C
{ "C_CLANG_TIDY"_s, IC::CanCompileSources },
{ "C_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
{ "C_CPPLINT"_s, IC::CanCompileSources },
{ "C_CPPCHECK"_s, IC::CanCompileSources },
{ "C_INCLUDE_WHAT_YOU_USE"_s, IC::CanCompileSources },
// -- C++
{ "CXX_CLANG_TIDY"_s, IC::CanCompileSources },
{ "CXX_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
{ "CXX_CPPLINT"_s, IC::CanCompileSources },
{ "CXX_CPPCHECK"_s, IC::CanCompileSources },
{ "CXX_INCLUDE_WHAT_YOU_USE"_s, IC::CanCompileSources },
// -- Objective C
{ "OBJC_CLANG_TIDY"_s, IC::CanCompileSources },
{ "OBJC_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
// -- Objective C++
{ "OBJCXX_CLANG_TIDY"_s, IC::CanCompileSources },
{ "OBJCXX_CLANG_TIDY_EXPORT_FIXES_DIR"_s, IC::CanCompileSources },
// -- Linking
{ "LINK_WHAT_YOU_USE"_s, IC::CanCompileSources },
// Build graph properties
{ "LINK_DEPENDS_NO_SHARED"_s, IC::CanCompileSources },
{ "UNITY_BUILD"_s, IC::CanCompileSources },
{ "UNITY_BUILD_UNIQUE_ID"_s, IC::CanCompileSources },
{ "UNITY_BUILD_BATCH_SIZE"_s, "8"_s, IC::CanCompileSources },
{ "UNITY_BUILD_MODE"_s, "BATCH"_s, IC::CanCompileSources },
{ "OPTIMIZE_DEPENDENCIES"_s, IC::CanCompileSources },
{ "VERIFY_INTERFACE_HEADER_SETS"_s },
// -- Android
{ "ANDROID_ANT_ADDITIONAL_OPTIONS"_s, IC::CanCompileSources },
{ "ANDROID_PROCESS_MAX"_s, IC::CanCompileSources },
{ "ANDROID_SKIP_ANT_STEP"_s, IC::CanCompileSources },
// -- Autogen
{ "AUTOGEN_COMMAND_LINE_LENGTH_MAX"_s, IC::CanCompileSources },
{ "AUTOGEN_ORIGIN_DEPENDS"_s, IC::CanCompileSources },
{ "AUTOGEN_PARALLEL"_s, IC::CanCompileSources },
{ "AUTOGEN_USE_SYSTEM_INCLUDE"_s, IC::CanCompileSources },
{ "AUTOGEN_BETTER_GRAPH_MULTI_CONFIG"_s, IC::CanCompileSources },
// -- moc
{ "AUTOMOC_DEPEND_FILTERS"_s, IC::CanCompileSources },
// -- C++
{ "CXX_SCAN_FOR_MODULES"_s, IC::CanCompileSources },
// -- Ninja
{ "JOB_POOL_COMPILE"_s, IC::CanCompileSources },
{ "JOB_POOL_LINK"_s, IC::CanCompileSources },
{ "JOB_POOL_PRECOMPILE_HEADER"_s, IC::CanCompileSources },
// -- Visual Studio
{ "VS_NO_COMPILE_BATCHING"_s, IC::CanCompileSources },
{ "VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION"_s, IC::CanCompileSources},
// Output location properties
{ "ARCHIVE_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
{ "ARCHIVE_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
{ "COMPILE_PDB_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
{ "COMPILE_PDB_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
{ "LIBRARY_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
{ "LIBRARY_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
{ "PDB_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
{ "PDB_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
{ "RUNTIME_OUTPUT_DIRECTORY"_s, IC::CanCompileSources },
{ "RUNTIME_OUTPUT_DIRECTORY_"_s, IC::TargetWithArtifact, R::PerConfig },
// macOS bundle properties
{ "FRAMEWORK"_s, IC::CanCompileSources },
{ "FRAMEWORK_MULTI_CONFIG_POSTFIX"_s, IC::CanCompileSources },
{ "MACOSX_BUNDLE"_s, IC::CanCompileSources },
// Usage requirement properties
{ "LINK_INTERFACE_LIBRARIES"_s, IC::CanCompileSources },
{ "MAP_IMPORTED_CONFIG_"_s, IC::NormalTarget, R::PerConfig },
{ "EXPORT_FIND_PACKAGE_NAME"_s, IC::NormalTarget },
// Metadata
{ "CROSSCOMPILING_EMULATOR"_s, IC::ExecutableTarget },
{ "EXPORT_COMPILE_COMMANDS"_s, IC::CanCompileSources },
{ "FOLDER"_s },
{ "TEST_LAUNCHER"_s, IC::ExecutableTarget },
// Xcode properties
{ "XCODE_GENERATE_SCHEME"_s, IC::NeedsXcode },
#ifdef __APPLE__
{ "XCODE_SCHEME_ADDRESS_SANITIZER"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_ADDRESS_SANITIZER_USE_AFTER_RETURN"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_DEBUG_DOCUMENT_VERSIONING"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_ENABLE_GPU_FRAME_CAPTURE_MODE"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_THREAD_SANITIZER"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_THREAD_SANITIZER_STOP"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_UNDEFINED_BEHAVIOUR_SANITIZER_STOP"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_LAUNCH_CONFIGURATION"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_ENABLE_GPU_API_VALIDATION"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_ENABLE_GPU_SHADER_VALIDATION"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_WORKING_DIRECTORY"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_DISABLE_MAIN_THREAD_CHECKER"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_MAIN_THREAD_CHECKER_STOP"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_MALLOC_SCRIBBLE"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_MALLOC_GUARD_EDGES"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_GUARD_MALLOC"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_LAUNCH_MODE"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_ZOMBIE_OBJECTS"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_MALLOC_STACK"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_DYNAMIC_LINKER_API_USAGE"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_DYNAMIC_LIBRARY_LOADS"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_SCHEME_ENVIRONMENT"_s, IC::NeedsXcodeAndCanCompileSources },
{ "XCODE_LINK_BUILD_PHASE_MODE"_s, "NONE"_s, IC::NeedsXcodeAndCanCompileSources },
#endif
/* clang-format on */
};
#undef COMMON_LANGUAGE_PROPERTIES
#undef IC
#undef R
}
class cmTargetInternals
{
public:
cmStateEnums::TargetType TargetType;
cmMakefile* Makefile;
cmPolicies::PolicyMap PolicyMap;
std::string Name;
std::string InstallPath;
std::string RuntimeInstallPath;
cmPropertyMap Properties;
bool IsGeneratorProvided;
bool HaveInstallRule;
bool IsDLLPlatform;
bool IsAIX;
bool IsApple;
bool IsAndroid;
bool BuildInterfaceIncludesAppended;
bool PerConfig;
cmTarget::Visibility TargetVisibility;
std::set<BT<std::pair<std::string, bool>>> Utilities;
std::vector<cmCustomCommand> PreBuildCommands;
std::vector<cmCustomCommand> PreLinkCommands;
std::vector<cmCustomCommand> PostBuildCommands;
std::vector<cmInstallTargetGenerator*> InstallGenerators;
std::set<std::string> SystemIncludeDirectories;
cmTarget::LinkLibraryVectorType OriginalLinkLibraries;
std::map<std::string, BTs<std::string>> LanguageStandardProperties;
std::map<cmTargetExport const*, std::vector<std::string>>
InstallIncludeDirectoriesEntries;
std::vector<std::pair<cmTarget::TLLSignature, cmListFileContext>>
TLLCommands;
std::map<std::string, cmFileSet> FileSets;
cmListFileBacktrace Backtrace;
cmFindPackageStack FindPackageStack;
UsageRequirementProperty IncludeDirectories;
UsageRequirementProperty CompileOptions;
UsageRequirementProperty CompileFeatures;
UsageRequirementProperty CompileDefinitions;
UsageRequirementProperty PrecompileHeaders;
UsageRequirementProperty Sources;
UsageRequirementProperty LinkOptions;
UsageRequirementProperty LinkDirectories;
UsageRequirementProperty LinkLibraries;
UsageRequirementProperty InterfaceLinkLibraries;
UsageRequirementProperty InterfaceLinkLibrariesDirect;
UsageRequirementProperty InterfaceLinkLibrariesDirectExclude;
UsageRequirementProperty ImportedCxxModulesIncludeDirectories;
UsageRequirementProperty ImportedCxxModulesCompileDefinitions;
UsageRequirementProperty ImportedCxxModulesCompileFeatures;
UsageRequirementProperty ImportedCxxModulesCompileOptions;
UsageRequirementProperty ImportedCxxModulesLinkLibraries;
FileSetType HeadersFileSets;
FileSetType CxxModulesFileSets;
cmTargetInternals();
bool IsImported() const;
bool CheckImportedLibName(std::string const& prop,
std::string const& value) const;
std::string ProcessSourceItemCMP0049(const std::string& s) const;
template <typename ValueType>
void AddDirectoryToFileSet(cmTarget* self, std::string const& fileSetName,
ValueType value, cm::string_view fileSetType,
cm::string_view description,
FileSetType::Action action);
template <typename ValueType>
void AddPathToFileSet(cmTarget* self, std::string const& fileSetName,
ValueType value, cm::string_view fileSetType,
cm::string_view description,
FileSetType::Action action);
cmValue GetFileSetDirectories(cmTarget const* self,
std::string const& fileSetName,
cm::string_view fileSetType) const;
cmValue GetFileSetPaths(cmTarget const* self, std::string const& fileSetName,
cm::string_view fileSetType) const;
cmListFileBacktrace GetBacktrace(
cm::optional<cmListFileBacktrace> const& bt) const
{
return bt ? *bt : this->Makefile->GetBacktrace();
}
};
cmTargetInternals::cmTargetInternals()
: IncludeDirectories("INCLUDE_DIRECTORIES"_s)
, CompileOptions("COMPILE_OPTIONS"_s)
, CompileFeatures("COMPILE_FEATURES"_s)
, CompileDefinitions("COMPILE_DEFINITIONS"_s)
, PrecompileHeaders("PRECOMPILE_HEADERS"_s)
, Sources("SOURCES"_s, UsageRequirementProperty::AppendEmpty::Yes)
, LinkOptions("LINK_OPTIONS"_s)
, LinkDirectories("LINK_DIRECTORIES"_s)
, LinkLibraries("LINK_LIBRARIES"_s)
, InterfaceLinkLibraries("INTERFACE_LINK_LIBRARIES"_s)
, InterfaceLinkLibrariesDirect("INTERFACE_LINK_LIBRARIES_DIRECT"_s)
, InterfaceLinkLibrariesDirectExclude(
"INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE"_s)
, ImportedCxxModulesIncludeDirectories(
"IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES"_s)
, ImportedCxxModulesCompileDefinitions(
"IMPORTED_CXX_MODULES_COMPILE_DEFINITIONS"_s)
, ImportedCxxModulesCompileFeatures(
"IMPORTED_CXX_MODULES_COMPILE_FEATURES"_s)
, ImportedCxxModulesCompileOptions("IMPORTED_CXX_MODULES_COMPILE_OPTIONS"_s)
, ImportedCxxModulesLinkLibraries("IMPORTED_CXX_MODULES_LINK_LIBRARIES"_s)
, HeadersFileSets("HEADERS"_s, "HEADER_DIRS"_s, "HEADER_SET"_s,
"HEADER_DIRS_"_s, "HEADER_SET_"_s, "Header"_s,
"The default header set"_s, "Header set"_s,
FileSetEntries("HEADER_SETS"_s),
FileSetEntries("INTERFACE_HEADER_SETS"_s))
, CxxModulesFileSets("CXX_MODULES"_s, "CXX_MODULE_DIRS"_s,
"CXX_MODULE_SET"_s, "CXX_MODULE_DIRS_"_s,
"CXX_MODULE_SET_"_s, "C++ module"_s,
"The default C++ module set"_s, "C++ module set"_s,
FileSetEntries("CXX_MODULE_SETS"_s),
FileSetEntries("INTERFACE_CXX_MODULE_SETS"_s))
{
}
template <typename ValueType>
bool FileSetType::WriteProperties(cmTarget* tgt, cmTargetInternals* impl,
const std::string& prop, ValueType value,
Action action)
{
if (prop == this->DefaultDirectoryProperty) {
impl->AddDirectoryToFileSet(tgt, std::string(this->TypeName), value,
this->TypeName, this->DefaultDescription,
action);
return true;
}
if (prop == this->DefaultPathProperty) {
impl->AddPathToFileSet(tgt, std::string(this->TypeName), value,
this->TypeName, this->DefaultDescription, action);
return true;
}
if (cmHasPrefix(prop, this->DirectoryPrefix)) {
auto fileSetName = prop.substr(this->DirectoryPrefix.size());
if (fileSetName.empty()) {
impl->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat(this->ArbitraryDescription, " name cannot be empty."));
} else {
impl->AddDirectoryToFileSet(
tgt, fileSetName, value, this->TypeName,
cmStrCat(this->ArbitraryDescription, " \"", fileSetName, "\""),
action);
}
return true;
}
if (cmHasPrefix(prop, this->PathPrefix)) {
auto fileSetName = prop.substr(this->PathPrefix.size());
if (fileSetName.empty()) {
impl->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat(this->ArbitraryDescription, " name cannot be empty."));
} else {
impl->AddPathToFileSet(
tgt, fileSetName, value, this->TypeName,
cmStrCat(this->ArbitraryDescription, " \"", fileSetName, "\""),
action);
}
return true;
}
return false;
}
std::pair<bool, cmValue> FileSetType::ReadProperties(
cmTarget const* tgt, cmTargetInternals const* impl,
const std::string& prop) const
{
bool did_read = false;
cmValue value = nullptr;
if (prop == this->DefaultDirectoryProperty) {
value = impl->GetFileSetDirectories(tgt, std::string(this->TypeName),
this->TypeName);
did_read = true;
} else if (prop == this->DefaultPathProperty) {
value =
impl->GetFileSetPaths(tgt, std::string(this->TypeName), this->TypeName);
did_read = true;
} else if (prop == this->SelfEntries.PropertyName) {
static std::string output;
output = cmList::to_string(this->SelfEntries.Entries);
value = cmValue(output);
did_read = true;
} else if (prop == this->InterfaceEntries.PropertyName) {
static std::string output;
output = cmList::to_string(this->InterfaceEntries.Entries);
value = cmValue(output);
did_read = true;
} else if (cmHasPrefix(prop, this->DirectoryPrefix)) {
std::string fileSetName = prop.substr(this->DirectoryPrefix.size());
if (!fileSetName.empty()) {
value = impl->GetFileSetDirectories(tgt, fileSetName, this->TypeName);
}
did_read = true;
} else if (cmHasPrefix(prop, this->PathPrefix)) {
std::string fileSetName = prop.substr(this->PathPrefix.size());
if (!fileSetName.empty()) {
value = impl->GetFileSetPaths(tgt, fileSetName, this->TypeName);
}
did_read = true;
}
return { did_read, value };
}
void FileSetType::AddFileSet(const std::string& name, cmFileSetVisibility vis,
cmListFileBacktrace bt)
{
if (cmFileSetVisibilityIsForSelf(vis)) {
this->SelfEntries.Entries.emplace_back(name, bt);
}
if (cmFileSetVisibilityIsForInterface(vis)) {
this->InterfaceEntries.Entries.emplace_back(name, std::move(bt));
}
}
template <typename ValueType>
bool UsageRequirementProperty::Write(
cmTargetInternals const* impl, cm::optional<cmListFileBacktrace> const& bt,
const std::string& prop, ValueType value, Action action)
{
if (prop == this->Name) {
this->WriteDirect(impl, bt, value, action);
return true;
}
return false;
}
template <typename ValueType>
void UsageRequirementProperty::WriteDirect(
cmTargetInternals const* impl, cm::optional<cmListFileBacktrace> const& bt,
ValueType value, Action action)
{
if (action == Action::Set) {
this->Entries.clear();
}
if (value) {
cmListFileBacktrace lfbt = impl->GetBacktrace(bt);
if (action == Action::Prepend) {
this->Entries.emplace(this->Entries.begin(), value, lfbt);
} else if (action == Action::Set || cmNonempty(value) ||
this->AppendBehavior == AppendEmpty::Yes) {
this->Entries.emplace_back(value, lfbt);
}
}
}
void UsageRequirementProperty::WriteDirect(BT<std::string> value,
Action action)
{
if (action == Action::Set) {
this->Entries.clear();
}
if (action == Action::Prepend) {
this->Entries.emplace(this->Entries.begin(), std::move(value));
} else {
this->Entries.emplace_back(std::move(value));
}
}
std::pair<bool, cmValue> UsageRequirementProperty::Read(
const std::string& prop) const
{
bool did_read = false;
cmValue value = nullptr;
if (prop == this->Name) {
if (!this->Entries.empty()) {
// Storage to back the returned `cmValue`.
static std::string output;
output = cmList::to_string(this->Entries);
value = cmValue(output);
}
did_read = true;
}
return { did_read, value };
}
cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
Visibility vis, cmMakefile* mf, PerConfig perConfig)
: impl(cm::make_unique<cmTargetInternals>())
{
assert(mf);
this->impl->TargetType = type;
this->impl->Makefile = mf;
this->impl->Name = name;
this->impl->IsGeneratorProvided = false;
this->impl->HaveInstallRule = false;
this->impl->IsDLLPlatform = false;
this->impl->IsAIX = false;
this->impl->IsApple = false;
this->impl->IsAndroid = false;
this->impl->TargetVisibility = vis;
this->impl->BuildInterfaceIncludesAppended = false;
this->impl->PerConfig = (perConfig == PerConfig::Yes);
// Check whether this is a DLL platform.
this->impl->IsDLLPlatform =
!this->impl->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")
.empty();
// Check whether we are targeting AIX.
{
std::string const& systemName =
this->impl->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME");
this->impl->IsAIX = (systemName == "AIX" || systemName == "OS400");
}
// Check whether we are targeting Apple.
this->impl->IsApple = this->impl->Makefile->IsOn("APPLE");
// Check whether we are targeting an Android platform.
this->impl->IsAndroid = (this->impl->Makefile->GetSafeDefinition(
"CMAKE_SYSTEM_NAME") == "Android");
// Save the backtrace of target construction.
this->impl->Backtrace = this->impl->Makefile->GetBacktrace();
if (this->impl->IsImported()) {
this->impl->FindPackageStack = this->impl->Makefile->GetFindPackageStack();
}
if (this->IsNormal()) {
// Initialize the INCLUDE_DIRECTORIES property based on the current value
// of the same directory property:
this->impl->IncludeDirectories.CopyFromEntries(
this->impl->Makefile->GetIncludeDirectoriesEntries());
{
auto const& sysInc = this->impl->Makefile->GetSystemIncludeDirectories();
this->impl->SystemIncludeDirectories.insert(sysInc.begin(),
sysInc.end());
}
this->impl->CompileOptions.CopyFromEntries(
this->impl->Makefile->GetCompileOptionsEntries());
this->impl->LinkOptions.CopyFromEntries(
this->impl->Makefile->GetLinkOptionsEntries());
this->impl->LinkDirectories.CopyFromEntries(
this->impl->Makefile->GetLinkDirectoriesEntries());
}
// Record current policies for later use.
this->impl->Makefile->RecordPolicies(this->impl->PolicyMap);
if (this->impl->TargetType == cmStateEnums::INTERFACE_LIBRARY) {
// This policy is checked in a few conditions. The properties relevant
// to the policy are always ignored for cmStateEnums::INTERFACE_LIBRARY
// targets,
// so ensure that the conditions don't lead to nonsense.
this->impl->PolicyMap.Set(cmPolicies::CMP0022, cmPolicies::NEW);
}
std::set<TargetProperty::InitCondition> metConditions;
metConditions.insert(TargetProperty::InitCondition::Always);
if (this->CanCompileSources()) {
metConditions.insert(TargetProperty::InitCondition::CanCompileSources);