forked from Kitware/CMake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmGeneratorTarget.cxx
5500 lines (4927 loc) · 183 KB
/
cmGeneratorTarget.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 "cmGeneratorTarget.h"
#include "cmsys/RegularExpression.hxx"
#include <algorithm>
#include <assert.h>
#include <errno.h>
#include <iterator>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cmAlgorithms.h"
#include "cmComputeLinkInformation.h"
#include "cmCustomCommand.h"
#include "cmCustomCommandGenerator.h"
#include "cmCustomCommandLines.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorExpressionDAGChecker.h"
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmPropertyMap.h"
#include "cmSourceFile.h"
#include "cmSourceFileLocation.h"
#include "cmState.h"
#include "cmSystemTools.h"
#include "cmTarget.h"
#include "cmTargetLinkLibraryType.h"
#include "cmTargetPropertyComputer.h"
#include "cm_auto_ptr.hxx"
#include "cm_unordered_set.hxx"
#include "cmake.h"
class cmMessenger;
template <>
const char* cmTargetPropertyComputer::GetSources<cmGeneratorTarget>(
cmGeneratorTarget const* tgt, cmMessenger* /* messenger */,
cmListFileBacktrace const& /* context */)
{
return tgt->GetSourcesProperty();
}
template <>
const char* cmTargetPropertyComputer::ComputeLocationForBuild<
cmGeneratorTarget>(cmGeneratorTarget const* tgt)
{
return tgt->GetLocation("");
}
template <>
const char* cmTargetPropertyComputer::ComputeLocation<cmGeneratorTarget>(
cmGeneratorTarget const* tgt, const std::string& config)
{
return tgt->GetLocation(config);
}
class cmGeneratorTarget::TargetPropertyEntry
{
static cmLinkImplItem NoLinkImplItem;
public:
TargetPropertyEntry(CM_AUTO_PTR<cmCompiledGeneratorExpression> cge,
cmLinkImplItem const& item = NoLinkImplItem)
: ge(cge)
, LinkImplItem(item)
{
}
const CM_AUTO_PTR<cmCompiledGeneratorExpression> ge;
cmLinkImplItem const& LinkImplItem;
};
cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
void CreatePropertyGeneratorExpressions(
cmStringRange const& entries, cmBacktraceRange const& backtraces,
std::vector<cmGeneratorTarget::TargetPropertyEntry*>& items,
bool evaluateForBuildsystem = false)
{
std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
for (std::vector<std::string>::const_iterator it = entries.begin();
it != entries.end(); ++it, ++btIt) {
cmGeneratorExpression ge(*btIt);
CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
items.push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
}
}
cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
: Target(t)
, FortranModuleDirectoryCreated(false)
, SourceFileFlagsConstructed(false)
, PolicyWarnedCMP0022(false)
, PolicyReportedCMP0069(false)
, DebugIncludesDone(false)
, DebugCompileOptionsDone(false)
, DebugCompileFeaturesDone(false)
, DebugCompileDefinitionsDone(false)
, DebugSourcesDone(false)
, LinkImplementationLanguageIsContextDependent(true)
, UtilityItemsDone(false)
{
this->Makefile = this->Target->GetMakefile();
this->LocalGenerator = lg;
this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
this->GlobalGenerator->ComputeTargetObjectDirectory(this);
CreatePropertyGeneratorExpressions(t->GetIncludeDirectoriesEntries(),
t->GetIncludeDirectoriesBacktraces(),
this->IncludeDirectoriesEntries);
CreatePropertyGeneratorExpressions(t->GetCompileOptionsEntries(),
t->GetCompileOptionsBacktraces(),
this->CompileOptionsEntries);
CreatePropertyGeneratorExpressions(t->GetCompileFeaturesEntries(),
t->GetCompileFeaturesBacktraces(),
this->CompileFeaturesEntries);
CreatePropertyGeneratorExpressions(t->GetCompileDefinitionsEntries(),
t->GetCompileDefinitionsBacktraces(),
this->CompileDefinitionsEntries);
CreatePropertyGeneratorExpressions(t->GetSourceEntries(),
t->GetSourceBacktraces(),
this->SourceEntries, true);
this->DLLPlatform =
(this->Makefile->IsOn("WIN32") || this->Makefile->IsOn("CYGWIN") ||
this->Makefile->IsOn("MINGW"));
this->PolicyMap = t->PolicyMap;
}
cmGeneratorTarget::~cmGeneratorTarget()
{
cmDeleteAll(this->IncludeDirectoriesEntries);
cmDeleteAll(this->CompileOptionsEntries);
cmDeleteAll(this->CompileFeaturesEntries);
cmDeleteAll(this->CompileDefinitionsEntries);
cmDeleteAll(this->SourceEntries);
cmDeleteAll(this->LinkInformation);
}
const char* cmGeneratorTarget::GetSourcesProperty() const
{
std::vector<std::string> values;
for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
it = this->SourceEntries.begin(),
end = this->SourceEntries.end();
it != end; ++it) {
values.push_back((*it)->ge->GetInput());
}
static std::string value;
value.clear();
value = cmJoin(values, "");
return value.c_str();
}
cmGlobalGenerator* cmGeneratorTarget::GetGlobalGenerator() const
{
return this->GetLocalGenerator()->GetGlobalGenerator();
}
cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
{
return this->LocalGenerator;
}
cmStateEnums::TargetType cmGeneratorTarget::GetType() const
{
return this->Target->GetType();
}
const std::string& cmGeneratorTarget::GetName() const
{
return this->Target->GetName();
}
std::string cmGeneratorTarget::GetExportName() const
{
const char* exportName = this->GetProperty("EXPORT_NAME");
if (exportName && *exportName) {
if (!cmGeneratorExpression::IsValidTargetName(exportName)) {
std::ostringstream e;
e << "EXPORT_NAME property \"" << exportName << "\" for \""
<< this->GetName() << "\": is not valid.";
cmSystemTools::Error(e.str().c_str());
return "";
}
return exportName;
}
return this->GetName();
}
const char* cmGeneratorTarget::GetProperty(const std::string& prop) const
{
if (!cmTargetPropertyComputer::PassesWhitelist(
this->GetType(), prop, this->Makefile->GetMessenger(),
this->GetBacktrace())) {
return CM_NULLPTR;
}
if (const char* result = cmTargetPropertyComputer::GetProperty(
this, prop, this->Makefile->GetMessenger(), this->GetBacktrace())) {
return result;
}
if (cmSystemTools::GetFatalErrorOccured()) {
return CM_NULLPTR;
}
return this->Target->GetProperty(prop);
}
const char* cmGeneratorTarget::GetOutputTargetType(
cmStateEnums::ArtifactType artifact) const
{
switch (this->GetType()) {
case cmStateEnums::SHARED_LIBRARY:
if (this->IsDLLPlatform()) {
switch (artifact) {
case cmStateEnums::RuntimeBinaryArtifact:
// A DLL shared library is treated as a runtime target.
return "RUNTIME";
case cmStateEnums::ImportLibraryArtifact:
// A DLL import library is treated as an archive target.
return "ARCHIVE";
}
} else {
// For non-DLL platforms shared libraries are treated as
// library targets.
return "LIBRARY";
}
break;
case cmStateEnums::STATIC_LIBRARY:
// Static libraries are always treated as archive targets.
return "ARCHIVE";
case cmStateEnums::MODULE_LIBRARY:
switch (artifact) {
case cmStateEnums::RuntimeBinaryArtifact:
// Module import libraries are treated as archive targets.
return "LIBRARY";
case cmStateEnums::ImportLibraryArtifact:
// Module libraries are always treated as library targets.
return "ARCHIVE";
}
break;
case cmStateEnums::EXECUTABLE:
switch (artifact) {
case cmStateEnums::RuntimeBinaryArtifact:
// Executables are always treated as runtime targets.
return "RUNTIME";
case cmStateEnums::ImportLibraryArtifact:
// Executable import libraries are treated as archive targets.
return "ARCHIVE";
}
break;
default:
break;
}
return "";
}
std::string cmGeneratorTarget::GetOutputName(
const std::string& config, cmStateEnums::ArtifactType artifact) const
{
// Lookup/compute/cache the output name for this configuration.
OutputNameKey key(config, artifact);
cmGeneratorTarget::OutputNameMapType::iterator i =
this->OutputNameMap.find(key);
if (i == this->OutputNameMap.end()) {
// Add empty name in map to detect potential recursion.
OutputNameMapType::value_type entry(key, "");
i = this->OutputNameMap.insert(entry).first;
// Compute output name.
std::vector<std::string> props;
std::string type = this->GetOutputTargetType(artifact);
std::string configUpper = cmSystemTools::UpperCase(config);
if (!type.empty() && !configUpper.empty()) {
// <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
props.push_back(type + "_OUTPUT_NAME_" + configUpper);
}
if (!type.empty()) {
// <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
props.push_back(type + "_OUTPUT_NAME");
}
if (!configUpper.empty()) {
// OUTPUT_NAME_<CONFIG>
props.push_back("OUTPUT_NAME_" + configUpper);
// <CONFIG>_OUTPUT_NAME
props.push_back(configUpper + "_OUTPUT_NAME");
}
// OUTPUT_NAME
props.push_back("OUTPUT_NAME");
std::string outName;
for (std::vector<std::string>::const_iterator it = props.begin();
it != props.end(); ++it) {
if (const char* outNameProp = this->GetProperty(*it)) {
outName = outNameProp;
break;
}
}
if (outName.empty()) {
outName = this->GetName();
}
// Now evaluate genex and update the previously-prepared map entry.
cmGeneratorExpression ge;
CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
i->second = cge->Evaluate(this->LocalGenerator, config);
} else if (i->second.empty()) {
// An empty map entry indicates we have been called recursively
// from the above block.
this->LocalGenerator->GetCMakeInstance()->IssueMessage(
cmake::FATAL_ERROR,
"Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
this->GetBacktrace());
}
return i->second;
}
void cmGeneratorTarget::AddSourceCommon(const std::string& src)
{
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmGeneratorExpression ge(lfbt);
CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(src);
cge->SetEvaluateForBuildsystem(true);
this->SourceEntries.push_back(new TargetPropertyEntry(cge));
this->KindedSourcesMap.clear();
this->LinkImplementationLanguageIsContextDependent = true;
}
void cmGeneratorTarget::AddSource(const std::string& src)
{
this->Target->AddSource(src);
this->AddSourceCommon(src);
}
void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
{
this->Target->AddTracedSources(srcs);
if (!srcs.empty()) {
this->AddSourceCommon(cmJoin(srcs, ";"));
}
}
void cmGeneratorTarget::AddIncludeDirectory(const std::string& src,
bool before)
{
this->Target->InsertInclude(src, this->Makefile->GetBacktrace(), before);
cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
cmGeneratorExpression ge(lfbt);
CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(src);
cge->SetEvaluateForBuildsystem(true);
// Insert before begin/end
std::vector<TargetPropertyEntry*>::iterator pos = before
? this->IncludeDirectoriesEntries.begin()
: this->IncludeDirectoriesEntries.end();
this->IncludeDirectoriesEntries.insert(pos, new TargetPropertyEntry(cge));
}
std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends(
cmSourceFile const* sf) const
{
SourceEntriesType::const_iterator i = this->SourceDepends.find(sf);
if (i != this->SourceDepends.end()) {
return &i->second.Depends;
}
return CM_NULLPTR;
}
static void handleSystemIncludesDep(
cmLocalGenerator* lg, cmGeneratorTarget const* depTgt,
const std::string& config, cmGeneratorTarget const* headTarget,
cmGeneratorExpressionDAGChecker* dagChecker,
std::vector<std::string>& result, bool excludeImported)
{
if (const char* dirs =
depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) {
cmGeneratorExpression ge;
cmSystemTools::ExpandListArgument(
ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
dagChecker),
result);
}
if (!depTgt->IsImported() || excludeImported) {
return;
}
if (const char* dirs =
depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES")) {
cmGeneratorExpression ge;
cmSystemTools::ExpandListArgument(
ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
dagChecker),
result);
}
}
/* clang-format off */
#define IMPLEMENT_VISIT(KIND) \
{ \
KindedSources const& kinded = this->GetKindedSources(config); \
for (std::vector<SourceAndKind>::const_iterator \
si = kinded.Sources.begin(); si != kinded.Sources.end(); ++si) { \
if (si->Kind == KIND) { \
data.push_back(si->Source); \
} \
} \
}
/* clang-format on */
void cmGeneratorTarget::GetObjectSources(
std::vector<cmSourceFile const*>& data, const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindObjectSource);
if (!this->Objects.empty()) {
return;
}
for (std::vector<cmSourceFile const*>::const_iterator it = data.begin();
it != data.end(); ++it) {
this->Objects[*it];
}
this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
}
void cmGeneratorTarget::ComputeObjectMapping()
{
if (!this->Objects.empty()) {
return;
}
std::vector<std::string> configs;
this->Makefile->GetConfigurations(configs);
if (configs.empty()) {
configs.push_back("");
}
for (std::vector<std::string>::const_iterator ci = configs.begin();
ci != configs.end(); ++ci) {
std::vector<cmSourceFile const*> sourceFiles;
this->GetObjectSources(sourceFiles, *ci);
}
}
const char* cmGeneratorTarget::GetFeature(const std::string& feature,
const std::string& config) const
{
if (!config.empty()) {
std::string featureConfig = feature;
featureConfig += "_";
featureConfig += cmSystemTools::UpperCase(config);
if (const char* value = this->GetProperty(featureConfig)) {
return value;
}
}
if (const char* value = this->GetProperty(feature)) {
return value;
}
return this->LocalGenerator->GetFeature(feature, config);
}
bool cmGeneratorTarget::IsIPOEnabled(const std::string& config) const
{
const char* feature = "INTERPROCEDURAL_OPTIMIZATION";
const bool result = cmSystemTools::IsOn(this->GetFeature(feature, config));
if (!result) {
// 'INTERPROCEDURAL_OPTIMIZATION' is off, no need to check policies
return false;
}
cmPolicies::PolicyStatus cmp0069 = this->GetPolicyStatusCMP0069();
if (cmp0069 == cmPolicies::OLD || cmp0069 == cmPolicies::WARN) {
if (this->Makefile->IsOn("_CMAKE_IPO_LEGACY_BEHAVIOR")) {
return true;
}
if (this->PolicyReportedCMP0069) {
// problem is already reported, no need to issue a message
return false;
}
if (cmp0069 == cmPolicies::WARN) {
std::ostringstream w;
w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0069) << "\n";
w << "INTERPROCEDURAL_OPTIMIZATION property will be ignored for target "
<< "'" << this->GetName() << "'.";
this->LocalGenerator->GetCMakeInstance()->IssueMessage(
cmake::AUTHOR_WARNING, w.str(), this->GetBacktrace());
this->PolicyReportedCMP0069 = true;
}
return false;
}
// Note: check consistency with messages from CheckIPOSupported
const char* message = CM_NULLPTR;
if (!this->Makefile->IsOn("_CMAKE_IPO_SUPPORTED_BY_CMAKE")) {
message = "CMake doesn't support IPO for current compiler";
} else if (!this->Makefile->IsOn(
"_CMAKE_IPO_MAY_BE_SUPPORTED_BY_COMPILER")) {
message = "Compiler doesn't support IPO";
} else if (!this->GlobalGenerator->IsIPOSupported()) {
message = "CMake doesn't support IPO for current generator";
}
if (!message) {
// No error/warning messages
return true;
}
if (this->PolicyReportedCMP0069) {
// problem is already reported, no need to issue a message
return false;
}
this->PolicyReportedCMP0069 = true;
this->LocalGenerator->GetCMakeInstance()->IssueMessage(
cmake::FATAL_ERROR, message, this->GetBacktrace());
return false;
}
const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
{
this->ComputeObjectMapping();
return this->Objects[file];
}
const char* cmGeneratorTarget::GetCustomObjectExtension() const
{
static std::string extension;
const bool has_ptx_extension =
this->GetPropertyAsBool("CUDA_PTX_COMPILATION");
if (has_ptx_extension) {
extension = ".ptx";
return extension.c_str();
}
return CM_NULLPTR;
}
void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
{
this->ExplicitObjectName.insert(sf);
}
bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
{
const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
std::set<cmSourceFile const*>::const_iterator it =
this->ExplicitObjectName.find(file);
return it != this->ExplicitObjectName.end();
}
void cmGeneratorTarget::GetModuleDefinitionSources(
std::vector<cmSourceFile const*>& data, const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindModuleDefinition);
}
void cmGeneratorTarget::GetHeaderSources(
std::vector<cmSourceFile const*>& data, const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindHeader);
}
void cmGeneratorTarget::GetExtraSources(std::vector<cmSourceFile const*>& data,
const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindExtra);
}
void cmGeneratorTarget::GetCustomCommands(
std::vector<cmSourceFile const*>& data, const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindCustomCommand);
}
void cmGeneratorTarget::GetExternalObjects(
std::vector<cmSourceFile const*>& data, const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindExternalObject);
}
void cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& headers,
const std::string& config) const
{
KindedSources const& kinded = this->GetKindedSources(config);
headers = kinded.ExpectedResxHeaders;
}
void cmGeneratorTarget::GetResxSources(std::vector<cmSourceFile const*>& data,
const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindResx);
}
void cmGeneratorTarget::GetAppManifest(std::vector<cmSourceFile const*>& data,
const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindAppManifest);
}
void cmGeneratorTarget::GetManifests(std::vector<cmSourceFile const*>& data,
const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindManifest);
}
void cmGeneratorTarget::GetCertificates(std::vector<cmSourceFile const*>& data,
const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindCertificate);
}
void cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
const std::string& config) const
{
KindedSources const& kinded = this->GetKindedSources(config);
headers = kinded.ExpectedXamlHeaders;
}
void cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
const std::string& config) const
{
KindedSources const& kinded = this->GetKindedSources(config);
srcs = kinded.ExpectedXamlSources;
}
std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
{
if (!this->UtilityItemsDone) {
this->UtilityItemsDone = true;
std::set<std::string> const& utilities = this->GetUtilities();
for (std::set<std::string>::const_iterator i = utilities.begin();
i != utilities.end(); ++i) {
cmGeneratorTarget* gt =
this->LocalGenerator->FindGeneratorTargetToUse(*i);
this->UtilityItems.insert(cmLinkItem(*i, gt));
}
}
return this->UtilityItems;
}
void cmGeneratorTarget::GetXamlSources(std::vector<cmSourceFile const*>& data,
const std::string& config) const
{
IMPLEMENT_VISIT(SourceKindXaml);
}
const char* cmGeneratorTarget::GetLocation(const std::string& config) const
{
static std::string location;
if (this->IsImported()) {
location = this->Target->ImportedGetFullPath(
config, cmStateEnums::RuntimeBinaryArtifact);
} else {
location = this->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
}
return location.c_str();
}
std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreBuildCommands()
const
{
return this->Target->GetPreBuildCommands();
}
std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreLinkCommands()
const
{
return this->Target->GetPreLinkCommands();
}
std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPostBuildCommands()
const
{
return this->Target->GetPostBuildCommands();
}
bool cmGeneratorTarget::IsImported() const
{
return this->Target->IsImported();
}
bool cmGeneratorTarget::IsImportedGloballyVisible() const
{
return this->Target->IsImportedGloballyVisible();
}
const char* cmGeneratorTarget::GetLocationForBuild() const
{
static std::string location;
if (this->IsImported()) {
location = this->Target->ImportedGetFullPath(
"", cmStateEnums::RuntimeBinaryArtifact);
return location.c_str();
}
// Now handle the deprecated build-time configuration location.
location = this->GetDirectory();
const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
if (cfgid && strcmp(cfgid, ".") != 0) {
location += "/";
location += cfgid;
}
if (this->IsAppBundleOnApple()) {
std::string macdir = this->BuildBundleDirectory("", "", FullLevel);
if (!macdir.empty()) {
location += "/";
location += macdir;
}
}
location += "/";
location += this->GetFullName("", cmStateEnums::RuntimeBinaryArtifact);
return location.c_str();
}
bool cmGeneratorTarget::IsSystemIncludeDirectory(
const std::string& dir, const std::string& config) const
{
assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
std::string config_upper;
if (!config.empty()) {
config_upper = cmSystemTools::UpperCase(config);
}
typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
IncludeCacheType::const_iterator iter =
this->SystemIncludesCache.find(config_upper);
if (iter == this->SystemIncludesCache.end()) {
cmGeneratorExpressionDAGChecker dagChecker(
this->GetName(), "SYSTEM_INCLUDE_DIRECTORIES", CM_NULLPTR, CM_NULLPTR);
bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
std::vector<std::string> result;
for (std::set<std::string>::const_iterator it =
this->Target->GetSystemIncludeDirectories().begin();
it != this->Target->GetSystemIncludeDirectories().end(); ++it) {
cmGeneratorExpression ge;
cmSystemTools::ExpandListArgument(
ge.Parse(*it)->Evaluate(this->LocalGenerator, config, false, this,
&dagChecker),
result);
}
std::vector<cmGeneratorTarget const*> const& deps =
this->GetLinkImplementationClosure(config);
for (std::vector<cmGeneratorTarget const *>::const_iterator
li = deps.begin(),
le = deps.end();
li != le; ++li) {
handleSystemIncludesDep(this->LocalGenerator, *li, config, this,
&dagChecker, result, excludeImported);
}
std::for_each(result.begin(), result.end(),
cmSystemTools::ConvertToUnixSlashes);
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()), result.end());
IncludeCacheType::value_type entry(config_upper, result);
iter = this->SystemIncludesCache.insert(entry).first;
}
return std::binary_search(iter->second.begin(), iter->second.end(), dir);
}
bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
{
return this->Target->GetPropertyAsBool(prop);
}
static void AddInterfaceEntries(
cmGeneratorTarget const* thisTarget, std::string const& config,
std::string const& prop,
std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
{
if (cmLinkImplementationLibraries const* impl =
thisTarget->GetLinkImplementationLibraries(config)) {
for (std::vector<cmLinkImplItem>::const_iterator
it = impl->Libraries.begin(),
end = impl->Libraries.end();
it != end; ++it) {
if (it->Target) {
std::string genex = "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
cmGeneratorExpression ge(it->Backtrace);
CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
cge->SetEvaluateForBuildsystem(true);
entries.push_back(
new cmGeneratorTarget::TargetPropertyEntry(cge, *it));
}
}
}
}
static bool processSources(
cmGeneratorTarget const* tgt,
const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
std::vector<std::string>& srcs, CM_UNORDERED_SET<std::string>& uniqueSrcs,
cmGeneratorExpressionDAGChecker* dagChecker, std::string const& config,
bool debugSources)
{
cmMakefile* mf = tgt->Target->GetMakefile();
bool contextDependent = false;
for (std::vector<cmGeneratorTarget::TargetPropertyEntry *>::const_iterator
it = entries.begin(),
end = entries.end();
it != end; ++it) {
cmLinkImplItem const& item = (*it)->LinkImplItem;
std::string const& targetName = item;
std::vector<std::string> entrySources;
cmSystemTools::ExpandListArgument(
(*it)->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, tgt,
dagChecker),
entrySources);
if ((*it)->ge->GetHadContextSensitiveCondition()) {
contextDependent = true;
}
for (std::vector<std::string>::iterator i = entrySources.begin();
i != entrySources.end(); ++i) {
std::string& src = *i;
cmSourceFile* sf = mf->GetOrCreateSource(src);
std::string e;
std::string fullPath = sf->GetFullPath(&e);
if (fullPath.empty()) {
if (!e.empty()) {
cmake* cm = tgt->GetLocalGenerator()->GetCMakeInstance();
cm->IssueMessage(cmake::FATAL_ERROR, e, tgt->GetBacktrace());
}
return contextDependent;
}
if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src.c_str())) {
std::ostringstream err;
if (!targetName.empty()) {
err << "Target \"" << targetName
<< "\" contains relative "
"path in its INTERFACE_SOURCES:\n"
" \""
<< src << "\"";
} else {
err << "Found relative path while evaluating sources of "
"\""
<< tgt->GetName() << "\":\n \"" << src << "\"\n";
}
tgt->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, err.str());
return contextDependent;
}
src = fullPath;
}
std::string usedSources;
for (std::vector<std::string>::iterator li = entrySources.begin();
li != entrySources.end(); ++li) {
std::string src = *li;
if (uniqueSrcs.insert(src).second) {
srcs.push_back(src);
if (debugSources) {
usedSources += " * " + src + "\n";
}
}
}
if (!usedSources.empty()) {
tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
cmake::LOG, std::string("Used sources for target ") + tgt->GetName() +
":\n" + usedSources,
(*it)->ge->GetBacktrace());
}
}
return contextDependent;
}
void cmGeneratorTarget::GetSourceFiles(std::vector<std::string>& files,
const std::string& config) const
{
assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
if (!this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
// At configure-time, this method can be called as part of getting the
// LOCATION property or to export() a file to be include()d. However
// there is no cmGeneratorTarget at configure-time, so search the SOURCES
// for TARGET_OBJECTS instead for backwards compatibility with OLD
// behavior of CMP0024 and CMP0026 only.
cmStringRange sourceEntries = this->Target->GetSourceEntries();
for (cmStringRange::const_iterator i = sourceEntries.begin();
i != sourceEntries.end(); ++i) {
std::string const& entry = *i;
std::vector<std::string> items;
cmSystemTools::ExpandListArgument(entry, items);
for (std::vector<std::string>::const_iterator li = items.begin();
li != items.end(); ++li) {
if (cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
(*li)[li->size() - 1] == '>') {
continue;
}
files.push_back(*li);
}
}
return;
}
std::vector<std::string> debugProperties;
const char* debugProp =
this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
if (debugProp) {
cmSystemTools::ExpandListArgument(debugProp, debugProperties);
}
bool debugSources = !this->DebugSourcesDone &&
std::find(debugProperties.begin(), debugProperties.end(), "SOURCES") !=
debugProperties.end();
if (this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
this->DebugSourcesDone = true;
}
cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), "SOURCES",
CM_NULLPTR, CM_NULLPTR);
CM_UNORDERED_SET<std::string> uniqueSrcs;
bool contextDependentDirectSources =
processSources(this, this->SourceEntries, files, uniqueSrcs, &dagChecker,
config, debugSources);
std::vector<cmGeneratorTarget::TargetPropertyEntry*>
linkInterfaceSourcesEntries;
AddInterfaceEntries(this, config, "INTERFACE_SOURCES",
linkInterfaceSourcesEntries);
std::vector<std::string>::size_type numFilesBefore = files.size();
bool contextDependentInterfaceSources =
processSources(this, linkInterfaceSourcesEntries, files, uniqueSrcs,
&dagChecker, config, debugSources);
if (!contextDependentDirectSources &&
!(contextDependentInterfaceSources && numFilesBefore < files.size())) {
this->LinkImplementationLanguageIsContextDependent = false;
}
cmDeleteAll(linkInterfaceSourcesEntries);
}
void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*>& files,
const std::string& config) const
{
if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
// Since we are still configuring not all sources may exist yet,
// so we need to avoid full source classification because that
// requires the absolute paths to all sources to be determined.
// Since this is only for compatibility with old policies that
// projects should not depend on anymore, just compute the files
// without memoizing them.
std::vector<std::string> srcs;
this->GetSourceFiles(srcs, config);
std::set<cmSourceFile*> emitted;
for (std::vector<std::string>::const_iterator i = srcs.begin();
i != srcs.end(); ++i) {
cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
if (emitted.insert(sf).second) {
files.push_back(sf);
}
}
return;
}
KindedSources const& kinded = this->GetKindedSources(config);
files.reserve(kinded.Sources.size());
for (std::vector<SourceAndKind>::const_iterator si = kinded.Sources.begin();
si != kinded.Sources.end(); ++si) {
files.push_back(si->Source);
}
}
void cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
std::vector<cmSourceFile*>& files, const std::string& config) const
{
KindedSources const& kinded = this->GetKindedSources(config);
files.reserve(kinded.Sources.size());
for (std::vector<SourceAndKind>::const_iterator si = kinded.Sources.begin();
si != kinded.Sources.end(); ++si) {