/src/CMake/Source/cmExportTryCompileFileGenerator.cxx
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #include "cmExportTryCompileFileGenerator.h" |
4 | | |
5 | | #include <map> |
6 | | #include <utility> |
7 | | |
8 | | #include <cm/memory> |
9 | | #include <cmext/string_view> |
10 | | |
11 | | #include "cmFileSet.h" |
12 | | #include "cmGenExContext.h" |
13 | | #include "cmGeneratorExpression.h" |
14 | | #include "cmGeneratorExpressionDAGChecker.h" |
15 | | #include "cmGeneratorTarget.h" |
16 | | #include "cmGlobalGenerator.h" |
17 | | #include "cmList.h" |
18 | | #include "cmLocalGenerator.h" |
19 | | #include "cmMakefile.h" |
20 | | #include "cmMessageType.h" |
21 | | #include "cmOutputConverter.h" |
22 | | #include "cmStateTypes.h" |
23 | | #include "cmStringAlgorithms.h" |
24 | | #include "cmSystemTools.h" |
25 | | #include "cmTarget.h" |
26 | | #include "cmValue.h" |
27 | | |
28 | | cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator( |
29 | | cmGlobalGenerator* gg, std::vector<std::string> const& targets, |
30 | | cmMakefile* mf, std::set<std::string> const& langs) |
31 | 0 | : Languages(langs.begin(), langs.end()) |
32 | 0 | { |
33 | 0 | gg->CreateImportedGenerationObjects(mf, targets, this->Exports); |
34 | 0 | } Unexecuted instantiation: cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator(cmGlobalGenerator*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, cmMakefile*, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) Unexecuted instantiation: cmExportTryCompileFileGenerator::cmExportTryCompileFileGenerator(cmGlobalGenerator*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, cmMakefile*, std::__1::set<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) |
35 | | |
36 | | void cmExportTryCompileFileGenerator::IssueMessage( |
37 | | MessageType type, std::string const& message) const |
38 | 0 | { |
39 | 0 | switch (type) { |
40 | 0 | case MessageType::FATAL_ERROR: |
41 | 0 | case MessageType::AUTHOR_ERROR: |
42 | 0 | case MessageType::INTERNAL_ERROR: |
43 | 0 | case MessageType::DEPRECATION_ERROR: |
44 | 0 | cmSystemTools::Error(message); |
45 | 0 | break; |
46 | 0 | case MessageType::WARNING: |
47 | 0 | case MessageType::AUTHOR_WARNING: |
48 | 0 | case MessageType::DEPRECATION_WARNING: |
49 | 0 | cmSystemTools::Message(cmStrCat("CMake Warning: "_s, message), |
50 | 0 | "Warning"); |
51 | 0 | break; |
52 | 0 | default: |
53 | 0 | cmSystemTools::Message(message); |
54 | 0 | } |
55 | 0 | } |
56 | | |
57 | | bool cmExportTryCompileFileGenerator::GenerateMainFile(std::ostream& os) |
58 | 0 | { |
59 | 0 | std::set<cmGeneratorTarget const*> emitted; |
60 | 0 | std::set<cmGeneratorTarget const*> emittedDeps; |
61 | 0 | while (!this->Exports.empty()) { |
62 | 0 | cmGeneratorTarget const* te = this->Exports.back(); |
63 | 0 | this->Exports.pop_back(); |
64 | 0 | if (emitted.insert(te).second) { |
65 | 0 | emittedDeps.insert(te); |
66 | 0 | this->GenerateImportTargetCode(os, te, te->GetType()); |
67 | |
|
68 | 0 | ImportPropertyMap properties; |
69 | |
|
70 | 0 | for (std::string const& lang : this->Languages) { |
71 | 0 | for (auto i : cmGeneratorTarget::BuiltinTransitiveProperties) { |
72 | 0 | this->FindTargets(std::string(i.second.InterfaceName), te, lang, |
73 | 0 | emittedDeps); |
74 | 0 | } |
75 | 0 | } |
76 | |
|
77 | 0 | this->PopulateProperties(te, properties, emittedDeps); |
78 | |
|
79 | 0 | this->GenerateInterfaceProperties(te, os, properties); |
80 | 0 | } |
81 | 0 | } |
82 | 0 | return true; |
83 | 0 | } |
84 | | |
85 | | std::string cmExportTryCompileFileGenerator::FindTargets( |
86 | | std::string const& propName, cmGeneratorTarget const* tgt, |
87 | | std::string const& language, std::set<cmGeneratorTarget const*>& emitted) |
88 | 0 | { |
89 | 0 | cmValue prop = tgt->GetProperty(propName); |
90 | 0 | if (!prop) { |
91 | 0 | return std::string(); |
92 | 0 | } |
93 | | |
94 | 0 | cm::GenEx::Context context(tgt->LocalGenerator, this->Config, language); |
95 | |
|
96 | 0 | cmGeneratorExpression ge(*tgt->Makefile->GetCMakeInstance()); |
97 | |
|
98 | 0 | std::unique_ptr<cmGeneratorExpressionDAGChecker> parentDagChecker; |
99 | 0 | if (propName == "INTERFACE_LINK_OPTIONS") { |
100 | | // To please constraint checks of DAGChecker, this property must have |
101 | | // LINK_OPTIONS property as parent |
102 | 0 | parentDagChecker = cm::make_unique<cmGeneratorExpressionDAGChecker>( |
103 | 0 | tgt, "LINK_OPTIONS", nullptr, nullptr, context); |
104 | 0 | } |
105 | 0 | cmGeneratorExpressionDAGChecker dagChecker{ |
106 | 0 | tgt, propName, nullptr, parentDagChecker.get(), context, |
107 | 0 | }; |
108 | |
|
109 | 0 | std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*prop); |
110 | |
|
111 | 0 | cmTarget dummyHead("try_compile_dummy_exe", cmStateEnums::EXECUTABLE, |
112 | 0 | cmTarget::Visibility::Normal, tgt->Target->GetMakefile(), |
113 | 0 | cmTarget::PerConfig::Yes); |
114 | 0 | dummyHead.SetIsForTryCompile(); |
115 | |
|
116 | 0 | cmGeneratorTarget gDummyHead(&dummyHead, tgt->GetLocalGenerator()); |
117 | |
|
118 | 0 | std::string result = cge->Evaluate(context, &dagChecker, &gDummyHead, tgt); |
119 | |
|
120 | 0 | std::set<cmGeneratorTarget const*> const& allTargets = |
121 | 0 | cge->GetAllTargetsSeen(); |
122 | 0 | for (cmGeneratorTarget const* target : allTargets) { |
123 | 0 | if (emitted.insert(target).second) { |
124 | 0 | this->Exports.push_back(target); |
125 | 0 | } |
126 | 0 | } |
127 | 0 | return result; |
128 | 0 | } |
129 | | |
130 | | void cmExportTryCompileFileGenerator::PopulateProperties( |
131 | | cmGeneratorTarget const* target, ImportPropertyMap& properties, |
132 | | std::set<cmGeneratorTarget const*>& emitted) |
133 | 0 | { |
134 | | // Look through all non-special properties. |
135 | 0 | std::vector<std::string> props = target->GetPropertyKeys(); |
136 | | // Include special properties that might be relevant here. |
137 | 0 | props.emplace_back("INTERFACE_LINK_LIBRARIES"); |
138 | 0 | props.emplace_back("INTERFACE_LINK_LIBRARIES_DIRECT"); |
139 | 0 | props.emplace_back("INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE"); |
140 | 0 | for (std::string const& p : props) { |
141 | 0 | cmValue v = target->GetProperty(p); |
142 | 0 | if (!v) { |
143 | 0 | continue; |
144 | 0 | } |
145 | 0 | properties[p] = *v; |
146 | |
|
147 | 0 | if (cmHasLiteralPrefix(p, "IMPORTED_LINK_INTERFACE_LIBRARIES") || |
148 | 0 | cmHasLiteralPrefix(p, "IMPORTED_LINK_DEPENDENT_LIBRARIES") || |
149 | 0 | cmHasLiteralPrefix(p, "INTERFACE_LINK_LIBRARIES")) { |
150 | 0 | std::string evalResult = |
151 | 0 | this->FindTargets(p, target, std::string(), emitted); |
152 | |
|
153 | 0 | cmList depends{ evalResult }; |
154 | 0 | for (std::string const& li : depends) { |
155 | 0 | cmGeneratorTarget* tgt = |
156 | 0 | target->GetLocalGenerator()->FindGeneratorTargetToUse(li); |
157 | 0 | if (tgt && emitted.insert(tgt).second) { |
158 | 0 | this->Exports.push_back(tgt); |
159 | 0 | } |
160 | 0 | } |
161 | 0 | } |
162 | 0 | } |
163 | 0 | } |
164 | | |
165 | | std::string cmExportTryCompileFileGenerator::InstallNameDir( |
166 | | cmGeneratorTarget const* target, std::string const& config) |
167 | 0 | { |
168 | 0 | std::string install_name_dir; |
169 | |
|
170 | 0 | cmMakefile* mf = target->Target->GetMakefile(); |
171 | 0 | if (mf->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) { |
172 | 0 | install_name_dir = target->GetInstallNameDirForBuildTree(config); |
173 | 0 | } |
174 | |
|
175 | 0 | return install_name_dir; |
176 | 0 | } |
177 | | |
178 | | std::string cmExportTryCompileFileGenerator::GetFileSetDirectories( |
179 | | cmGeneratorTarget* /*gte*/, cmFileSet* fileSet, cmTargetExport const* /*te*/) |
180 | 0 | { |
181 | 0 | return cmOutputConverter::EscapeForCMake( |
182 | 0 | cmList::to_string(fileSet->GetDirectoryEntries())); |
183 | 0 | } |
184 | | |
185 | | std::string cmExportTryCompileFileGenerator::GetFileSetFiles( |
186 | | cmGeneratorTarget* /*gte*/, cmFileSet* fileSet, cmTargetExport const* /*te*/) |
187 | 0 | { |
188 | 0 | return cmOutputConverter::EscapeForCMake( |
189 | 0 | cmList::to_string(fileSet->GetFileEntries())); |
190 | 0 | } |