/src/CMake/Source/cmGeneratorTarget.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 "cmGeneratorTarget.h" |
4 | | |
5 | | #include <algorithm> |
6 | | #include <array> |
7 | | #include <cassert> |
8 | | #include <cstddef> |
9 | | #include <cstdio> |
10 | | #include <cstring> |
11 | | #include <sstream> |
12 | | #include <string> |
13 | | #include <unordered_set> |
14 | | #include <utility> |
15 | | |
16 | | #include <cm/memory> |
17 | | #include <cm/optional> |
18 | | #include <cm/string_view> |
19 | | #include <cmext/algorithm> |
20 | | #include <cmext/string_view> |
21 | | |
22 | | #include "cmsys/String.h" |
23 | | |
24 | | #include "cmAlgorithms.h" |
25 | | #include "cmComputeLinkInformation.h" // IWYU pragma: keep |
26 | | #include "cmCryptoHash.h" |
27 | | #include "cmCxxModuleMetadata.h" |
28 | | #include "cmCxxModuleUsageEffects.h" |
29 | | #include "cmExperimental.h" |
30 | | #include "cmFileSet.h" |
31 | | #include "cmFileSetMetadata.h" |
32 | | #include "cmFileTimes.h" |
33 | | #include "cmGenExContext.h" |
34 | | #include "cmGeneratedFileStream.h" |
35 | | #include "cmGeneratorExpression.h" |
36 | | #include "cmGeneratorExpressionDAGChecker.h" |
37 | | #include "cmGeneratorFileSet.h" |
38 | | #include "cmGeneratorFileSets.h" |
39 | | #include "cmGeneratorOptions.h" |
40 | | #include "cmGlobalGenerator.h" |
41 | | #include "cmList.h" |
42 | | #include "cmLocalGenerator.h" |
43 | | #include "cmMakefile.h" |
44 | | #include "cmMessageType.h" |
45 | | #include "cmOutputConverter.h" |
46 | | #include "cmPropertyMap.h" |
47 | | #include "cmRulePlaceholderExpander.h" |
48 | | #include "cmSourceFile.h" |
49 | | #include "cmSourceFileLocationKind.h" |
50 | | #include "cmStandardLevel.h" |
51 | | #include "cmStandardLevelResolver.h" |
52 | | #include "cmState.h" |
53 | | #include "cmStateTypes.h" |
54 | | #include "cmStringAlgorithms.h" |
55 | | #include "cmSystemTools.h" |
56 | | #include "cmTarget.h" |
57 | | #include "cmTargetLinkLibraryType.h" |
58 | | #include "cmTargetPropertyComputer.h" |
59 | | #include "cmTargetTraceDependencies.h" |
60 | | #include "cmake.h" |
61 | | |
62 | | namespace { |
63 | | using UseTo = cmGeneratorTarget::UseTo; |
64 | | } |
65 | | |
66 | | template <> |
67 | | cmValue cmTargetPropertyComputer::GetSources<cmGeneratorTarget>( |
68 | | cmGeneratorTarget const* tgt) |
69 | 0 | { |
70 | 0 | return tgt->GetSourcesProperty(); |
71 | 0 | } |
72 | | |
73 | | template <> |
74 | | std::string const& |
75 | | cmTargetPropertyComputer::ImportedLocation<cmGeneratorTarget>( |
76 | | cmGeneratorTarget const* tgt, std::string const& config) |
77 | 0 | { |
78 | 0 | return tgt->GetLocation(config); |
79 | 0 | } |
80 | | |
81 | | static void CreatePropertyGeneratorExpressions( |
82 | | cmake& cmakeInstance, cmBTStringRange entries, |
83 | | std::vector<std::unique_ptr<cm::TargetPropertyEntry>>& items, |
84 | | bool evaluateForBuildsystem = false) |
85 | 0 | { |
86 | 0 | for (auto const& entry : entries) { |
87 | 0 | items.emplace_back(cm::TargetPropertyEntry::Create( |
88 | 0 | cmakeInstance, entry, evaluateForBuildsystem)); |
89 | 0 | } |
90 | 0 | } |
91 | | |
92 | | cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) |
93 | 0 | : Target(t) |
94 | 0 | , Makefile(t->GetMakefile()) |
95 | 0 | , LocalGenerator(lg) |
96 | 0 | , GlobalGenerator(lg->GetGlobalGenerator()) |
97 | 0 | , FileSets(cm::make_unique<cmGeneratorFileSets>(this, lg)) |
98 | 0 | { |
99 | 0 | this->GlobalGenerator->ComputeTargetObjectDirectory(this); |
100 | |
|
101 | 0 | CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), |
102 | 0 | t->GetIncludeDirectoriesEntries(), |
103 | 0 | this->IncludeDirectoriesEntries); |
104 | |
|
105 | 0 | CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), |
106 | 0 | t->GetCompileOptionsEntries(), |
107 | 0 | this->CompileOptionsEntries); |
108 | |
|
109 | 0 | CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), |
110 | 0 | t->GetCompileFeaturesEntries(), |
111 | 0 | this->CompileFeaturesEntries); |
112 | |
|
113 | 0 | CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), |
114 | 0 | t->GetCompileDefinitionsEntries(), |
115 | 0 | this->CompileDefinitionsEntries); |
116 | |
|
117 | 0 | CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), |
118 | 0 | t->GetLinkOptionsEntries(), |
119 | 0 | this->LinkOptionsEntries); |
120 | |
|
121 | 0 | CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), |
122 | 0 | t->GetLinkDirectoriesEntries(), |
123 | 0 | this->LinkDirectoriesEntries); |
124 | |
|
125 | 0 | CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(), |
126 | 0 | t->GetPrecompileHeadersEntries(), |
127 | 0 | this->PrecompileHeadersEntries); |
128 | |
|
129 | 0 | CreatePropertyGeneratorExpressions( |
130 | 0 | *lg->GetCMakeInstance(), t->GetSourceEntries(), this->SourceEntries, true); |
131 | |
|
132 | 0 | this->PolicyMap = t->GetPolicyMap(); |
133 | | |
134 | | // Get hard-coded linker language |
135 | 0 | if (this->Target->GetProperty("HAS_CXX")) { |
136 | 0 | this->LinkerLanguage = "CXX"; |
137 | 0 | } else { |
138 | 0 | this->LinkerLanguage = this->Target->GetSafeProperty("LINKER_LANGUAGE"); |
139 | 0 | } |
140 | |
|
141 | 0 | auto configs = |
142 | 0 | this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); |
143 | 0 | std::string build_db_languages[] = { "CXX" }; |
144 | 0 | for (auto const& language : build_db_languages) { |
145 | 0 | for (auto const& config : configs) { |
146 | 0 | auto bdb_path = this->BuildDatabasePath(language, config); |
147 | 0 | if (!bdb_path.empty()) { |
148 | 0 | this->Makefile->GetOrCreateGeneratedSource(bdb_path); |
149 | 0 | this->GetGlobalGenerator()->AddBuildDatabaseFile(language, config, |
150 | 0 | bdb_path); |
151 | 0 | } |
152 | 0 | } |
153 | 0 | } |
154 | 0 | } |
155 | | |
156 | 0 | cmGeneratorTarget::~cmGeneratorTarget() = default; |
157 | | |
158 | | cmValue cmGeneratorTarget::GetSourcesProperty() const |
159 | 0 | { |
160 | 0 | std::vector<std::string> values; |
161 | 0 | for (auto const& se : this->SourceEntries) { |
162 | 0 | values.push_back(se->GetInput()); |
163 | 0 | } |
164 | 0 | static std::string value; |
165 | 0 | value = cmList::to_string(values); |
166 | 0 | return cmValue(value); |
167 | 0 | } |
168 | | |
169 | | cmGlobalGenerator* cmGeneratorTarget::GetGlobalGenerator() const |
170 | 0 | { |
171 | 0 | return this->GetLocalGenerator()->GetGlobalGenerator(); |
172 | 0 | } |
173 | | |
174 | | cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const |
175 | 0 | { |
176 | 0 | return this->LocalGenerator; |
177 | 0 | } |
178 | | |
179 | | cmStateEnums::TargetType cmGeneratorTarget::GetType() const |
180 | 0 | { |
181 | 0 | return this->Target->GetType(); |
182 | 0 | } |
183 | | |
184 | | std::string const& cmGeneratorTarget::GetName() const |
185 | 0 | { |
186 | 0 | return this->Target->GetName(); |
187 | 0 | } |
188 | | |
189 | | std::string cmGeneratorTarget::GetFamilyName() const |
190 | 0 | { |
191 | 0 | if (!this->IsImported() && !this->IsSynthetic()) { |
192 | 0 | return this->Target->GetTemplateName(); |
193 | 0 | } |
194 | 0 | cmCryptoHash hasher(cmCryptoHash::AlgoSHA3_512); |
195 | 0 | constexpr size_t HASH_TRUNCATION = 12; |
196 | 0 | auto dirhash = |
197 | 0 | hasher.HashString(this->GetLocalGenerator()->GetCurrentBinaryDirectory()); |
198 | 0 | auto targetIdent = hasher.HashString(cmStrCat("@d_", dirhash)); |
199 | 0 | return cmStrCat(this->Target->GetTemplateName(), '@', |
200 | 0 | targetIdent.substr(0, HASH_TRUNCATION)); |
201 | 0 | } |
202 | | |
203 | | std::string cmGeneratorTarget::GetExportName() const |
204 | 0 | { |
205 | 0 | cmValue exportName = this->GetProperty("EXPORT_NAME"); |
206 | |
|
207 | 0 | if (cmNonempty(exportName)) { |
208 | 0 | if (!cmGeneratorExpression::IsValidTargetName(*exportName)) { |
209 | 0 | std::ostringstream e; |
210 | 0 | e << "EXPORT_NAME property \"" << *exportName << "\" for \"" |
211 | 0 | << this->GetName() << "\": is not valid."; |
212 | 0 | cmSystemTools::Error(e.str()); |
213 | 0 | return ""; |
214 | 0 | } |
215 | 0 | return *exportName; |
216 | 0 | } |
217 | 0 | return this->GetName(); |
218 | 0 | } |
219 | | |
220 | | std::string cmGeneratorTarget::GetFilesystemExportName() const |
221 | 0 | { |
222 | 0 | auto fs_safe = this->GetExportName(); |
223 | | // First escape any `_` characters to avoid collisions. |
224 | 0 | cmSystemTools::ReplaceString(fs_safe, "_", "__"); |
225 | | // Escape other characters that are not generally filesystem-safe. |
226 | 0 | cmSystemTools::ReplaceString(fs_safe, ":", "_c"); |
227 | 0 | return fs_safe; |
228 | 0 | } |
229 | | |
230 | | cmValue cmGeneratorTarget::GetProperty(std::string const& prop) const |
231 | 0 | { |
232 | 0 | if (cmValue result = |
233 | 0 | cmTargetPropertyComputer::GetProperty(this, prop, *this->Makefile)) { |
234 | 0 | return result; |
235 | 0 | } |
236 | 0 | if (cmSystemTools::GetFatalErrorOccurred()) { |
237 | 0 | return nullptr; |
238 | 0 | } |
239 | 0 | return this->Target->GetProperty(prop); |
240 | 0 | } |
241 | | |
242 | | std::string const& cmGeneratorTarget::GetSafeProperty( |
243 | | std::string const& prop) const |
244 | 0 | { |
245 | 0 | return this->GetProperty(prop); |
246 | 0 | } |
247 | | |
248 | | char const* cmGeneratorTarget::GetOutputTargetType( |
249 | | cmStateEnums::ArtifactType artifact) const |
250 | 0 | { |
251 | 0 | if (this->IsFrameworkOnApple() || this->GetGlobalGenerator()->IsXcode()) { |
252 | | // import file (i.e. .tbd file) is always in same location as library |
253 | 0 | artifact = cmStateEnums::RuntimeBinaryArtifact; |
254 | 0 | } |
255 | |
|
256 | 0 | switch (this->GetType()) { |
257 | 0 | case cmStateEnums::SHARED_LIBRARY: |
258 | 0 | if (this->IsDLLPlatform()) { |
259 | 0 | switch (artifact) { |
260 | 0 | case cmStateEnums::RuntimeBinaryArtifact: |
261 | | // A DLL shared library is treated as a runtime target. |
262 | 0 | return "RUNTIME"; |
263 | 0 | case cmStateEnums::ImportLibraryArtifact: |
264 | | // A DLL import library is treated as an archive target. |
265 | 0 | return "ARCHIVE"; |
266 | 0 | } |
267 | 0 | } else { |
268 | 0 | switch (artifact) { |
269 | 0 | case cmStateEnums::RuntimeBinaryArtifact: |
270 | | // For non-DLL platforms shared libraries are treated as |
271 | | // library targets. |
272 | 0 | return "LIBRARY"; |
273 | 0 | case cmStateEnums::ImportLibraryArtifact: |
274 | | // Library import libraries are treated as archive targets. |
275 | 0 | return "ARCHIVE"; |
276 | 0 | } |
277 | 0 | } |
278 | 0 | break; |
279 | 0 | case cmStateEnums::STATIC_LIBRARY: |
280 | | // Static libraries are always treated as archive targets. |
281 | 0 | return "ARCHIVE"; |
282 | 0 | case cmStateEnums::MODULE_LIBRARY: |
283 | 0 | switch (artifact) { |
284 | 0 | case cmStateEnums::RuntimeBinaryArtifact: |
285 | | // Module libraries are always treated as library targets. |
286 | 0 | return "LIBRARY"; |
287 | 0 | case cmStateEnums::ImportLibraryArtifact: |
288 | | // Module import libraries are treated as archive targets. |
289 | 0 | return "ARCHIVE"; |
290 | 0 | } |
291 | 0 | break; |
292 | 0 | case cmStateEnums::OBJECT_LIBRARY: |
293 | | // Object libraries are always treated as object targets. |
294 | 0 | return "OBJECT"; |
295 | 0 | case cmStateEnums::EXECUTABLE: |
296 | 0 | switch (artifact) { |
297 | 0 | case cmStateEnums::RuntimeBinaryArtifact: |
298 | | // Executables are always treated as runtime targets. |
299 | 0 | return "RUNTIME"; |
300 | 0 | case cmStateEnums::ImportLibraryArtifact: |
301 | | // Executable import libraries are treated as archive targets. |
302 | 0 | return "ARCHIVE"; |
303 | 0 | } |
304 | 0 | break; |
305 | 0 | default: |
306 | 0 | break; |
307 | 0 | } |
308 | 0 | return ""; |
309 | 0 | } |
310 | | |
311 | | std::string cmGeneratorTarget::GetOutputName( |
312 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
313 | 0 | { |
314 | | // Lookup/compute/cache the output name for this configuration. |
315 | 0 | OutputNameKey key(config, artifact); |
316 | 0 | auto i = this->OutputNameMap.find(key); |
317 | 0 | if (i == this->OutputNameMap.end()) { |
318 | | // Add empty name in map to detect potential recursion. |
319 | 0 | OutputNameMapType::value_type entry(key, ""); |
320 | 0 | i = this->OutputNameMap.insert(entry).first; |
321 | | |
322 | | // Compute output name. |
323 | 0 | std::vector<std::string> props; |
324 | 0 | std::string type = this->GetOutputTargetType(artifact); |
325 | 0 | std::string configUpper = cmSystemTools::UpperCase(config); |
326 | 0 | if (!type.empty() && !configUpper.empty()) { |
327 | | // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG> |
328 | 0 | props.push_back(cmStrCat(type, "_OUTPUT_NAME_", configUpper)); |
329 | 0 | } |
330 | 0 | if (!type.empty()) { |
331 | | // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME |
332 | 0 | props.push_back(type + "_OUTPUT_NAME"); |
333 | 0 | } |
334 | 0 | if (!configUpper.empty()) { |
335 | | // OUTPUT_NAME_<CONFIG> |
336 | 0 | props.push_back("OUTPUT_NAME_" + configUpper); |
337 | | // <CONFIG>_OUTPUT_NAME |
338 | 0 | props.push_back(configUpper + "_OUTPUT_NAME"); |
339 | 0 | } |
340 | | // OUTPUT_NAME |
341 | 0 | props.emplace_back("OUTPUT_NAME"); |
342 | |
|
343 | 0 | std::string outName; |
344 | 0 | for (std::string const& p : props) { |
345 | 0 | if (cmValue outNameProp = this->GetProperty(p)) { |
346 | 0 | outName = *outNameProp; |
347 | 0 | break; |
348 | 0 | } |
349 | 0 | } |
350 | |
|
351 | 0 | if (outName.empty()) { |
352 | 0 | outName = this->GetName(); |
353 | 0 | } |
354 | | |
355 | | // Now evaluate genex and update the previously-prepared map entry. |
356 | 0 | i->second = |
357 | 0 | cmGeneratorExpression::Evaluate(outName, this->LocalGenerator, config); |
358 | 0 | } else if (i->second.empty()) { |
359 | | // An empty map entry indicates we have been called recursively |
360 | | // from the above block. |
361 | 0 | this->LocalGenerator->GetCMakeInstance()->IssueMessage( |
362 | 0 | MessageType::FATAL_ERROR, |
363 | 0 | cmStrCat("Target '", this->GetName(), |
364 | 0 | "' OUTPUT_NAME depends on itself."), |
365 | 0 | this->GetBacktrace()); |
366 | 0 | } |
367 | 0 | return i->second; |
368 | 0 | } |
369 | | |
370 | | std::string cmGeneratorTarget::GetFilePrefix( |
371 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
372 | 0 | { |
373 | 0 | if (this->IsImported()) { |
374 | 0 | cmValue prefix = this->GetFilePrefixInternal(config, artifact); |
375 | 0 | return prefix ? *prefix : std::string(); |
376 | 0 | } |
377 | 0 | return this->GetFullNameInternalComponents(config, artifact).prefix; |
378 | 0 | } |
379 | | std::string cmGeneratorTarget::GetFileSuffix( |
380 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
381 | 0 | { |
382 | 0 | if (this->IsImported()) { |
383 | 0 | cmValue suffix = this->GetFileSuffixInternal(config, artifact); |
384 | 0 | return suffix ? *suffix : std::string(); |
385 | 0 | } |
386 | 0 | return this->GetFullNameInternalComponents(config, artifact).suffix; |
387 | 0 | } |
388 | | |
389 | | std::string cmGeneratorTarget::GetFilePostfix(std::string const& config) const |
390 | 0 | { |
391 | 0 | cmValue postfix = nullptr; |
392 | 0 | std::string frameworkPostfix; |
393 | 0 | if (!config.empty()) { |
394 | 0 | std::string configProp = |
395 | 0 | cmStrCat(cmSystemTools::UpperCase(config), "_POSTFIX"); |
396 | 0 | postfix = this->GetProperty(configProp); |
397 | | |
398 | | // Mac application bundles and frameworks have no regular postfix like |
399 | | // libraries do. |
400 | 0 | if (!this->IsImported() && postfix && |
401 | 0 | (this->IsAppBundleOnApple() || this->IsFrameworkOnApple())) { |
402 | 0 | postfix = nullptr; |
403 | 0 | } |
404 | | |
405 | | // Frameworks created by multi config generators can have a special |
406 | | // framework postfix. |
407 | 0 | frameworkPostfix = this->GetFrameworkMultiConfigPostfix(config); |
408 | 0 | if (!frameworkPostfix.empty()) { |
409 | 0 | postfix = cmValue(frameworkPostfix); |
410 | 0 | } |
411 | 0 | } |
412 | 0 | return postfix ? *postfix : std::string(); |
413 | 0 | } |
414 | | |
415 | | std::string cmGeneratorTarget::GetFrameworkMultiConfigPostfix( |
416 | | std::string const& config) const |
417 | 0 | { |
418 | 0 | cmValue postfix = nullptr; |
419 | 0 | if (!config.empty()) { |
420 | 0 | std::string configProp = cmStrCat("FRAMEWORK_MULTI_CONFIG_POSTFIX_", |
421 | 0 | cmSystemTools::UpperCase(config)); |
422 | 0 | postfix = this->GetProperty(configProp); |
423 | |
|
424 | 0 | if (!this->IsImported() && postfix && |
425 | 0 | (this->IsFrameworkOnApple() && |
426 | 0 | !this->GetGlobalGenerator()->IsMultiConfig())) { |
427 | 0 | postfix = nullptr; |
428 | 0 | } |
429 | 0 | } |
430 | 0 | return postfix ? *postfix : std::string(); |
431 | 0 | } |
432 | | |
433 | | cmValue cmGeneratorTarget::GetFilePrefixInternal( |
434 | | std::string const& config, cmStateEnums::ArtifactType artifact, |
435 | | std::string const& language) const |
436 | 0 | { |
437 | | // no prefix for non-main target types. |
438 | 0 | if (this->GetType() != cmStateEnums::STATIC_LIBRARY && |
439 | 0 | this->GetType() != cmStateEnums::SHARED_LIBRARY && |
440 | 0 | this->GetType() != cmStateEnums::MODULE_LIBRARY && |
441 | 0 | this->GetType() != cmStateEnums::EXECUTABLE) { |
442 | 0 | return nullptr; |
443 | 0 | } |
444 | | |
445 | 0 | bool const isImportedLibraryArtifact = |
446 | 0 | (artifact == cmStateEnums::ImportLibraryArtifact); |
447 | | |
448 | | // Return an empty prefix for the import library if this platform |
449 | | // does not support import libraries. |
450 | 0 | if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) { |
451 | 0 | return nullptr; |
452 | 0 | } |
453 | | |
454 | | // The implib option is only allowed for shared libraries, module |
455 | | // libraries, and executables. |
456 | 0 | if (this->GetType() != cmStateEnums::SHARED_LIBRARY && |
457 | 0 | this->GetType() != cmStateEnums::MODULE_LIBRARY && |
458 | 0 | this->GetType() != cmStateEnums::EXECUTABLE) { |
459 | 0 | artifact = cmStateEnums::RuntimeBinaryArtifact; |
460 | 0 | } |
461 | | |
462 | | // Compute prefix value. |
463 | 0 | cmValue targetPrefix = |
464 | 0 | (isImportedLibraryArtifact ? this->GetProperty("IMPORT_PREFIX") |
465 | 0 | : this->GetProperty("PREFIX")); |
466 | |
|
467 | 0 | if (!targetPrefix) { |
468 | 0 | char const* prefixVar = this->Target->GetPrefixVariableInternal(artifact); |
469 | 0 | if (!language.empty() && cmNonempty(prefixVar)) { |
470 | 0 | std::string langPrefix = cmStrCat(prefixVar, '_', language); |
471 | 0 | targetPrefix = this->Makefile->GetDefinition(langPrefix); |
472 | 0 | } |
473 | | |
474 | | // if there is no prefix on the target nor specific language |
475 | | // use the cmake definition. |
476 | 0 | if (!targetPrefix && prefixVar) { |
477 | 0 | targetPrefix = this->Makefile->GetDefinition(prefixVar); |
478 | 0 | } |
479 | 0 | } |
480 | |
|
481 | 0 | return targetPrefix; |
482 | 0 | } |
483 | | |
484 | | cmValue cmGeneratorTarget::GetFileSuffixInternal( |
485 | | std::string const& config, cmStateEnums::ArtifactType artifact, |
486 | | std::string const& language) const |
487 | 0 | { |
488 | | // no suffix for non-main target types. |
489 | 0 | if (this->GetType() != cmStateEnums::STATIC_LIBRARY && |
490 | 0 | this->GetType() != cmStateEnums::SHARED_LIBRARY && |
491 | 0 | this->GetType() != cmStateEnums::MODULE_LIBRARY && |
492 | 0 | this->GetType() != cmStateEnums::EXECUTABLE) { |
493 | 0 | return nullptr; |
494 | 0 | } |
495 | | |
496 | 0 | bool const isImportedLibraryArtifact = |
497 | 0 | (artifact == cmStateEnums::ImportLibraryArtifact); |
498 | | |
499 | | // Return an empty suffix for the import library if this platform |
500 | | // does not support import libraries. |
501 | 0 | if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) { |
502 | 0 | return nullptr; |
503 | 0 | } |
504 | | |
505 | | // The implib option is only allowed for shared libraries, module |
506 | | // libraries, and executables. |
507 | 0 | if (this->GetType() != cmStateEnums::SHARED_LIBRARY && |
508 | 0 | this->GetType() != cmStateEnums::MODULE_LIBRARY && |
509 | 0 | this->GetType() != cmStateEnums::EXECUTABLE) { |
510 | 0 | artifact = cmStateEnums::RuntimeBinaryArtifact; |
511 | 0 | } |
512 | | |
513 | | // Compute suffix value. |
514 | 0 | cmValue targetSuffix = |
515 | 0 | (isImportedLibraryArtifact ? this->GetProperty("IMPORT_SUFFIX") |
516 | 0 | : this->GetProperty("SUFFIX")); |
517 | |
|
518 | 0 | if (!targetSuffix) { |
519 | 0 | char const* suffixVar = this->Target->GetSuffixVariableInternal(artifact); |
520 | 0 | if (!language.empty() && cmNonempty(suffixVar)) { |
521 | 0 | std::string langSuffix = cmStrCat(suffixVar, '_', language); |
522 | 0 | targetSuffix = this->Makefile->GetDefinition(langSuffix); |
523 | 0 | } |
524 | | |
525 | | // if there is no suffix on the target nor specific language |
526 | | // use the cmake definition. |
527 | 0 | if (!targetSuffix && suffixVar) { |
528 | 0 | targetSuffix = this->Makefile->GetDefinition(suffixVar); |
529 | 0 | } |
530 | 0 | } |
531 | |
|
532 | 0 | return targetSuffix; |
533 | 0 | } |
534 | | |
535 | | void cmGeneratorTarget::ClearSourcesCache() |
536 | 0 | { |
537 | 0 | this->AllConfigSources.clear(); |
538 | 0 | this->AllConfigCompileLanguages.clear(); |
539 | 0 | this->KindedSourcesMap.clear(); |
540 | 0 | this->SourcesAreContextDependent = Tribool::Indeterminate; |
541 | 0 | this->Objects.clear(); |
542 | 0 | this->VisitedConfigsForObjects.clear(); |
543 | 0 | this->LinkImplClosureForLinkMap.clear(); |
544 | 0 | this->LinkImplClosureForUsageMap.clear(); |
545 | 0 | this->LinkImplMap.clear(); |
546 | 0 | this->LinkImplUsageRequirementsOnlyMap.clear(); |
547 | 0 | this->IncludeDirectoriesCache.clear(); |
548 | 0 | this->CompileOptionsCache.clear(); |
549 | 0 | this->CompileDefinitionsCache.clear(); |
550 | 0 | this->CustomTransitiveBuildPropertiesMap.clear(); |
551 | 0 | this->CustomTransitiveInterfacePropertiesMap.clear(); |
552 | 0 | this->PrecompileHeadersCache.clear(); |
553 | 0 | this->LinkOptionsCache.clear(); |
554 | 0 | this->LinkDirectoriesCache.clear(); |
555 | 0 | this->RuntimeBinaryFullNameCache.clear(); |
556 | 0 | this->ImportLibraryFullNameCache.clear(); |
557 | 0 | } |
558 | | |
559 | | void cmGeneratorTarget::ClearLinkInterfaceCache() |
560 | 0 | { |
561 | 0 | this->LinkInterfaceMap.clear(); |
562 | 0 | this->LinkInterfaceUsageRequirementsOnlyMap.clear(); |
563 | 0 | } |
564 | | |
565 | | void cmGeneratorTarget::AddSourceCommon(std::string const& src, bool before) |
566 | 0 | { |
567 | 0 | this->SourceEntries.insert( |
568 | 0 | before ? this->SourceEntries.begin() : this->SourceEntries.end(), |
569 | 0 | TargetPropertyEntry::Create( |
570 | 0 | *this->LocalGenerator->GetCMakeInstance(), |
571 | 0 | BT<std::string>(src, this->Makefile->GetBacktrace()), true)); |
572 | 0 | this->ClearSourcesCache(); |
573 | 0 | } |
574 | | |
575 | | cmSourceFile* cmGeneratorTarget::AddSource(std::string const& src, bool before) |
576 | 0 | { |
577 | 0 | auto* sf = this->Target->AddSource(src, before); |
578 | 0 | this->AddSourceCommon(src, before); |
579 | 0 | return sf; |
580 | 0 | } |
581 | | |
582 | | void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs) |
583 | 0 | { |
584 | 0 | this->Target->AddTracedSources(srcs); |
585 | 0 | if (!srcs.empty()) { |
586 | 0 | this->AddSourceCommon(cmJoin(srcs, ";")); |
587 | 0 | } |
588 | 0 | } |
589 | | |
590 | | void cmGeneratorTarget::AddIncludeDirectory(std::string const& src, |
591 | | bool before) |
592 | 0 | { |
593 | 0 | this->Target->InsertInclude( |
594 | 0 | BT<std::string>(src, this->Makefile->GetBacktrace()), before); |
595 | 0 | this->IncludeDirectoriesEntries.insert( |
596 | 0 | before ? this->IncludeDirectoriesEntries.begin() |
597 | 0 | : this->IncludeDirectoriesEntries.end(), |
598 | 0 | TargetPropertyEntry::Create( |
599 | 0 | *this->Makefile->GetCMakeInstance(), |
600 | 0 | BT<std::string>(src, this->Makefile->GetBacktrace()), true)); |
601 | 0 | } |
602 | | |
603 | | void cmGeneratorTarget::AddSystemIncludeDirectory(std::string const& inc, |
604 | | std::string const& lang) |
605 | 0 | { |
606 | 0 | std::string config_upper; |
607 | 0 | auto const& configs = |
608 | 0 | this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); |
609 | |
|
610 | 0 | for (auto const& config : configs) { |
611 | 0 | std::string inc_with_config = inc; |
612 | 0 | if (!config.empty()) { |
613 | 0 | cmSystemTools::ReplaceString(inc_with_config, "$<CONFIG>", config); |
614 | 0 | config_upper = cmSystemTools::UpperCase(config); |
615 | 0 | } |
616 | 0 | auto const& key = cmStrCat(config_upper, '/', lang); |
617 | 0 | this->Target->AddSystemIncludeDirectories({ inc_with_config }); |
618 | 0 | if (this->SystemIncludesCache.find(key) == |
619 | 0 | this->SystemIncludesCache.end()) { |
620 | 0 | this->AddSystemIncludeCacheKey(key, config, lang); |
621 | 0 | } |
622 | 0 | this->SystemIncludesCache[key].emplace_back(inc_with_config); |
623 | | |
624 | | // SystemIncludesCache should be sorted so that binary search can be used |
625 | 0 | std::sort(this->SystemIncludesCache[key].begin(), |
626 | 0 | this->SystemIncludesCache[key].end()); |
627 | 0 | } |
628 | 0 | } |
629 | | |
630 | | std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends( |
631 | | cmSourceFile const* sf) const |
632 | 0 | { |
633 | 0 | auto i = this->SourceDepends.find(sf); |
634 | 0 | if (i != this->SourceDepends.end()) { |
635 | 0 | return &i->second.Depends; |
636 | 0 | } |
637 | 0 | return nullptr; |
638 | 0 | } |
639 | | |
640 | | namespace { |
641 | | void handleSystemIncludesDep(cmLocalGenerator const* lg, |
642 | | cmGeneratorTarget const* depTgt, |
643 | | std::string const& config, |
644 | | cmGeneratorTarget const* headTarget, |
645 | | cmGeneratorExpressionDAGChecker* dagChecker, |
646 | | cmList& result, bool excludeImported, |
647 | | std::string const& language) |
648 | 0 | { |
649 | 0 | if (cmValue dirs = |
650 | 0 | depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) { |
651 | 0 | result.append(cmGeneratorExpression::Evaluate( |
652 | 0 | *dirs, lg, config, headTarget, dagChecker, depTgt, language)); |
653 | 0 | } |
654 | 0 | if (!depTgt->GetPropertyAsBool("SYSTEM")) { |
655 | 0 | return; |
656 | 0 | } |
657 | 0 | if (depTgt->IsImported()) { |
658 | 0 | if (excludeImported) { |
659 | 0 | return; |
660 | 0 | } |
661 | 0 | if (depTgt->GetPropertyAsBool("IMPORTED_NO_SYSTEM")) { |
662 | 0 | return; |
663 | 0 | } |
664 | 0 | } |
665 | | |
666 | 0 | if (cmValue dirs = depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES")) { |
667 | 0 | result.append(cmGeneratorExpression::Evaluate( |
668 | 0 | *dirs, lg, config, headTarget, dagChecker, depTgt, language)); |
669 | 0 | } |
670 | |
|
671 | 0 | if (depTgt->Target->IsFrameworkOnApple() || |
672 | 0 | depTgt->IsImportedFrameworkFolderOnApple(config)) { |
673 | 0 | if (auto fwDescriptor = depTgt->GetGlobalGenerator()->SplitFrameworkPath( |
674 | 0 | depTgt->GetLocation(config))) { |
675 | 0 | result.push_back(fwDescriptor->Directory); |
676 | 0 | result.push_back(fwDescriptor->GetFrameworkPath()); |
677 | 0 | } |
678 | 0 | } |
679 | 0 | } |
680 | | } |
681 | | |
682 | | /* clang-format off */ |
683 | | #define IMPLEMENT_VISIT(KIND) \ |
684 | 0 | do { \ |
685 | 0 | KindedSources const& kinded = this->GetKindedSources(config); \ |
686 | 0 | for (SourceAndKind const& s : kinded.Sources) { \ |
687 | 0 | if (s.Kind == KIND) { \ |
688 | 0 | data.push_back(s.Source.Value); \ |
689 | 0 | } \ |
690 | 0 | } \ |
691 | 0 | } while (false) |
692 | | /* clang-format on */ |
693 | | |
694 | | void cmGeneratorTarget::GetObjectSources( |
695 | | std::vector<cmSourceFile const*>& data, std::string const& config) const |
696 | 0 | { |
697 | 0 | IMPLEMENT_VISIT(SourceKindObjectSource); |
698 | |
|
699 | 0 | if (this->VisitedConfigsForObjects.count(config)) { |
700 | 0 | return; |
701 | 0 | } |
702 | | |
703 | 0 | for (cmSourceFile const* it : data) { |
704 | 0 | this->Objects[it]; |
705 | 0 | } |
706 | |
|
707 | 0 | this->LocalGenerator->ComputeObjectFilenames(this->Objects, config, this); |
708 | 0 | this->VisitedConfigsForObjects.insert(config); |
709 | 0 | } |
710 | | |
711 | | void cmGeneratorTarget::ComputeObjectMapping() |
712 | 0 | { |
713 | 0 | auto const& configs = |
714 | 0 | this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); |
715 | 0 | std::set<std::string> configSet(configs.begin(), configs.end()); |
716 | 0 | if (configSet == this->VisitedConfigsForObjects) { |
717 | 0 | return; |
718 | 0 | } |
719 | | |
720 | 0 | for (std::string const& c : configs) { |
721 | 0 | std::vector<cmSourceFile const*> sourceFiles; |
722 | 0 | this->GetObjectSources(sourceFiles, c); |
723 | 0 | } |
724 | 0 | } |
725 | | |
726 | | cmValue cmGeneratorTarget::GetFeature(std::string const& feature, |
727 | | std::string const& config) const |
728 | 0 | { |
729 | 0 | if (!config.empty()) { |
730 | 0 | std::string featureConfig = |
731 | 0 | cmStrCat(feature, '_', cmSystemTools::UpperCase(config)); |
732 | 0 | if (cmValue value = this->GetProperty(featureConfig)) { |
733 | 0 | return value; |
734 | 0 | } |
735 | 0 | } |
736 | 0 | if (cmValue value = this->GetProperty(feature)) { |
737 | 0 | return value; |
738 | 0 | } |
739 | 0 | return this->LocalGenerator->GetFeature(feature, config); |
740 | 0 | } |
741 | | |
742 | | std::string cmGeneratorTarget::GetLinkerTypeProperty( |
743 | | std::string const& lang, std::string const& config) const |
744 | 0 | { |
745 | 0 | std::string propName{ "LINKER_TYPE" }; |
746 | 0 | auto linkerType = this->GetProperty(propName); |
747 | 0 | if (!linkerType.IsEmpty()) { |
748 | 0 | cm::GenEx::Context context(this->LocalGenerator, config, lang); |
749 | 0 | cmGeneratorExpressionDAGChecker dagChecker{ |
750 | 0 | this, propName, nullptr, nullptr, context, |
751 | 0 | }; |
752 | 0 | auto ltype = cmGeneratorExpression::Evaluate( |
753 | 0 | *linkerType, context.LG, context.Config, this, &dagChecker, this, |
754 | 0 | context.Language); |
755 | 0 | if (this->IsDeviceLink()) { |
756 | 0 | cmList list{ ltype }; |
757 | 0 | auto const DL_BEGIN = "<DEVICE_LINK>"_s; |
758 | 0 | auto const DL_END = "</DEVICE_LINK>"_s; |
759 | 0 | cm::erase_if(list, [&](std::string const& item) { |
760 | 0 | return item == DL_BEGIN || item == DL_END; |
761 | 0 | }); |
762 | 0 | return list.to_string(); |
763 | 0 | } |
764 | 0 | return ltype; |
765 | 0 | } |
766 | 0 | return std::string{}; |
767 | 0 | } |
768 | | |
769 | | char const* cmGeneratorTarget::GetLinkPIEProperty( |
770 | | std::string const& config) const |
771 | 0 | { |
772 | 0 | static std::string PICValue; |
773 | |
|
774 | 0 | PICValue = this->GetLinkInterfaceDependentStringAsBoolProperty( |
775 | 0 | "POSITION_INDEPENDENT_CODE", config); |
776 | |
|
777 | 0 | if (PICValue == "(unset)") { |
778 | | // POSITION_INDEPENDENT_CODE is not set |
779 | 0 | return nullptr; |
780 | 0 | } |
781 | | |
782 | 0 | auto status = this->GetPolicyStatusCMP0083(); |
783 | 0 | return (status != cmPolicies::WARN && status != cmPolicies::OLD) |
784 | 0 | ? PICValue.c_str() |
785 | 0 | : nullptr; |
786 | 0 | } |
787 | | |
788 | | bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang, |
789 | | std::string const& config) const |
790 | 0 | { |
791 | 0 | cmValue feature = this->GetFeature("INTERPROCEDURAL_OPTIMIZATION", config); |
792 | |
|
793 | 0 | if (!feature.IsOn()) { |
794 | | // 'INTERPROCEDURAL_OPTIMIZATION' is off, no need to check policies |
795 | 0 | return false; |
796 | 0 | } |
797 | | |
798 | 0 | if (lang != "C" && lang != "CXX" && lang != "CUDA" && lang != "Fortran") { |
799 | | // We do not define IPO behavior for other languages. |
800 | 0 | return false; |
801 | 0 | } |
802 | | |
803 | 0 | if (lang == "CUDA") { |
804 | | // CUDA IPO requires both CUDA_ARCHITECTURES and CUDA_SEPARABLE_COMPILATION |
805 | 0 | if (cmIsOff(this->GetSafeProperty("CUDA_ARCHITECTURES")) || |
806 | 0 | cmIsOff(this->GetSafeProperty("CUDA_SEPARABLE_COMPILATION"))) { |
807 | 0 | return false; |
808 | 0 | } |
809 | 0 | } |
810 | | |
811 | 0 | cmPolicies::PolicyStatus cmp0069 = this->GetPolicyStatusCMP0069(); |
812 | |
|
813 | 0 | if (cmp0069 == cmPolicies::OLD || cmp0069 == cmPolicies::WARN) { |
814 | 0 | if (this->Makefile->IsOn( |
815 | 0 | cmStrCat("_CMAKE_", lang, "_IPO_LEGACY_BEHAVIOR"))) { |
816 | 0 | return true; |
817 | 0 | } |
818 | 0 | if (this->PolicyReportedCMP0069) { |
819 | | // problem is already reported, no need to issue a message |
820 | 0 | return false; |
821 | 0 | } |
822 | 0 | bool const in_try_compile = |
823 | 0 | this->LocalGenerator->GetCMakeInstance()->GetIsInTryCompile(); |
824 | 0 | if (cmp0069 == cmPolicies::WARN && !in_try_compile) { |
825 | 0 | this->Makefile->IssuePolicyWarning( |
826 | 0 | cmPolicies::CMP0069, {}, |
827 | 0 | cmStrCat("INTERPROCEDURAL_OPTIMIZATION property " |
828 | 0 | "will be ignored for target '"_s, |
829 | 0 | this->GetName(), "'."_s), |
830 | 0 | this->GetBacktrace()); |
831 | |
|
832 | 0 | this->PolicyReportedCMP0069 = true; |
833 | 0 | } |
834 | 0 | return false; |
835 | 0 | } |
836 | | |
837 | | // Note: check consistency with messages from CheckIPOSupported |
838 | 0 | char const* message = nullptr; |
839 | 0 | if (!this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_SUPPORTED_BY_CMAKE")) { |
840 | 0 | message = "CMake doesn't support IPO for current compiler"; |
841 | 0 | } else if (!this->Makefile->IsOn("_CMAKE_" + lang + |
842 | 0 | "_IPO_MAY_BE_SUPPORTED_BY_COMPILER")) { |
843 | 0 | message = "Compiler doesn't support IPO"; |
844 | 0 | } else if (!this->GlobalGenerator->IsIPOSupported()) { |
845 | 0 | message = "CMake doesn't support IPO for current generator"; |
846 | 0 | } |
847 | |
|
848 | 0 | if (!message) { |
849 | | // No error/warning messages |
850 | 0 | return true; |
851 | 0 | } |
852 | | |
853 | 0 | if (this->PolicyReportedCMP0069) { |
854 | | // problem is already reported, no need to issue a message |
855 | 0 | return false; |
856 | 0 | } |
857 | | |
858 | 0 | this->PolicyReportedCMP0069 = true; |
859 | |
|
860 | 0 | this->LocalGenerator->GetCMakeInstance()->IssueMessage( |
861 | 0 | MessageType::FATAL_ERROR, message, this->GetBacktrace()); |
862 | 0 | return false; |
863 | 0 | } |
864 | | |
865 | | std::string const& cmGeneratorTarget::GetObjectName(cmSourceFile const* file) |
866 | 0 | { |
867 | 0 | this->ComputeObjectMapping(); |
868 | 0 | auto const useShortPaths = this->GetUseShortObjectNames() |
869 | 0 | ? cmObjectLocations::UseShortPath::Yes |
870 | 0 | : cmObjectLocations::UseShortPath::No; |
871 | 0 | return this->Objects[file].GetPath(useShortPaths); |
872 | 0 | } |
873 | | |
874 | | char const* cmGeneratorTarget::GetCustomObjectExtension() const |
875 | 0 | { |
876 | 0 | struct compiler_mode |
877 | 0 | { |
878 | 0 | std::string variable; |
879 | 0 | std::string extension; |
880 | 0 | }; |
881 | 0 | static std::array<compiler_mode, 4> const modes{ |
882 | 0 | { { "CUDA_PTX_COMPILATION", ".ptx" }, |
883 | 0 | { "CUDA_CUBIN_COMPILATION", ".cubin" }, |
884 | 0 | { "CUDA_FATBIN_COMPILATION", ".fatbin" }, |
885 | 0 | { "CUDA_OPTIX_COMPILATION", ".optixir" } } |
886 | 0 | }; |
887 | |
|
888 | 0 | std::string const& compiler = |
889 | 0 | this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID"); |
890 | 0 | if (!compiler.empty()) { |
891 | 0 | for (auto const& m : modes) { |
892 | 0 | bool const has_extension = this->GetPropertyAsBool(m.variable); |
893 | 0 | if (has_extension) { |
894 | 0 | return m.extension.c_str(); |
895 | 0 | } |
896 | 0 | } |
897 | 0 | } |
898 | 0 | return nullptr; |
899 | 0 | } |
900 | | |
901 | | void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf) |
902 | 0 | { |
903 | 0 | this->ExplicitObjectName.insert(sf); |
904 | 0 | } |
905 | | |
906 | | bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const |
907 | 0 | { |
908 | 0 | const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping(); |
909 | 0 | auto it = this->ExplicitObjectName.find(file); |
910 | 0 | return it != this->ExplicitObjectName.end(); |
911 | 0 | } |
912 | | |
913 | | BTs<std::string> const* cmGeneratorTarget::GetLanguageStandardProperty( |
914 | | std::string const& lang, std::string const& config) const |
915 | 0 | { |
916 | 0 | std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang); |
917 | 0 | auto langStandardIter = this->LanguageStandardMap.find(key); |
918 | 0 | if (langStandardIter != this->LanguageStandardMap.end()) { |
919 | 0 | return &langStandardIter->second; |
920 | 0 | } |
921 | | |
922 | 0 | return this->Target->GetLanguageStandardProperty( |
923 | 0 | cmStrCat(lang, "_STANDARD")); |
924 | 0 | } |
925 | | |
926 | | cmValue cmGeneratorTarget::GetLanguageStandard(std::string const& lang, |
927 | | std::string const& config) const |
928 | 0 | { |
929 | 0 | BTs<std::string> const* languageStandard = |
930 | 0 | this->GetLanguageStandardProperty(lang, config); |
931 | |
|
932 | 0 | if (languageStandard) { |
933 | 0 | return cmValue(languageStandard->Value); |
934 | 0 | } |
935 | | |
936 | 0 | return nullptr; |
937 | 0 | } |
938 | | |
939 | | cmValue cmGeneratorTarget::GetPropertyWithPairedLanguageSupport( |
940 | | std::string const& lang, char const* suffix) const |
941 | 0 | { |
942 | 0 | cmValue propertyValue = this->Target->GetProperty(cmStrCat(lang, suffix)); |
943 | 0 | if (!propertyValue) { |
944 | | // Check if we should use the value set by another language. |
945 | 0 | if (lang == "OBJC") { |
946 | 0 | propertyValue = this->GetPropertyWithPairedLanguageSupport("C", suffix); |
947 | 0 | } else if (lang == "OBJCXX" || lang == "CUDA" || lang == "HIP") { |
948 | 0 | propertyValue = |
949 | 0 | this->GetPropertyWithPairedLanguageSupport("CXX", suffix); |
950 | 0 | } |
951 | 0 | } |
952 | 0 | return propertyValue; |
953 | 0 | } |
954 | | |
955 | | cmValue cmGeneratorTarget::GetLanguageExtensions(std::string const& lang) const |
956 | 0 | { |
957 | 0 | return this->GetPropertyWithPairedLanguageSupport(lang, "_EXTENSIONS"); |
958 | 0 | } |
959 | | |
960 | | bool cmGeneratorTarget::GetLanguageStandardRequired( |
961 | | std::string const& lang) const |
962 | 0 | { |
963 | 0 | return this->GetPropertyWithPairedLanguageSupport(lang, "_STANDARD_REQUIRED") |
964 | 0 | .IsOn(); |
965 | 0 | } |
966 | | |
967 | | void cmGeneratorTarget::GetModuleDefinitionSources( |
968 | | std::vector<cmSourceFile const*>& data, std::string const& config) const |
969 | 0 | { |
970 | 0 | IMPLEMENT_VISIT(SourceKindModuleDefinition); |
971 | 0 | } |
972 | | |
973 | | void cmGeneratorTarget::GetHeaderSources( |
974 | | std::vector<cmSourceFile const*>& data, std::string const& config) const |
975 | 0 | { |
976 | 0 | IMPLEMENT_VISIT(SourceKindHeader); |
977 | 0 | } |
978 | | |
979 | | void cmGeneratorTarget::GetCxxModuleSources( |
980 | | std::vector<cmSourceFile const*>& data, std::string const& config) const |
981 | 0 | { |
982 | 0 | IMPLEMENT_VISIT(SourceKindCxxModuleSource); |
983 | 0 | } |
984 | | |
985 | | void cmGeneratorTarget::GetExtraSources(std::vector<cmSourceFile const*>& data, |
986 | | std::string const& config) const |
987 | 0 | { |
988 | 0 | IMPLEMENT_VISIT(SourceKindExtra); |
989 | 0 | } |
990 | | |
991 | | void cmGeneratorTarget::GetCustomCommands( |
992 | | std::vector<cmSourceFile const*>& data, std::string const& config) const |
993 | 0 | { |
994 | 0 | IMPLEMENT_VISIT(SourceKindCustomCommand); |
995 | 0 | } |
996 | | |
997 | | void cmGeneratorTarget::GetExternalObjects( |
998 | | std::vector<cmSourceFile const*>& data, std::string const& config) const |
999 | 0 | { |
1000 | 0 | IMPLEMENT_VISIT(SourceKindExternalObject); |
1001 | 0 | } |
1002 | | |
1003 | | void cmGeneratorTarget::GetManifests(std::vector<cmSourceFile const*>& data, |
1004 | | std::string const& config) const |
1005 | 0 | { |
1006 | 0 | IMPLEMENT_VISIT(SourceKindManifest); |
1007 | 0 | } |
1008 | | |
1009 | | void cmGeneratorTarget::GetRustMainCrateRoot( |
1010 | | std::vector<cmSourceFile const*>& data, std::string const& config) const |
1011 | 0 | { |
1012 | 0 | IMPLEMENT_VISIT(SourceKindRustMainCrateRoot); |
1013 | 0 | } |
1014 | | |
1015 | | cmSourceFile const* cmGeneratorTarget::GetRustMainCrateRoot( |
1016 | | std::string const& config) const |
1017 | 0 | { |
1018 | 0 | std::vector<cmSourceFile const*> files; |
1019 | 0 | GetRustMainCrateRoot(files, config); |
1020 | 0 | if (files.empty()) { |
1021 | 0 | return nullptr; |
1022 | 0 | } |
1023 | 0 | assert(files.size() == 1); |
1024 | 0 | return files[0]; |
1025 | 0 | } |
1026 | | |
1027 | | std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const |
1028 | 0 | { |
1029 | 0 | if (!this->UtilityItemsDone) { |
1030 | 0 | this->UtilityItemsDone = true; |
1031 | 0 | std::set<BT<std::pair<std::string, bool>>> const& utilities = |
1032 | 0 | this->GetUtilities(); |
1033 | 0 | for (BT<std::pair<std::string, bool>> const& i : utilities) { |
1034 | 0 | if (cmGeneratorTarget* gt = |
1035 | 0 | this->LocalGenerator->FindGeneratorTargetToUse(i.Value.first)) { |
1036 | 0 | this->UtilityItems.insert(cmLinkItem(gt, i.Value.second, i.Backtrace)); |
1037 | 0 | } else { |
1038 | 0 | this->UtilityItems.insert( |
1039 | 0 | cmLinkItem(i.Value.first, i.Value.second, i.Backtrace)); |
1040 | 0 | } |
1041 | 0 | } |
1042 | 0 | if (cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget()) { |
1043 | 0 | this->UtilityItems.insert( |
1044 | 0 | cmLinkItem(reuseTarget, false, cmListFileBacktrace())); |
1045 | 0 | } |
1046 | 0 | } |
1047 | 0 | return this->UtilityItems; |
1048 | 0 | } |
1049 | | |
1050 | | std::string const& cmGeneratorTarget::GetLocation( |
1051 | | std::string const& config) const |
1052 | 0 | { |
1053 | 0 | static std::string location; |
1054 | 0 | if (this->IsImported()) { |
1055 | 0 | location = this->Target->ImportedGetFullPath( |
1056 | 0 | config, cmStateEnums::RuntimeBinaryArtifact); |
1057 | 0 | } else { |
1058 | 0 | location = this->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact); |
1059 | 0 | } |
1060 | 0 | return location; |
1061 | 0 | } |
1062 | | |
1063 | | cm::optional<std::string> cmGeneratorTarget::MaybeGetLocation( |
1064 | | std::string const& config) const |
1065 | 0 | { |
1066 | 0 | cm::optional<std::string> location; |
1067 | 0 | if (cmGeneratorTarget::ImportInfo const* imp = this->GetImportInfo(config)) { |
1068 | 0 | if (!imp->Location.empty()) { |
1069 | 0 | location = imp->Location; |
1070 | 0 | } |
1071 | 0 | } else { |
1072 | 0 | location = this->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact); |
1073 | 0 | } |
1074 | 0 | return location; |
1075 | 0 | } |
1076 | | |
1077 | | std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreBuildCommands() |
1078 | | const |
1079 | 0 | { |
1080 | 0 | return this->Target->GetPreBuildCommands(); |
1081 | 0 | } |
1082 | | |
1083 | | std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreLinkCommands() |
1084 | | const |
1085 | 0 | { |
1086 | 0 | return this->Target->GetPreLinkCommands(); |
1087 | 0 | } |
1088 | | |
1089 | | std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPostBuildCommands() |
1090 | | const |
1091 | 0 | { |
1092 | 0 | return this->Target->GetPostBuildCommands(); |
1093 | 0 | } |
1094 | | |
1095 | | void cmGeneratorTarget::AppendCustomCommandSideEffects( |
1096 | | std::set<cmGeneratorTarget const*>& sideEffects) const |
1097 | 0 | { |
1098 | 0 | if (!this->GetPreBuildCommands().empty() || |
1099 | 0 | !this->GetPreLinkCommands().empty() || |
1100 | 0 | !this->GetPostBuildCommands().empty()) { |
1101 | 0 | sideEffects.insert(this); |
1102 | 0 | } else { |
1103 | 0 | for (auto const& source : this->GetAllConfigSources()) { |
1104 | 0 | if (source.Source->GetCustomCommand()) { |
1105 | 0 | sideEffects.insert(this); |
1106 | 0 | break; |
1107 | 0 | } |
1108 | 0 | } |
1109 | 0 | } |
1110 | 0 | } |
1111 | | |
1112 | | void cmGeneratorTarget::AppendLanguageSideEffects( |
1113 | | std::map<std::string, std::set<cmGeneratorTarget const*>>& sideEffects) const |
1114 | 0 | { |
1115 | 0 | static std::set<cm::string_view> const LANGS_WITH_NO_SIDE_EFFECTS = { |
1116 | 0 | "C"_s, "CXX"_s, "OBJC"_s, "OBJCXX"_s, "ASM"_s, "CUDA"_s, "HIP"_s |
1117 | 0 | }; |
1118 | |
|
1119 | 0 | for (auto const& lang : this->GetAllConfigCompileLanguages()) { |
1120 | 0 | if (!LANGS_WITH_NO_SIDE_EFFECTS.count(lang)) { |
1121 | 0 | sideEffects[lang].insert(this); |
1122 | 0 | } |
1123 | 0 | } |
1124 | 0 | } |
1125 | | |
1126 | | bool cmGeneratorTarget::IsInBuildSystem() const |
1127 | 0 | { |
1128 | 0 | if (this->IsImported()) { |
1129 | 0 | return false; |
1130 | 0 | } |
1131 | 0 | switch (this->Target->GetType()) { |
1132 | 0 | case cmStateEnums::EXECUTABLE: |
1133 | 0 | case cmStateEnums::STATIC_LIBRARY: |
1134 | 0 | case cmStateEnums::SHARED_LIBRARY: |
1135 | 0 | case cmStateEnums::MODULE_LIBRARY: |
1136 | 0 | case cmStateEnums::OBJECT_LIBRARY: |
1137 | 0 | case cmStateEnums::UTILITY: |
1138 | 0 | case cmStateEnums::GLOBAL_TARGET: |
1139 | 0 | return true; |
1140 | 0 | case cmStateEnums::INTERFACE_LIBRARY: |
1141 | | // An INTERFACE library is in the build system if it has SOURCES |
1142 | | // or C++ module filesets. |
1143 | 0 | if (!this->SourceEntries.empty() || |
1144 | 0 | !this->GetFileSets(cm::FileSetMetadata::HEADERS).empty() || |
1145 | 0 | !this->GetFileSets(cm::FileSetMetadata::CXX_MODULES).empty()) { |
1146 | 0 | return true; |
1147 | 0 | } |
1148 | 0 | break; |
1149 | 0 | case cmStateEnums::UNKNOWN_LIBRARY: |
1150 | 0 | break; |
1151 | 0 | } |
1152 | 0 | return false; |
1153 | 0 | } |
1154 | | |
1155 | | bool cmGeneratorTarget::IsNormal() const |
1156 | 0 | { |
1157 | 0 | return this->Target->IsNormal(); |
1158 | 0 | } |
1159 | | |
1160 | | bool cmGeneratorTarget::IsRuntimeBinary() const |
1161 | 0 | { |
1162 | 0 | return this->Target->IsRuntimeBinary(); |
1163 | 0 | } |
1164 | | |
1165 | | bool cmGeneratorTarget::IsSynthetic() const |
1166 | 0 | { |
1167 | 0 | return this->Target->IsSynthetic(); |
1168 | 0 | } |
1169 | | |
1170 | | bool cmGeneratorTarget::IsImported() const |
1171 | 0 | { |
1172 | 0 | return this->Target->IsImported(); |
1173 | 0 | } |
1174 | | |
1175 | | bool cmGeneratorTarget::IsImportedGloballyVisible() const |
1176 | 0 | { |
1177 | 0 | return this->Target->IsImportedGloballyVisible(); |
1178 | 0 | } |
1179 | | |
1180 | | bool cmGeneratorTarget::IsSymbolic() const |
1181 | 0 | { |
1182 | 0 | return this->Target->IsSymbolic(); |
1183 | 0 | } |
1184 | | |
1185 | | bool cmGeneratorTarget::IsForeign() const |
1186 | 0 | { |
1187 | 0 | return this->Target->IsForeign(); |
1188 | 0 | } |
1189 | | |
1190 | | bool cmGeneratorTarget::CanCompileSources() const |
1191 | 0 | { |
1192 | 0 | return this->Target->CanCompileSources(); |
1193 | 0 | } |
1194 | | |
1195 | | bool cmGeneratorTarget::HasKnownRuntimeArtifactLocation( |
1196 | | std::string const& config) const |
1197 | 0 | { |
1198 | 0 | if (!this->IsRuntimeBinary()) { |
1199 | 0 | return false; |
1200 | 0 | } |
1201 | 0 | if (!this->IsImported()) { |
1202 | 0 | return true; |
1203 | 0 | } |
1204 | 0 | ImportInfo const* info = this->GetImportInfo(config); |
1205 | 0 | return info && !info->Location.empty(); |
1206 | 0 | } |
1207 | | |
1208 | | std::string const& cmGeneratorTarget::GetLocationForBuild() const |
1209 | 0 | { |
1210 | 0 | static std::string location; |
1211 | 0 | if (this->IsImported()) { |
1212 | 0 | location = this->Target->ImportedGetFullPath( |
1213 | 0 | "", cmStateEnums::RuntimeBinaryArtifact); |
1214 | 0 | return location; |
1215 | 0 | } |
1216 | | |
1217 | | // Now handle the deprecated build-time configuration location. |
1218 | 0 | std::string const noConfig; |
1219 | 0 | location = this->GetDirectory(noConfig); |
1220 | 0 | cmValue cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR"); |
1221 | 0 | if (cfgid && (*cfgid != ".")) { |
1222 | 0 | location += "/"; |
1223 | 0 | location += *cfgid; |
1224 | 0 | } |
1225 | |
|
1226 | 0 | if (this->IsAppBundleOnApple()) { |
1227 | 0 | std::string macdir = this->BuildBundleDirectory("", "", FullLevel); |
1228 | 0 | if (!macdir.empty()) { |
1229 | 0 | location += "/"; |
1230 | 0 | location += macdir; |
1231 | 0 | } |
1232 | 0 | } |
1233 | 0 | location += "/"; |
1234 | 0 | location += this->GetFullName("", cmStateEnums::RuntimeBinaryArtifact); |
1235 | 0 | return location; |
1236 | 0 | } |
1237 | | |
1238 | | void cmGeneratorTarget::AddSystemIncludeCacheKey( |
1239 | | std::string const& key, std::string const& config, |
1240 | | std::string const& language) const |
1241 | 0 | { |
1242 | 0 | cm::GenEx::Context context(this->LocalGenerator, config, language); |
1243 | 0 | cmGeneratorExpressionDAGChecker dagChecker{ |
1244 | 0 | this, "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr, context, |
1245 | 0 | }; |
1246 | |
|
1247 | 0 | bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED"); |
1248 | |
|
1249 | 0 | cmList result; |
1250 | 0 | for (std::string const& it : this->Target->GetSystemIncludeDirectories()) { |
1251 | 0 | result.append( |
1252 | 0 | cmGeneratorExpression::Evaluate(it, context.LG, context.Config, this, |
1253 | 0 | &dagChecker, nullptr, context.Language)); |
1254 | 0 | } |
1255 | |
|
1256 | 0 | std::vector<cmGeneratorTarget const*> const& deps = |
1257 | 0 | this->GetLinkImplementationClosure(config, UseTo::Compile); |
1258 | 0 | for (cmGeneratorTarget const* dep : deps) { |
1259 | 0 | handleSystemIncludesDep(context.LG, dep, context.Config, this, &dagChecker, |
1260 | 0 | result, excludeImported, context.Language); |
1261 | 0 | } |
1262 | |
|
1263 | 0 | cmLinkImplementation const* impl = |
1264 | 0 | this->GetLinkImplementation(config, UseTo::Compile); |
1265 | 0 | if (impl) { |
1266 | 0 | auto runtimeEntries = impl->LanguageRuntimeLibraries.find(language); |
1267 | 0 | if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) { |
1268 | 0 | for (auto const& lib : runtimeEntries->second) { |
1269 | 0 | if (lib.Target) { |
1270 | 0 | handleSystemIncludesDep(context.LG, lib.Target, context.Config, this, |
1271 | 0 | &dagChecker, result, excludeImported, |
1272 | 0 | context.Language); |
1273 | 0 | } |
1274 | 0 | } |
1275 | 0 | } |
1276 | 0 | } |
1277 | |
|
1278 | 0 | std::for_each(result.begin(), result.end(), |
1279 | 0 | cmSystemTools::ConvertToUnixSlashes); |
1280 | 0 | std::sort(result.begin(), result.end()); |
1281 | 0 | result.erase(std::unique(result.begin(), result.end()), result.end()); |
1282 | 0 | SystemIncludesCache.emplace(key, result); |
1283 | 0 | } |
1284 | | |
1285 | | bool cmGeneratorTarget::IsSystemIncludeDirectory( |
1286 | | std::string const& dir, std::string const& config, |
1287 | | std::string const& language) const |
1288 | 0 | { |
1289 | 0 | std::string config_upper; |
1290 | 0 | if (!config.empty()) { |
1291 | 0 | config_upper = cmSystemTools::UpperCase(config); |
1292 | 0 | } |
1293 | |
|
1294 | 0 | std::string key = cmStrCat(config_upper, '/', language); |
1295 | 0 | auto iter = this->SystemIncludesCache.find(key); |
1296 | |
|
1297 | 0 | if (iter == this->SystemIncludesCache.end()) { |
1298 | 0 | this->AddSystemIncludeCacheKey(key, config, language); |
1299 | 0 | iter = this->SystemIncludesCache.find(key); |
1300 | 0 | } |
1301 | |
|
1302 | 0 | return std::binary_search(iter->second.begin(), iter->second.end(), dir); |
1303 | 0 | } |
1304 | | |
1305 | | bool cmGeneratorTarget::GetPropertyAsBool(std::string const& prop) const |
1306 | 0 | { |
1307 | 0 | return this->Target->GetPropertyAsBool(prop); |
1308 | 0 | } |
1309 | | |
1310 | | std::string cmGeneratorTarget::GetCompilePDBName( |
1311 | | std::string const& config) const |
1312 | 0 | { |
1313 | 0 | if (cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget()) { |
1314 | 0 | if (reuseTarget != this) { |
1315 | 0 | return reuseTarget->GetCompilePDBName(config); |
1316 | 0 | } |
1317 | 0 | } |
1318 | | |
1319 | | // Check for a per-configuration output directory target property. |
1320 | 0 | std::string configUpper = cmSystemTools::UpperCase(config); |
1321 | 0 | std::string configProp = cmStrCat("COMPILE_PDB_NAME_", configUpper); |
1322 | 0 | cmValue config_name = this->GetProperty(configProp); |
1323 | 0 | if (cmNonempty(config_name)) { |
1324 | 0 | std::string pdbName = cmGeneratorExpression::Evaluate( |
1325 | 0 | *config_name, this->LocalGenerator, config, this); |
1326 | 0 | NameComponents const& components = GetFullNameInternalComponents( |
1327 | 0 | config, cmStateEnums::RuntimeBinaryArtifact); |
1328 | 0 | return components.prefix + pdbName + ".pdb"; |
1329 | 0 | } |
1330 | | |
1331 | 0 | cmValue name = this->GetProperty("COMPILE_PDB_NAME"); |
1332 | 0 | if (cmNonempty(name)) { |
1333 | 0 | std::string pdbName = cmGeneratorExpression::Evaluate( |
1334 | 0 | *name, this->LocalGenerator, config, this); |
1335 | 0 | NameComponents const& components = GetFullNameInternalComponents( |
1336 | 0 | config, cmStateEnums::RuntimeBinaryArtifact); |
1337 | 0 | return components.prefix + pdbName + ".pdb"; |
1338 | 0 | } |
1339 | | |
1340 | | // If the target is PCH-reused or PCH-reuses, we need a stable name for the |
1341 | | // PDB file so that reusing targets can construct a stable name for it. |
1342 | 0 | cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget(); |
1343 | 0 | bool const hasReuse = reuseTarget && reuseTarget != this; |
1344 | 0 | if (this->PchReused || hasReuse) { |
1345 | 0 | NameComponents const& components = GetFullNameInternalComponents( |
1346 | 0 | config, cmStateEnums::RuntimeBinaryArtifact); |
1347 | 0 | return cmStrCat(components.prefix, this->GetName(), ".pdb"); |
1348 | 0 | } |
1349 | | |
1350 | 0 | return std::string{}; |
1351 | 0 | } |
1352 | | |
1353 | | std::string cmGeneratorTarget::GetCompilePDBPath( |
1354 | | std::string const& config) const |
1355 | 0 | { |
1356 | 0 | std::string dir = this->GetCompilePDBDirectory(config); |
1357 | 0 | std::string name = this->GetCompilePDBName(config); |
1358 | 0 | if (dir.empty() && !name.empty() && this->HaveWellDefinedOutputFiles()) { |
1359 | 0 | dir = this->GetPDBDirectory(config); |
1360 | 0 | } |
1361 | 0 | if (!dir.empty()) { |
1362 | 0 | dir += "/"; |
1363 | 0 | } |
1364 | 0 | return dir + name; |
1365 | 0 | } |
1366 | | |
1367 | | bool cmGeneratorTarget::HasSOName(std::string const& config) const |
1368 | 0 | { |
1369 | | // soname is supported only for shared libraries and modules, |
1370 | | // and then only when the platform supports an soname flag. |
1371 | 0 | return ((this->GetType() == cmStateEnums::SHARED_LIBRARY) && |
1372 | 0 | !this->GetPropertyAsBool("NO_SONAME") && |
1373 | 0 | (this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)) || |
1374 | 0 | this->IsArchivedAIXSharedLibrary())); |
1375 | 0 | } |
1376 | | |
1377 | | bool cmGeneratorTarget::NeedRelinkBeforeInstall( |
1378 | | std::string const& config) const |
1379 | 0 | { |
1380 | | // Only executables and shared libraries can have an rpath and may |
1381 | | // need relinking. |
1382 | 0 | if (this->GetType() != cmStateEnums::EXECUTABLE && |
1383 | 0 | this->GetType() != cmStateEnums::SHARED_LIBRARY && |
1384 | 0 | this->GetType() != cmStateEnums::MODULE_LIBRARY) { |
1385 | 0 | return false; |
1386 | 0 | } |
1387 | | |
1388 | | // If there is no install location this target will not be installed |
1389 | | // and therefore does not need relinking. |
1390 | 0 | if (!this->Target->GetHaveInstallRule()) { |
1391 | 0 | return false; |
1392 | 0 | } |
1393 | | |
1394 | | // If skipping all rpaths completely then no relinking is needed. |
1395 | 0 | if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) { |
1396 | 0 | return false; |
1397 | 0 | } |
1398 | | |
1399 | | // If building with the install-tree rpath no relinking is needed. |
1400 | 0 | if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) { |
1401 | 0 | return false; |
1402 | 0 | } |
1403 | | |
1404 | | // If chrpath is going to be used no relinking is needed. |
1405 | 0 | if (this->IsChrpathUsed(config)) { |
1406 | 0 | return false; |
1407 | 0 | } |
1408 | | |
1409 | | // Check for rpath support on this platform. |
1410 | 0 | std::string ll = this->GetLinkerLanguage(config); |
1411 | 0 | if (!ll.empty()) { |
1412 | 0 | std::string flagVar = |
1413 | 0 | cmStrCat("CMAKE_SHARED_LIBRARY_RUNTIME_", ll, "_FLAG"); |
1414 | 0 | if (!this->Makefile->IsSet(flagVar)) { |
1415 | | // There is no rpath support on this platform so nothing needs |
1416 | | // relinking. |
1417 | 0 | return false; |
1418 | 0 | } |
1419 | 0 | } else { |
1420 | | // No linker language is known. This error will be reported by |
1421 | | // other code. |
1422 | 0 | return false; |
1423 | 0 | } |
1424 | | |
1425 | | // If either a build or install tree rpath is set then the rpath |
1426 | | // will likely change between the build tree and install tree and |
1427 | | // this target must be relinked. |
1428 | 0 | bool have_rpath = |
1429 | 0 | this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH(config); |
1430 | 0 | bool is_ninja = this->LocalGenerator->GetGlobalGenerator()->IsNinja(); |
1431 | |
|
1432 | 0 | if (have_rpath && is_ninja) { |
1433 | 0 | std::ostringstream w; |
1434 | | /* clang-format off */ |
1435 | 0 | w << |
1436 | 0 | "The install of the " << this->GetName() << " target requires changing " |
1437 | 0 | "an RPATH from the build tree, but this is not supported with the Ninja " |
1438 | 0 | "generator unless on an ELF-based or XCOFF-based platform. " |
1439 | 0 | "The CMAKE_BUILD_WITH_INSTALL_RPATH variable may be set to avoid this " |
1440 | 0 | "relinking step." |
1441 | 0 | ; |
1442 | | /* clang-format on */ |
1443 | |
|
1444 | 0 | cmake* cm = this->LocalGenerator->GetCMakeInstance(); |
1445 | 0 | cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace()); |
1446 | 0 | } |
1447 | |
|
1448 | 0 | return have_rpath; |
1449 | 0 | } |
1450 | | |
1451 | | bool cmGeneratorTarget::IsChrpathUsed(std::string const& config) const |
1452 | 0 | { |
1453 | | // Only certain target types have an rpath. |
1454 | 0 | if (!(this->GetType() == cmStateEnums::SHARED_LIBRARY || |
1455 | 0 | this->GetType() == cmStateEnums::MODULE_LIBRARY || |
1456 | 0 | this->GetType() == cmStateEnums::EXECUTABLE)) { |
1457 | 0 | return false; |
1458 | 0 | } |
1459 | | |
1460 | | // If the target will not be installed we do not need to change its |
1461 | | // rpath. |
1462 | 0 | if (!this->Target->GetHaveInstallRule()) { |
1463 | 0 | return false; |
1464 | 0 | } |
1465 | | |
1466 | | // Skip chrpath if skipping rpath altogether. |
1467 | 0 | if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) { |
1468 | 0 | return false; |
1469 | 0 | } |
1470 | | |
1471 | | // Skip chrpath if it does not need to be changed at install time. |
1472 | 0 | if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) { |
1473 | 0 | return false; |
1474 | 0 | } |
1475 | | |
1476 | | // Allow the user to disable builtin chrpath explicitly. |
1477 | 0 | if (this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH")) { |
1478 | 0 | return false; |
1479 | 0 | } |
1480 | | |
1481 | 0 | if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) { |
1482 | 0 | return true; |
1483 | 0 | } |
1484 | | |
1485 | | // Enable if the rpath flag uses a separator and the target uses |
1486 | | // binaries we know how to edit. |
1487 | 0 | std::string ll = this->GetLinkerLanguage(config); |
1488 | 0 | if (!ll.empty()) { |
1489 | 0 | std::string sepVar = |
1490 | 0 | cmStrCat("CMAKE_SHARED_LIBRARY_RUNTIME_", ll, "_FLAG_SEP"); |
1491 | 0 | cmValue sep = this->Makefile->GetDefinition(sepVar); |
1492 | 0 | if (cmNonempty(sep)) { |
1493 | | // TODO: Add binary format check to ABI detection and get rid of |
1494 | | // CMAKE_EXECUTABLE_FORMAT. |
1495 | 0 | if (cmValue fmt = |
1496 | 0 | this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT")) { |
1497 | 0 | if (*fmt == "ELF") { |
1498 | 0 | return true; |
1499 | 0 | } |
1500 | | #if defined(CMake_USE_XCOFF_PARSER) |
1501 | | if (*fmt == "XCOFF") { |
1502 | | return true; |
1503 | | } |
1504 | | #endif |
1505 | 0 | } |
1506 | 0 | } |
1507 | 0 | } |
1508 | 0 | return false; |
1509 | 0 | } |
1510 | | |
1511 | | bool cmGeneratorTarget::IsImportedSharedLibWithoutSOName( |
1512 | | std::string const& config) const |
1513 | 0 | { |
1514 | 0 | if (this->IsImported() && this->GetType() == cmStateEnums::SHARED_LIBRARY) { |
1515 | 0 | if (cmGeneratorTarget::ImportInfo const* info = |
1516 | 0 | this->GetImportInfo(config)) { |
1517 | 0 | return info->NoSOName; |
1518 | 0 | } |
1519 | 0 | } |
1520 | 0 | return false; |
1521 | 0 | } |
1522 | | |
1523 | | bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir( |
1524 | | std::string const& config) const |
1525 | 0 | { |
1526 | 0 | TargetPtrToBoolMap& cache = this->MacOSXRpathInstallNameDirCache[config]; |
1527 | 0 | auto const lookup = cache.find(this->Target); |
1528 | |
|
1529 | 0 | if (lookup != cache.cend()) { |
1530 | 0 | return lookup->second; |
1531 | 0 | } |
1532 | | |
1533 | 0 | bool const result = this->DetermineHasMacOSXRpathInstallNameDir(config); |
1534 | 0 | cache[this->Target] = result; |
1535 | 0 | return result; |
1536 | 0 | } |
1537 | | |
1538 | | bool cmGeneratorTarget::DetermineHasMacOSXRpathInstallNameDir( |
1539 | | std::string const& config) const |
1540 | 0 | { |
1541 | 0 | bool install_name_is_rpath = false; |
1542 | 0 | bool macosx_rpath = false; |
1543 | |
|
1544 | 0 | if (!this->IsImported()) { |
1545 | 0 | if (this->GetType() != cmStateEnums::SHARED_LIBRARY) { |
1546 | 0 | return false; |
1547 | 0 | } |
1548 | 0 | cmValue install_name = this->GetProperty("INSTALL_NAME_DIR"); |
1549 | 0 | bool use_install_name = this->MacOSXUseInstallNameDir(); |
1550 | 0 | if (install_name && use_install_name && *install_name == "@rpath") { |
1551 | 0 | install_name_is_rpath = true; |
1552 | 0 | } else if (install_name && use_install_name) { |
1553 | 0 | return false; |
1554 | 0 | } |
1555 | 0 | if (!install_name_is_rpath) { |
1556 | 0 | macosx_rpath = this->MacOSXRpathInstallNameDirDefault(); |
1557 | 0 | } |
1558 | 0 | } else { |
1559 | | // Lookup the imported soname. |
1560 | 0 | if (cmGeneratorTarget::ImportInfo const* info = |
1561 | 0 | this->GetImportInfo(config)) { |
1562 | 0 | if (!info->NoSOName && !info->SOName.empty()) { |
1563 | 0 | if (cmHasLiteralPrefix(info->SOName, "@rpath/")) { |
1564 | 0 | install_name_is_rpath = true; |
1565 | 0 | } |
1566 | 0 | } else { |
1567 | 0 | std::string install_name; |
1568 | 0 | cmSystemTools::GuessLibraryInstallName(info->Location, install_name); |
1569 | 0 | if (install_name.find("@rpath") != std::string::npos) { |
1570 | 0 | install_name_is_rpath = true; |
1571 | 0 | } |
1572 | 0 | } |
1573 | 0 | } |
1574 | 0 | } |
1575 | | |
1576 | 0 | if (!install_name_is_rpath && !macosx_rpath) { |
1577 | 0 | return false; |
1578 | 0 | } |
1579 | | |
1580 | 0 | if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) { |
1581 | 0 | std::ostringstream w; |
1582 | 0 | w << "Attempting to use "; |
1583 | 0 | if (macosx_rpath) { |
1584 | 0 | w << "MACOSX_RPATH"; |
1585 | 0 | } else { |
1586 | 0 | w << "@rpath"; |
1587 | 0 | } |
1588 | 0 | w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set."; |
1589 | 0 | w << " This could be because you are using a Mac OS X version"; |
1590 | 0 | w << " less than 10.5 or because CMake's platform configuration is"; |
1591 | 0 | w << " corrupt."; |
1592 | 0 | cmake* cm = this->LocalGenerator->GetCMakeInstance(); |
1593 | 0 | cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace()); |
1594 | 0 | } |
1595 | |
|
1596 | 0 | return true; |
1597 | 0 | } |
1598 | | |
1599 | | bool cmGeneratorTarget::MacOSXRpathInstallNameDirDefault() const |
1600 | 0 | { |
1601 | | // we can't do rpaths when unsupported |
1602 | 0 | if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) { |
1603 | 0 | return false; |
1604 | 0 | } |
1605 | | |
1606 | 0 | cmValue macosx_rpath_str = this->GetProperty("MACOSX_RPATH"); |
1607 | 0 | if (macosx_rpath_str) { |
1608 | 0 | return this->GetPropertyAsBool("MACOSX_RPATH"); |
1609 | 0 | } |
1610 | | |
1611 | 0 | return true; |
1612 | 0 | } |
1613 | | |
1614 | | bool cmGeneratorTarget::MacOSXUseInstallNameDir() const |
1615 | 0 | { |
1616 | 0 | cmValue build_with_install_name = |
1617 | 0 | this->GetProperty("BUILD_WITH_INSTALL_NAME_DIR"); |
1618 | 0 | if (build_with_install_name) { |
1619 | 0 | return build_with_install_name.IsOn(); |
1620 | 0 | } |
1621 | | |
1622 | 0 | cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068(); |
1623 | 0 | if (cmp0068 == cmPolicies::NEW) { |
1624 | 0 | return false; |
1625 | 0 | } |
1626 | | |
1627 | 0 | bool use_install_name = this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"); |
1628 | |
|
1629 | 0 | if (use_install_name && cmp0068 == cmPolicies::WARN) { |
1630 | 0 | this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget( |
1631 | 0 | this->GetName()); |
1632 | 0 | } |
1633 | |
|
1634 | 0 | return use_install_name; |
1635 | 0 | } |
1636 | | |
1637 | | bool cmGeneratorTarget::CanGenerateInstallNameDir( |
1638 | | InstallNameType name_type) const |
1639 | 0 | { |
1640 | 0 | cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068(); |
1641 | |
|
1642 | 0 | if (cmp0068 == cmPolicies::NEW) { |
1643 | 0 | return true; |
1644 | 0 | } |
1645 | | |
1646 | 0 | bool skip = this->Makefile->IsOn("CMAKE_SKIP_RPATH"); |
1647 | 0 | if (name_type == INSTALL_NAME_FOR_INSTALL) { |
1648 | 0 | skip |= this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"); |
1649 | 0 | } else { |
1650 | 0 | skip |= this->GetPropertyAsBool("SKIP_BUILD_RPATH"); |
1651 | 0 | } |
1652 | |
|
1653 | 0 | if (skip && cmp0068 == cmPolicies::WARN) { |
1654 | 0 | this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget( |
1655 | 0 | this->GetName()); |
1656 | 0 | } |
1657 | |
|
1658 | 0 | return !skip; |
1659 | 0 | } |
1660 | | |
1661 | | std::string cmGeneratorTarget::GetSOName( |
1662 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
1663 | 0 | { |
1664 | 0 | if (this->IsImported()) { |
1665 | | // Lookup the imported soname. |
1666 | 0 | if (cmGeneratorTarget::ImportInfo const* info = |
1667 | 0 | this->GetImportInfo(config)) { |
1668 | 0 | if (info->NoSOName) { |
1669 | | // The imported library has no builtin soname so the name |
1670 | | // searched at runtime will be just the filename. |
1671 | 0 | return cmSystemTools::GetFilenameName(info->Location); |
1672 | 0 | } |
1673 | | // Use the soname given if any. |
1674 | 0 | if (this->IsFrameworkOnApple()) { |
1675 | 0 | auto fwDescriptor = this->GetGlobalGenerator()->SplitFrameworkPath( |
1676 | 0 | info->SOName, cmGlobalGenerator::FrameworkFormat::Strict); |
1677 | 0 | if (fwDescriptor) { |
1678 | 0 | return fwDescriptor->GetVersionedName(); |
1679 | 0 | } |
1680 | 0 | } |
1681 | 0 | if (cmHasLiteralPrefix(info->SOName, "@rpath/")) { |
1682 | 0 | return info->SOName.substr(cmStrLen("@rpath/")); |
1683 | 0 | } |
1684 | 0 | return info->SOName; |
1685 | 0 | } |
1686 | 0 | return ""; |
1687 | 0 | } |
1688 | | // Compute the soname that will be built. |
1689 | 0 | return artifact == cmStateEnums::RuntimeBinaryArtifact |
1690 | 0 | ? this->GetLibraryNames(config).SharedObject |
1691 | 0 | : this->GetLibraryNames(config).ImportLibrary; |
1692 | 0 | } |
1693 | | |
1694 | | namespace { |
1695 | | bool shouldAddFullLevel(cmGeneratorTarget::BundleDirectoryLevel level) |
1696 | 0 | { |
1697 | 0 | return level == cmGeneratorTarget::FullLevel; |
1698 | 0 | } |
1699 | | |
1700 | | bool shouldAddContentLevel(cmGeneratorTarget::BundleDirectoryLevel level) |
1701 | 0 | { |
1702 | 0 | return level == cmGeneratorTarget::ContentLevel || shouldAddFullLevel(level); |
1703 | 0 | } |
1704 | | } |
1705 | | |
1706 | | std::string cmGeneratorTarget::GetAppBundleDirectory( |
1707 | | std::string const& config, BundleDirectoryLevel level) const |
1708 | 0 | { |
1709 | 0 | std::string fpath = cmStrCat( |
1710 | 0 | this->GetFullName(config, cmStateEnums::RuntimeBinaryArtifact), '.'); |
1711 | 0 | cmValue ext = this->GetProperty("BUNDLE_EXTENSION"); |
1712 | 0 | fpath += (ext ? *ext : "app"); |
1713 | 0 | if (shouldAddContentLevel(level) && |
1714 | 0 | !this->Makefile->PlatformIsAppleEmbedded()) { |
1715 | 0 | fpath += "/Contents"; |
1716 | 0 | if (shouldAddFullLevel(level)) { |
1717 | 0 | fpath += "/MacOS"; |
1718 | 0 | } |
1719 | 0 | } |
1720 | 0 | return fpath; |
1721 | 0 | } |
1722 | | |
1723 | | bool cmGeneratorTarget::IsBundleOnApple() const |
1724 | 0 | { |
1725 | 0 | return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() || |
1726 | 0 | this->IsCFBundleOnApple(); |
1727 | 0 | } |
1728 | | |
1729 | | bool cmGeneratorTarget::IsWin32Executable(std::string const& config) const |
1730 | 0 | { |
1731 | 0 | return cmIsOn(cmGeneratorExpression::Evaluate( |
1732 | 0 | this->GetSafeProperty("WIN32_EXECUTABLE"), this->LocalGenerator, config)); |
1733 | 0 | } |
1734 | | |
1735 | | std::string cmGeneratorTarget::GetCFBundleDirectory( |
1736 | | std::string const& config, BundleDirectoryLevel level) const |
1737 | 0 | { |
1738 | 0 | std::string fpath = cmStrCat( |
1739 | 0 | this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact), '.'); |
1740 | 0 | std::string ext; |
1741 | 0 | if (cmValue p = this->GetProperty("BUNDLE_EXTENSION")) { |
1742 | 0 | ext = *p; |
1743 | 0 | } else { |
1744 | 0 | if (this->IsXCTestOnApple()) { |
1745 | 0 | ext = "xctest"; |
1746 | 0 | } else { |
1747 | 0 | ext = "bundle"; |
1748 | 0 | } |
1749 | 0 | } |
1750 | 0 | fpath += ext; |
1751 | 0 | if (shouldAddContentLevel(level) && |
1752 | 0 | !this->Makefile->PlatformIsAppleEmbedded()) { |
1753 | 0 | fpath += "/Contents"; |
1754 | 0 | if (shouldAddFullLevel(level)) { |
1755 | 0 | fpath += "/MacOS"; |
1756 | 0 | } |
1757 | 0 | } |
1758 | 0 | return fpath; |
1759 | 0 | } |
1760 | | |
1761 | | std::string cmGeneratorTarget::GetFrameworkDirectory( |
1762 | | std::string const& config, BundleDirectoryLevel level) const |
1763 | 0 | { |
1764 | 0 | std::string fpath = cmStrCat( |
1765 | 0 | this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact), '.'); |
1766 | 0 | cmValue ext = this->GetProperty("BUNDLE_EXTENSION"); |
1767 | 0 | fpath += (ext ? *ext : "framework"); |
1768 | 0 | if (shouldAddFullLevel(level) && |
1769 | 0 | !this->Makefile->PlatformIsAppleEmbedded()) { |
1770 | 0 | fpath += "/Versions/"; |
1771 | 0 | fpath += this->GetFrameworkVersion(); |
1772 | 0 | } |
1773 | 0 | return fpath; |
1774 | 0 | } |
1775 | | |
1776 | | std::string cmGeneratorTarget::GetFullName( |
1777 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
1778 | 0 | { |
1779 | 0 | if (this->IsImported()) { |
1780 | 0 | return this->GetFullNameImported(config, artifact); |
1781 | 0 | } |
1782 | 0 | return this->GetFullNameInternal(config, artifact); |
1783 | 0 | } |
1784 | | |
1785 | | std::string cmGeneratorTarget::GetInstallNameDirForBuildTree( |
1786 | | std::string const& config) const |
1787 | 0 | { |
1788 | 0 | if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) { |
1789 | | |
1790 | | // If building directly for installation then the build tree install_name |
1791 | | // is the same as the install tree. |
1792 | 0 | if (this->MacOSXUseInstallNameDir()) { |
1793 | 0 | std::string installPrefix = |
1794 | 0 | this->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX"); |
1795 | 0 | return this->GetInstallNameDirForInstallTree(config, installPrefix); |
1796 | 0 | } |
1797 | | |
1798 | | // Use the build tree directory for the target. |
1799 | 0 | if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_BUILD)) { |
1800 | 0 | std::string dir; |
1801 | 0 | if (this->MacOSXRpathInstallNameDirDefault()) { |
1802 | 0 | dir = "@rpath"; |
1803 | 0 | } else { |
1804 | 0 | dir = this->GetDirectory(config); |
1805 | 0 | } |
1806 | 0 | dir += "/"; |
1807 | 0 | return dir; |
1808 | 0 | } |
1809 | 0 | } |
1810 | 0 | return ""; |
1811 | 0 | } |
1812 | | |
1813 | | std::string cmGeneratorTarget::GetInstallNameDirForInstallTree( |
1814 | | std::string const& config, std::string const& installPrefix) const |
1815 | 0 | { |
1816 | 0 | if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) { |
1817 | 0 | std::string dir; |
1818 | 0 | cmValue install_name_dir = this->GetProperty("INSTALL_NAME_DIR"); |
1819 | |
|
1820 | 0 | if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_INSTALL)) { |
1821 | 0 | if (cmNonempty(install_name_dir)) { |
1822 | 0 | dir = *install_name_dir; |
1823 | 0 | cmGeneratorExpression::ReplaceInstallPrefix(dir, installPrefix); |
1824 | 0 | dir = |
1825 | 0 | cmGeneratorExpression::Evaluate(dir, this->LocalGenerator, config); |
1826 | 0 | if (!dir.empty()) { |
1827 | 0 | dir = cmStrCat(dir, '/'); |
1828 | 0 | } |
1829 | 0 | } |
1830 | 0 | } |
1831 | 0 | if (!install_name_dir) { |
1832 | 0 | if (this->MacOSXRpathInstallNameDirDefault()) { |
1833 | 0 | dir = "@rpath/"; |
1834 | 0 | } |
1835 | 0 | } |
1836 | 0 | return dir; |
1837 | 0 | } |
1838 | 0 | return ""; |
1839 | 0 | } |
1840 | | |
1841 | | cmListFileBacktrace cmGeneratorTarget::GetBacktrace() const |
1842 | 0 | { |
1843 | 0 | return this->Target->GetBacktrace(); |
1844 | 0 | } |
1845 | | |
1846 | | std::set<BT<std::pair<std::string, bool>>> const& |
1847 | | cmGeneratorTarget::GetUtilities() const |
1848 | 0 | { |
1849 | 0 | return this->Target->GetUtilities(); |
1850 | 0 | } |
1851 | | |
1852 | | bool cmGeneratorTarget::HaveWellDefinedOutputFiles() const |
1853 | 0 | { |
1854 | 0 | return this->GetType() == cmStateEnums::STATIC_LIBRARY || |
1855 | 0 | this->GetType() == cmStateEnums::SHARED_LIBRARY || |
1856 | 0 | this->GetType() == cmStateEnums::MODULE_LIBRARY || |
1857 | 0 | this->GetType() == cmStateEnums::OBJECT_LIBRARY || |
1858 | 0 | this->GetType() == cmStateEnums::EXECUTABLE; |
1859 | 0 | } |
1860 | | |
1861 | | std::string const* cmGeneratorTarget::GetExportMacro() const |
1862 | 0 | { |
1863 | | // Define the symbol for targets that export symbols. |
1864 | 0 | if (this->GetType() == cmStateEnums::SHARED_LIBRARY || |
1865 | 0 | this->GetType() == cmStateEnums::MODULE_LIBRARY || |
1866 | 0 | this->IsExecutableWithExports()) { |
1867 | 0 | if (cmValue custom_export_name = this->GetProperty("DEFINE_SYMBOL")) { |
1868 | 0 | this->ExportMacro = *custom_export_name; |
1869 | 0 | } else { |
1870 | 0 | std::string in = cmStrCat(this->GetName(), "_EXPORTS"); |
1871 | 0 | this->ExportMacro = cmSystemTools::MakeCidentifier(in); |
1872 | 0 | } |
1873 | 0 | return &this->ExportMacro; |
1874 | 0 | } |
1875 | 0 | return nullptr; |
1876 | 0 | } |
1877 | | |
1878 | | cmList const& cmGeneratorTarget::GetSharedLibraryCompileDefs( |
1879 | | std::string const& config) const |
1880 | 0 | { |
1881 | 0 | { |
1882 | 0 | auto it = this->SharedLibraryCompileDefs.find(config); |
1883 | 0 | if (it != this->SharedLibraryCompileDefs.end()) { |
1884 | 0 | return it->second; |
1885 | 0 | } |
1886 | 0 | } |
1887 | | |
1888 | 0 | auto emplaceResult = |
1889 | 0 | this->SharedLibraryCompileDefs.emplace(config, cmList{}); |
1890 | 0 | auto& defs = emplaceResult.first->second; |
1891 | 0 | if (this->GetType() != cmStateEnums::SHARED_LIBRARY && |
1892 | 0 | this->GetType() != cmStateEnums::MODULE_LIBRARY) { |
1893 | 0 | return defs; |
1894 | 0 | } |
1895 | | |
1896 | 0 | if (this->GetPolicyStatusCMP0203() != cmPolicies::NEW) { |
1897 | 0 | return defs; |
1898 | 0 | } |
1899 | | |
1900 | 0 | auto linkerLang = this->GetLinkerLanguage(config); |
1901 | 0 | auto definitionVar = |
1902 | 0 | cmStrCat("CMAKE_", linkerLang, "_SHARED_LIBRARY_COMPILE_DEFINITIONS"); |
1903 | 0 | defs = this->Makefile->GetSafeDefinition(definitionVar); |
1904 | |
|
1905 | 0 | return defs; |
1906 | 0 | } |
1907 | | |
1908 | | cmGeneratorTarget::NameComponents const& |
1909 | | cmGeneratorTarget::GetFullNameComponents( |
1910 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
1911 | 0 | { |
1912 | 0 | return this->GetFullNameInternalComponents(config, artifact); |
1913 | 0 | } |
1914 | | |
1915 | | std::string cmGeneratorTarget::BuildBundleDirectory( |
1916 | | std::string const& base, std::string const& config, |
1917 | | BundleDirectoryLevel level) const |
1918 | 0 | { |
1919 | 0 | std::string fpath = base; |
1920 | 0 | if (this->IsAppBundleOnApple()) { |
1921 | 0 | fpath += this->GetAppBundleDirectory(config, level); |
1922 | 0 | } |
1923 | 0 | if (this->IsFrameworkOnApple()) { |
1924 | 0 | fpath += this->GetFrameworkDirectory(config, level); |
1925 | 0 | } |
1926 | 0 | if (this->IsCFBundleOnApple()) { |
1927 | 0 | fpath += this->GetCFBundleDirectory(config, level); |
1928 | 0 | } |
1929 | 0 | return fpath; |
1930 | 0 | } |
1931 | | |
1932 | | std::string cmGeneratorTarget::GetMacContentDirectory( |
1933 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
1934 | 0 | { |
1935 | | // Start with the output directory for the target. |
1936 | 0 | std::string fpath = cmStrCat(this->GetDirectory(config, artifact), '/'); |
1937 | 0 | BundleDirectoryLevel level = ContentLevel; |
1938 | 0 | if (this->IsFrameworkOnApple()) { |
1939 | | // additional files with a framework go into the version specific |
1940 | | // directory |
1941 | 0 | level = FullLevel; |
1942 | 0 | } |
1943 | 0 | fpath = this->BuildBundleDirectory(fpath, config, level); |
1944 | 0 | return fpath; |
1945 | 0 | } |
1946 | | |
1947 | | std::string cmGeneratorTarget::GetEffectiveFolderName() const |
1948 | 0 | { |
1949 | 0 | std::string effectiveFolder; |
1950 | |
|
1951 | 0 | if (!this->GlobalGenerator->UseFolderProperty()) { |
1952 | 0 | return effectiveFolder; |
1953 | 0 | } |
1954 | | |
1955 | 0 | cmValue targetFolder = this->GetProperty("FOLDER"); |
1956 | 0 | if (targetFolder) { |
1957 | 0 | effectiveFolder += *targetFolder; |
1958 | 0 | } |
1959 | |
|
1960 | 0 | return effectiveFolder; |
1961 | 0 | } |
1962 | | |
1963 | | cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo( |
1964 | | std::string const& config) const |
1965 | 0 | { |
1966 | | // There is no compile information for imported targets. |
1967 | 0 | if (this->IsImported()) { |
1968 | 0 | return nullptr; |
1969 | 0 | } |
1970 | | |
1971 | 0 | if (this->GetType() > cmStateEnums::OBJECT_LIBRARY) { |
1972 | 0 | std::string msg = cmStrCat("cmTarget::GetCompileInfo called for ", |
1973 | 0 | this->GetName(), " which has type ", |
1974 | 0 | cmState::GetTargetTypeName(this->GetType())); |
1975 | 0 | this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg); |
1976 | 0 | return nullptr; |
1977 | 0 | } |
1978 | | |
1979 | | // Lookup/compute/cache the compile information for this configuration. |
1980 | 0 | std::string config_upper; |
1981 | 0 | if (!config.empty()) { |
1982 | 0 | config_upper = cmSystemTools::UpperCase(config); |
1983 | 0 | } |
1984 | 0 | auto i = this->CompileInfoMap.find(config_upper); |
1985 | 0 | if (i == this->CompileInfoMap.end()) { |
1986 | 0 | CompileInfo info; |
1987 | 0 | this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir); |
1988 | 0 | CompileInfoMapType::value_type entry(config_upper, info); |
1989 | 0 | i = this->CompileInfoMap.insert(entry).first; |
1990 | 0 | } |
1991 | 0 | return &i->second; |
1992 | 0 | } |
1993 | | |
1994 | | cmGeneratorTarget::ModuleDefinitionInfo const* |
1995 | | cmGeneratorTarget::GetModuleDefinitionInfo(std::string const& config) const |
1996 | 0 | { |
1997 | | // A module definition file only makes sense on certain target types. |
1998 | 0 | if (this->GetType() != cmStateEnums::SHARED_LIBRARY && |
1999 | 0 | this->GetType() != cmStateEnums::MODULE_LIBRARY && |
2000 | 0 | !this->IsExecutableWithExports()) { |
2001 | 0 | return nullptr; |
2002 | 0 | } |
2003 | | |
2004 | | // Lookup/compute/cache the compile information for this configuration. |
2005 | 0 | std::string config_upper; |
2006 | 0 | if (!config.empty()) { |
2007 | 0 | config_upper = cmSystemTools::UpperCase(config); |
2008 | 0 | } |
2009 | 0 | auto i = this->ModuleDefinitionInfoMap.find(config_upper); |
2010 | 0 | if (i == this->ModuleDefinitionInfoMap.end()) { |
2011 | 0 | ModuleDefinitionInfo info; |
2012 | 0 | this->ComputeModuleDefinitionInfo(config, info); |
2013 | 0 | ModuleDefinitionInfoMapType::value_type entry(config_upper, info); |
2014 | 0 | i = this->ModuleDefinitionInfoMap.insert(entry).first; |
2015 | 0 | } |
2016 | 0 | return &i->second; |
2017 | 0 | } |
2018 | | |
2019 | | void cmGeneratorTarget::ComputeModuleDefinitionInfo( |
2020 | | std::string const& config, ModuleDefinitionInfo& info) const |
2021 | 0 | { |
2022 | 0 | this->GetModuleDefinitionSources(info.Sources, config); |
2023 | 0 | info.WindowsExportAllSymbols = |
2024 | 0 | this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") && |
2025 | 0 | this->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS"); |
2026 | 0 | #if !defined(CMAKE_BOOTSTRAP) |
2027 | 0 | info.DefFileGenerated = |
2028 | 0 | info.WindowsExportAllSymbols || info.Sources.size() > 1; |
2029 | | #else |
2030 | | // Our __create_def helper is not available during CMake bootstrap. |
2031 | | info.DefFileGenerated = false; |
2032 | | #endif |
2033 | 0 | if (info.DefFileGenerated) { |
2034 | 0 | info.DefFile = |
2035 | 0 | this->GetObjectDirectory(config) /* has slash */ + "exports.def"; |
2036 | 0 | } else if (!info.Sources.empty()) { |
2037 | 0 | info.DefFile = info.Sources.front()->GetFullPath(); |
2038 | 0 | } |
2039 | 0 | } |
2040 | | |
2041 | | bool cmGeneratorTarget::IsAIX() const |
2042 | 0 | { |
2043 | 0 | return this->Target->IsAIX(); |
2044 | 0 | } |
2045 | | |
2046 | | bool cmGeneratorTarget::IsApple() const |
2047 | 0 | { |
2048 | 0 | return this->Target->IsApple(); |
2049 | 0 | } |
2050 | | |
2051 | | bool cmGeneratorTarget::IsDLLPlatform() const |
2052 | 0 | { |
2053 | 0 | return this->Target->IsDLLPlatform(); |
2054 | 0 | } |
2055 | | |
2056 | | void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string>& result, |
2057 | | std::string const& config) const |
2058 | 0 | { |
2059 | 0 | char const* prop = |
2060 | 0 | this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS", config); |
2061 | 0 | if (!prop) { |
2062 | 0 | return; |
2063 | 0 | } |
2064 | | |
2065 | 0 | cm::GenEx::Context context(this->LocalGenerator, config); |
2066 | 0 | cmGeneratorExpressionDAGChecker dagChecker{ |
2067 | 0 | this, "AUTOUIC_OPTIONS", nullptr, nullptr, context, |
2068 | 0 | }; |
2069 | 0 | cmExpandList(cmGeneratorExpression::Evaluate( |
2070 | 0 | prop, context.LG, context.Config, this, &dagChecker), |
2071 | 0 | result); |
2072 | 0 | } |
2073 | | |
2074 | | void cmGeneratorTarget::TraceDependencies() |
2075 | 0 | { |
2076 | | // CMake-generated targets have no dependencies to trace. Normally tracing |
2077 | | // would find nothing anyway, but when building CMake itself the "install" |
2078 | | // target command ends up referencing the "cmake" target but we do not |
2079 | | // really want the dependency because "install" depend on "all" anyway. |
2080 | 0 | if (this->GetType() == cmStateEnums::GLOBAL_TARGET) { |
2081 | 0 | return; |
2082 | 0 | } |
2083 | | |
2084 | | // Use a helper object to trace the dependencies. |
2085 | 0 | cmTargetTraceDependencies tracer(this); |
2086 | 0 | tracer.Trace(); |
2087 | 0 | } |
2088 | | |
2089 | | std::string cmGeneratorTarget::GetCompilePDBDirectory( |
2090 | | std::string const& config) const |
2091 | 0 | { |
2092 | 0 | if (CompileInfo const* info = this->GetCompileInfo(config)) { |
2093 | 0 | return info->CompilePdbDir; |
2094 | 0 | } |
2095 | 0 | return ""; |
2096 | 0 | } |
2097 | | |
2098 | | std::vector<std::string> cmGeneratorTarget::GetAppleArchs( |
2099 | | std::string const& config, cm::optional<std::string> lang) const |
2100 | 0 | { |
2101 | 0 | cmList archList; |
2102 | 0 | if (!this->IsApple()) { |
2103 | 0 | return std::move(archList.data()); |
2104 | 0 | } |
2105 | 0 | cmValue archs = nullptr; |
2106 | 0 | if (!config.empty()) { |
2107 | 0 | std::string defVarName = |
2108 | 0 | cmStrCat("OSX_ARCHITECTURES_", cmSystemTools::UpperCase(config)); |
2109 | 0 | archs = this->GetProperty(defVarName); |
2110 | 0 | } |
2111 | 0 | if (!archs) { |
2112 | 0 | archs = this->GetProperty("OSX_ARCHITECTURES"); |
2113 | 0 | } |
2114 | 0 | if (archs) { |
2115 | 0 | archList.assign(*archs); |
2116 | 0 | } |
2117 | 0 | if (archList.empty() && |
2118 | | // Fall back to a default architecture if no compiler target is set. |
2119 | 0 | (!lang || |
2120 | 0 | this->Makefile |
2121 | 0 | ->GetDefinition(cmStrCat("CMAKE_", *lang, "_COMPILER_TARGET")) |
2122 | 0 | .IsEmpty())) { |
2123 | 0 | archList.assign( |
2124 | 0 | this->Makefile->GetDefinition("_CMAKE_APPLE_ARCHS_DEFAULT")); |
2125 | 0 | } |
2126 | 0 | return std::move(archList.data()); |
2127 | 0 | } |
2128 | | |
2129 | | namespace { |
2130 | | |
2131 | | bool IsSupportedClassifiedFlagsLanguage(std::string const& lang) |
2132 | 0 | { |
2133 | 0 | return lang == "CXX"_s; |
2134 | 0 | } |
2135 | | |
2136 | | bool CanUseCompilerLauncher(std::string const& lang) |
2137 | 0 | { |
2138 | | // Also found in `cmCommonTargetGenerator::GetCompilerLauncher`. |
2139 | 0 | return lang == "C"_s || lang == "CXX"_s || lang == "Fortran"_s || |
2140 | 0 | lang == "CUDA"_s || lang == "HIP"_s || lang == "ISPC"_s || |
2141 | 0 | lang == "OBJC"_s || lang == "OBJCXX"_s; |
2142 | 0 | } |
2143 | | |
2144 | | // FIXME: return a vector of `cm::string_view` instead to avoid lots of tiny |
2145 | | // allocations. |
2146 | | std::vector<std::string> SplitFlags(std::string const& flags) |
2147 | 0 | { |
2148 | 0 | std::vector<std::string> options; |
2149 | |
|
2150 | | #ifdef _WIN32 |
2151 | | cmSystemTools::ParseWindowsCommandLine(flags.c_str(), options); |
2152 | | #else |
2153 | 0 | cmSystemTools::ParseUnixCommandLine(flags.c_str(), options); |
2154 | 0 | #endif |
2155 | |
|
2156 | 0 | return options; |
2157 | 0 | } |
2158 | | |
2159 | | } |
2160 | | |
2161 | | cmGeneratorTarget::ClassifiedFlags |
2162 | | cmGeneratorTarget::GetClassifiedFlagsForSource(cmSourceFile const* sf, |
2163 | | std::string const& config) |
2164 | 0 | { |
2165 | 0 | auto& sourceFlagsCache = this->Configs[config].SourceFlags; |
2166 | 0 | auto cacheEntry = sourceFlagsCache.lower_bound(sf); |
2167 | 0 | if (cacheEntry != sourceFlagsCache.end() && cacheEntry->first == sf) { |
2168 | 0 | return cacheEntry->second; |
2169 | 0 | } |
2170 | | |
2171 | 0 | ClassifiedFlags flags; |
2172 | 0 | std::string const& lang = sf->GetLanguage(); |
2173 | |
|
2174 | 0 | if (!IsSupportedClassifiedFlagsLanguage(lang)) { |
2175 | 0 | return flags; |
2176 | 0 | } |
2177 | | |
2178 | 0 | auto* const lg = this->GetLocalGenerator(); |
2179 | 0 | auto const* const mf = this->Makefile; |
2180 | 0 | cmGeneratorFileSet const* const fileSet = |
2181 | 0 | this->GetFileSetForSource(config, sf); |
2182 | | |
2183 | | // Compute the compiler launcher flags. |
2184 | 0 | if (CanUseCompilerLauncher(lang)) { |
2185 | | // Compiler launchers are all execution flags and should not be relevant to |
2186 | | // the actual compilation. |
2187 | 0 | FlagClassification cls = FlagClassification::ExecutionFlag; |
2188 | 0 | FlagKind kind = FlagKind::NotAFlag; |
2189 | |
|
2190 | 0 | std::string const clauncher_prop = cmStrCat(lang, "_COMPILER_LAUNCHER"); |
2191 | 0 | cmValue clauncher = this->GetProperty(clauncher_prop); |
2192 | 0 | std::string const evaluatedClauncher = cmGeneratorExpression::Evaluate( |
2193 | 0 | *clauncher, lg, config, this, nullptr, this, lang); |
2194 | |
|
2195 | 0 | for (auto const& flag : SplitFlags(evaluatedClauncher)) { |
2196 | 0 | flags.emplace_back(cls, kind, flag); |
2197 | 0 | } |
2198 | 0 | } |
2199 | |
|
2200 | 0 | ClassifiedFlags define_flags; |
2201 | 0 | ClassifiedFlags include_flags; |
2202 | 0 | ClassifiedFlags compile_flags; |
2203 | |
|
2204 | 0 | SourceVariables sfVars = this->GetSourceVariables(sf, config); |
2205 | | |
2206 | | // Compute language flags. |
2207 | 0 | { |
2208 | 0 | FlagClassification cls = FlagClassification::BaselineFlag; |
2209 | 0 | FlagKind kind = FlagKind::Compile; |
2210 | |
|
2211 | 0 | std::string mfFlags; |
2212 | | // Explicitly add the explicit language flag before any other flag |
2213 | | // so user flags can override it. |
2214 | 0 | this->AddExplicitLanguageFlags(mfFlags, *sf); |
2215 | |
|
2216 | 0 | for (auto const& flag : SplitFlags(mfFlags)) { |
2217 | 0 | flags.emplace_back(cls, kind, flag); |
2218 | 0 | } |
2219 | 0 | } |
2220 | |
|
2221 | 0 | std::unordered_map<std::string, std::string> pchSources; |
2222 | 0 | std::string filterArch; |
2223 | |
|
2224 | 0 | { |
2225 | 0 | std::vector<std::string> pchArchs = this->GetPchArchs(config, lang); |
2226 | |
|
2227 | 0 | for (std::string const& arch : pchArchs) { |
2228 | 0 | std::string const pchSource = this->GetPchSource(config, lang, arch); |
2229 | 0 | if (pchSource == sf->GetFullPath()) { |
2230 | 0 | filterArch = arch; |
2231 | 0 | } |
2232 | 0 | if (!pchSource.empty()) { |
2233 | 0 | pchSources.insert(std::make_pair(pchSource, arch)); |
2234 | 0 | } |
2235 | 0 | } |
2236 | 0 | } |
2237 | | |
2238 | | // File set specific flags |
2239 | 0 | if (fileSet) { |
2240 | | // include flags |
2241 | 0 | { |
2242 | 0 | auto fsIncludes = fileSet->BelongsTo(this) |
2243 | 0 | ? fileSet->GetIncludeDirectories(config, lang) |
2244 | 0 | : fileSet->GetInterfaceIncludeDirectories(config, lang); |
2245 | 0 | if (!fsIncludes.empty()) { |
2246 | 0 | std::vector<std::string> includes; |
2247 | 0 | lg->AppendIncludeDirectories(includes, cm::remove_BT(fsIncludes), *sf); |
2248 | |
|
2249 | 0 | auto includeFlags = |
2250 | 0 | lg->GetIncludeFlags(includes, this, lang, config, false); |
2251 | |
|
2252 | 0 | for (auto&& flag : SplitFlags(includeFlags)) { |
2253 | 0 | include_flags.emplace_back(FlagClassification::PrivateFlag, |
2254 | 0 | FlagKind::Include, std::move(flag)); |
2255 | 0 | } |
2256 | 0 | } |
2257 | 0 | } |
2258 | 0 | } |
2259 | | |
2260 | | // source specific flags |
2261 | 0 | { |
2262 | | // include flags |
2263 | 0 | if (cmValue srcIncludes = sf->GetProperty("INCLUDE_DIRECTORIES")) { |
2264 | 0 | std::vector<std::string> includes; |
2265 | 0 | lg->AppendIncludeDirectories(includes, srcIncludes, *sf); |
2266 | |
|
2267 | 0 | auto includeFlags = |
2268 | 0 | lg->GetIncludeFlags(includes, this, lang, config, false); |
2269 | |
|
2270 | 0 | for (auto&& flag : SplitFlags(includeFlags)) { |
2271 | 0 | include_flags.emplace_back(FlagClassification::PrivateFlag, |
2272 | 0 | FlagKind::Include, std::move(flag)); |
2273 | 0 | } |
2274 | 0 | } |
2275 | 0 | } |
2276 | | |
2277 | | // Compute target-wide flags. |
2278 | 0 | { |
2279 | 0 | FlagClassification cls = FlagClassification::BaselineFlag; |
2280 | | |
2281 | | // Compile flags |
2282 | 0 | { |
2283 | 0 | FlagKind kind = FlagKind::Compile; |
2284 | 0 | std::string targetFlags; |
2285 | |
|
2286 | 0 | lg->GetTargetCompileFlags(this, config, lang, targetFlags, filterArch); |
2287 | |
|
2288 | 0 | for (auto&& flag : SplitFlags(targetFlags)) { |
2289 | 0 | compile_flags.emplace_back(cls, kind, std::move(flag)); |
2290 | 0 | } |
2291 | 0 | } |
2292 | | |
2293 | | // Define flags |
2294 | 0 | { |
2295 | 0 | FlagKind kind = FlagKind::Definition; |
2296 | 0 | std::set<std::string> defines; |
2297 | |
|
2298 | 0 | lg->GetTargetDefines(this, config, lang, defines); |
2299 | |
|
2300 | 0 | std::string defineFlags; |
2301 | 0 | lg->JoinDefines(defines, defineFlags, lang); |
2302 | |
|
2303 | 0 | for (auto&& flag : SplitFlags(defineFlags)) { |
2304 | 0 | define_flags.emplace_back(cls, kind, std::move(flag)); |
2305 | 0 | } |
2306 | 0 | } |
2307 | | |
2308 | | // Include flags |
2309 | 0 | { |
2310 | 0 | FlagKind kind = FlagKind::Include; |
2311 | 0 | std::vector<std::string> includes; |
2312 | |
|
2313 | 0 | lg->GetIncludeDirectories(includes, this, lang, config); |
2314 | 0 | auto includeFlags = |
2315 | 0 | lg->GetIncludeFlags(includes, this, lang, config, false); |
2316 | |
|
2317 | 0 | for (auto&& flag : SplitFlags(includeFlags)) { |
2318 | 0 | include_flags.emplace_back(cls, kind, std::move(flag)); |
2319 | 0 | } |
2320 | 0 | } |
2321 | 0 | } |
2322 | |
|
2323 | 0 | std::string const COMPILE_OPTIONS("COMPILE_OPTIONS"); |
2324 | 0 | cmGeneratorExpressionInterpreter genexInterpreter(lg, config, this, lang); |
2325 | | |
2326 | | // Source-specific flags. |
2327 | 0 | { |
2328 | | // Define flags |
2329 | 0 | { |
2330 | 0 | if (cmValue srcDefines = sf->GetProperty("COMPILE_DEFINITIONS")) { |
2331 | 0 | std::set<std::string> defines; |
2332 | 0 | lg->AppendDefines(defines, srcDefines); |
2333 | |
|
2334 | 0 | std::string defineFlags; |
2335 | 0 | lg->JoinDefines(defines, defineFlags, lang); |
2336 | |
|
2337 | 0 | for (auto&& flag : SplitFlags(defineFlags)) { |
2338 | 0 | define_flags.emplace_back(FlagClassification::PrivateFlag, |
2339 | 0 | FlagKind::Definition, std::move(flag)); |
2340 | 0 | } |
2341 | 0 | } |
2342 | 0 | } |
2343 | | |
2344 | | // Compile flags. |
2345 | 0 | { |
2346 | 0 | std::string const COMPILE_FLAGS("COMPILE_FLAGS"); |
2347 | |
|
2348 | 0 | FlagClassification cls = FlagClassification::PrivateFlag; |
2349 | 0 | FlagKind kind = FlagKind::Compile; |
2350 | |
|
2351 | 0 | std::string sourceFlags; |
2352 | |
|
2353 | 0 | if (cmValue cflags = sf->GetProperty(COMPILE_FLAGS)) { |
2354 | 0 | lg->AppendFlags(sourceFlags, |
2355 | 0 | genexInterpreter.Evaluate(*cflags, COMPILE_FLAGS)); |
2356 | 0 | } |
2357 | |
|
2358 | 0 | if (cmValue coptions = sf->GetProperty(COMPILE_OPTIONS)) { |
2359 | 0 | lg->AppendCompileOptions( |
2360 | 0 | sourceFlags, genexInterpreter.Evaluate(*coptions, COMPILE_OPTIONS)); |
2361 | 0 | } |
2362 | |
|
2363 | 0 | for (auto&& flag : SplitFlags(sourceFlags)) { |
2364 | 0 | compile_flags.emplace_back(cls, kind, std::move(flag)); |
2365 | 0 | } |
2366 | 0 | } |
2367 | 0 | } |
2368 | | |
2369 | | // File set specific flags |
2370 | 0 | if (fileSet) { |
2371 | | // Define flags |
2372 | 0 | { |
2373 | 0 | auto fsDefines = fileSet->BelongsTo(this) |
2374 | 0 | ? fileSet->GetCompileDefinitions(config, lang) |
2375 | 0 | : fileSet->GetInterfaceCompileDefinitions(config, lang); |
2376 | 0 | if (!fsDefines.empty()) { |
2377 | 0 | std::set<std::string> defines; |
2378 | 0 | lg->AppendDefines(defines, fsDefines); |
2379 | |
|
2380 | 0 | std::string defineFlags; |
2381 | 0 | lg->JoinDefines(defines, defineFlags, lang); |
2382 | |
|
2383 | 0 | for (auto&& flag : SplitFlags(defineFlags)) { |
2384 | 0 | define_flags.emplace_back(FlagClassification::PrivateFlag, |
2385 | 0 | FlagKind::Definition, std::move(flag)); |
2386 | 0 | } |
2387 | 0 | } |
2388 | 0 | } |
2389 | | |
2390 | | // Compile flags. |
2391 | 0 | { |
2392 | 0 | auto options = fileSet->BelongsTo(this) |
2393 | 0 | ? fileSet->GetCompileOptions(config, lang) |
2394 | 0 | : fileSet->GetInterfaceCompileOptions(config, lang); |
2395 | 0 | if (!options.empty()) { |
2396 | 0 | std::string compileFlags; |
2397 | 0 | lg->AppendCompileOptions(compileFlags, cm::remove_BT(options)); |
2398 | |
|
2399 | 0 | for (auto&& flag : SplitFlags(compileFlags)) { |
2400 | 0 | compile_flags.emplace_back(FlagClassification::PrivateFlag, |
2401 | 0 | FlagKind::Compile, std::move(flag)); |
2402 | 0 | } |
2403 | 0 | } |
2404 | 0 | } |
2405 | 0 | } |
2406 | | |
2407 | | // Dependency tracking flags. |
2408 | 0 | { |
2409 | 0 | if (!sfVars.DependencyFlags.empty()) { |
2410 | 0 | cmRulePlaceholderExpander::RuleVariables vars; |
2411 | 0 | auto rulePlaceholderExpander = lg->CreateRulePlaceholderExpander(); |
2412 | |
|
2413 | 0 | vars.DependencyFile = sfVars.DependencyFile.c_str(); |
2414 | 0 | vars.DependencyTarget = sfVars.DependencyTarget.c_str(); |
2415 | |
|
2416 | 0 | std::string depfileFlags = sfVars.DependencyFlags; |
2417 | 0 | rulePlaceholderExpander->ExpandRuleVariables(lg, depfileFlags, vars); |
2418 | 0 | for (auto&& flag : SplitFlags(depfileFlags)) { |
2419 | 0 | compile_flags.emplace_back(FlagClassification::LocationFlag, |
2420 | 0 | FlagKind::BuildSystem, std::move(flag)); |
2421 | 0 | } |
2422 | 0 | } |
2423 | 0 | } |
2424 | | |
2425 | | // Precompiled headers. |
2426 | 0 | { |
2427 | 0 | FlagClassification cls = FlagClassification::PrivateFlag; |
2428 | 0 | FlagKind kind = FlagKind::Compile; |
2429 | |
|
2430 | 0 | std::string pchFlags; |
2431 | | |
2432 | | // Add precompile headers compile options. |
2433 | 0 | if (!((fileSet && sf->GetProperty("SKIP_PRECOMPILE_HEADERS")) || |
2434 | 0 | sf->GetProperty("SKIP_PRECOMPILE_HEADERS"))) { |
2435 | 0 | if (!pchSources.empty()) { |
2436 | 0 | std::string pchOptions; |
2437 | 0 | auto pchIt = pchSources.find(sf->GetFullPath()); |
2438 | 0 | if (pchIt != pchSources.end()) { |
2439 | 0 | pchOptions = |
2440 | 0 | this->GetPchCreateCompileOptions(config, lang, pchIt->second); |
2441 | 0 | } else { |
2442 | 0 | pchOptions = this->GetPchUseCompileOptions(config, lang); |
2443 | 0 | } |
2444 | |
|
2445 | 0 | this->LocalGenerator->AppendCompileOptions( |
2446 | 0 | pchFlags, genexInterpreter.Evaluate(pchOptions, COMPILE_OPTIONS)); |
2447 | 0 | } |
2448 | 0 | } |
2449 | |
|
2450 | 0 | for (auto&& flag : SplitFlags(pchFlags)) { |
2451 | 0 | compile_flags.emplace_back(cls, kind, std::move(flag)); |
2452 | 0 | } |
2453 | 0 | } |
2454 | | |
2455 | | // C++ module flags. |
2456 | 0 | bool useBmiTemplate = false; |
2457 | 0 | if (lang == "CXX"_s) { |
2458 | 0 | FlagClassification cls = FlagClassification::LocationFlag; |
2459 | 0 | FlagKind kind = FlagKind::BuildSystem; |
2460 | |
|
2461 | 0 | std::string bmiFlags; |
2462 | |
|
2463 | 0 | auto const* fs = this->GetFileSetForSource(config, sf); |
2464 | 0 | if (fs && fs->GetType() == cm::FileSetMetadata::CXX_MODULES) { |
2465 | 0 | if (lang != "CXX"_s) { |
2466 | 0 | mf->IssueMessage( |
2467 | 0 | MessageType::FATAL_ERROR, |
2468 | 0 | cmStrCat( |
2469 | 0 | "Target \"", this->Target->GetName(), "\" contains the source\n ", |
2470 | 0 | sf->GetFullPath(), "\nin a file set of type \"", fs->GetType(), |
2471 | 0 | R"(" but the source is not classified as a "CXX" source.)")); |
2472 | 0 | } |
2473 | |
|
2474 | 0 | if (!this->Target->IsNormal()) { |
2475 | 0 | if (!mf->GetDefinition("CMAKE_CXX_COMPILE_BMI").IsEmpty()) { |
2476 | 0 | useBmiTemplate = true; |
2477 | 0 | } else { |
2478 | 0 | std::string flag = |
2479 | 0 | mf->GetSafeDefinition("CMAKE_CXX_MODULE_BMI_ONLY_FLAG"); |
2480 | 0 | cmRulePlaceholderExpander::RuleVariables compileObjectVars; |
2481 | 0 | compileObjectVars.Object = sfVars.ObjectFileDir.c_str(); |
2482 | 0 | auto rulePlaceholderExpander = lg->CreateRulePlaceholderExpander(); |
2483 | 0 | rulePlaceholderExpander->ExpandRuleVariables(lg, flag, |
2484 | 0 | compileObjectVars); |
2485 | 0 | lg->AppendCompileOptions(bmiFlags, flag); |
2486 | 0 | } |
2487 | 0 | } |
2488 | 0 | } |
2489 | |
|
2490 | 0 | for (auto&& flag : SplitFlags(bmiFlags)) { |
2491 | 0 | compile_flags.emplace_back(cls, kind, std::move(flag)); |
2492 | 0 | } |
2493 | 0 | } |
2494 | |
|
2495 | 0 | cmRulePlaceholderExpander::RuleVariables vars; |
2496 | 0 | vars.CMTargetName = this->GetName().c_str(); |
2497 | 0 | vars.CMTargetType = cmState::GetTargetTypeName(this->GetType()).c_str(); |
2498 | 0 | vars.Language = lang.c_str(); |
2499 | |
|
2500 | 0 | auto const sfPath = this->LocalGenerator->ConvertToOutputFormat( |
2501 | 0 | sf->GetFullPath(), cmOutputConverter::SHELL); |
2502 | | |
2503 | | // Compute the base compiler command line. We'll find placeholders and |
2504 | | // replace them with arguments later in this function. |
2505 | 0 | { |
2506 | 0 | FlagClassification cls = FlagClassification::ExecutionFlag; |
2507 | 0 | FlagKind kind = FlagKind::NotAFlag; |
2508 | |
|
2509 | 0 | std::string const cmdVar = |
2510 | 0 | cmStrCat("CMAKE_", lang, "_COMPILE_", useBmiTemplate ? "BMI" : "OBJECT"); |
2511 | 0 | std::string const& compileCmd = mf->GetRequiredDefinition(cmdVar); |
2512 | 0 | cmList compileCmds(compileCmd); // FIXME: which command to use? |
2513 | 0 | std::string& cmd = compileCmds[0]; |
2514 | 0 | auto rulePlaceholderExpander = lg->CreateRulePlaceholderExpander(); |
2515 | |
|
2516 | 0 | static std::string const PlaceholderDefines = "__CMAKE_DEFINES"; |
2517 | 0 | static std::string const PlaceholderIncludes = "__CMAKE_INCLUDES"; |
2518 | 0 | static std::string const PlaceholderFlags = "__CMAKE_FLAGS"; |
2519 | 0 | static std::string const PlaceholderSource = "__CMAKE_SOURCE"; |
2520 | |
|
2521 | 0 | vars.Defines = PlaceholderDefines.c_str(); |
2522 | 0 | vars.Includes = PlaceholderIncludes.c_str(); |
2523 | 0 | vars.TargetPDB = sfVars.TargetPDB.c_str(); |
2524 | 0 | vars.TargetCompilePDB = sfVars.TargetCompilePDB.c_str(); |
2525 | 0 | vars.Object = sfVars.ObjectFileDir.c_str(); |
2526 | 0 | vars.ObjectDir = sfVars.ObjectDir.c_str(); |
2527 | 0 | vars.ObjectFileDir = sfVars.ObjectFileDir.c_str(); |
2528 | 0 | vars.TargetSupportDir = sfVars.TargetSupportDir.c_str(); |
2529 | 0 | vars.Flags = PlaceholderFlags.c_str(); |
2530 | 0 | vars.DependencyFile = sfVars.DependencyFile.c_str(); |
2531 | 0 | vars.DependencyTarget = sfVars.DependencyTarget.c_str(); |
2532 | 0 | vars.Source = PlaceholderSource.c_str(); |
2533 | |
|
2534 | 0 | rulePlaceholderExpander->ExpandRuleVariables(lg, cmd, vars); |
2535 | 0 | for (auto&& flag : SplitFlags(cmd)) { |
2536 | 0 | if (flag == PlaceholderDefines) { |
2537 | 0 | flags.insert(flags.end(), define_flags.begin(), define_flags.end()); |
2538 | 0 | } else if (flag == PlaceholderIncludes) { |
2539 | 0 | flags.insert(flags.end(), include_flags.begin(), include_flags.end()); |
2540 | 0 | } else if (flag == PlaceholderFlags) { |
2541 | 0 | flags.insert(flags.end(), compile_flags.begin(), compile_flags.end()); |
2542 | 0 | } else if (flag == PlaceholderSource) { |
2543 | 0 | flags.emplace_back(FlagClassification::LocationFlag, |
2544 | 0 | FlagKind::BuildSystem, sfPath); |
2545 | 0 | } else { |
2546 | 0 | flags.emplace_back(cls, kind, std::move(flag)); |
2547 | | // All remaining flags here are build system flags. |
2548 | 0 | kind = FlagKind::BuildSystem; |
2549 | 0 | } |
2550 | 0 | } |
2551 | 0 | } |
2552 | |
|
2553 | 0 | cacheEntry = sourceFlagsCache.emplace_hint(cacheEntry, sf, std::move(flags)); |
2554 | 0 | return cacheEntry->second; |
2555 | 0 | } |
2556 | | |
2557 | | cmGeneratorTarget::SourceVariables cmGeneratorTarget::GetSourceVariables( |
2558 | | cmSourceFile const* sf, std::string const& config) |
2559 | 0 | { |
2560 | 0 | SourceVariables vars; |
2561 | 0 | auto const language = sf->GetLanguage(); |
2562 | 0 | auto const targetType = this->GetType(); |
2563 | 0 | auto const* const lg = this->GetLocalGenerator(); |
2564 | 0 | auto const* const gg = this->GetGlobalGenerator(); |
2565 | 0 | auto const* const mf = this->Makefile; |
2566 | | |
2567 | | // PDB settings. |
2568 | 0 | { |
2569 | 0 | if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") || |
2570 | 0 | mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID") || |
2571 | 0 | mf->GetDefinition("MSVC_CUDA_ARCHITECTURE_ID")) { |
2572 | 0 | std::string pdbPath; |
2573 | 0 | std::string compilePdbPath; |
2574 | 0 | if (targetType <= cmStateEnums::OBJECT_LIBRARY) { |
2575 | 0 | compilePdbPath = this->GetCompilePDBPath(config); |
2576 | 0 | if (compilePdbPath.empty()) { |
2577 | | // Match VS default: `$(IntDir)vc$(PlatformToolsetVersion).pdb`. |
2578 | | // A trailing slash tells the toolchain to add its default file name. |
2579 | 0 | compilePdbPath = this->GetSupportDirectory(); |
2580 | 0 | if (gg->IsMultiConfig()) { |
2581 | 0 | compilePdbPath = cmStrCat(compilePdbPath, '/', config); |
2582 | 0 | } |
2583 | 0 | compilePdbPath += '/'; |
2584 | 0 | if (targetType == cmStateEnums::STATIC_LIBRARY) { |
2585 | | // Match VS default for static libs: `$(IntDir)$(ProjectName).pdb`. |
2586 | 0 | compilePdbPath = cmStrCat(compilePdbPath, this->GetName(), ".pdb"); |
2587 | 0 | } |
2588 | 0 | } |
2589 | 0 | } |
2590 | |
|
2591 | 0 | if (targetType == cmStateEnums::EXECUTABLE || |
2592 | 0 | targetType == cmStateEnums::STATIC_LIBRARY || |
2593 | 0 | targetType == cmStateEnums::SHARED_LIBRARY || |
2594 | 0 | targetType == cmStateEnums::MODULE_LIBRARY) { |
2595 | 0 | pdbPath = cmStrCat(this->GetPDBDirectory(config), '/', |
2596 | 0 | this->GetPDBName(config)); |
2597 | 0 | } |
2598 | |
|
2599 | 0 | vars.TargetPDB = lg->ConvertToOutputFormat( |
2600 | 0 | gg->ConvertToOutputPath(std::move(pdbPath)), cmOutputConverter::SHELL); |
2601 | 0 | vars.TargetCompilePDB = lg->ConvertToOutputFormat( |
2602 | 0 | gg->ConvertToOutputPath(std::move(compilePdbPath)), |
2603 | 0 | cmOutputConverter::SHELL); |
2604 | 0 | } |
2605 | 0 | } |
2606 | | |
2607 | | // Object settings. |
2608 | 0 | { |
2609 | 0 | std::string const targetSupportDir = lg->MaybeRelativeToTopBinDir( |
2610 | 0 | gg->ConvertToOutputPath(this->GetCMFSupportDirectory())); |
2611 | 0 | std::string const objectDir = gg->ConvertToOutputPath( |
2612 | 0 | cmStrCat(this->GetSupportDirectory(), gg->GetConfigDirectory(config))); |
2613 | 0 | std::string const objectFileName = this->GetObjectName(sf); |
2614 | 0 | std::string const objectFilePath = |
2615 | 0 | cmStrCat(objectDir, '/', objectFileName); |
2616 | |
|
2617 | 0 | vars.TargetSupportDir = |
2618 | 0 | lg->ConvertToOutputFormat(targetSupportDir, cmOutputConverter::SHELL); |
2619 | 0 | vars.ObjectDir = |
2620 | 0 | lg->ConvertToOutputFormat(objectDir, cmOutputConverter::SHELL); |
2621 | 0 | vars.ObjectFileDir = |
2622 | 0 | lg->ConvertToOutputFormat(objectFilePath, cmOutputConverter::SHELL); |
2623 | | |
2624 | | // Dependency settings. |
2625 | 0 | { |
2626 | 0 | std::string const depfileFormatName = |
2627 | 0 | cmStrCat("CMAKE_", language, "_DEPFILE_FORMAT"); |
2628 | 0 | std::string const depfileFormat = |
2629 | 0 | mf->GetSafeDefinition(depfileFormatName); |
2630 | 0 | if (depfileFormat != "msvc"_s) { |
2631 | 0 | std::string const flagsName = |
2632 | 0 | cmStrCat("CMAKE_DEPFILE_FLAGS_", language); |
2633 | 0 | std::string const depfileFlags = mf->GetSafeDefinition(flagsName); |
2634 | 0 | if (!depfileFlags.empty()) { |
2635 | 0 | bool replaceExt = false; |
2636 | 0 | if (!language.empty()) { |
2637 | 0 | std::string const repVar = |
2638 | 0 | cmStrCat("CMAKE_", language, "_DEPFILE_EXTENSION_REPLACE"); |
2639 | 0 | replaceExt = mf->IsOn(repVar); |
2640 | 0 | } |
2641 | 0 | std::string const depfilePath = cmStrCat( |
2642 | 0 | objectDir, '/', |
2643 | 0 | replaceExt |
2644 | 0 | ? cmSystemTools::GetFilenameWithoutLastExtension(objectFileName) |
2645 | 0 | : objectFileName, |
2646 | 0 | ".d"); |
2647 | |
|
2648 | 0 | vars.DependencyFlags = depfileFlags; |
2649 | 0 | vars.DependencyTarget = vars.ObjectFileDir; |
2650 | 0 | vars.DependencyFile = |
2651 | 0 | lg->ConvertToOutputFormat(depfilePath, cmOutputConverter::SHELL); |
2652 | 0 | } |
2653 | 0 | } |
2654 | 0 | } |
2655 | 0 | } |
2656 | |
|
2657 | 0 | return vars; |
2658 | 0 | } |
2659 | | |
2660 | | void cmGeneratorTarget::AddExplicitLanguageFlags(std::string& flags, |
2661 | | cmSourceFile const& sf) const |
2662 | 0 | { |
2663 | 0 | cmValue lang = sf.GetProperty("LANGUAGE"); |
2664 | 0 | if (!lang) { |
2665 | 0 | return; |
2666 | 0 | } |
2667 | | |
2668 | 0 | switch (this->GetPolicyStatusCMP0119()) { |
2669 | 0 | case cmPolicies::WARN: |
2670 | 0 | CM_FALLTHROUGH; |
2671 | 0 | case cmPolicies::OLD: |
2672 | | // The OLD behavior is to not add explicit language flags. |
2673 | 0 | return; |
2674 | 0 | case cmPolicies::NEW: |
2675 | | // The NEW behavior is to add explicit language flags. |
2676 | 0 | break; |
2677 | 0 | } |
2678 | | |
2679 | 0 | this->LocalGenerator->AppendFeatureOptions(flags, *lang, |
2680 | 0 | "EXPLICIT_LANGUAGE"); |
2681 | 0 | } |
2682 | | |
2683 | | void cmGeneratorTarget::AddCUDAArchitectureFlags(cmBuildStep compileOrLink, |
2684 | | std::string const& config, |
2685 | | std::string& flags) const |
2686 | 0 | { |
2687 | 0 | std::string arch = this->GetSafeProperty("CUDA_ARCHITECTURES"); |
2688 | |
|
2689 | 0 | if (arch.empty()) { |
2690 | 0 | switch (this->GetPolicyStatusCMP0104()) { |
2691 | 0 | case cmPolicies::WARN: |
2692 | 0 | if (!this->LocalGenerator->GetCMakeInstance()->GetIsInTryCompile()) { |
2693 | 0 | this->Makefile->IssuePolicyWarning( |
2694 | 0 | cmPolicies::CMP0104, {}, |
2695 | 0 | cmStrCat("CUDA_ARCHITECTURES is empty for target \""_s, |
2696 | 0 | this->GetName(), "\"."_s)); |
2697 | 0 | } |
2698 | 0 | CM_FALLTHROUGH; |
2699 | 0 | case cmPolicies::OLD: |
2700 | 0 | break; |
2701 | 0 | default: |
2702 | 0 | this->Makefile->IssueMessage( |
2703 | 0 | MessageType::FATAL_ERROR, |
2704 | 0 | "CUDA_ARCHITECTURES is empty for target \"" + this->GetName() + |
2705 | 0 | "\"."); |
2706 | 0 | } |
2707 | 0 | } |
2708 | | |
2709 | | // If CUDA_ARCHITECTURES is false we don't add any architectures. |
2710 | 0 | if (cmIsOff(arch)) { |
2711 | 0 | return; |
2712 | 0 | } |
2713 | | |
2714 | 0 | this->AddCUDAArchitectureFlagsImpl(compileOrLink, config, "CUDA", |
2715 | 0 | std::move(arch), flags); |
2716 | 0 | } |
2717 | | |
2718 | | void cmGeneratorTarget::AddCUDAArchitectureFlagsImpl(cmBuildStep compileOrLink, |
2719 | | std::string const& config, |
2720 | | std::string const& lang, |
2721 | | std::string arch, |
2722 | | std::string& flags) const |
2723 | 0 | { |
2724 | 0 | std::string const& compiler = this->Makefile->GetSafeDefinition( |
2725 | 0 | cmStrCat("CMAKE_", lang, "_COMPILER_ID")); |
2726 | 0 | bool const ipoEnabled = this->IsIPOEnabled(lang, config); |
2727 | | |
2728 | | // Check for special modes: `all`, `all-major`. |
2729 | 0 | if (arch == "all" || arch == "all-major") { |
2730 | 0 | if (compiler == "NVIDIA" && |
2731 | 0 | cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL, |
2732 | 0 | this->Makefile->GetDefinition(cmStrCat( |
2733 | 0 | "CMAKE_", lang, "_COMPILER_VERSION")), |
2734 | 0 | "11.5")) { |
2735 | 0 | flags = cmStrCat(flags, " -arch=", arch); |
2736 | 0 | return; |
2737 | 0 | } |
2738 | 0 | if (arch == "all") { |
2739 | 0 | arch = *this->Makefile->GetDefinition( |
2740 | 0 | cmStrCat("CMAKE_", lang, "_ARCHITECTURES_ALL")); |
2741 | 0 | } else if (arch == "all-major") { |
2742 | 0 | arch = *this->Makefile->GetDefinition( |
2743 | 0 | cmStrCat("CMAKE_", lang, "_ARCHITECTURES_ALL_MAJOR")); |
2744 | 0 | } |
2745 | 0 | } else if (arch == "native") { |
2746 | 0 | cmValue native = this->Makefile->GetDefinition( |
2747 | 0 | cmStrCat("CMAKE_", lang, "_ARCHITECTURES_NATIVE")); |
2748 | 0 | if (native.IsEmpty()) { |
2749 | 0 | this->Makefile->IssueMessage( |
2750 | 0 | MessageType::FATAL_ERROR, |
2751 | 0 | cmStrCat(lang, |
2752 | 0 | "_ARCHITECTURES is set to \"native\", but no NVIDIA GPU was " |
2753 | 0 | "detected.")); |
2754 | 0 | } |
2755 | 0 | if (compiler == "NVIDIA" && |
2756 | 0 | cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL, |
2757 | 0 | this->Makefile->GetDefinition(cmStrCat( |
2758 | 0 | "CMAKE_", lang, "_COMPILER_VERSION")), |
2759 | 0 | "11.6")) { |
2760 | 0 | flags = cmStrCat(flags, " -arch=", arch); |
2761 | 0 | return; |
2762 | 0 | } |
2763 | 0 | arch = *native; |
2764 | 0 | } |
2765 | | |
2766 | 0 | struct CudaArchitecture |
2767 | 0 | { |
2768 | 0 | std::string name; |
2769 | 0 | bool real{ true }; |
2770 | 0 | bool virtual_{ true }; |
2771 | 0 | }; |
2772 | 0 | std::vector<CudaArchitecture> architectures; |
2773 | |
|
2774 | 0 | { |
2775 | 0 | cmList options(arch); |
2776 | |
|
2777 | 0 | for (auto& option : options) { |
2778 | 0 | CudaArchitecture architecture; |
2779 | | |
2780 | | // Architecture name is up to the first specifier. |
2781 | 0 | std::size_t pos = option.find_first_of('-'); |
2782 | 0 | architecture.name = option.substr(0, pos); |
2783 | |
|
2784 | 0 | if (pos != std::string::npos) { |
2785 | 0 | cm::string_view specifier{ option.c_str() + pos + 1, |
2786 | 0 | option.length() - pos - 1 }; |
2787 | |
|
2788 | 0 | if (specifier == "real") { |
2789 | 0 | architecture.real = true; |
2790 | 0 | architecture.virtual_ = false; |
2791 | 0 | } else if (specifier == "virtual") { |
2792 | 0 | architecture.real = false; |
2793 | 0 | architecture.virtual_ = true; |
2794 | 0 | } else { |
2795 | 0 | this->Makefile->IssueMessage( |
2796 | 0 | MessageType::FATAL_ERROR, |
2797 | 0 | "Unknown CUDA architecture specifier \"" + std::string(specifier) + |
2798 | 0 | "\"."); |
2799 | 0 | } |
2800 | 0 | } |
2801 | |
|
2802 | 0 | architectures.emplace_back(architecture); |
2803 | 0 | } |
2804 | 0 | } |
2805 | |
|
2806 | 0 | if (compiler == "NVIDIA") { |
2807 | 0 | if (ipoEnabled && compileOrLink == cmBuildStep::Link) { |
2808 | 0 | if (cmValue cudaIPOFlags = this->Makefile->GetDefinition( |
2809 | 0 | cmStrCat("CMAKE_", lang, "_LINK_OPTIONS_IPO"))) { |
2810 | 0 | flags += *cudaIPOFlags; |
2811 | 0 | } |
2812 | 0 | } |
2813 | |
|
2814 | 0 | for (CudaArchitecture& architecture : architectures) { |
2815 | 0 | flags = cmStrCat(std::move(flags), " \"--generate-code=arch=compute_", |
2816 | 0 | architecture.name, ",code=["); |
2817 | |
|
2818 | 0 | if (architecture.virtual_) { |
2819 | 0 | flags = cmStrCat(std::move(flags), "compute_", architecture.name); |
2820 | |
|
2821 | 0 | if (ipoEnabled || architecture.real) { |
2822 | 0 | flags += ','; |
2823 | 0 | } |
2824 | 0 | } |
2825 | |
|
2826 | 0 | if (ipoEnabled) { |
2827 | 0 | if (compileOrLink == cmBuildStep::Compile) { |
2828 | 0 | flags = cmStrCat(std::move(flags), "lto_", architecture.name); |
2829 | 0 | } else if (compileOrLink == cmBuildStep::Link) { |
2830 | 0 | flags = cmStrCat(std::move(flags), "sm_", architecture.name); |
2831 | 0 | } |
2832 | 0 | } else if (architecture.real) { |
2833 | 0 | flags = cmStrCat(std::move(flags), "sm_", architecture.name); |
2834 | 0 | } |
2835 | |
|
2836 | 0 | flags += "]\""; |
2837 | 0 | } |
2838 | 0 | } else if (compiler == "Clang" && compileOrLink == cmBuildStep::Compile) { |
2839 | 0 | for (CudaArchitecture& architecture : architectures) { |
2840 | 0 | flags = |
2841 | 0 | cmStrCat(std::move(flags), " --cuda-gpu-arch=sm_", architecture.name); |
2842 | |
|
2843 | 0 | if (!architecture.real) { |
2844 | 0 | this->Makefile->IssueMessage( |
2845 | 0 | MessageType::WARNING, |
2846 | 0 | "Clang doesn't support disabling CUDA real code generation."); |
2847 | 0 | } |
2848 | |
|
2849 | 0 | if (!architecture.virtual_) { |
2850 | 0 | flags = cmStrCat(std::move(flags), " --no-cuda-include-ptx=sm_", |
2851 | 0 | architecture.name); |
2852 | 0 | } |
2853 | 0 | } |
2854 | 0 | } |
2855 | 0 | } |
2856 | | |
2857 | | void cmGeneratorTarget::AddISPCTargetFlags(std::string& flags) const |
2858 | 0 | { |
2859 | 0 | std::string const& arch = this->GetSafeProperty("ISPC_INSTRUCTION_SETS"); |
2860 | | |
2861 | | // If ISPC_TARGET is false we don't add any architectures. |
2862 | 0 | if (cmIsOff(arch)) { |
2863 | 0 | return; |
2864 | 0 | } |
2865 | | |
2866 | 0 | std::string const& compiler = |
2867 | 0 | this->Makefile->GetSafeDefinition("CMAKE_ISPC_COMPILER_ID"); |
2868 | |
|
2869 | 0 | if (compiler == "Intel") { |
2870 | 0 | cmList targets(arch); |
2871 | 0 | if (!targets.empty()) { |
2872 | 0 | flags += cmStrCat(" --target=", cmWrap("", targets, "", ",")); |
2873 | 0 | } |
2874 | 0 | } |
2875 | 0 | } |
2876 | | |
2877 | | void cmGeneratorTarget::AddHIPArchitectureFlags(cmBuildStep compileOrLink, |
2878 | | std::string const& config, |
2879 | | std::string& flags) const |
2880 | 0 | { |
2881 | 0 | std::string arch = this->GetSafeProperty("HIP_ARCHITECTURES"); |
2882 | |
|
2883 | 0 | if (arch.empty()) { |
2884 | 0 | this->Makefile->IssueMessage( |
2885 | 0 | MessageType::FATAL_ERROR, |
2886 | 0 | cmStrCat("HIP_ARCHITECTURES is empty for target \"", this->GetName(), |
2887 | 0 | "\".")); |
2888 | 0 | } |
2889 | | |
2890 | | // If HIP_ARCHITECTURES is false we don't add any architectures. |
2891 | 0 | if (cmIsOff(arch)) { |
2892 | 0 | return; |
2893 | 0 | } |
2894 | | |
2895 | 0 | if (this->Makefile->GetSafeDefinition("CMAKE_HIP_PLATFORM") == "nvidia") { |
2896 | 0 | this->AddCUDAArchitectureFlagsImpl(compileOrLink, config, "HIP", |
2897 | 0 | std::move(arch), flags); |
2898 | 0 | return; |
2899 | 0 | } |
2900 | | |
2901 | | // For spirv platform, chipStar handles targeting via the hip package |
2902 | 0 | if (this->Makefile->GetSafeDefinition("CMAKE_HIP_PLATFORM") == "spirv") { |
2903 | 0 | return; |
2904 | 0 | } |
2905 | | |
2906 | 0 | cmList options(arch); |
2907 | |
|
2908 | 0 | for (std::string& option : options) { |
2909 | 0 | flags += " --offload-arch=" + option; |
2910 | 0 | } |
2911 | 0 | } |
2912 | | |
2913 | | void cmGeneratorTarget::AddRustTargetFlags(std::string& flags) const |
2914 | 0 | { |
2915 | 0 | cmValue const edition = this->GetProperty("Rust_EDITION"); |
2916 | 0 | if (edition && !edition->empty()) { |
2917 | 0 | flags += " --edition=" + *edition; |
2918 | 0 | } |
2919 | 0 | } |
2920 | | |
2921 | | void cmGeneratorTarget::AddSwiftTargetFlags(std::string& flags) const |
2922 | 0 | { |
2923 | 0 | if (cmValue version = GetProperty("Swift_LANGUAGE_VERSION")) { |
2924 | 0 | if (cmSystemTools::VersionCompare( |
2925 | 0 | cmSystemTools::OP_GREATER_EQUAL, |
2926 | 0 | this->Makefile->GetDefinition("CMAKE_Swift_COMPILER_VERSION"), |
2927 | 0 | "4.2")) { |
2928 | 0 | flags += " -swift-version " + *version; |
2929 | 0 | } |
2930 | 0 | } |
2931 | |
|
2932 | 0 | if (!this->GetGlobalGenerator()->IsXcode() && |
2933 | 0 | cmSystemTools::VersionCompare( |
2934 | 0 | cmSystemTools::OP_GREATER_EQUAL, |
2935 | 0 | this->Makefile->GetDefinition("CMAKE_Swift_COMPILER_VERSION"), |
2936 | 0 | "5.8")) { |
2937 | | // Note: The Xcode generator sets the `SWIFT_PACKAGE_NAME` BuildSettings |
2938 | | // attribute |
2939 | 0 | std::string const packageName = this->GetSwiftPackageName(); |
2940 | 0 | if (!packageName.empty()) { |
2941 | 0 | std::string const packageFlag = |
2942 | 0 | this->Makefile->GetSafeDefinition("CMAKE_Swift_PACKAGE_NAME_FLAG"); |
2943 | | // Add the package name to the flags |
2944 | 0 | flags += " " + packageFlag + " " + packageName; |
2945 | 0 | } |
2946 | 0 | } |
2947 | 0 | } |
2948 | | |
2949 | | void cmGeneratorTarget::AddCUDAToolkitFlags(std::string& flags) const |
2950 | 0 | { |
2951 | 0 | std::string const& compiler = |
2952 | 0 | this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID"); |
2953 | |
|
2954 | 0 | if (compiler == "Clang") { |
2955 | | // Pass CUDA toolkit explicitly to Clang. |
2956 | | // Clang's searching for the system CUDA toolkit isn't very good and it's |
2957 | | // expected the user will explicitly pass the toolkit path. |
2958 | | // This also avoids Clang having to search for the toolkit on every |
2959 | | // invocation. |
2960 | 0 | std::string toolkitRoot = |
2961 | 0 | this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_LIBRARY_ROOT"); |
2962 | |
|
2963 | 0 | if (!toolkitRoot.empty()) { |
2964 | 0 | flags += " --cuda-path=" + |
2965 | 0 | this->LocalGenerator->ConvertToOutputFormat(toolkitRoot, |
2966 | 0 | cmOutputConverter::SHELL); |
2967 | 0 | } |
2968 | 0 | } |
2969 | 0 | } |
2970 | | |
2971 | | //---------------------------------------------------------------------------- |
2972 | | std::string cmGeneratorTarget::GetFeatureSpecificLinkRuleVariable( |
2973 | | std::string const& var, std::string const& lang, |
2974 | | std::string const& config) const |
2975 | 0 | { |
2976 | 0 | if (this->IsIPOEnabled(lang, config)) { |
2977 | 0 | std::string varIPO = var + "_IPO"; |
2978 | 0 | if (this->Makefile->IsDefinitionSet(varIPO)) { |
2979 | 0 | return varIPO; |
2980 | 0 | } |
2981 | 0 | } |
2982 | | |
2983 | 0 | return var; |
2984 | 0 | } |
2985 | | |
2986 | | //---------------------------------------------------------------------------- |
2987 | | std::string cmGeneratorTarget::GetCreateRuleVariable( |
2988 | | std::string const& lang, std::string const& config) const |
2989 | 0 | { |
2990 | 0 | switch (this->GetType()) { |
2991 | 0 | case cmStateEnums::STATIC_LIBRARY: { |
2992 | 0 | std::string var = cmStrCat("CMAKE_", lang, "_CREATE_STATIC_LIBRARY"); |
2993 | 0 | return this->GetFeatureSpecificLinkRuleVariable(var, lang, config); |
2994 | 0 | } |
2995 | 0 | case cmStateEnums::SHARED_LIBRARY: |
2996 | 0 | if (this->IsArchivedAIXSharedLibrary()) { |
2997 | 0 | return cmStrCat("CMAKE_", lang, "_CREATE_SHARED_LIBRARY_ARCHIVE"); |
2998 | 0 | } |
2999 | 0 | return cmStrCat("CMAKE_", lang, "_CREATE_SHARED_LIBRARY"); |
3000 | 0 | case cmStateEnums::MODULE_LIBRARY: |
3001 | 0 | return cmStrCat("CMAKE_", lang, "_CREATE_SHARED_MODULE"); |
3002 | 0 | case cmStateEnums::EXECUTABLE: |
3003 | 0 | if (this->IsExecutableWithExports()) { |
3004 | 0 | std::string linkExeWithExports = |
3005 | 0 | cmStrCat("CMAKE_", lang, "_LINK_EXECUTABLE_WITH_EXPORTS"); |
3006 | 0 | if (this->Makefile->IsDefinitionSet(linkExeWithExports)) { |
3007 | 0 | return linkExeWithExports; |
3008 | 0 | } |
3009 | 0 | } |
3010 | 0 | return cmStrCat("CMAKE_", lang, "_LINK_EXECUTABLE"); |
3011 | 0 | default: |
3012 | 0 | break; |
3013 | 0 | } |
3014 | 0 | return {}; |
3015 | 0 | } |
3016 | | |
3017 | | //---------------------------------------------------------------------------- |
3018 | | std::string cmGeneratorTarget::GetClangTidyExportFixesDirectory( |
3019 | | std::string const& lang) const |
3020 | 0 | { |
3021 | 0 | cmValue val = |
3022 | 0 | this->GetProperty(cmStrCat(lang, "_CLANG_TIDY_EXPORT_FIXES_DIR")); |
3023 | 0 | if (!cmNonempty(val)) { |
3024 | 0 | return {}; |
3025 | 0 | } |
3026 | | |
3027 | 0 | std::string path = *val; |
3028 | 0 | if (!cmSystemTools::FileIsFullPath(path)) { |
3029 | 0 | path = |
3030 | 0 | cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), '/', path); |
3031 | 0 | } |
3032 | 0 | return cmSystemTools::CollapseFullPath(path); |
3033 | 0 | } |
3034 | | |
3035 | | struct CycleWatcher |
3036 | | { |
3037 | | CycleWatcher(bool& flag) |
3038 | 0 | : Flag(flag) |
3039 | 0 | { |
3040 | 0 | this->Flag = true; |
3041 | 0 | } |
3042 | 0 | ~CycleWatcher() { this->Flag = false; } |
3043 | | bool& Flag; |
3044 | | }; |
3045 | | |
3046 | | cmGeneratorTarget const* cmGeneratorTarget::GetPchReuseTarget() const |
3047 | 0 | { |
3048 | 0 | if (this->ComputingPchReuse) { |
3049 | | // TODO: Get the full cycle. |
3050 | 0 | if (!this->PchReuseCycleDetected) { |
3051 | 0 | this->Makefile->IssueMessage( |
3052 | 0 | MessageType::FATAL_ERROR, |
3053 | 0 | cmStrCat("Circular PCH reuse target involving '", this->GetName(), |
3054 | 0 | '\'')); |
3055 | 0 | } |
3056 | 0 | this->PchReuseCycleDetected = true; |
3057 | 0 | return nullptr; |
3058 | 0 | } |
3059 | 0 | CycleWatcher watch(this->ComputingPchReuse); |
3060 | 0 | (void)watch; |
3061 | 0 | cmValue pchReuseFrom = this->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM"); |
3062 | 0 | if (!pchReuseFrom) { |
3063 | 0 | return nullptr; |
3064 | 0 | } |
3065 | 0 | cmGeneratorTarget const* generatorTarget = |
3066 | 0 | this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom); |
3067 | 0 | if (!generatorTarget) { |
3068 | 0 | this->Makefile->IssueMessage( |
3069 | 0 | MessageType::FATAL_ERROR, |
3070 | 0 | cmStrCat( |
3071 | 0 | "Target \"", *pchReuseFrom, "\" for the \"", this->GetName(), |
3072 | 0 | R"(" target's "PRECOMPILE_HEADERS_REUSE_FROM" property does not exist.)")); |
3073 | 0 | } |
3074 | 0 | if (this->GetProperty("PRECOMPILE_HEADERS").IsOn()) { |
3075 | 0 | this->Makefile->IssueMessage( |
3076 | 0 | MessageType::FATAL_ERROR, |
3077 | 0 | cmStrCat("PRECOMPILE_HEADERS property is already set on target (\"", |
3078 | 0 | this->GetName(), "\")\n")); |
3079 | 0 | } |
3080 | |
|
3081 | 0 | if (generatorTarget) { |
3082 | 0 | if (generatorTarget->GetPropertyAsBool("DISABLE_PRECOMPILE_HEADERS")) { |
3083 | 0 | this->Makefile->IssueMessage( |
3084 | 0 | MessageType::WARNING, |
3085 | 0 | cmStrCat( |
3086 | 0 | "Target \"", *pchReuseFrom, "\" for the \"", this->GetName(), |
3087 | 0 | R"(" target's "PRECOMPILE_HEADERS_REUSE_FROM" property has set "DISABLE_PRECOMPILE_HEADERS"; ignoring.)")); |
3088 | 0 | return nullptr; |
3089 | 0 | } |
3090 | | |
3091 | 0 | if (auto const* recurseReuseTarget = |
3092 | 0 | generatorTarget->GetPchReuseTarget()) { |
3093 | 0 | return recurseReuseTarget; |
3094 | 0 | } |
3095 | 0 | } |
3096 | 0 | return generatorTarget; |
3097 | 0 | } |
3098 | | |
3099 | | cmGeneratorTarget* cmGeneratorTarget::GetPchReuseTarget() |
3100 | 0 | { |
3101 | 0 | if (this->ComputingPchReuse) { |
3102 | | // TODO: Get the full cycle. |
3103 | 0 | if (!this->PchReuseCycleDetected) { |
3104 | 0 | this->Makefile->IssueMessage( |
3105 | 0 | MessageType::FATAL_ERROR, |
3106 | 0 | cmStrCat("Circular PCH reuse target involving '", this->GetName(), |
3107 | 0 | '\'')); |
3108 | 0 | } |
3109 | 0 | this->PchReuseCycleDetected = true; |
3110 | 0 | return nullptr; |
3111 | 0 | } |
3112 | 0 | CycleWatcher watch(this->ComputingPchReuse); |
3113 | 0 | (void)watch; |
3114 | 0 | cmValue pchReuseFrom = this->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM"); |
3115 | 0 | if (!pchReuseFrom) { |
3116 | 0 | return nullptr; |
3117 | 0 | } |
3118 | 0 | cmGeneratorTarget* generatorTarget = |
3119 | 0 | this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom); |
3120 | 0 | if (!generatorTarget) { |
3121 | 0 | this->Makefile->IssueMessage( |
3122 | 0 | MessageType::FATAL_ERROR, |
3123 | 0 | cmStrCat( |
3124 | 0 | "Target \"", *pchReuseFrom, "\" for the \"", this->GetName(), |
3125 | 0 | R"(" target's "PRECOMPILE_HEADERS_REUSE_FROM" property does not exist.)")); |
3126 | 0 | } |
3127 | 0 | if (this->GetProperty("PRECOMPILE_HEADERS").IsOn()) { |
3128 | 0 | this->Makefile->IssueMessage( |
3129 | 0 | MessageType::FATAL_ERROR, |
3130 | 0 | cmStrCat("PRECOMPILE_HEADERS property is already set on target (\"", |
3131 | 0 | this->GetName(), "\")\n")); |
3132 | 0 | } |
3133 | |
|
3134 | 0 | if (generatorTarget) { |
3135 | 0 | if (generatorTarget->GetPropertyAsBool("DISABLE_PRECOMPILE_HEADERS")) { |
3136 | 0 | this->Makefile->IssueMessage( |
3137 | 0 | MessageType::WARNING, |
3138 | 0 | cmStrCat( |
3139 | 0 | "Target \"", *pchReuseFrom, "\" for the \"", this->GetName(), |
3140 | 0 | R"(" target's "PRECOMPILE_HEADERS_REUSE_FROM" property has set "DISABLE_PRECOMPILE_HEADERS"; ignoring.)")); |
3141 | 0 | return nullptr; |
3142 | 0 | } |
3143 | | |
3144 | 0 | if (auto* recurseReuseTarget = generatorTarget->GetPchReuseTarget()) { |
3145 | 0 | return recurseReuseTarget; |
3146 | 0 | } |
3147 | 0 | } |
3148 | 0 | return generatorTarget; |
3149 | 0 | } |
3150 | | |
3151 | | std::vector<std::string> cmGeneratorTarget::GetPchArchs( |
3152 | | std::string const& config, std::string const& lang) const |
3153 | 0 | { |
3154 | 0 | std::vector<std::string> pchArchs; |
3155 | 0 | if (!this->GetGlobalGenerator()->IsXcode()) { |
3156 | 0 | pchArchs = this->GetAppleArchs(config, lang); |
3157 | 0 | } |
3158 | 0 | if (pchArchs.size() < 2) { |
3159 | | // We do not need per-arch PCH files when building for one architecture. |
3160 | 0 | pchArchs = { {} }; |
3161 | 0 | } |
3162 | 0 | return pchArchs; |
3163 | 0 | } |
3164 | | |
3165 | | std::string cmGeneratorTarget::GetPchHeader(std::string const& config, |
3166 | | std::string const& language, |
3167 | | std::string const& arch) const |
3168 | 0 | { |
3169 | 0 | if (language != "C" && language != "CXX" && language != "OBJC" && |
3170 | 0 | language != "OBJCXX") { |
3171 | 0 | return std::string(); |
3172 | 0 | } |
3173 | | |
3174 | 0 | if (this->GetPropertyAsBool("DISABLE_PRECOMPILE_HEADERS")) { |
3175 | 0 | return std::string(); |
3176 | 0 | } |
3177 | 0 | cmGeneratorTarget const* generatorTarget = this; |
3178 | 0 | cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget(); |
3179 | 0 | bool const haveReuseTarget = reuseTarget && reuseTarget != this; |
3180 | 0 | if (reuseTarget) { |
3181 | 0 | generatorTarget = reuseTarget; |
3182 | 0 | } |
3183 | |
|
3184 | 0 | auto const inserted = |
3185 | 0 | this->PchHeaders.insert(std::make_pair(language + config + arch, "")); |
3186 | 0 | if (inserted.second) { |
3187 | 0 | std::vector<BT<std::string>> const headers = |
3188 | 0 | this->GetPrecompileHeaders(config, language); |
3189 | 0 | if (headers.empty() && !haveReuseTarget) { |
3190 | 0 | return std::string(); |
3191 | 0 | } |
3192 | 0 | std::string& filename = inserted.first->second; |
3193 | |
|
3194 | 0 | std::map<std::string, std::string> const languageToExtension = { |
3195 | 0 | { "C", ".h" }, |
3196 | 0 | { "CXX", ".hxx" }, |
3197 | 0 | { "OBJC", ".objc.h" }, |
3198 | 0 | { "OBJCXX", ".objcxx.hxx" } |
3199 | 0 | }; |
3200 | |
|
3201 | 0 | filename = generatorTarget->GetCMFSupportDirectory(); |
3202 | |
|
3203 | 0 | if (this->GetGlobalGenerator()->IsMultiConfig()) { |
3204 | 0 | filename = cmStrCat(filename, '/', config); |
3205 | 0 | } |
3206 | | |
3207 | | // This is acceptable as its the source file, won't have a rename/hash |
3208 | 0 | filename = |
3209 | 0 | cmStrCat(filename, "/cmake_pch", arch.empty() ? "" : cmStrCat('_', arch), |
3210 | 0 | languageToExtension.at(language)); |
3211 | |
|
3212 | 0 | std::string const filename_tmp = cmStrCat(filename, ".tmp"); |
3213 | 0 | if (!haveReuseTarget) { |
3214 | 0 | cmValue pchPrologue = |
3215 | 0 | this->Makefile->GetDefinition("CMAKE_PCH_PROLOGUE"); |
3216 | 0 | cmValue pchEpilogue = |
3217 | 0 | this->Makefile->GetDefinition("CMAKE_PCH_EPILOGUE"); |
3218 | |
|
3219 | 0 | std::string firstHeaderOnDisk; |
3220 | 0 | { |
3221 | 0 | cmGeneratedFileStream file( |
3222 | 0 | filename_tmp, false, |
3223 | 0 | this->GetGlobalGenerator()->GetMakefileEncoding()); |
3224 | 0 | file << "/* generated by CMake */\n\n"; |
3225 | 0 | if (pchPrologue) { |
3226 | 0 | file << *pchPrologue << "\n"; |
3227 | 0 | } |
3228 | 0 | if (this->GetGlobalGenerator()->IsXcode()) { |
3229 | 0 | file << "#ifndef CMAKE_SKIP_PRECOMPILE_HEADERS\n"; |
3230 | 0 | } |
3231 | 0 | if (language == "CXX" && !this->GetGlobalGenerator()->IsXcode()) { |
3232 | 0 | file << "#ifdef __cplusplus\n"; |
3233 | 0 | } |
3234 | 0 | for (auto const& header_bt : headers) { |
3235 | 0 | if (header_bt.Value.empty()) { |
3236 | 0 | continue; |
3237 | 0 | } |
3238 | 0 | if (header_bt.Value[0] == '<' || header_bt.Value[0] == '\"') { |
3239 | 0 | file << "#include " << header_bt.Value << "\n"; |
3240 | 0 | } else { |
3241 | 0 | file << "#include \"" << header_bt.Value << "\"\n"; |
3242 | 0 | } |
3243 | |
|
3244 | 0 | if (cmSystemTools::FileExists(header_bt.Value) && |
3245 | 0 | firstHeaderOnDisk.empty()) { |
3246 | 0 | firstHeaderOnDisk = header_bt.Value; |
3247 | 0 | } |
3248 | 0 | } |
3249 | 0 | if (language == "CXX" && !this->GetGlobalGenerator()->IsXcode()) { |
3250 | 0 | file << "#endif // __cplusplus\n"; |
3251 | 0 | } |
3252 | 0 | if (this->GetGlobalGenerator()->IsXcode()) { |
3253 | 0 | file << "#endif // CMAKE_SKIP_PRECOMPILE_HEADERS\n"; |
3254 | 0 | } |
3255 | 0 | if (pchEpilogue) { |
3256 | 0 | file << *pchEpilogue << "\n"; |
3257 | 0 | } |
3258 | 0 | } |
3259 | |
|
3260 | 0 | if (!firstHeaderOnDisk.empty()) { |
3261 | 0 | cmFileTimes::Copy(firstHeaderOnDisk, filename_tmp); |
3262 | 0 | } |
3263 | |
|
3264 | 0 | cmSystemTools::MoveFileIfDifferent(filename_tmp, filename); |
3265 | 0 | } |
3266 | 0 | } |
3267 | 0 | return inserted.first->second; |
3268 | 0 | } |
3269 | | |
3270 | | std::string cmGeneratorTarget::GetPchSource(std::string const& config, |
3271 | | std::string const& language, |
3272 | | std::string const& arch) const |
3273 | 0 | { |
3274 | 0 | if (language != "C" && language != "CXX" && language != "OBJC" && |
3275 | 0 | language != "OBJCXX") { |
3276 | 0 | return std::string(); |
3277 | 0 | } |
3278 | 0 | auto const inserted = |
3279 | 0 | this->PchSources.insert(std::make_pair(language + config + arch, "")); |
3280 | 0 | if (inserted.second) { |
3281 | 0 | std::string const pchHeader = this->GetPchHeader(config, language, arch); |
3282 | 0 | if (pchHeader.empty()) { |
3283 | 0 | return std::string(); |
3284 | 0 | } |
3285 | 0 | std::string& filename = inserted.first->second; |
3286 | |
|
3287 | 0 | cmGeneratorTarget const* generatorTarget = this; |
3288 | 0 | cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget(); |
3289 | 0 | bool const haveReuseTarget = reuseTarget && reuseTarget != this; |
3290 | 0 | if (reuseTarget) { |
3291 | 0 | generatorTarget = reuseTarget; |
3292 | 0 | } |
3293 | |
|
3294 | 0 | filename = |
3295 | 0 | cmStrCat(generatorTarget->GetCMFSupportDirectory(), "/cmake_pch"); |
3296 | | |
3297 | | // For GCC the source extension will be transformed into .h[xx].gch |
3298 | 0 | if (!this->Makefile->IsOn("CMAKE_LINK_PCH")) { |
3299 | 0 | std::map<std::string, std::string> const languageToExtension = { |
3300 | 0 | { "C", ".h.c" }, |
3301 | 0 | { "CXX", ".hxx.cxx" }, |
3302 | 0 | { "OBJC", ".objc.h.m" }, |
3303 | 0 | { "OBJCXX", ".objcxx.hxx.mm" } |
3304 | 0 | }; |
3305 | |
|
3306 | 0 | filename = cmStrCat(filename, arch.empty() ? "" : cmStrCat('_', arch), |
3307 | 0 | languageToExtension.at(language)); |
3308 | 0 | } else { |
3309 | 0 | std::map<std::string, std::string> const languageToExtension = { |
3310 | 0 | { "C", ".c" }, { "CXX", ".cxx" }, { "OBJC", ".m" }, { "OBJCXX", ".mm" } |
3311 | 0 | }; |
3312 | |
|
3313 | 0 | filename = cmStrCat(filename, arch.empty() ? "" : cmStrCat('_', arch), |
3314 | 0 | languageToExtension.at(language)); |
3315 | 0 | } |
3316 | |
|
3317 | 0 | std::string const filename_tmp = cmStrCat(filename, ".tmp"); |
3318 | 0 | if (!haveReuseTarget) { |
3319 | 0 | { |
3320 | 0 | cmGeneratedFileStream file(filename_tmp); |
3321 | 0 | file << "/* generated by CMake */\n"; |
3322 | 0 | } |
3323 | 0 | cmFileTimes::Copy(pchHeader, filename_tmp); |
3324 | 0 | cmSystemTools::MoveFileIfDifferent(filename_tmp, filename); |
3325 | 0 | } |
3326 | 0 | } |
3327 | 0 | return inserted.first->second; |
3328 | 0 | } |
3329 | | |
3330 | | std::string cmGeneratorTarget::GetPchFileObject(std::string const& config, |
3331 | | std::string const& language, |
3332 | | std::string const& arch) |
3333 | 0 | { |
3334 | 0 | if (language != "C" && language != "CXX" && language != "OBJC" && |
3335 | 0 | language != "OBJCXX") { |
3336 | 0 | return std::string(); |
3337 | 0 | } |
3338 | 0 | auto const inserted = |
3339 | 0 | this->PchObjectFiles.insert(std::make_pair(language + config + arch, "")); |
3340 | 0 | if (inserted.second) { |
3341 | 0 | std::string const pchSource = this->GetPchSource(config, language, arch); |
3342 | 0 | if (pchSource.empty()) { |
3343 | 0 | return std::string(); |
3344 | 0 | } |
3345 | 0 | std::string& filename = inserted.first->second; |
3346 | |
|
3347 | 0 | auto* pchSf = this->Makefile->GetOrCreateSource( |
3348 | 0 | pchSource, false, cmSourceFileLocationKind::Known); |
3349 | 0 | pchSf->SetSpecialSourceType(cmSourceFile::SpecialSourceType::PchSource); |
3350 | 0 | pchSf->ResolveFullPath(); |
3351 | 0 | filename = cmStrCat(this->GetObjectDirectory(config), '/', |
3352 | 0 | this->GetObjectName(pchSf)); |
3353 | 0 | } |
3354 | 0 | return inserted.first->second; |
3355 | 0 | } |
3356 | | |
3357 | | std::string cmGeneratorTarget::GetPchFile(std::string const& config, |
3358 | | std::string const& language, |
3359 | | std::string const& arch) |
3360 | 0 | { |
3361 | 0 | auto const inserted = |
3362 | 0 | this->PchFiles.insert(std::make_pair(language + config + arch, "")); |
3363 | 0 | if (inserted.second) { |
3364 | 0 | std::string& pchFile = inserted.first->second; |
3365 | |
|
3366 | 0 | std::string const pchExtension = |
3367 | 0 | this->Makefile->GetSafeDefinition("CMAKE_PCH_EXTENSION"); |
3368 | |
|
3369 | 0 | if (this->Makefile->IsOn("CMAKE_LINK_PCH")) { |
3370 | 0 | auto replaceExtension = [](std::string const& str, |
3371 | 0 | std::string const& ext) -> std::string { |
3372 | 0 | auto dot_pos = str.rfind('.'); |
3373 | 0 | std::string result; |
3374 | 0 | if (dot_pos != std::string::npos) { |
3375 | 0 | result = str.substr(0, dot_pos); |
3376 | 0 | } |
3377 | 0 | result += ext; |
3378 | 0 | return result; |
3379 | 0 | }; |
3380 | |
|
3381 | 0 | cmGeneratorTarget* generatorTarget = this; |
3382 | 0 | cmGeneratorTarget* reuseTarget = this->GetPchReuseTarget(); |
3383 | 0 | if (reuseTarget) { |
3384 | 0 | generatorTarget = reuseTarget; |
3385 | 0 | } |
3386 | |
|
3387 | 0 | std::string const pchFileObject = |
3388 | 0 | generatorTarget->GetPchFileObject(config, language, arch); |
3389 | 0 | if (!pchExtension.empty()) { |
3390 | 0 | pchFile = replaceExtension(pchFileObject, pchExtension); |
3391 | 0 | } |
3392 | 0 | } else { |
3393 | 0 | if (this->GetUseShortObjectNames() && !pchExtension.empty()) { |
3394 | 0 | auto pchSource = this->GetPchSource(config, language, arch); |
3395 | 0 | auto* pchSf = this->Makefile->GetOrCreateSource( |
3396 | 0 | pchSource, false, cmSourceFileLocationKind::Known); |
3397 | 0 | pchSf->SetSpecialSourceType( |
3398 | 0 | cmSourceFile::SpecialSourceType::PchSource); |
3399 | 0 | pchSf->ResolveFullPath(); |
3400 | 0 | std::string cfgSubdir; |
3401 | 0 | if (this->GetGlobalGenerator()->IsMultiConfig()) { |
3402 | 0 | cfgSubdir = cmStrCat(config, '/'); |
3403 | 0 | } |
3404 | 0 | pchFile = cmStrCat( |
3405 | 0 | this->GetSupportDirectory(), '/', cfgSubdir, |
3406 | 0 | this->LocalGenerator->GetShortObjectFileName(*pchSf), pchExtension); |
3407 | 0 | } else { |
3408 | 0 | pchFile = |
3409 | 0 | cmStrCat(this->GetPchHeader(config, language, arch), pchExtension); |
3410 | 0 | } |
3411 | 0 | } |
3412 | 0 | } |
3413 | 0 | return inserted.first->second; |
3414 | 0 | } |
3415 | | |
3416 | | std::string cmGeneratorTarget::GetPchCreateCompileOptions( |
3417 | | std::string const& config, std::string const& language, |
3418 | | std::string const& arch) |
3419 | 0 | { |
3420 | 0 | auto const inserted = this->PchCreateCompileOptions.insert( |
3421 | 0 | std::make_pair(language + config + arch, "")); |
3422 | 0 | if (inserted.second) { |
3423 | 0 | std::string& createOptionList = inserted.first->second; |
3424 | |
|
3425 | 0 | if (this->GetPropertyAsBool("PCH_WARN_INVALID")) { |
3426 | 0 | createOptionList = this->Makefile->GetSafeDefinition( |
3427 | 0 | cmStrCat("CMAKE_", language, "_COMPILE_OPTIONS_INVALID_PCH")); |
3428 | 0 | } |
3429 | |
|
3430 | 0 | if (this->GetPropertyAsBool("PCH_INSTANTIATE_TEMPLATES")) { |
3431 | 0 | std::string varName = cmStrCat( |
3432 | 0 | "CMAKE_", language, "_COMPILE_OPTIONS_INSTANTIATE_TEMPLATES_PCH"); |
3433 | 0 | std::string instantiateOption = |
3434 | 0 | this->Makefile->GetSafeDefinition(varName); |
3435 | 0 | if (!instantiateOption.empty()) { |
3436 | 0 | createOptionList = cmStrCat(createOptionList, ';', instantiateOption); |
3437 | 0 | } |
3438 | 0 | } |
3439 | |
|
3440 | 0 | std::string const createOptVar = |
3441 | 0 | cmStrCat("CMAKE_", language, "_COMPILE_OPTIONS_CREATE_PCH"); |
3442 | |
|
3443 | 0 | createOptionList = cmStrCat( |
3444 | 0 | createOptionList, ';', this->Makefile->GetSafeDefinition(createOptVar)); |
3445 | |
|
3446 | 0 | std::string const pchHeader = this->GetPchHeader(config, language, arch); |
3447 | 0 | std::string const pchFile = this->GetPchFile(config, language, arch); |
3448 | |
|
3449 | 0 | if (GlobalGenerator->IsFastbuild()) { |
3450 | | // Account for potential spaces in a shell-friendly way. |
3451 | 0 | cmSystemTools::ReplaceString(createOptionList, "<PCH_HEADER>", |
3452 | 0 | cmStrCat('"', pchHeader, '"')); |
3453 | 0 | cmSystemTools::ReplaceString(createOptionList, "<PCH_FILE>", |
3454 | 0 | cmStrCat('"', pchFile, '"')); |
3455 | 0 | } else { |
3456 | 0 | cmSystemTools::ReplaceString(createOptionList, "<PCH_HEADER>", |
3457 | 0 | pchHeader); |
3458 | 0 | cmSystemTools::ReplaceString(createOptionList, "<PCH_FILE>", pchFile); |
3459 | 0 | } |
3460 | 0 | } |
3461 | 0 | return inserted.first->second; |
3462 | 0 | } |
3463 | | |
3464 | | std::string cmGeneratorTarget::GetPchUseCompileOptions( |
3465 | | std::string const& config, std::string const& language, |
3466 | | std::string const& arch) |
3467 | 0 | { |
3468 | 0 | auto const inserted = this->PchUseCompileOptions.insert( |
3469 | 0 | std::make_pair(language + config + arch, "")); |
3470 | 0 | if (inserted.second) { |
3471 | 0 | std::string& useOptionList = inserted.first->second; |
3472 | |
|
3473 | 0 | if (this->GetPropertyAsBool("PCH_WARN_INVALID")) { |
3474 | 0 | useOptionList = this->Makefile->GetSafeDefinition( |
3475 | 0 | cmStrCat("CMAKE_", language, "_COMPILE_OPTIONS_INVALID_PCH")); |
3476 | 0 | } |
3477 | |
|
3478 | 0 | std::string const useOptVar = |
3479 | 0 | cmStrCat(language, "_COMPILE_OPTIONS_USE_PCH"); |
3480 | |
|
3481 | 0 | std::string const& useOptionListProperty = |
3482 | 0 | this->GetSafeProperty(useOptVar); |
3483 | |
|
3484 | 0 | useOptionList = cmStrCat( |
3485 | 0 | useOptionList, ';', |
3486 | 0 | useOptionListProperty.empty() |
3487 | 0 | ? this->Makefile->GetSafeDefinition(cmStrCat("CMAKE_", useOptVar)) |
3488 | 0 | : useOptionListProperty); |
3489 | |
|
3490 | 0 | std::string const pchHeader = this->GetPchHeader(config, language, arch); |
3491 | 0 | std::string const pchFile = this->GetPchFile(config, language, arch); |
3492 | |
|
3493 | 0 | if (GlobalGenerator->IsFastbuild()) { |
3494 | | // Account for potential spaces in a shell-friendly way. |
3495 | 0 | cmSystemTools::ReplaceString(useOptionList, "<PCH_HEADER>", |
3496 | 0 | cmStrCat('"', pchHeader, '"')); |
3497 | 0 | cmSystemTools::ReplaceString(useOptionList, "<PCH_FILE>", |
3498 | 0 | cmStrCat('"', pchFile, '"')); |
3499 | 0 | } else { |
3500 | 0 | cmSystemTools::ReplaceString(useOptionList, "<PCH_HEADER>", pchHeader); |
3501 | 0 | cmSystemTools::ReplaceString(useOptionList, "<PCH_FILE>", pchFile); |
3502 | 0 | } |
3503 | 0 | } |
3504 | 0 | return inserted.first->second; |
3505 | 0 | } |
3506 | | |
3507 | | void cmGeneratorTarget::AddSourceFileToUnityBatch( |
3508 | | std::string const& sourceFilename) |
3509 | 0 | { |
3510 | 0 | this->UnityBatchedSourceFiles.insert(sourceFilename); |
3511 | 0 | } |
3512 | | |
3513 | | bool cmGeneratorTarget::IsSourceFilePartOfUnityBatch( |
3514 | | std::string const& sourceFilename) const |
3515 | 0 | { |
3516 | 0 | if (!this->GetPropertyAsBool("UNITY_BUILD")) { |
3517 | 0 | return false; |
3518 | 0 | } |
3519 | | |
3520 | 0 | return this->UnityBatchedSourceFiles.find(sourceFilename) != |
3521 | 0 | this->UnityBatchedSourceFiles.end(); |
3522 | 0 | } |
3523 | | |
3524 | | void cmGeneratorTarget::ComputeTargetManifest(std::string const& config) const |
3525 | 0 | { |
3526 | 0 | if (this->IsImported()) { |
3527 | 0 | return; |
3528 | 0 | } |
3529 | 0 | cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator(); |
3530 | | |
3531 | | // Get the names. |
3532 | 0 | cmGeneratorTarget::Names targetNames; |
3533 | 0 | if (this->GetType() == cmStateEnums::EXECUTABLE) { |
3534 | 0 | targetNames = this->GetExecutableNames(config); |
3535 | 0 | } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY || |
3536 | 0 | this->GetType() == cmStateEnums::SHARED_LIBRARY || |
3537 | 0 | this->GetType() == cmStateEnums::MODULE_LIBRARY) { |
3538 | 0 | targetNames = this->GetLibraryNames(config); |
3539 | 0 | } else { |
3540 | 0 | return; |
3541 | 0 | } |
3542 | | |
3543 | | // Get the directory. |
3544 | 0 | std::string dir = |
3545 | 0 | this->GetDirectory(config, cmStateEnums::RuntimeBinaryArtifact); |
3546 | | |
3547 | | // Add each name. |
3548 | 0 | std::string f; |
3549 | 0 | if (!targetNames.Output.empty()) { |
3550 | 0 | f = cmStrCat(dir, '/', targetNames.Output); |
3551 | 0 | gg->AddToManifest(f); |
3552 | 0 | } |
3553 | 0 | if (!targetNames.SharedObject.empty()) { |
3554 | 0 | f = cmStrCat(dir, '/', targetNames.SharedObject); |
3555 | 0 | gg->AddToManifest(f); |
3556 | 0 | } |
3557 | 0 | if (!targetNames.Real.empty()) { |
3558 | 0 | f = cmStrCat(dir, '/', targetNames.Real); |
3559 | 0 | gg->AddToManifest(f); |
3560 | 0 | } |
3561 | 0 | if (!targetNames.PDB.empty()) { |
3562 | 0 | f = cmStrCat(dir, '/', targetNames.PDB); |
3563 | 0 | gg->AddToManifest(f); |
3564 | 0 | } |
3565 | |
|
3566 | 0 | dir = this->GetDirectory(config, cmStateEnums::ImportLibraryArtifact); |
3567 | 0 | if (!targetNames.ImportOutput.empty()) { |
3568 | 0 | f = cmStrCat(dir, '/', targetNames.ImportOutput); |
3569 | 0 | gg->AddToManifest(f); |
3570 | 0 | } |
3571 | 0 | if (!targetNames.ImportLibrary.empty()) { |
3572 | 0 | f = cmStrCat(dir, '/', targetNames.ImportLibrary); |
3573 | 0 | gg->AddToManifest(f); |
3574 | 0 | } |
3575 | 0 | if (!targetNames.ImportReal.empty()) { |
3576 | 0 | f = cmStrCat(dir, '/', targetNames.ImportReal); |
3577 | 0 | gg->AddToManifest(f); |
3578 | 0 | } |
3579 | 0 | } |
3580 | | |
3581 | | cm::optional<cmStandardLevel> cmGeneratorTarget::GetExplicitStandardLevel( |
3582 | | std::string const& lang, std::string const& config) const |
3583 | 0 | { |
3584 | 0 | cm::optional<cmStandardLevel> level; |
3585 | 0 | std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang); |
3586 | 0 | auto i = this->ExplicitStandardLevel.find(key); |
3587 | 0 | if (i != this->ExplicitStandardLevel.end()) { |
3588 | 0 | level = i->second; |
3589 | 0 | } |
3590 | 0 | return level; |
3591 | 0 | } |
3592 | | |
3593 | | void cmGeneratorTarget::UpdateExplicitStandardLevel(std::string const& lang, |
3594 | | std::string const& config, |
3595 | | cmStandardLevel level) |
3596 | 0 | { |
3597 | 0 | auto e = this->ExplicitStandardLevel.emplace( |
3598 | 0 | cmStrCat(cmSystemTools::UpperCase(config), '-', lang), level); |
3599 | 0 | if (!e.second && e.first->second < level) { |
3600 | 0 | e.first->second = level; |
3601 | 0 | } |
3602 | 0 | } |
3603 | | |
3604 | | bool cmGeneratorTarget::ComputeCompileFeatures(std::string const& config) |
3605 | 0 | { |
3606 | 0 | cmStandardLevelResolver standardResolver(this->Makefile); |
3607 | |
|
3608 | 0 | for (std::string const& lang : |
3609 | 0 | this->Makefile->GetState()->GetEnabledLanguages()) { |
3610 | 0 | if (cmValue languageStd = this->GetLanguageStandard(lang, config)) { |
3611 | 0 | if (cm::optional<cmStandardLevel> langLevel = |
3612 | 0 | standardResolver.LanguageStandardLevel(lang, *languageStd)) { |
3613 | 0 | this->UpdateExplicitStandardLevel(lang, config, *langLevel); |
3614 | 0 | } |
3615 | 0 | } |
3616 | 0 | } |
3617 | | |
3618 | | // Compute the language standard based on the compile features. |
3619 | 0 | std::vector<BT<std::string>> features = this->GetCompileFeatures(config); |
3620 | 0 | for (BT<std::string> const& f : features) { |
3621 | 0 | std::string lang; |
3622 | 0 | if (!standardResolver.CompileFeatureKnown(this->Target->GetName(), f.Value, |
3623 | 0 | lang, nullptr)) { |
3624 | 0 | return false; |
3625 | 0 | } |
3626 | | |
3627 | 0 | std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang); |
3628 | 0 | cmValue currentLanguageStandard = this->GetLanguageStandard(lang, config); |
3629 | |
|
3630 | 0 | cm::optional<cmStandardLevel> featureLevel; |
3631 | 0 | std::string newRequiredStandard; |
3632 | 0 | if (!standardResolver.GetNewRequiredStandard( |
3633 | 0 | this->Target->GetName(), f.Value, currentLanguageStandard, |
3634 | 0 | featureLevel, newRequiredStandard)) { |
3635 | 0 | return false; |
3636 | 0 | } |
3637 | | |
3638 | 0 | if (featureLevel) { |
3639 | 0 | this->UpdateExplicitStandardLevel(lang, config, *featureLevel); |
3640 | 0 | } |
3641 | |
|
3642 | 0 | if (!newRequiredStandard.empty()) { |
3643 | 0 | BTs<std::string>& languageStandardProperty = |
3644 | 0 | this->LanguageStandardMap[key]; |
3645 | 0 | if (languageStandardProperty.Value != newRequiredStandard) { |
3646 | 0 | languageStandardProperty.Value = newRequiredStandard; |
3647 | 0 | languageStandardProperty.Backtraces.clear(); |
3648 | 0 | } |
3649 | 0 | languageStandardProperty.Backtraces.emplace_back(f.Backtrace); |
3650 | 0 | } |
3651 | 0 | } |
3652 | | |
3653 | 0 | return true; |
3654 | 0 | } |
3655 | | |
3656 | | bool cmGeneratorTarget::ComputeCompileFeatures( |
3657 | | std::string const& config, std::set<LanguagePair> const& languagePairs) |
3658 | 0 | { |
3659 | 0 | for (auto const& language : languagePairs) { |
3660 | 0 | BTs<std::string> const* generatorTargetLanguageStandard = |
3661 | 0 | this->GetLanguageStandardProperty(language.first, config); |
3662 | 0 | if (!generatorTargetLanguageStandard) { |
3663 | | // If the standard isn't explicitly set we copy it over from the |
3664 | | // specified paired language. |
3665 | 0 | std::string key = |
3666 | 0 | cmStrCat(cmSystemTools::UpperCase(config), '-', language.first); |
3667 | 0 | BTs<std::string> const* standardToCopy = |
3668 | 0 | this->GetLanguageStandardProperty(language.second, config); |
3669 | 0 | if (standardToCopy) { |
3670 | 0 | this->LanguageStandardMap[key] = *standardToCopy; |
3671 | 0 | generatorTargetLanguageStandard = &this->LanguageStandardMap[key]; |
3672 | 0 | } else { |
3673 | 0 | cmValue defaultStandard = this->Makefile->GetDefinition( |
3674 | 0 | cmStrCat("CMAKE_", language.second, "_STANDARD_DEFAULT")); |
3675 | 0 | if (defaultStandard) { |
3676 | 0 | this->LanguageStandardMap[key] = BTs<std::string>(*defaultStandard); |
3677 | 0 | generatorTargetLanguageStandard = &this->LanguageStandardMap[key]; |
3678 | 0 | } |
3679 | 0 | } |
3680 | | |
3681 | | // Custom updates for the CUDA standard. |
3682 | 0 | if (generatorTargetLanguageStandard && (language.first == "CUDA")) { |
3683 | 0 | if (generatorTargetLanguageStandard->Value == "98") { |
3684 | 0 | this->LanguageStandardMap[key].Value = "03"; |
3685 | 0 | } |
3686 | 0 | } |
3687 | 0 | } |
3688 | 0 | } |
3689 | |
|
3690 | 0 | return true; |
3691 | 0 | } |
3692 | | |
3693 | | std::string cmGeneratorTarget::GetImportedLibName( |
3694 | | std::string const& config) const |
3695 | 0 | { |
3696 | 0 | if (cmGeneratorTarget::ImportInfo const* info = |
3697 | 0 | this->GetImportInfo(config)) { |
3698 | 0 | return info->LibName; |
3699 | 0 | } |
3700 | 0 | return std::string(); |
3701 | 0 | } |
3702 | | |
3703 | | std::string cmGeneratorTarget::GetFullPath(std::string const& config, |
3704 | | cmStateEnums::ArtifactType artifact, |
3705 | | bool realname) const |
3706 | 0 | { |
3707 | 0 | if (this->IsImported()) { |
3708 | 0 | return this->Target->ImportedGetFullPath(config, artifact); |
3709 | 0 | } |
3710 | 0 | return this->NormalGetFullPath(config, artifact, realname); |
3711 | 0 | } |
3712 | | |
3713 | | std::string cmGeneratorTarget::NormalGetFullPath( |
3714 | | std::string const& config, cmStateEnums::ArtifactType artifact, |
3715 | | bool realname) const |
3716 | 0 | { |
3717 | 0 | std::string fpath = cmStrCat(this->GetDirectory(config, artifact), '/'); |
3718 | 0 | if (this->IsAppBundleOnApple()) { |
3719 | 0 | fpath = |
3720 | 0 | cmStrCat(this->BuildBundleDirectory(fpath, config, FullLevel), '/'); |
3721 | 0 | } |
3722 | | |
3723 | | // Add the full name of the target. |
3724 | 0 | switch (artifact) { |
3725 | 0 | case cmStateEnums::RuntimeBinaryArtifact: |
3726 | 0 | if (realname) { |
3727 | 0 | fpath += this->NormalGetRealName(config); |
3728 | 0 | } else { |
3729 | 0 | fpath += |
3730 | 0 | this->GetFullName(config, cmStateEnums::RuntimeBinaryArtifact); |
3731 | 0 | } |
3732 | 0 | break; |
3733 | 0 | case cmStateEnums::ImportLibraryArtifact: |
3734 | 0 | if (realname) { |
3735 | 0 | fpath += |
3736 | 0 | this->NormalGetRealName(config, cmStateEnums::ImportLibraryArtifact); |
3737 | 0 | } else { |
3738 | 0 | fpath += |
3739 | 0 | this->GetFullName(config, cmStateEnums::ImportLibraryArtifact); |
3740 | 0 | } |
3741 | 0 | break; |
3742 | 0 | } |
3743 | 0 | return fpath; |
3744 | 0 | } |
3745 | | |
3746 | | std::string cmGeneratorTarget::NormalGetRealName( |
3747 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
3748 | 0 | { |
3749 | | // This should not be called for imported targets. |
3750 | | // TODO: Split cmTarget into a class hierarchy to get compile-time |
3751 | | // enforcement of the limited imported target API. |
3752 | 0 | if (this->IsImported()) { |
3753 | 0 | std::string msg = cmStrCat("NormalGetRealName called on imported target: ", |
3754 | 0 | this->GetName()); |
3755 | 0 | this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg); |
3756 | 0 | } |
3757 | |
|
3758 | 0 | Names names = this->GetType() == cmStateEnums::EXECUTABLE |
3759 | 0 | ? this->GetExecutableNames(config) |
3760 | 0 | : this->GetLibraryNames(config); |
3761 | | |
3762 | | // Compute the real name that will be built. |
3763 | 0 | return artifact == cmStateEnums::RuntimeBinaryArtifact ? names.Real |
3764 | 0 | : names.ImportReal; |
3765 | 0 | } |
3766 | | |
3767 | | cmGeneratorTarget::Names cmGeneratorTarget::GetLibraryNames( |
3768 | | std::string const& config) const |
3769 | 0 | { |
3770 | 0 | cmGeneratorTarget::Names targetNames; |
3771 | | |
3772 | | // This should not be called for imported targets. |
3773 | | // TODO: Split cmTarget into a class hierarchy to get compile-time |
3774 | | // enforcement of the limited imported target API. |
3775 | 0 | if (this->IsImported()) { |
3776 | 0 | std::string msg = |
3777 | 0 | cmStrCat("GetLibraryNames called on imported target: ", this->GetName()); |
3778 | 0 | this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg); |
3779 | 0 | } |
3780 | | |
3781 | | // Check for library version properties. |
3782 | 0 | cmValue version = this->GetProperty("VERSION"); |
3783 | 0 | cmValue soversion = this->GetProperty("SOVERSION"); |
3784 | 0 | if (!this->HasSOName(config) || |
3785 | 0 | this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") || |
3786 | 0 | this->IsFrameworkOnApple()) { |
3787 | | // Versioning is supported only for shared libraries and modules, |
3788 | | // and then only when the platform supports an soname flag. |
3789 | 0 | version = nullptr; |
3790 | 0 | soversion = nullptr; |
3791 | 0 | } |
3792 | 0 | if (version && !soversion) { |
3793 | | // The soversion must be set if the library version is set. Use |
3794 | | // the library version as the soversion. |
3795 | 0 | soversion = version; |
3796 | 0 | } |
3797 | 0 | if (!version && soversion) { |
3798 | | // Use the soversion as the library version. |
3799 | 0 | version = soversion; |
3800 | 0 | } |
3801 | | |
3802 | | // Get the components of the library name. |
3803 | 0 | NameComponents const& components = this->GetFullNameInternalComponents( |
3804 | 0 | config, cmStateEnums::RuntimeBinaryArtifact); |
3805 | | |
3806 | | // The library name. |
3807 | 0 | targetNames.Base = components.base; |
3808 | 0 | targetNames.Output = |
3809 | 0 | cmStrCat(components.prefix, targetNames.Base, components.suffix); |
3810 | |
|
3811 | 0 | if (this->IsFrameworkOnApple()) { |
3812 | 0 | targetNames.Real = components.prefix; |
3813 | 0 | if (!this->Makefile->PlatformIsAppleEmbedded()) { |
3814 | 0 | targetNames.Real += |
3815 | 0 | cmStrCat("Versions/", this->GetFrameworkVersion(), '/'); |
3816 | 0 | } |
3817 | 0 | targetNames.Real += cmStrCat(targetNames.Base, components.suffix); |
3818 | 0 | targetNames.SharedObject = targetNames.Real; |
3819 | 0 | } else if (this->IsArchivedAIXSharedLibrary()) { |
3820 | 0 | targetNames.SharedObject = |
3821 | 0 | cmStrCat(components.prefix, targetNames.Base, ".so"); |
3822 | 0 | if (soversion) { |
3823 | 0 | targetNames.SharedObject += "."; |
3824 | 0 | targetNames.SharedObject += *soversion; |
3825 | 0 | } |
3826 | 0 | targetNames.Real = targetNames.Output; |
3827 | 0 | } else { |
3828 | | // The library's soname. |
3829 | 0 | targetNames.SharedObject = this->ComputeVersionedName( |
3830 | 0 | components.prefix, targetNames.Base, components.suffix, |
3831 | 0 | targetNames.Output, soversion); |
3832 | | |
3833 | | // The library's real name on disk. |
3834 | 0 | targetNames.Real = this->ComputeVersionedName( |
3835 | 0 | components.prefix, targetNames.Base, components.suffix, |
3836 | 0 | targetNames.Output, version); |
3837 | 0 | } |
3838 | | |
3839 | | // The import library names. |
3840 | 0 | if (this->GetType() == cmStateEnums::SHARED_LIBRARY || |
3841 | 0 | this->GetType() == cmStateEnums::MODULE_LIBRARY) { |
3842 | 0 | NameComponents const& importComponents = |
3843 | 0 | this->GetFullNameInternalComponents(config, |
3844 | 0 | cmStateEnums::ImportLibraryArtifact); |
3845 | 0 | targetNames.ImportOutput = cmStrCat( |
3846 | 0 | importComponents.prefix, importComponents.base, importComponents.suffix); |
3847 | |
|
3848 | 0 | if (this->IsFrameworkOnApple() && this->IsSharedLibraryWithExports()) { |
3849 | 0 | targetNames.ImportReal = components.prefix; |
3850 | 0 | if (!this->Makefile->PlatformIsAppleEmbedded()) { |
3851 | 0 | targetNames.ImportReal += |
3852 | 0 | cmStrCat("Versions/", this->GetFrameworkVersion(), '/'); |
3853 | 0 | } |
3854 | 0 | targetNames.ImportReal += |
3855 | 0 | cmStrCat(importComponents.base, importComponents.suffix); |
3856 | 0 | targetNames.ImportLibrary = targetNames.ImportOutput; |
3857 | 0 | } else { |
3858 | | // The import library's soname. |
3859 | 0 | targetNames.ImportLibrary = this->ComputeVersionedName( |
3860 | 0 | importComponents.prefix, importComponents.base, |
3861 | 0 | importComponents.suffix, targetNames.ImportOutput, soversion); |
3862 | | |
3863 | | // The import library's real name on disk. |
3864 | 0 | targetNames.ImportReal = this->ComputeVersionedName( |
3865 | 0 | importComponents.prefix, importComponents.base, |
3866 | 0 | importComponents.suffix, targetNames.ImportOutput, version); |
3867 | 0 | } |
3868 | 0 | } |
3869 | | |
3870 | | // The program database file name. |
3871 | 0 | targetNames.PDB = this->GetPDBName(config); |
3872 | |
|
3873 | 0 | return targetNames; |
3874 | 0 | } |
3875 | | |
3876 | | cmGeneratorTarget::Names cmGeneratorTarget::GetExecutableNames( |
3877 | | std::string const& config) const |
3878 | 0 | { |
3879 | 0 | cmGeneratorTarget::Names targetNames; |
3880 | | |
3881 | | // This should not be called for imported targets. |
3882 | | // TODO: Split cmTarget into a class hierarchy to get compile-time |
3883 | | // enforcement of the limited imported target API. |
3884 | 0 | if (this->IsImported()) { |
3885 | 0 | std::string msg = cmStrCat( |
3886 | 0 | "GetExecutableNames called on imported target: ", this->GetName()); |
3887 | 0 | this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg); |
3888 | 0 | } |
3889 | | |
3890 | | // This versioning is supported only for executables and then only |
3891 | | // when the platform supports symbolic links. |
3892 | | #if defined(_WIN32) && !defined(__CYGWIN__) |
3893 | | cmValue version; |
3894 | | #else |
3895 | | // Check for executable version properties. |
3896 | 0 | cmValue version = this->GetProperty("VERSION"); |
3897 | 0 | if (this->GetType() != cmStateEnums::EXECUTABLE || |
3898 | 0 | this->Makefile->IsOn("XCODE")) { |
3899 | 0 | version = nullptr; |
3900 | 0 | } |
3901 | 0 | #endif |
3902 | | |
3903 | | // Get the components of the executable name. |
3904 | 0 | NameComponents const& components = this->GetFullNameInternalComponents( |
3905 | 0 | config, cmStateEnums::RuntimeBinaryArtifact); |
3906 | | |
3907 | | // The executable name. |
3908 | 0 | targetNames.Base = components.base; |
3909 | |
|
3910 | 0 | if (this->IsArchivedAIXSharedLibrary()) { |
3911 | 0 | targetNames.Output = components.prefix + targetNames.Base; |
3912 | 0 | } else { |
3913 | 0 | targetNames.Output = |
3914 | 0 | components.prefix + targetNames.Base + components.suffix; |
3915 | 0 | } |
3916 | | |
3917 | | // The executable's real name on disk. |
3918 | | #if defined(__CYGWIN__) |
3919 | | targetNames.Real = components.prefix + targetNames.Base; |
3920 | | #else |
3921 | 0 | targetNames.Real = targetNames.Output; |
3922 | 0 | #endif |
3923 | 0 | if (version) { |
3924 | 0 | targetNames.Real += "-"; |
3925 | 0 | targetNames.Real += *version; |
3926 | 0 | } |
3927 | | #if defined(__CYGWIN__) |
3928 | | targetNames.Real += components.suffix; |
3929 | | #endif |
3930 | | |
3931 | | // The import library name. |
3932 | 0 | targetNames.ImportLibrary = |
3933 | 0 | this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact); |
3934 | 0 | targetNames.ImportReal = targetNames.ImportLibrary; |
3935 | 0 | targetNames.ImportOutput = targetNames.ImportLibrary; |
3936 | | |
3937 | | // The program database file name. |
3938 | 0 | targetNames.PDB = this->GetPDBName(config); |
3939 | |
|
3940 | 0 | return targetNames; |
3941 | 0 | } |
3942 | | |
3943 | | std::string cmGeneratorTarget::GetFullNameInternal( |
3944 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
3945 | 0 | { |
3946 | 0 | NameComponents const& components = |
3947 | 0 | this->GetFullNameInternalComponents(config, artifact); |
3948 | 0 | return components.prefix + components.base + components.suffix; |
3949 | 0 | } |
3950 | | |
3951 | | std::string cmGeneratorTarget::ImportedGetLocation( |
3952 | | std::string const& config) const |
3953 | 0 | { |
3954 | 0 | assert(this->IsImported()); |
3955 | 0 | return this->Target->ImportedGetFullPath( |
3956 | 0 | config, cmStateEnums::RuntimeBinaryArtifact); |
3957 | 0 | } |
3958 | | |
3959 | | std::string cmGeneratorTarget::GetFullNameImported( |
3960 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
3961 | 0 | { |
3962 | 0 | return cmSystemTools::GetFilenameName( |
3963 | 0 | this->Target->ImportedGetFullPath(config, artifact)); |
3964 | 0 | } |
3965 | | |
3966 | | cmGeneratorTarget::NameComponents const& |
3967 | | cmGeneratorTarget::GetFullNameInternalComponents( |
3968 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
3969 | 0 | { |
3970 | 0 | assert(artifact == cmStateEnums::RuntimeBinaryArtifact || |
3971 | 0 | artifact == cmStateEnums::ImportLibraryArtifact); |
3972 | 0 | FullNameCache& cache = artifact == cmStateEnums::RuntimeBinaryArtifact |
3973 | 0 | ? RuntimeBinaryFullNameCache |
3974 | 0 | : ImportLibraryFullNameCache; |
3975 | 0 | auto search = cache.find(config); |
3976 | 0 | if (search != cache.end()) { |
3977 | 0 | return search->second; |
3978 | 0 | } |
3979 | | // Use just the target name for non-main target types. |
3980 | 0 | if (this->GetType() != cmStateEnums::STATIC_LIBRARY && |
3981 | 0 | this->GetType() != cmStateEnums::SHARED_LIBRARY && |
3982 | 0 | this->GetType() != cmStateEnums::MODULE_LIBRARY && |
3983 | 0 | this->GetType() != cmStateEnums::EXECUTABLE) { |
3984 | 0 | NameComponents components; |
3985 | 0 | components.base = this->GetName(); |
3986 | 0 | return cache.emplace(config, std::move(components)).first->second; |
3987 | 0 | } |
3988 | | |
3989 | 0 | bool const isImportedLibraryArtifact = |
3990 | 0 | (artifact == cmStateEnums::ImportLibraryArtifact); |
3991 | | |
3992 | | // Return an empty name for the import library if this platform |
3993 | | // does not support import libraries. |
3994 | 0 | if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) { |
3995 | 0 | return cache.emplace(config, NameComponents()).first->second; |
3996 | 0 | } |
3997 | | |
3998 | 0 | NameComponents parts; |
3999 | 0 | std::string& outPrefix = parts.prefix; |
4000 | 0 | std::string& outBase = parts.base; |
4001 | 0 | std::string& outSuffix = parts.suffix; |
4002 | | |
4003 | | // retrieve prefix and suffix |
4004 | 0 | std::string ll = this->GetLinkerLanguage(config); |
4005 | 0 | cmValue targetPrefix = this->GetFilePrefixInternal(config, artifact, ll); |
4006 | 0 | cmValue targetSuffix = this->GetFileSuffixInternal(config, artifact, ll); |
4007 | | |
4008 | | // The implib option is only allowed for shared libraries, module |
4009 | | // libraries, and executables. |
4010 | 0 | if (this->GetType() != cmStateEnums::SHARED_LIBRARY && |
4011 | 0 | this->GetType() != cmStateEnums::MODULE_LIBRARY && |
4012 | 0 | this->GetType() != cmStateEnums::EXECUTABLE) { |
4013 | 0 | artifact = cmStateEnums::RuntimeBinaryArtifact; |
4014 | 0 | } |
4015 | | |
4016 | | // Compute the full name for main target types. |
4017 | 0 | std::string configPostfix = this->GetFilePostfix(config); |
4018 | | |
4019 | | // frameworks have directory prefix |
4020 | 0 | std::string fw_prefix; |
4021 | 0 | if (this->IsFrameworkOnApple()) { |
4022 | 0 | fw_prefix = |
4023 | 0 | cmStrCat(this->GetFrameworkDirectory(config, ContentLevel), '/'); |
4024 | 0 | targetPrefix = cmValue(fw_prefix); |
4025 | 0 | if (!isImportedLibraryArtifact) { |
4026 | | // no suffix |
4027 | 0 | targetSuffix = nullptr; |
4028 | 0 | } |
4029 | 0 | } |
4030 | |
|
4031 | 0 | if (this->IsCFBundleOnApple()) { |
4032 | 0 | fw_prefix = cmStrCat(this->GetCFBundleDirectory(config, FullLevel), '/'); |
4033 | 0 | targetPrefix = cmValue(fw_prefix); |
4034 | 0 | targetSuffix = nullptr; |
4035 | 0 | } |
4036 | | |
4037 | | // Begin the final name with the prefix. |
4038 | 0 | outPrefix = targetPrefix ? *targetPrefix : ""; |
4039 | | |
4040 | | // Append the target name or property-specified name. |
4041 | 0 | outBase += this->GetOutputName(config, artifact); |
4042 | | |
4043 | | // Append the per-configuration postfix. |
4044 | | // When using Xcode, the postfix should be part of the suffix rather than |
4045 | | // the base, because the suffix ends up being used in Xcode's |
4046 | | // EXECUTABLE_SUFFIX attribute. |
4047 | 0 | if (this->IsFrameworkOnApple() && this->GetGlobalGenerator()->IsXcode()) { |
4048 | 0 | configPostfix += *targetSuffix; |
4049 | 0 | targetSuffix = cmValue(configPostfix); |
4050 | 0 | } else { |
4051 | 0 | outBase += configPostfix; |
4052 | 0 | } |
4053 | | |
4054 | | // Name shared libraries with their version number on some platforms. |
4055 | 0 | if (cmValue soversion = this->GetProperty("SOVERSION")) { |
4056 | 0 | cmValue dllProp; |
4057 | 0 | if (this->IsDLLPlatform()) { |
4058 | 0 | dllProp = this->GetProperty("DLL_NAME_WITH_SOVERSION"); |
4059 | 0 | } |
4060 | 0 | if (this->GetType() == cmStateEnums::SHARED_LIBRARY && |
4061 | 0 | !isImportedLibraryArtifact && |
4062 | 0 | (dllProp.IsOn() || |
4063 | 0 | (!dllProp.IsSet() && |
4064 | 0 | this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION")))) { |
4065 | 0 | outBase += "-"; |
4066 | 0 | outBase += *soversion; |
4067 | 0 | } |
4068 | 0 | } |
4069 | | |
4070 | | // Append the suffix. |
4071 | 0 | outSuffix = targetSuffix ? *targetSuffix : ""; |
4072 | |
|
4073 | 0 | return cache.emplace(config, std::move(parts)).first->second; |
4074 | 0 | } |
4075 | | |
4076 | | std::string cmGeneratorTarget::GetLinkerLanguage( |
4077 | | std::string const& config) const |
4078 | 0 | { |
4079 | 0 | return this->GetLinkClosure(config)->LinkerLanguage; |
4080 | 0 | } |
4081 | | |
4082 | | std::string cmGeneratorTarget::GetLinkerTool(std::string const& config) const |
4083 | 0 | { |
4084 | 0 | return this->GetLinkerTool(this->GetLinkerLanguage(config), config); |
4085 | 0 | } |
4086 | | |
4087 | | std::string cmGeneratorTarget::GetLinkerTool(std::string const& lang, |
4088 | | std::string const& config) const |
4089 | 0 | { |
4090 | 0 | auto linkMode = cmStrCat( |
4091 | 0 | "CMAKE_", lang, this->IsDeviceLink() ? "_DEVICE_" : "_", "LINK_MODE"); |
4092 | 0 | auto mode = this->Makefile->GetDefinition(linkMode); |
4093 | 0 | if (!mode || mode != "LINKER"_s) { |
4094 | 0 | return this->Makefile->GetDefinition("CMAKE_LINKER"); |
4095 | 0 | } |
4096 | | |
4097 | 0 | auto linkerType = this->GetLinkerTypeProperty(lang, config); |
4098 | 0 | if (linkerType.empty()) { |
4099 | 0 | linkerType = "DEFAULT"; |
4100 | 0 | } |
4101 | 0 | auto usingLinker = |
4102 | 0 | cmStrCat("CMAKE_", lang, "_USING_", this->IsDeviceLink() ? "DEVICE_" : "", |
4103 | 0 | "LINKER_", linkerType); |
4104 | 0 | auto linkerTool = this->Makefile->GetDefinition(usingLinker); |
4105 | |
|
4106 | 0 | if (!linkerTool) { |
4107 | 0 | if (this->GetGlobalGenerator()->IsVisualStudio() && |
4108 | 0 | linkerType == "DEFAULT"_s) { |
4109 | 0 | return std::string{}; |
4110 | 0 | } |
4111 | | |
4112 | | // fall-back to generic definition |
4113 | 0 | linkerTool = this->Makefile->GetDefinition("CMAKE_LINKER"); |
4114 | |
|
4115 | 0 | if (linkerType != "DEFAULT"_s) { |
4116 | 0 | auto isCMakeLinkerType = [](std::string const& type) -> bool { |
4117 | 0 | return std::all_of(type.cbegin(), type.cend(), cmsysString_isupper); |
4118 | 0 | }; |
4119 | 0 | if (isCMakeLinkerType(linkerType)) { |
4120 | 0 | this->LocalGenerator->IssueMessage( |
4121 | 0 | MessageType::FATAL_ERROR, |
4122 | 0 | cmStrCat("LINKER_TYPE '", linkerType, |
4123 | 0 | "' is unknown or not supported by this toolchain.")); |
4124 | 0 | } else { |
4125 | 0 | this->LocalGenerator->IssueMessage( |
4126 | 0 | MessageType::FATAL_ERROR, |
4127 | 0 | cmStrCat("LINKER_TYPE '", linkerType, |
4128 | 0 | "' is unknown. Did you forget to define the '", usingLinker, |
4129 | 0 | "' variable?")); |
4130 | 0 | } |
4131 | 0 | } |
4132 | 0 | } |
4133 | | |
4134 | 0 | return linkerTool; |
4135 | 0 | } |
4136 | | |
4137 | | bool cmGeneratorTarget::LinkerEnforcesNoAllowShLibUndefined( |
4138 | | std::string const& config) const |
4139 | 0 | { |
4140 | | // FIXME(#25486): Account for the LINKER_TYPE target property. |
4141 | | // Also factor out the hard-coded list below into a platform |
4142 | | // information table based on the linker id. |
4143 | 0 | std::string ll = this->GetLinkerLanguage(config); |
4144 | 0 | std::string linkerIdVar = cmStrCat("CMAKE_", ll, "_COMPILER_LINKER_ID"); |
4145 | 0 | cmValue linkerId = this->Makefile->GetDefinition(linkerIdVar); |
4146 | | // The GNU bfd-based linker may enforce '--no-allow-shlib-undefined' |
4147 | | // recursively by default. The Solaris linker has similar behavior. |
4148 | 0 | return linkerId && (*linkerId == "GNU" || *linkerId == "Solaris"); |
4149 | 0 | } |
4150 | | |
4151 | | std::string cmGeneratorTarget::GetPDBOutputName( |
4152 | | std::string const& config) const |
4153 | 0 | { |
4154 | | // Lookup/compute/cache the pdb output name for this configuration. |
4155 | 0 | auto i = this->PdbOutputNameMap.find(config); |
4156 | 0 | if (i == this->PdbOutputNameMap.end()) { |
4157 | | // Add empty name in map to detect potential recursion. |
4158 | 0 | PdbOutputNameMapType::value_type entry(config, ""); |
4159 | 0 | i = this->PdbOutputNameMap.insert(entry).first; |
4160 | | |
4161 | | // Compute output name. |
4162 | 0 | std::vector<std::string> props; |
4163 | 0 | std::string configUpper = cmSystemTools::UpperCase(config); |
4164 | 0 | if (!configUpper.empty()) { |
4165 | | // PDB_NAME_<CONFIG> |
4166 | 0 | props.push_back("PDB_NAME_" + configUpper); |
4167 | 0 | } |
4168 | | |
4169 | | // PDB_NAME |
4170 | 0 | props.emplace_back("PDB_NAME"); |
4171 | |
|
4172 | 0 | std::string outName; |
4173 | 0 | for (std::string const& p : props) { |
4174 | 0 | if (cmValue outNameProp = this->GetProperty(p)) { |
4175 | 0 | outName = *outNameProp; |
4176 | 0 | break; |
4177 | 0 | } |
4178 | 0 | } |
4179 | | |
4180 | | // Now evaluate genex and update the previously-prepared map entry. |
4181 | 0 | if (outName.empty()) { |
4182 | 0 | i->second = cmStrCat( |
4183 | 0 | this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact), |
4184 | 0 | this->GetPolicyStatusCMP0202() != cmPolicies::NEW |
4185 | 0 | ? this->GetFilePostfix(config) |
4186 | 0 | : ""); |
4187 | 0 | } else { |
4188 | 0 | i->second = |
4189 | 0 | cmGeneratorExpression::Evaluate(outName, this->LocalGenerator, config); |
4190 | 0 | } |
4191 | 0 | } else if (i->second.empty()) { |
4192 | | // An empty map entry indicates we have been called recursively |
4193 | | // from the above block. |
4194 | 0 | this->LocalGenerator->GetCMakeInstance()->IssueMessage( |
4195 | 0 | MessageType::FATAL_ERROR, |
4196 | 0 | cmStrCat("Target '", this->GetName(), "' PDB_NAME depends on itself."), |
4197 | 0 | this->GetBacktrace()); |
4198 | 0 | } |
4199 | 0 | return i->second; |
4200 | 0 | } |
4201 | | |
4202 | | std::string cmGeneratorTarget::GetPDBName(std::string const& config) const |
4203 | 0 | { |
4204 | 0 | NameComponents const& parts = this->GetFullNameInternalComponents( |
4205 | 0 | config, cmStateEnums::RuntimeBinaryArtifact); |
4206 | |
|
4207 | 0 | std::string base = this->GetPDBOutputName(config); |
4208 | |
|
4209 | 0 | return cmStrCat(parts.prefix, base, |
4210 | 0 | this->GetPolicyStatusCMP0202() == cmPolicies::NEW |
4211 | 0 | ? this->GetFilePostfix(config) |
4212 | 0 | : "", |
4213 | 0 | ".pdb"); |
4214 | 0 | } |
4215 | | |
4216 | | std::string cmGeneratorTarget::GetObjectDirectory( |
4217 | | std::string const& config) const |
4218 | 0 | { |
4219 | 0 | std::string obj_dir = |
4220 | 0 | this->GlobalGenerator->ExpandCFGIntDir(this->ObjectDirectory, config); |
4221 | | #if defined(__APPLE__) |
4222 | | // Replace Xcode's placeholder for the object file directory since |
4223 | | // installation and export scripts need to know the real directory. |
4224 | | // Xcode has build-time settings (e.g. for sanitizers) that affect this, |
4225 | | // but we use the default here. Users that want to enable sanitizers |
4226 | | // will do so at the cost of object library installation and export. |
4227 | | cmSystemTools::ReplaceString(obj_dir, "$(OBJECT_FILE_DIR_normal:base)", |
4228 | | "Objects-normal"); |
4229 | | #endif |
4230 | 0 | return obj_dir; |
4231 | 0 | } |
4232 | | |
4233 | | void cmGeneratorTarget::GetTargetObjectNames( |
4234 | | std::string const& config, std::vector<std::string>& objects) const |
4235 | 0 | { |
4236 | 0 | this->GetTargetObjectNames( |
4237 | 0 | config, [](cmSourceFile const&) -> bool { return true; }, objects); |
4238 | 0 | } |
4239 | | |
4240 | | void cmGeneratorTarget::GetTargetObjectNames( |
4241 | | std::string const& config, std::function<bool(cmSourceFile const&)> filter, |
4242 | | std::vector<std::string>& objects) const |
4243 | 0 | { |
4244 | 0 | this->GetTargetObjectLocations( |
4245 | 0 | config, filter, |
4246 | 0 | [&objects](cmObjectLocation const& buildLoc, cmObjectLocation const&) { |
4247 | 0 | objects.push_back(buildLoc.GetPath()); |
4248 | 0 | }); |
4249 | 0 | } |
4250 | | |
4251 | | void cmGeneratorTarget::GetTargetObjectLocations( |
4252 | | std::string const& config, |
4253 | | std::function<void(cmObjectLocation const&, cmObjectLocation const&)> cb) |
4254 | | const |
4255 | 0 | { |
4256 | 0 | this->GetTargetObjectLocations( |
4257 | 0 | config, [](cmSourceFile const&) -> bool { return true; }, cb); |
4258 | 0 | } |
4259 | | |
4260 | | void cmGeneratorTarget::GetTargetObjectLocations( |
4261 | | std::string const& config, std::function<bool(cmSourceFile const&)> filter, |
4262 | | std::function<void(cmObjectLocation const&, cmObjectLocation const&)> cb) |
4263 | | const |
4264 | 0 | { |
4265 | 0 | std::vector<cmSourceFile const*> objectSources; |
4266 | 0 | this->GetObjectSources(objectSources, config); |
4267 | 0 | std::map<cmSourceFile const*, cmObjectLocations> mapping; |
4268 | |
|
4269 | 0 | for (cmSourceFile const* sf : objectSources) { |
4270 | 0 | mapping[sf]; |
4271 | 0 | } |
4272 | |
|
4273 | 0 | this->LocalGenerator->ComputeObjectFilenames(mapping, config, this); |
4274 | |
|
4275 | 0 | auto const buildUseShortPaths = this->GetUseShortObjectNames() |
4276 | 0 | ? cmObjectLocations::UseShortPath::Yes |
4277 | 0 | : cmObjectLocations::UseShortPath::No; |
4278 | 0 | auto const installUseShortPaths = this->GetUseShortObjectNamesForInstall(); |
4279 | |
|
4280 | 0 | for (cmSourceFile const* src : objectSources) { |
4281 | 0 | if (filter(*src)) { |
4282 | | // Find the object file name corresponding to this source file. |
4283 | 0 | auto map_it = mapping.find(src); |
4284 | 0 | auto const& buildLoc = map_it->second.GetLocation(buildUseShortPaths); |
4285 | 0 | auto const& installLoc = |
4286 | 0 | map_it->second.GetInstallLocation(installUseShortPaths, config); |
4287 | | // It must exist because we populated the mapping just above. |
4288 | 0 | assert(!buildLoc.GetPath().empty()); |
4289 | 0 | assert(!installLoc.GetPath().empty()); |
4290 | 0 | cb(buildLoc, installLoc); |
4291 | 0 | } |
4292 | 0 | } |
4293 | | |
4294 | | // We need to compute the relative path from the root of |
4295 | | // of the object directory to handle subdirectory paths |
4296 | 0 | std::string rootObjectDir = this->GetObjectDirectory(config); |
4297 | 0 | rootObjectDir = cmSystemTools::CollapseFullPath(rootObjectDir); |
4298 | 0 | auto ispcObjects = this->GetGeneratedISPCObjects(config); |
4299 | 0 | for (auto const& output : ispcObjects) { |
4300 | 0 | if (filter(*output.first)) { |
4301 | 0 | auto relativePathFromObjectDir = |
4302 | 0 | output.second.substr(rootObjectDir.size()); |
4303 | 0 | cmObjectLocation ispcLoc(relativePathFromObjectDir); |
4304 | | // FIXME: apply short path to this object if needed. |
4305 | 0 | cb(ispcLoc, ispcLoc); |
4306 | 0 | } |
4307 | 0 | } |
4308 | 0 | } |
4309 | | |
4310 | | bool cmGeneratorTarget::StrictTargetComparison::operator()( |
4311 | | cmGeneratorTarget const* t1, cmGeneratorTarget const* t2) const |
4312 | 0 | { |
4313 | 0 | int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str()); |
4314 | 0 | if (nameResult == 0) { |
4315 | 0 | return strcmp( |
4316 | 0 | t1->GetLocalGenerator()->GetCurrentBinaryDirectory().c_str(), |
4317 | 0 | t2->GetLocalGenerator()->GetCurrentBinaryDirectory().c_str()) < 0; |
4318 | 0 | } |
4319 | 0 | return nameResult < 0; |
4320 | 0 | } |
4321 | | |
4322 | | struct cmGeneratorTarget::SourceFileFlags |
4323 | | cmGeneratorTarget::GetTargetSourceFileFlags(cmSourceFile const* sf) const |
4324 | 0 | { |
4325 | 0 | struct SourceFileFlags flags; |
4326 | 0 | this->ConstructSourceFileFlags(); |
4327 | 0 | auto si = this->SourceFlagsMap.find(sf); |
4328 | 0 | if (si != this->SourceFlagsMap.end()) { |
4329 | 0 | flags = si->second; |
4330 | 0 | } else { |
4331 | | // Handle the MACOSX_PACKAGE_LOCATION property on source files that |
4332 | | // were not listed in one of the other lists. |
4333 | 0 | if (cmValue location = sf->GetProperty("MACOSX_PACKAGE_LOCATION")) { |
4334 | 0 | flags.MacFolder = location->c_str(); |
4335 | 0 | bool const stripResources = |
4336 | 0 | this->GlobalGenerator->ShouldStripResourcePath(this->Makefile); |
4337 | 0 | if (*location == "Resources") { |
4338 | 0 | flags.Type = cmGeneratorTarget::SourceFileTypeResource; |
4339 | 0 | if (stripResources) { |
4340 | 0 | flags.MacFolder = ""; |
4341 | 0 | } |
4342 | 0 | } else if (cmHasLiteralPrefix(*location, "Resources/")) { |
4343 | 0 | flags.Type = cmGeneratorTarget::SourceFileTypeDeepResource; |
4344 | 0 | if (stripResources) { |
4345 | 0 | flags.MacFolder += cmStrLen("Resources/"); |
4346 | 0 | } |
4347 | 0 | } else { |
4348 | 0 | flags.Type = cmGeneratorTarget::SourceFileTypeMacContent; |
4349 | 0 | } |
4350 | 0 | } |
4351 | 0 | } |
4352 | 0 | return flags; |
4353 | 0 | } |
4354 | | |
4355 | | void cmGeneratorTarget::ConstructSourceFileFlags() const |
4356 | 0 | { |
4357 | 0 | if (this->SourceFileFlagsConstructed) { |
4358 | 0 | return; |
4359 | 0 | } |
4360 | 0 | this->SourceFileFlagsConstructed = true; |
4361 | | |
4362 | | // Process public headers to mark the source files. |
4363 | 0 | if (cmValue files = this->GetProperty("PUBLIC_HEADER")) { |
4364 | 0 | cmList relFiles{ *files }; |
4365 | 0 | for (auto const& relFile : relFiles) { |
4366 | 0 | if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) { |
4367 | 0 | SourceFileFlags& flags = this->SourceFlagsMap[sf]; |
4368 | 0 | flags.MacFolder = "Headers"; |
4369 | 0 | flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader; |
4370 | 0 | } |
4371 | 0 | } |
4372 | 0 | } |
4373 | | |
4374 | | // Process private headers after public headers so that they take |
4375 | | // precedence if a file is listed in both. |
4376 | 0 | if (cmValue files = this->GetProperty("PRIVATE_HEADER")) { |
4377 | 0 | cmList relFiles{ *files }; |
4378 | 0 | for (auto const& relFile : relFiles) { |
4379 | 0 | if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) { |
4380 | 0 | SourceFileFlags& flags = this->SourceFlagsMap[sf]; |
4381 | 0 | flags.MacFolder = "PrivateHeaders"; |
4382 | 0 | flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader; |
4383 | 0 | } |
4384 | 0 | } |
4385 | 0 | } |
4386 | | |
4387 | | // Mark sources listed as resources. |
4388 | 0 | if (cmValue files = this->GetProperty("RESOURCE")) { |
4389 | 0 | cmList relFiles{ *files }; |
4390 | 0 | for (auto const& relFile : relFiles) { |
4391 | 0 | if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) { |
4392 | 0 | SourceFileFlags& flags = this->SourceFlagsMap[sf]; |
4393 | 0 | flags.MacFolder = ""; |
4394 | 0 | if (!this->GlobalGenerator->ShouldStripResourcePath(this->Makefile)) { |
4395 | 0 | flags.MacFolder = "Resources"; |
4396 | 0 | } |
4397 | 0 | flags.Type = cmGeneratorTarget::SourceFileTypeResource; |
4398 | 0 | } |
4399 | 0 | } |
4400 | 0 | } |
4401 | 0 | } |
4402 | | |
4403 | | bool cmGeneratorTarget::SetDeviceLink(bool deviceLink) |
4404 | 0 | { |
4405 | 0 | bool previous = this->DeviceLink; |
4406 | 0 | this->DeviceLink = deviceLink; |
4407 | 0 | return previous; |
4408 | 0 | } |
4409 | | |
4410 | | void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const |
4411 | 0 | { |
4412 | 0 | int patch; |
4413 | 0 | this->GetTargetVersion("VERSION", major, minor, patch); |
4414 | 0 | } |
4415 | | |
4416 | | void cmGeneratorTarget::GetTargetVersionFallback( |
4417 | | std::string const& property, std::string const& fallback_property, |
4418 | | int& major, int& minor, int& patch) const |
4419 | 0 | { |
4420 | 0 | if (this->GetProperty(property)) { |
4421 | 0 | this->GetTargetVersion(property, major, minor, patch); |
4422 | 0 | } else { |
4423 | 0 | this->GetTargetVersion(fallback_property, major, minor, patch); |
4424 | 0 | } |
4425 | 0 | } |
4426 | | |
4427 | | void cmGeneratorTarget::GetTargetVersion(std::string const& property, |
4428 | | int& major, int& minor, |
4429 | | int& patch) const |
4430 | 0 | { |
4431 | | // Set the default values. |
4432 | 0 | major = 0; |
4433 | 0 | minor = 0; |
4434 | 0 | patch = 0; |
4435 | |
|
4436 | 0 | assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY); |
4437 | |
|
4438 | 0 | if (cmValue version = this->GetProperty(property)) { |
4439 | | // Try to parse the version number and store the results that were |
4440 | | // successfully parsed. |
4441 | 0 | int parsed_major; |
4442 | 0 | int parsed_minor; |
4443 | 0 | int parsed_patch; |
4444 | 0 | switch (sscanf(version->c_str(), "%d.%d.%d", &parsed_major, &parsed_minor, |
4445 | 0 | &parsed_patch)) { |
4446 | 0 | case 3: |
4447 | 0 | patch = parsed_patch; |
4448 | 0 | CM_FALLTHROUGH; |
4449 | 0 | case 2: |
4450 | 0 | minor = parsed_minor; |
4451 | 0 | CM_FALLTHROUGH; |
4452 | 0 | case 1: |
4453 | 0 | major = parsed_major; |
4454 | 0 | CM_FALLTHROUGH; |
4455 | 0 | default: |
4456 | 0 | break; |
4457 | 0 | } |
4458 | 0 | } |
4459 | 0 | } |
4460 | | |
4461 | | std::string cmGeneratorTarget::GetRuntimeLinkLibrary( |
4462 | | std::string const& lang, std::string const& config) const |
4463 | 0 | { |
4464 | | // This is activated by the presence of a default selection whether or |
4465 | | // not it is overridden by a property. |
4466 | 0 | cmValue runtimeLibraryDefault = this->Makefile->GetDefinition( |
4467 | 0 | cmStrCat("CMAKE_", lang, "_RUNTIME_LIBRARY_DEFAULT")); |
4468 | 0 | if (!cmNonempty(runtimeLibraryDefault)) { |
4469 | 0 | return std::string(); |
4470 | 0 | } |
4471 | 0 | cmValue runtimeLibraryValue = |
4472 | 0 | this->Target->GetProperty(cmStrCat(lang, "_RUNTIME_LIBRARY")); |
4473 | 0 | if (!runtimeLibraryValue) { |
4474 | 0 | runtimeLibraryValue = runtimeLibraryDefault; |
4475 | 0 | } |
4476 | 0 | return cmSystemTools::UpperCase(cmGeneratorExpression::Evaluate( |
4477 | 0 | *runtimeLibraryValue, this->LocalGenerator, config, this)); |
4478 | 0 | } |
4479 | | |
4480 | | std::string cmGeneratorTarget::GetFortranModuleDirectory( |
4481 | | std::string const& working_dir) const |
4482 | 0 | { |
4483 | 0 | if (!this->FortranModuleDirectoryCreated) { |
4484 | 0 | this->FortranModuleDirectory = |
4485 | 0 | this->CreateFortranModuleDirectory(working_dir); |
4486 | 0 | this->FortranModuleDirectoryCreated = true; |
4487 | 0 | } |
4488 | |
|
4489 | 0 | return this->FortranModuleDirectory; |
4490 | 0 | } |
4491 | | |
4492 | | bool cmGeneratorTarget::IsFortranBuildingIntrinsicModules() const |
4493 | 0 | { |
4494 | | // ATTENTION Before 4.0 the property name was misspelled. |
4495 | | // Check the correct name first and than the old name. |
4496 | 0 | if (cmValue prop = this->GetProperty("Fortran_BUILDING_INTRINSIC_MODULES")) { |
4497 | 0 | return prop.IsOn(); |
4498 | 0 | } |
4499 | 0 | if (cmValue prop = |
4500 | 0 | this->GetProperty("Fortran_BUILDING_INSTRINSIC_MODULES")) { |
4501 | 0 | return prop.IsOn(); |
4502 | 0 | } |
4503 | 0 | return false; |
4504 | 0 | } |
4505 | | |
4506 | | std::string cmGeneratorTarget::CreateFortranModuleDirectory( |
4507 | | std::string const& working_dir) const |
4508 | 0 | { |
4509 | 0 | std::string mod_dir; |
4510 | 0 | std::string target_mod_dir; |
4511 | 0 | if (cmValue prop = this->GetProperty("Fortran_MODULE_DIRECTORY")) { |
4512 | 0 | target_mod_dir = *prop; |
4513 | 0 | } else { |
4514 | 0 | std::string const& default_mod_dir = |
4515 | 0 | this->LocalGenerator->GetCurrentBinaryDirectory(); |
4516 | 0 | if (default_mod_dir != working_dir) { |
4517 | 0 | target_mod_dir = default_mod_dir; |
4518 | 0 | } |
4519 | 0 | } |
4520 | 0 | cmValue moddir_flag = |
4521 | 0 | this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG"); |
4522 | 0 | if (!target_mod_dir.empty() && moddir_flag) { |
4523 | | // Compute the full path to the module directory. |
4524 | 0 | if (cmSystemTools::FileIsFullPath(target_mod_dir)) { |
4525 | | // Already a full path. |
4526 | 0 | mod_dir = target_mod_dir; |
4527 | 0 | } else { |
4528 | | // Interpret relative to the current output directory. |
4529 | 0 | mod_dir = cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), |
4530 | 0 | '/', target_mod_dir); |
4531 | 0 | } |
4532 | | |
4533 | | // Make sure the module output directory exists. |
4534 | 0 | cmSystemTools::MakeDirectory(mod_dir); |
4535 | 0 | } |
4536 | 0 | return mod_dir; |
4537 | 0 | } |
4538 | | |
4539 | | void cmGeneratorTarget::AddISPCGeneratedHeader(std::string const& header, |
4540 | | std::string const& config) |
4541 | 0 | { |
4542 | 0 | std::string config_upper; |
4543 | 0 | if (!config.empty()) { |
4544 | 0 | config_upper = cmSystemTools::UpperCase(config); |
4545 | 0 | } |
4546 | 0 | auto iter = this->ISPCGeneratedHeaders.find(config_upper); |
4547 | 0 | if (iter == this->ISPCGeneratedHeaders.end()) { |
4548 | 0 | std::vector<std::string> headers; |
4549 | 0 | headers.emplace_back(header); |
4550 | 0 | this->ISPCGeneratedHeaders.insert({ config_upper, headers }); |
4551 | 0 | } else { |
4552 | 0 | iter->second.emplace_back(header); |
4553 | 0 | } |
4554 | 0 | } |
4555 | | |
4556 | | std::vector<std::string> cmGeneratorTarget::GetGeneratedISPCHeaders( |
4557 | | std::string const& config) const |
4558 | 0 | { |
4559 | 0 | std::string config_upper; |
4560 | 0 | if (!config.empty()) { |
4561 | 0 | config_upper = cmSystemTools::UpperCase(config); |
4562 | 0 | } |
4563 | 0 | auto iter = this->ISPCGeneratedHeaders.find(config_upper); |
4564 | 0 | if (iter == this->ISPCGeneratedHeaders.end()) { |
4565 | 0 | return std::vector<std::string>{}; |
4566 | 0 | } |
4567 | 0 | return iter->second; |
4568 | 0 | } |
4569 | | |
4570 | | void cmGeneratorTarget::AddISPCGeneratedObject( |
4571 | | std::vector<std::pair<cmSourceFile const*, std::string>>&& objs, |
4572 | | std::string const& config) |
4573 | 0 | { |
4574 | 0 | std::string config_upper; |
4575 | 0 | if (!config.empty()) { |
4576 | 0 | config_upper = cmSystemTools::UpperCase(config); |
4577 | 0 | } |
4578 | 0 | auto iter = this->ISPCGeneratedObjects.find(config_upper); |
4579 | 0 | if (iter == this->ISPCGeneratedObjects.end()) { |
4580 | 0 | this->ISPCGeneratedObjects.insert({ config_upper, objs }); |
4581 | 0 | } else { |
4582 | 0 | iter->second.insert(iter->second.end(), objs.begin(), objs.end()); |
4583 | 0 | } |
4584 | 0 | } |
4585 | | |
4586 | | std::vector<std::pair<cmSourceFile const*, std::string>> |
4587 | | cmGeneratorTarget::GetGeneratedISPCObjects(std::string const& config) const |
4588 | 0 | { |
4589 | 0 | std::string config_upper; |
4590 | 0 | if (!config.empty()) { |
4591 | 0 | config_upper = cmSystemTools::UpperCase(config); |
4592 | 0 | } |
4593 | 0 | auto iter = this->ISPCGeneratedObjects.find(config_upper); |
4594 | 0 | if (iter == this->ISPCGeneratedObjects.end()) { |
4595 | 0 | return std::vector<std::pair<cmSourceFile const*, std::string>>{}; |
4596 | 0 | } |
4597 | 0 | return iter->second; |
4598 | 0 | } |
4599 | | |
4600 | | std::string cmGeneratorTarget::GetFrameworkVersion() const |
4601 | 0 | { |
4602 | 0 | assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY); |
4603 | |
|
4604 | 0 | if (cmValue fversion = this->GetProperty("FRAMEWORK_VERSION")) { |
4605 | 0 | return *fversion; |
4606 | 0 | } |
4607 | 0 | if (cmValue tversion = this->GetProperty("VERSION")) { |
4608 | 0 | return *tversion; |
4609 | 0 | } |
4610 | 0 | return "A"; |
4611 | 0 | } |
4612 | | |
4613 | | std::string cmGeneratorTarget::ComputeVersionedName(std::string const& prefix, |
4614 | | std::string const& base, |
4615 | | std::string const& suffix, |
4616 | | std::string const& name, |
4617 | | cmValue version) const |
4618 | 0 | { |
4619 | 0 | std::string vName = this->IsApple() ? (prefix + base) : name; |
4620 | 0 | if (version) { |
4621 | 0 | vName += "."; |
4622 | 0 | vName += *version; |
4623 | 0 | } |
4624 | 0 | vName += this->IsApple() ? suffix : std::string(); |
4625 | 0 | return vName; |
4626 | 0 | } |
4627 | | |
4628 | | std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const |
4629 | 0 | { |
4630 | 0 | return this->Target->GetProperties().GetKeys(); |
4631 | 0 | } |
4632 | | |
4633 | | void cmGeneratorTarget::ReportPropertyOrigin( |
4634 | | std::string const& p, std::string const& result, std::string const& report, |
4635 | | std::string const& compatibilityType) const |
4636 | 0 | { |
4637 | 0 | cmList debugProperties{ this->Target->GetMakefile()->GetDefinition( |
4638 | 0 | "CMAKE_DEBUG_TARGET_PROPERTIES") }; |
4639 | 0 | bool debugOrigin = !this->DebugCompatiblePropertiesDone[p] && |
4640 | 0 | cm::contains(debugProperties, p); |
4641 | |
|
4642 | 0 | this->DebugCompatiblePropertiesDone[p] = true; |
4643 | 0 | if (!debugOrigin) { |
4644 | 0 | return; |
4645 | 0 | } |
4646 | | |
4647 | 0 | std::string areport = |
4648 | 0 | cmStrCat(compatibilityType, " of property \"", p, "\" for target \"", |
4649 | 0 | this->GetName(), "\" (result: \"", result, "\"):\n", report); |
4650 | |
|
4651 | 0 | this->LocalGenerator->GetCMakeInstance()->IssueMessage(MessageType::LOG, |
4652 | 0 | areport); |
4653 | 0 | } |
4654 | | |
4655 | | std::string cmGeneratorTarget::GetDirectory( |
4656 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
4657 | 0 | { |
4658 | 0 | if (this->IsImported()) { |
4659 | 0 | auto fullPath = this->Target->ImportedGetFullPath(config, artifact); |
4660 | 0 | if (this->IsFrameworkOnApple()) { |
4661 | 0 | auto fwDescriptor = this->GetGlobalGenerator()->SplitFrameworkPath( |
4662 | 0 | fullPath, cmGlobalGenerator::FrameworkFormat::Strict); |
4663 | 0 | if (fwDescriptor) { |
4664 | 0 | return fwDescriptor->Directory; |
4665 | 0 | } |
4666 | 0 | } |
4667 | | // Return the directory from which the target is imported. |
4668 | 0 | return cmSystemTools::GetFilenamePath(fullPath); |
4669 | 0 | } |
4670 | 0 | if (OutputInfo const* info = this->GetOutputInfo(config)) { |
4671 | | // Return the directory in which the target will be built. |
4672 | 0 | switch (artifact) { |
4673 | 0 | case cmStateEnums::RuntimeBinaryArtifact: |
4674 | 0 | return info->OutDir; |
4675 | 0 | case cmStateEnums::ImportLibraryArtifact: |
4676 | 0 | return info->ImpDir; |
4677 | 0 | } |
4678 | 0 | } |
4679 | 0 | return ""; |
4680 | 0 | } |
4681 | | |
4682 | | bool cmGeneratorTarget::UsesDefaultOutputDir( |
4683 | | std::string const& config, cmStateEnums::ArtifactType artifact) const |
4684 | 0 | { |
4685 | 0 | std::string dir; |
4686 | 0 | return this->ComputeOutputDir(config, artifact, dir); |
4687 | 0 | } |
4688 | | |
4689 | | cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo( |
4690 | | std::string const& config) const |
4691 | 0 | { |
4692 | | // There is no output information for imported targets. |
4693 | 0 | if (this->IsImported()) { |
4694 | 0 | return nullptr; |
4695 | 0 | } |
4696 | | |
4697 | | // Synthetic targets don't have output. |
4698 | 0 | if (this->IsSynthetic()) { |
4699 | 0 | return nullptr; |
4700 | 0 | } |
4701 | | |
4702 | | // Only libraries and executables have well-defined output files. |
4703 | 0 | if (!this->HaveWellDefinedOutputFiles()) { |
4704 | 0 | std::string msg = cmStrCat("cmGeneratorTarget::GetOutputInfo called for ", |
4705 | 0 | this->GetName(), " which has type ", |
4706 | 0 | cmState::GetTargetTypeName(this->GetType())); |
4707 | 0 | this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg); |
4708 | 0 | return nullptr; |
4709 | 0 | } |
4710 | | |
4711 | | // Lookup/compute/cache the output information for this configuration. |
4712 | 0 | std::string config_upper; |
4713 | 0 | if (!config.empty()) { |
4714 | 0 | config_upper = cmSystemTools::UpperCase(config); |
4715 | 0 | } |
4716 | 0 | auto i = this->OutputInfoMap.find(config_upper); |
4717 | 0 | if (i == this->OutputInfoMap.end()) { |
4718 | | // Add empty info in map to detect potential recursion. |
4719 | 0 | OutputInfo info; |
4720 | 0 | OutputInfoMapType::value_type entry(config_upper, info); |
4721 | 0 | i = this->OutputInfoMap.insert(entry).first; |
4722 | | |
4723 | | // Compute output directories. |
4724 | 0 | this->ComputeOutputDir(config, cmStateEnums::RuntimeBinaryArtifact, |
4725 | 0 | info.OutDir); |
4726 | 0 | this->ComputeOutputDir(config, cmStateEnums::ImportLibraryArtifact, |
4727 | 0 | info.ImpDir); |
4728 | 0 | if (!this->ComputePDBOutputDir("PDB", config, info.PdbDir)) { |
4729 | 0 | info.PdbDir = info.OutDir; |
4730 | 0 | } |
4731 | | |
4732 | | // Now update the previously-prepared map entry. |
4733 | 0 | i->second = info; |
4734 | 0 | } else if (i->second.empty()) { |
4735 | | // An empty map entry indicates we have been called recursively |
4736 | | // from the above block. |
4737 | 0 | this->LocalGenerator->GetCMakeInstance()->IssueMessage( |
4738 | 0 | MessageType::FATAL_ERROR, |
4739 | 0 | cmStrCat("Target '", this->GetName(), |
4740 | 0 | "' OUTPUT_DIRECTORY depends on itself."), |
4741 | 0 | this->GetBacktrace()); |
4742 | 0 | return nullptr; |
4743 | 0 | } |
4744 | 0 | return &i->second; |
4745 | 0 | } |
4746 | | |
4747 | | bool cmGeneratorTarget::ComputeOutputDir(std::string const& config, |
4748 | | cmStateEnums::ArtifactType artifact, |
4749 | | std::string& out) const |
4750 | 0 | { |
4751 | 0 | bool usesDefaultOutputDir = false; |
4752 | 0 | std::string conf = config; |
4753 | | |
4754 | | // Look for a target property defining the target output directory |
4755 | | // based on the target type. |
4756 | 0 | std::string targetTypeName = this->GetOutputTargetType(artifact); |
4757 | 0 | std::string propertyName; |
4758 | 0 | if (!targetTypeName.empty()) { |
4759 | 0 | propertyName = cmStrCat(targetTypeName, "_OUTPUT_DIRECTORY"); |
4760 | 0 | } |
4761 | | |
4762 | | // Check for a per-configuration output directory target property. |
4763 | 0 | std::string configUpper = cmSystemTools::UpperCase(conf); |
4764 | 0 | std::string configProp; |
4765 | 0 | if (!targetTypeName.empty()) { |
4766 | 0 | configProp = cmStrCat(targetTypeName, "_OUTPUT_DIRECTORY_", configUpper); |
4767 | 0 | } |
4768 | | |
4769 | | // Select an output directory. |
4770 | 0 | if (cmValue config_outdir = this->GetProperty(configProp)) { |
4771 | | // Use the user-specified per-configuration output directory. |
4772 | 0 | out = cmGeneratorExpression::Evaluate(*config_outdir, this->LocalGenerator, |
4773 | 0 | config, this); |
4774 | | |
4775 | | // Skip per-configuration subdirectory. |
4776 | 0 | conf.clear(); |
4777 | 0 | } else if (cmValue outdir = this->GetProperty(propertyName)) { |
4778 | | // Use the user-specified output directory. |
4779 | 0 | out = cmGeneratorExpression::Evaluate(*outdir, this->LocalGenerator, |
4780 | 0 | config, this); |
4781 | | // Skip per-configuration subdirectory if the value contained a |
4782 | | // generator expression. |
4783 | 0 | if (out != *outdir) { |
4784 | 0 | conf.clear(); |
4785 | 0 | } |
4786 | 0 | } else if (this->GetType() == cmStateEnums::EXECUTABLE) { |
4787 | | // Lookup the output path for executables. |
4788 | 0 | out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH"); |
4789 | 0 | } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY || |
4790 | 0 | this->GetType() == cmStateEnums::SHARED_LIBRARY || |
4791 | 0 | this->GetType() == cmStateEnums::MODULE_LIBRARY) { |
4792 | | // Lookup the output path for libraries. |
4793 | 0 | out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH"); |
4794 | 0 | } |
4795 | 0 | if (out.empty()) { |
4796 | | // Default to the current output directory. |
4797 | 0 | usesDefaultOutputDir = true; |
4798 | 0 | out = "."; |
4799 | 0 | } |
4800 | | |
4801 | | // Convert the output path to a full path in case it is |
4802 | | // specified as a relative path. Treat a relative path as |
4803 | | // relative to the current output directory for this makefile. |
4804 | 0 | out = (cmSystemTools::CollapseFullPath( |
4805 | 0 | out, this->LocalGenerator->GetCurrentBinaryDirectory())); |
4806 | | |
4807 | | // The generator may add the configuration's subdirectory. |
4808 | 0 | if (!conf.empty()) { |
4809 | 0 | bool useEPN = |
4810 | 0 | this->GlobalGenerator->UseEffectivePlatformName(this->Makefile); |
4811 | 0 | std::string suffix = |
4812 | 0 | usesDefaultOutputDir && useEPN ? "${EFFECTIVE_PLATFORM_NAME}" : ""; |
4813 | 0 | this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig( |
4814 | 0 | "/", conf, suffix, out); |
4815 | 0 | } |
4816 | |
|
4817 | 0 | return usesDefaultOutputDir; |
4818 | 0 | } |
4819 | | |
4820 | | bool cmGeneratorTarget::ComputePDBOutputDir(std::string const& kind, |
4821 | | std::string const& config, |
4822 | | std::string& out) const |
4823 | 0 | { |
4824 | | // Look for a target property defining the target output directory |
4825 | | // based on the target type. |
4826 | 0 | std::string propertyName; |
4827 | 0 | if (!kind.empty()) { |
4828 | 0 | propertyName = cmStrCat(kind, "_OUTPUT_DIRECTORY"); |
4829 | 0 | } |
4830 | 0 | std::string conf = config; |
4831 | | |
4832 | | // Check for a per-configuration output directory target property. |
4833 | 0 | std::string configUpper = cmSystemTools::UpperCase(conf); |
4834 | 0 | std::string configProp; |
4835 | 0 | if (!kind.empty()) { |
4836 | 0 | configProp = cmStrCat(kind, "_OUTPUT_DIRECTORY_", configUpper); |
4837 | 0 | } |
4838 | | |
4839 | | // Select an output directory. |
4840 | 0 | if (cmValue config_outdir = this->GetProperty(configProp)) { |
4841 | | // Use the user-specified per-configuration output directory. |
4842 | 0 | out = cmGeneratorExpression::Evaluate(*config_outdir, this->LocalGenerator, |
4843 | 0 | config); |
4844 | | |
4845 | | // Skip per-configuration subdirectory. |
4846 | 0 | conf.clear(); |
4847 | 0 | } else if (cmValue outdir = this->GetProperty(propertyName)) { |
4848 | | // Use the user-specified output directory. |
4849 | 0 | out = |
4850 | 0 | cmGeneratorExpression::Evaluate(*outdir, this->LocalGenerator, config); |
4851 | | |
4852 | | // Skip per-configuration subdirectory if the value contained a |
4853 | | // generator expression. |
4854 | 0 | if (out != *outdir) { |
4855 | 0 | conf.clear(); |
4856 | 0 | } |
4857 | 0 | } |
4858 | 0 | if (out.empty()) { |
4859 | 0 | cmGeneratorTarget const* reuseTarget = this->GetPchReuseTarget(); |
4860 | 0 | bool const hasReuse = reuseTarget && reuseTarget != this; |
4861 | | // Compiler-generated PDB output always needed for REUSE_FROM. |
4862 | 0 | if (kind == "COMPILE_PDB"_s && (this->PchReused || hasReuse)) { |
4863 | 0 | out = this->GetSupportDirectory(); |
4864 | 0 | } else { |
4865 | 0 | return false; |
4866 | 0 | } |
4867 | 0 | } |
4868 | | |
4869 | | // Convert the output path to a full path in case it is |
4870 | | // specified as a relative path. Treat a relative path as |
4871 | | // relative to the current output directory for this makefile. |
4872 | 0 | out = (cmSystemTools::CollapseFullPath( |
4873 | 0 | out, this->LocalGenerator->GetCurrentBinaryDirectory())); |
4874 | | |
4875 | | // The generator may add the configuration's subdirectory. |
4876 | 0 | if (!conf.empty()) { |
4877 | 0 | this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig( |
4878 | 0 | "/", conf, "", out); |
4879 | 0 | } |
4880 | 0 | return true; |
4881 | 0 | } |
4882 | | |
4883 | | bool cmGeneratorTarget::HaveInstallTreeRPATH(std::string const& config) const |
4884 | 0 | { |
4885 | 0 | std::string install_rpath; |
4886 | 0 | this->GetInstallRPATH(config, install_rpath); |
4887 | 0 | return !install_rpath.empty() && |
4888 | 0 | !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"); |
4889 | 0 | } |
4890 | | |
4891 | | bool cmGeneratorTarget::GetBuildRPATH(std::string const& config, |
4892 | | std::string& rpath) const |
4893 | 0 | { |
4894 | 0 | return this->GetRPATH(config, "BUILD_RPATH", rpath); |
4895 | 0 | } |
4896 | | |
4897 | | bool cmGeneratorTarget::GetInstallRPATH(std::string const& config, |
4898 | | std::string& rpath) const |
4899 | 0 | { |
4900 | 0 | return this->GetRPATH(config, "INSTALL_RPATH", rpath); |
4901 | 0 | } |
4902 | | |
4903 | | bool cmGeneratorTarget::GetRPATH(std::string const& config, |
4904 | | std::string const& prop, |
4905 | | std::string& rpath) const |
4906 | 0 | { |
4907 | 0 | cmValue value = this->GetProperty(prop); |
4908 | 0 | if (!value) { |
4909 | 0 | return false; |
4910 | 0 | } |
4911 | | |
4912 | 0 | rpath = |
4913 | 0 | cmGeneratorExpression::Evaluate(*value, this->LocalGenerator, config); |
4914 | |
|
4915 | 0 | return true; |
4916 | 0 | } |
4917 | | |
4918 | | cmGeneratorTarget::ImportInfo const* cmGeneratorTarget::GetImportInfo( |
4919 | | std::string const& config) const |
4920 | 0 | { |
4921 | | // There is no imported information for non-imported targets. |
4922 | 0 | if (!this->IsImported()) { |
4923 | 0 | return nullptr; |
4924 | 0 | } |
4925 | | |
4926 | | // Lookup/compute/cache the import information for this |
4927 | | // configuration. |
4928 | 0 | std::string config_upper; |
4929 | 0 | if (!config.empty()) { |
4930 | 0 | config_upper = cmSystemTools::UpperCase(config); |
4931 | 0 | } else { |
4932 | 0 | config_upper = "NOCONFIG"; |
4933 | 0 | } |
4934 | |
|
4935 | 0 | auto i = this->ImportInfoMap.find(config_upper); |
4936 | 0 | if (i == this->ImportInfoMap.end()) { |
4937 | 0 | ImportInfo info; |
4938 | 0 | this->ComputeImportInfo(config_upper, info); |
4939 | 0 | ImportInfoMapType::value_type entry(config_upper, info); |
4940 | 0 | i = this->ImportInfoMap.insert(entry).first; |
4941 | 0 | } |
4942 | |
|
4943 | 0 | if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) { |
4944 | 0 | return &i->second; |
4945 | 0 | } |
4946 | | // If the location is empty then the target is not available for |
4947 | | // this configuration. |
4948 | 0 | if (i->second.Location.empty() && i->second.ImportLibrary.empty()) { |
4949 | 0 | return nullptr; |
4950 | 0 | } |
4951 | | |
4952 | | // Return the import information. |
4953 | 0 | return &i->second; |
4954 | 0 | } |
4955 | | |
4956 | | void cmGeneratorTarget::ComputeImportInfo(std::string const& desired_config, |
4957 | | ImportInfo& info) const |
4958 | 0 | { |
4959 | | // This method finds information about an imported target from its |
4960 | | // properties. The "IMPORTED_" namespace is reserved for properties |
4961 | | // defined by the project exporting the target. |
4962 | | |
4963 | | // Initialize members. |
4964 | 0 | info.NoSOName = false; |
4965 | |
|
4966 | 0 | cmValue loc = nullptr; |
4967 | 0 | cmValue imp = nullptr; |
4968 | 0 | std::string suffix; |
4969 | 0 | if (!this->Target->GetMappedConfig(desired_config, loc, imp, suffix)) { |
4970 | 0 | return; |
4971 | 0 | } |
4972 | | |
4973 | | // Get the link interface. |
4974 | 0 | { |
4975 | | // Use the INTERFACE_LINK_LIBRARIES special representation directly |
4976 | | // to get backtraces. |
4977 | 0 | cmBTStringRange entries = this->Target->GetLinkInterfaceEntries(); |
4978 | 0 | if (!entries.empty()) { |
4979 | 0 | info.LibrariesProp = "INTERFACE_LINK_LIBRARIES"; |
4980 | 0 | for (BT<std::string> const& entry : entries) { |
4981 | 0 | info.Libraries.emplace_back(entry); |
4982 | 0 | } |
4983 | 0 | } else if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) { |
4984 | 0 | std::string linkProp = |
4985 | 0 | cmStrCat("IMPORTED_LINK_INTERFACE_LIBRARIES", suffix); |
4986 | 0 | cmValue propertyLibs = this->GetProperty(linkProp); |
4987 | 0 | if (!propertyLibs) { |
4988 | 0 | linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES"; |
4989 | 0 | propertyLibs = this->GetProperty(linkProp); |
4990 | 0 | } |
4991 | 0 | if (propertyLibs) { |
4992 | 0 | info.LibrariesProp = linkProp; |
4993 | 0 | info.Libraries.emplace_back(*propertyLibs); |
4994 | 0 | } |
4995 | 0 | } |
4996 | 0 | } |
4997 | 0 | for (BT<std::string> const& entry : |
4998 | 0 | this->Target->GetLinkInterfaceDirectEntries()) { |
4999 | 0 | info.LibrariesHeadInclude.emplace_back(entry); |
5000 | 0 | } |
5001 | 0 | for (BT<std::string> const& entry : |
5002 | 0 | this->Target->GetLinkInterfaceDirectExcludeEntries()) { |
5003 | 0 | info.LibrariesHeadExclude.emplace_back(entry); |
5004 | 0 | } |
5005 | 0 | if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) { |
5006 | 0 | if (loc) { |
5007 | 0 | info.LibName = *loc; |
5008 | 0 | } |
5009 | 0 | return; |
5010 | 0 | } |
5011 | | |
5012 | | // A provided configuration has been chosen. Load the |
5013 | | // configuration's properties. |
5014 | | |
5015 | | // Get the location. |
5016 | 0 | if (loc) { |
5017 | 0 | info.Location = *loc; |
5018 | 0 | } else { |
5019 | 0 | std::string impProp = cmStrCat("IMPORTED_LOCATION", suffix); |
5020 | 0 | if (cmValue config_location = this->GetProperty(impProp)) { |
5021 | 0 | info.Location = *config_location; |
5022 | 0 | } else if (cmValue location = this->GetProperty("IMPORTED_LOCATION")) { |
5023 | 0 | info.Location = *location; |
5024 | 0 | } |
5025 | 0 | } |
5026 | | |
5027 | | // Get the soname. |
5028 | 0 | if (this->GetType() == cmStateEnums::SHARED_LIBRARY) { |
5029 | 0 | std::string soProp = cmStrCat("IMPORTED_SONAME", suffix); |
5030 | 0 | if (cmValue config_soname = this->GetProperty(soProp)) { |
5031 | 0 | info.SOName = *config_soname; |
5032 | 0 | } else if (cmValue soname = this->GetProperty("IMPORTED_SONAME")) { |
5033 | 0 | info.SOName = *soname; |
5034 | 0 | } |
5035 | 0 | } |
5036 | | |
5037 | | // Get the "no-soname" mark. |
5038 | 0 | if (this->GetType() == cmStateEnums::SHARED_LIBRARY) { |
5039 | 0 | std::string soProp = cmStrCat("IMPORTED_NO_SONAME", suffix); |
5040 | 0 | if (cmValue config_no_soname = this->GetProperty(soProp)) { |
5041 | 0 | info.NoSOName = config_no_soname.IsOn(); |
5042 | 0 | } else if (cmValue no_soname = this->GetProperty("IMPORTED_NO_SONAME")) { |
5043 | 0 | info.NoSOName = no_soname.IsOn(); |
5044 | 0 | } |
5045 | 0 | } |
5046 | | |
5047 | | // Get the import library. |
5048 | 0 | if (imp) { |
5049 | 0 | info.ImportLibrary = *imp; |
5050 | 0 | } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY || |
5051 | 0 | this->IsExecutableWithExports()) { |
5052 | 0 | std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix); |
5053 | 0 | if (cmValue config_implib = this->GetProperty(impProp)) { |
5054 | 0 | info.ImportLibrary = *config_implib; |
5055 | 0 | } else if (cmValue implib = this->GetProperty("IMPORTED_IMPLIB")) { |
5056 | 0 | info.ImportLibrary = *implib; |
5057 | 0 | } |
5058 | 0 | } |
5059 | | |
5060 | | // Get the link dependencies. |
5061 | 0 | { |
5062 | 0 | std::string linkProp = |
5063 | 0 | cmStrCat("IMPORTED_LINK_DEPENDENT_LIBRARIES", suffix); |
5064 | 0 | if (cmValue config_libs = this->GetProperty(linkProp)) { |
5065 | 0 | info.SharedDeps = *config_libs; |
5066 | 0 | } else if (cmValue libs = |
5067 | 0 | this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES")) { |
5068 | 0 | info.SharedDeps = *libs; |
5069 | 0 | } |
5070 | 0 | } |
5071 | | |
5072 | | // Get the link languages. |
5073 | 0 | if (this->LinkLanguagePropagatesToDependents()) { |
5074 | 0 | std::string linkProp = |
5075 | 0 | cmStrCat("IMPORTED_LINK_INTERFACE_LANGUAGES", suffix); |
5076 | 0 | if (cmValue config_libs = this->GetProperty(linkProp)) { |
5077 | 0 | info.Languages = *config_libs; |
5078 | 0 | } else if (cmValue libs = |
5079 | 0 | this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES")) { |
5080 | 0 | info.Languages = *libs; |
5081 | 0 | } |
5082 | 0 | } |
5083 | | |
5084 | | // Get information if target is managed assembly. |
5085 | 0 | { |
5086 | 0 | std::string linkProp = "IMPORTED_COMMON_LANGUAGE_RUNTIME"; |
5087 | 0 | if (cmValue pc = this->GetProperty(linkProp + suffix)) { |
5088 | 0 | info.Managed = this->CheckManagedType(*pc); |
5089 | 0 | } else if (cmValue p = this->GetProperty(linkProp)) { |
5090 | 0 | info.Managed = this->CheckManagedType(*p); |
5091 | 0 | } |
5092 | 0 | } |
5093 | | |
5094 | | // Get the cyclic repetition count. |
5095 | 0 | if (this->GetType() == cmStateEnums::STATIC_LIBRARY) { |
5096 | 0 | std::string linkProp = |
5097 | 0 | cmStrCat("IMPORTED_LINK_INTERFACE_MULTIPLICITY", suffix); |
5098 | 0 | if (cmValue config_reps = this->GetProperty(linkProp)) { |
5099 | 0 | sscanf(config_reps->c_str(), "%u", &info.Multiplicity); |
5100 | 0 | } else if (cmValue reps = |
5101 | 0 | this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY")) { |
5102 | 0 | sscanf(reps->c_str(), "%u", &info.Multiplicity); |
5103 | 0 | } |
5104 | 0 | } |
5105 | 0 | } |
5106 | | |
5107 | | bool cmGeneratorTarget::GetConfigCommonSourceFilesForXcode( |
5108 | | std::vector<cmSourceFile*>& files) const |
5109 | 0 | { |
5110 | 0 | std::vector<std::string> const& configs = |
5111 | 0 | this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); |
5112 | |
|
5113 | 0 | auto it = configs.begin(); |
5114 | 0 | std::string const& firstConfig = *it; |
5115 | 0 | this->GetSourceFilesWithoutObjectLibraries(files, firstConfig); |
5116 | |
|
5117 | 0 | for (; it != configs.end(); ++it) { |
5118 | 0 | std::vector<cmSourceFile*> configFiles; |
5119 | 0 | this->GetSourceFilesWithoutObjectLibraries(configFiles, *it); |
5120 | 0 | if (configFiles != files) { |
5121 | 0 | std::string firstConfigFiles; |
5122 | 0 | char const* sep = ""; |
5123 | 0 | for (cmSourceFile* f : files) { |
5124 | 0 | firstConfigFiles += sep; |
5125 | 0 | firstConfigFiles += f->ResolveFullPath(); |
5126 | 0 | sep = "\n "; |
5127 | 0 | } |
5128 | |
|
5129 | 0 | std::string thisConfigFiles; |
5130 | 0 | sep = ""; |
5131 | 0 | for (cmSourceFile* f : configFiles) { |
5132 | 0 | thisConfigFiles += sep; |
5133 | 0 | thisConfigFiles += f->ResolveFullPath(); |
5134 | 0 | sep = "\n "; |
5135 | 0 | } |
5136 | 0 | std::ostringstream e; |
5137 | | /* clang-format off */ |
5138 | 0 | e << "Target \"" << this->GetName() |
5139 | 0 | << "\" has source files which vary by " |
5140 | 0 | "configuration. This is not supported by the \"" |
5141 | 0 | << this->GlobalGenerator->GetName() |
5142 | 0 | << "\" generator.\n" |
5143 | 0 | "Config \"" << firstConfig << "\":\n" |
5144 | 0 | " " << firstConfigFiles << "\n" |
5145 | 0 | "Config \"" << *it << "\":\n" |
5146 | 0 | " " << thisConfigFiles << "\n"; |
5147 | | /* clang-format on */ |
5148 | 0 | this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str()); |
5149 | 0 | return false; |
5150 | 0 | } |
5151 | 0 | } |
5152 | 0 | return true; |
5153 | 0 | } |
5154 | | |
5155 | | void cmGeneratorTarget::GetObjectLibrariesInSources( |
5156 | | std::vector<BT<cmGeneratorTarget*>>& objlibs) const |
5157 | 0 | { |
5158 | | // FIXME: This searches SOURCES for TARGET_OBJECTS for backwards |
5159 | | // compatibility with the OLD behavior of CMP0026 since this |
5160 | | // could be called at configure time. CMP0026 has been removed, |
5161 | | // so this should now be called only at generate time. |
5162 | | // Therefore we should be able to improve the implementation |
5163 | | // with generate-time information. |
5164 | 0 | cmBTStringRange rng = this->Target->GetSourceEntries(); |
5165 | 0 | for (auto const& entry : rng) { |
5166 | 0 | cmList files{ entry.Value }; |
5167 | 0 | for (auto const& li : files) { |
5168 | 0 | if (cmHasLiteralPrefix(li, "$<TARGET_OBJECTS:") && li.back() == '>') { |
5169 | 0 | std::string objLibName = li.substr(17, li.size() - 18); |
5170 | |
|
5171 | 0 | if (cmGeneratorExpression::Find(objLibName) != std::string::npos) { |
5172 | 0 | continue; |
5173 | 0 | } |
5174 | 0 | cmGeneratorTarget* objLib = |
5175 | 0 | this->LocalGenerator->FindGeneratorTargetToUse(objLibName); |
5176 | 0 | if (objLib) { |
5177 | 0 | objlibs.emplace_back(objLib, entry.Backtrace); |
5178 | 0 | } |
5179 | 0 | } |
5180 | 0 | } |
5181 | 0 | } |
5182 | 0 | } |
5183 | | |
5184 | | std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const |
5185 | 0 | { |
5186 | | // Strip whitespace off the library names because we used to do this |
5187 | | // in case variables were expanded at generate time. We no longer |
5188 | | // do the expansion but users link to libraries like " ${VAR} ". |
5189 | 0 | std::string lib = item; |
5190 | 0 | std::string::size_type pos = lib.find_first_not_of(" \t\r\n"); |
5191 | 0 | if (pos != std::string::npos) { |
5192 | 0 | lib = lib.substr(pos); |
5193 | 0 | } |
5194 | 0 | pos = lib.find_last_not_of(" \t\r\n"); |
5195 | 0 | if (pos != std::string::npos) { |
5196 | 0 | lib.resize(pos + 1); |
5197 | 0 | } |
5198 | 0 | if (lib != item) { |
5199 | 0 | cmake* cm = this->LocalGenerator->GetCMakeInstance(); |
5200 | 0 | std::ostringstream e; |
5201 | 0 | e << "Target \"" << this->GetName() << "\" links to item \"" << item |
5202 | 0 | << "\" which has leading or trailing whitespace. " |
5203 | 0 | << "This is now an error according to policy CMP0004."; |
5204 | 0 | cm->IssueMessage(MessageType::FATAL_ERROR, e.str(), this->GetBacktrace()); |
5205 | 0 | } |
5206 | 0 | return lib; |
5207 | 0 | } |
5208 | | |
5209 | | bool cmGeneratorTarget::IsDeprecated() const |
5210 | 0 | { |
5211 | 0 | cmValue deprecation = this->GetProperty("DEPRECATION"); |
5212 | 0 | return cmNonempty(deprecation); |
5213 | 0 | } |
5214 | | |
5215 | | std::string cmGeneratorTarget::GetDeprecation() const |
5216 | 0 | { |
5217 | | // find DEPRECATION property |
5218 | 0 | if (cmValue deprecation = this->GetProperty("DEPRECATION")) { |
5219 | 0 | return *deprecation; |
5220 | 0 | } |
5221 | 0 | return std::string(); |
5222 | 0 | } |
5223 | | |
5224 | | void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages, |
5225 | | std::string const& config) const |
5226 | 0 | { |
5227 | | // Targets that do not compile anything have no languages. |
5228 | 0 | if (!this->CanCompileSources()) { |
5229 | 0 | return; |
5230 | 0 | } |
5231 | | |
5232 | 0 | std::vector<cmSourceFile*> sourceFiles; |
5233 | 0 | this->GetSourceFiles(sourceFiles, config); |
5234 | 0 | for (cmSourceFile* src : sourceFiles) { |
5235 | 0 | std::string const& lang = src->GetOrDetermineLanguage(); |
5236 | 0 | if (!lang.empty()) { |
5237 | 0 | languages.insert(lang); |
5238 | 0 | } |
5239 | 0 | } |
5240 | |
|
5241 | 0 | std::set<cmGeneratorTarget const*> objectLibraries = |
5242 | 0 | this->GetSourceObjectLibraries(config); |
5243 | 0 | for (cmGeneratorTarget const* objLib : objectLibraries) { |
5244 | 0 | objLib->GetLanguages(languages, config); |
5245 | 0 | } |
5246 | 0 | } |
5247 | | |
5248 | | std::set<cmGeneratorTarget const*> cmGeneratorTarget::GetSourceObjectLibraries( |
5249 | | std::string const& config) const |
5250 | 0 | { |
5251 | 0 | std::set<cmGeneratorTarget const*> objectLibraries; |
5252 | 0 | std::vector<cmSourceFile const*> externalObjects; |
5253 | 0 | this->GetExternalObjects(externalObjects, config); |
5254 | 0 | for (cmSourceFile const* extObj : externalObjects) { |
5255 | 0 | std::string objLib = extObj->GetObjectLibrary(); |
5256 | 0 | if (cmGeneratorTarget* tgt = |
5257 | 0 | this->LocalGenerator->FindGeneratorTargetToUse(objLib)) { |
5258 | 0 | objectLibraries.insert(tgt); |
5259 | 0 | } |
5260 | 0 | } |
5261 | |
|
5262 | 0 | return objectLibraries; |
5263 | 0 | } |
5264 | | |
5265 | | bool cmGeneratorTarget::IsLanguageUsed(std::string const& language, |
5266 | | std::string const& config) const |
5267 | 0 | { |
5268 | 0 | std::set<std::string> languages; |
5269 | 0 | this->GetLanguages(languages, config); |
5270 | 0 | return languages.count(language); |
5271 | 0 | } |
5272 | | |
5273 | | bool cmGeneratorTarget::IsCSharpOnly() const |
5274 | 0 | { |
5275 | | // Only certain target types may compile CSharp. |
5276 | 0 | if (this->GetType() != cmStateEnums::SHARED_LIBRARY && |
5277 | 0 | this->GetType() != cmStateEnums::STATIC_LIBRARY && |
5278 | 0 | this->GetType() != cmStateEnums::EXECUTABLE) { |
5279 | 0 | return false; |
5280 | 0 | } |
5281 | 0 | std::set<std::string> languages = this->GetAllConfigCompileLanguages(); |
5282 | | // Consider an explicit linker language property, but *not* the |
5283 | | // computed linker language that may depend on linked targets. |
5284 | 0 | cmValue linkLang = this->GetProperty("LINKER_LANGUAGE"); |
5285 | 0 | if (cmNonempty(linkLang)) { |
5286 | 0 | languages.insert(*linkLang); |
5287 | 0 | } |
5288 | 0 | return languages.size() == 1 && languages.count("CSharp") > 0; |
5289 | 0 | } |
5290 | | |
5291 | | bool cmGeneratorTarget::IsDotNetSdkTarget() const |
5292 | 0 | { |
5293 | 0 | return !this->GetProperty("DOTNET_SDK").IsEmpty(); |
5294 | 0 | } |
5295 | | |
5296 | | void cmGeneratorTarget::ComputeLinkImplementationLanguages( |
5297 | | std::string const& config, cmOptionalLinkImplementation& impl) const |
5298 | 0 | { |
5299 | | // This target needs runtime libraries for its source languages. |
5300 | 0 | std::set<std::string> languages; |
5301 | | // Get languages used in our source files. |
5302 | 0 | this->GetLanguages(languages, config); |
5303 | | // Copy the set of languages to the link implementation. |
5304 | 0 | impl.Languages.insert(impl.Languages.begin(), languages.begin(), |
5305 | 0 | languages.end()); |
5306 | 0 | } |
5307 | | |
5308 | | bool cmGeneratorTarget::HaveBuildTreeRPATH(std::string const& config) const |
5309 | 0 | { |
5310 | 0 | if (this->GetPropertyAsBool("SKIP_BUILD_RPATH")) { |
5311 | 0 | return false; |
5312 | 0 | } |
5313 | 0 | std::string build_rpath; |
5314 | 0 | if (this->GetBuildRPATH(config, build_rpath)) { |
5315 | 0 | return true; |
5316 | 0 | } |
5317 | 0 | if (cmLinkImplementationLibraries const* impl = |
5318 | 0 | this->GetLinkImplementationLibraries(config, UseTo::Link)) { |
5319 | 0 | return !impl->Libraries.empty(); |
5320 | 0 | } |
5321 | 0 | return false; |
5322 | 0 | } |
5323 | | |
5324 | | bool cmGeneratorTarget::IsNullImpliedByLinkLibraries( |
5325 | | std::string const& p) const |
5326 | 0 | { |
5327 | 0 | return cm::contains(this->LinkImplicitNullProperties, p); |
5328 | 0 | } |
5329 | | |
5330 | | namespace { |
5331 | | bool CreateCxxStdlibTarget(cmMakefile* makefile, cmLocalGenerator* lg, |
5332 | | std::string const& targetName, |
5333 | | std::string const& cxxTargetName, |
5334 | | std::string const& stdLevel, |
5335 | | std::vector<std::string> const& configs) |
5336 | 0 | { |
5337 | 0 | #ifndef CMAKE_BOOTSTRAP |
5338 | |
|
5339 | 0 | static cm::optional<cmCxxModuleMetadata> metadata; |
5340 | | |
5341 | | // Load metadata only when we need to create a target |
5342 | 0 | if (!metadata) { |
5343 | 0 | auto errorMessage = |
5344 | 0 | makefile->GetDefinition("CMAKE_CXX_COMPILER_IMPORT_STD_ERROR_MESSAGE"); |
5345 | 0 | if (!errorMessage.IsEmpty()) { |
5346 | 0 | makefile->IssueMessage( |
5347 | 0 | MessageType::FATAL_ERROR, |
5348 | 0 | cmStrCat(R"(The "CXX_MODULE_STD" property on target ")", targetName, |
5349 | 0 | "\" requires toolchain support, but it was not provided. " |
5350 | 0 | "Reason:\n ", |
5351 | 0 | *errorMessage)); |
5352 | 0 | return false; |
5353 | 0 | } |
5354 | | |
5355 | 0 | auto metadataPath = |
5356 | 0 | makefile->GetDefinition("CMAKE_CXX_STDLIB_MODULES_JSON"); |
5357 | 0 | if (metadataPath.IsEmpty()) { |
5358 | 0 | makefile->IssueMessage( |
5359 | 0 | MessageType::FATAL_ERROR, |
5360 | 0 | cmStrCat( |
5361 | 0 | R"("The "CXX_MODULE_STD" property on target ")", targetName, |
5362 | 0 | "\" requires CMAKE_CXX_STDLIB_MODULES_JSON be set, but it was not " |
5363 | 0 | "provided by the toolchain.")); |
5364 | 0 | return false; |
5365 | 0 | } |
5366 | | |
5367 | 0 | auto parseResult = cmCxxModuleMetadata::LoadFromFile(*metadataPath); |
5368 | 0 | if (!parseResult) { |
5369 | 0 | makefile->IssueMessage( |
5370 | 0 | MessageType::FATAL_ERROR, |
5371 | 0 | cmStrCat("Failed to load C++ standard library modules metadata " |
5372 | 0 | "from \"", |
5373 | 0 | *metadataPath, "\": ", parseResult.Error)); |
5374 | 0 | return false; |
5375 | 0 | } |
5376 | | |
5377 | 0 | metadata = std::move(*parseResult.Meta); |
5378 | 0 | } |
5379 | | |
5380 | 0 | auto const localTargetName = cmStrCat("__cmake_cxx_std_", stdLevel); |
5381 | 0 | cmStandardLevelResolver standardResolver(makefile); |
5382 | 0 | auto* stdlibTgt = makefile->AddLibrary( |
5383 | 0 | localTargetName, cmStateEnums::STATIC_LIBRARY, {}, true); |
5384 | 0 | cmCxxModuleMetadata::PopulateTarget(*stdlibTgt, *metadata, configs); |
5385 | 0 | standardResolver.AddRequiredTargetFeature(stdlibTgt, |
5386 | 0 | cmStrCat("cxx_std_", stdLevel)); |
5387 | 0 | auto gt = cm::make_unique<cmGeneratorTarget>(stdlibTgt, lg); |
5388 | 0 | for (auto const& config : configs) { |
5389 | 0 | gt->ComputeCompileFeatures(config); |
5390 | 0 | } |
5391 | |
|
5392 | 0 | lg->AddGeneratorTarget(std::move(gt)); |
5393 | 0 | makefile->AddAlias(cxxTargetName, localTargetName); |
5394 | |
|
5395 | 0 | #endif // CMAKE_BOOTSTRAP |
5396 | |
|
5397 | 0 | return true; |
5398 | 0 | } |
5399 | | } // namespace |
5400 | | |
5401 | | bool cmGeneratorTarget::ApplyCXXStdTargets() |
5402 | 0 | { |
5403 | 0 | cmStandardLevelResolver standardResolver(this->Makefile); |
5404 | 0 | cmStandardLevel const cxxStd23 = |
5405 | 0 | *standardResolver.LanguageStandardLevel("CXX", "23"); |
5406 | 0 | std::vector<std::string> const& configs = |
5407 | 0 | this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); |
5408 | 0 | auto std_prop = this->GetProperty("CXX_MODULE_STD"); |
5409 | 0 | if (!std_prop) { |
5410 | | // TODO(cxxmodules): Add a target policy to flip the default here. Set |
5411 | | // `std_prop` based on it. |
5412 | 0 | return true; |
5413 | 0 | } |
5414 | | |
5415 | 0 | std::string std_prop_value; |
5416 | 0 | if (std_prop) { |
5417 | | // Evaluate generator expressions. |
5418 | 0 | cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance()); |
5419 | 0 | auto cge = ge.Parse(*std_prop); |
5420 | 0 | if (!cge) { |
5421 | 0 | this->Makefile->IssueMessage( |
5422 | 0 | MessageType::FATAL_ERROR, |
5423 | 0 | cmStrCat(R"(The "CXX_MODULE_STD" property on the target ")", |
5424 | 0 | this->GetName(), "\" is not a valid generator expression.")); |
5425 | 0 | return false; |
5426 | 0 | } |
5427 | | // But do not allow context-sensitive queries. Whether a target uses |
5428 | | // `import std` should not depend on configuration or properties of the |
5429 | | // consumer (head target). The link language also shouldn't matter, so ban |
5430 | | // it as well. |
5431 | 0 | if (cge->GetHadHeadSensitiveCondition()) { |
5432 | | // Not reachable; all target-sensitive genexes actually fail to parse. |
5433 | 0 | this->Makefile->IssueMessage( |
5434 | 0 | MessageType::FATAL_ERROR, |
5435 | 0 | cmStrCat(R"(The "CXX_MODULE_STD" property on the target ")", |
5436 | 0 | this->GetName(), |
5437 | 0 | "\" contains a condition that queries the " |
5438 | 0 | "consuming target which is not supported.")); |
5439 | 0 | return false; |
5440 | 0 | } |
5441 | 0 | if (cge->GetHadLinkLanguageSensitiveCondition()) { |
5442 | | // Not reachable; all link language genexes actually fail to parse. |
5443 | 0 | this->Makefile->IssueMessage( |
5444 | 0 | MessageType::FATAL_ERROR, |
5445 | 0 | cmStrCat(R"(The "CXX_MODULE_STD" property on the target ")", |
5446 | 0 | this->GetName(), |
5447 | 0 | "\" contains a condition that queries the " |
5448 | 0 | "link language which is not supported.")); |
5449 | 0 | return false; |
5450 | 0 | } |
5451 | 0 | std_prop_value = cge->Evaluate(this->LocalGenerator, ""); |
5452 | 0 | if (cge->GetHadContextSensitiveCondition()) { |
5453 | 0 | this->Makefile->IssueMessage( |
5454 | 0 | MessageType::FATAL_ERROR, |
5455 | 0 | cmStrCat(R"(The "CXX_MODULE_STD" property on the target ")", |
5456 | 0 | this->GetName(), |
5457 | 0 | "\" contains a context-sensitive condition " |
5458 | 0 | "that is not supported.")); |
5459 | 0 | return false; |
5460 | 0 | } |
5461 | 0 | } |
5462 | 0 | auto use_std = cmIsOn(std_prop_value); |
5463 | | |
5464 | | // If we have a value and it is not true, there's nothing to do. |
5465 | 0 | if (std_prop && !use_std) { |
5466 | 0 | return true; |
5467 | 0 | } |
5468 | | |
5469 | 0 | for (auto const& config : configs) { |
5470 | 0 | if (this->HaveCxxModuleSupport(config) != Cxx20SupportLevel::Supported) { |
5471 | 0 | continue; |
5472 | 0 | } |
5473 | | |
5474 | 0 | cm::optional<cmStandardLevel> explicitLevel = |
5475 | 0 | this->GetExplicitStandardLevel("CXX", config); |
5476 | 0 | if (!explicitLevel || *explicitLevel < cxxStd23) { |
5477 | 0 | continue; |
5478 | 0 | } |
5479 | | |
5480 | 0 | auto const stdLevel = |
5481 | 0 | standardResolver.GetLevelString("CXX", *explicitLevel); |
5482 | 0 | auto const cxxTargetName = cmStrCat("__CMAKE::CXX", stdLevel); |
5483 | | |
5484 | | // Create the __CMAKE::CXX## target if it doesn't already exist |
5485 | 0 | if (!this->Makefile->FindTargetToUse(cxxTargetName) && |
5486 | 0 | !CreateCxxStdlibTarget(this->Makefile, this->LocalGenerator, |
5487 | 0 | this->GetName(), cxxTargetName, stdLevel, |
5488 | 0 | configs)) { |
5489 | 0 | return false; |
5490 | 0 | } |
5491 | | |
5492 | 0 | this->Target->AppendProperty( |
5493 | 0 | "LINK_LIBRARIES", |
5494 | 0 | cmStrCat("$<BUILD_LOCAL_INTERFACE:$<$<CONFIG:", config, |
5495 | 0 | ">:", cxxTargetName, ">>")); |
5496 | 0 | } |
5497 | | |
5498 | | // Check the experimental feature here. A toolchain may have |
5499 | | // skipped the check in the toolchain preparation logic. |
5500 | 0 | if (!cmExperimental::HasSupportEnabled( |
5501 | 0 | *this->Makefile, cmExperimental::Feature::CxxImportStd)) { |
5502 | 0 | this->Makefile->IssueMessage( |
5503 | 0 | MessageType::FATAL_ERROR, |
5504 | 0 | "Experimental `import std` support not enabled when detecting " |
5505 | 0 | "toolchain; it must be set before `CXX` is enabled (usually a " |
5506 | 0 | "`project()` call)."); |
5507 | 0 | return false; |
5508 | 0 | } |
5509 | | |
5510 | 0 | return true; |
5511 | 0 | } |
5512 | | |
5513 | | cmCxxModuleUsageEffects const& cmGeneratorTarget::GetCxxModuleUsageEffects() |
5514 | | const |
5515 | 0 | { |
5516 | 0 | if (!this->CxxModuleUsageEffects) { |
5517 | 0 | this->CxxModuleUsageEffects.emplace(this); |
5518 | 0 | } |
5519 | |
|
5520 | 0 | return *this->CxxModuleUsageEffects; |
5521 | 0 | } |
5522 | | |
5523 | | cmGeneratorTarget const* cmGeneratorTarget::GetTargetForCxxModules( |
5524 | | std::string const& config, cmGeneratorTarget const& bmiConsumer) const |
5525 | 0 | { |
5526 | 0 | auto const& consumingUsage = bmiConsumer.GetCxxModuleUsageEffects(); |
5527 | 0 | auto const& owningUsage = this->GetCxxModuleUsageEffects(); |
5528 | 0 | if (consumingUsage.GetHash() == owningUsage.GetHash()) { |
5529 | 0 | if (this->IsImported()) { |
5530 | 0 | return this->GetCxxSyntheticTarget(config, *this); |
5531 | 0 | } |
5532 | 0 | return this; |
5533 | 0 | } |
5534 | | |
5535 | 0 | return this->GetCxxSyntheticTarget(config, bmiConsumer); |
5536 | 0 | } |
5537 | | |
5538 | | cmGeneratorTarget const* cmGeneratorTarget::GetCxxSyntheticTarget( |
5539 | | std::string const& config, cmGeneratorTarget const& bmiConsumer) const |
5540 | 0 | { |
5541 | 0 | auto const& usageHash = bmiConsumer.GetCxxModuleUsageEffects().GetHash(); |
5542 | 0 | auto cached = this->SynthCxxTargets.find(usageHash); |
5543 | 0 | if (cached != this->SynthCxxTargets.end()) { |
5544 | 0 | return cached->second; |
5545 | 0 | } |
5546 | | |
5547 | 0 | auto targetNameBase = this->GetName(); |
5548 | 0 | if (this->IsImported()) { |
5549 | 0 | cmSystemTools::ReplaceString(targetNameBase, "::", "__"); |
5550 | 0 | } |
5551 | 0 | auto const targetName = |
5552 | 0 | cmStrCat(targetNameBase, "@synth_", this->SynthCxxTargets.size()); |
5553 | |
|
5554 | 0 | std::vector<std::string> allConfigs = |
5555 | 0 | this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); |
5556 | 0 | auto const* model = this->Target; |
5557 | 0 | auto* mf = this->Makefile; |
5558 | 0 | auto* lg = this->GetLocalGenerator(); |
5559 | 0 | auto* tgt = |
5560 | 0 | mf->AddSynthesizedTarget(cmStateEnums::INTERFACE_LIBRARY, targetName); |
5561 | | |
5562 | | // Copy relevant information from the existing target. |
5563 | | |
5564 | | // Copy policies to the target. |
5565 | 0 | tgt->CopyPolicyStatuses(model); |
5566 | | |
5567 | | // Copy file sets. |
5568 | 0 | { |
5569 | 0 | for (auto const* gfs : |
5570 | 0 | this->GetInterfaceFileSets(cm::FileSetMetadata::CXX_MODULES)) { |
5571 | 0 | auto* newFs = |
5572 | 0 | tgt |
5573 | 0 | ->GetOrCreateFileSet(gfs->GetName(), gfs->GetType(), |
5574 | 0 | cm::FileSetMetadata::Visibility::Public) |
5575 | 0 | .first; |
5576 | 0 | newFs->CopyEntries(gfs->GetFileSet()); |
5577 | 0 | } |
5578 | 0 | } |
5579 | | |
5580 | | // Copy properties which effect consumer compatibility |
5581 | 0 | tgt->CopyUsageEffects(bmiConsumer.Target); |
5582 | | |
5583 | | // Copy properties which don't effect consumer compatibility |
5584 | 0 | tgt->CopyCxxModulesEntries(model); |
5585 | | |
5586 | | // Copy other properties which may affect the C++ module BMI generation. |
5587 | 0 | tgt->CopyCxxModulesProperties(model); |
5588 | |
|
5589 | 0 | tgt->AddLinkLibrary(*mf, cmStrCat("$<COMPILE_ONLY:", model->GetName(), '>'), |
5590 | 0 | GENERAL_LibraryType); |
5591 | | |
5592 | | // Create the generator target and attach it to the local generator. |
5593 | 0 | auto gtp = cm::make_unique<cmGeneratorTarget>(tgt, lg); |
5594 | 0 | auto* syntheticTarget = gtp.get(); |
5595 | | |
5596 | | // See `localGen->ComputeTargetCompileFeatures()` call in |
5597 | | // `cmGlobalGenerator::Compute` for where non-synthetic targets resolve |
5598 | | // this. |
5599 | 0 | for (auto const& innerConfig : allConfigs) { |
5600 | 0 | gtp->ComputeCompileFeatures(innerConfig); |
5601 | 0 | } |
5602 | | // See `cmGlobalGenerator::ApplyCXXStdTargets` in |
5603 | | // `cmGlobalGenerator::Compute` for non-synthetic target resolutions. |
5604 | 0 | if (!gtp->ApplyCXXStdTargets()) { |
5605 | 0 | return nullptr; |
5606 | 0 | } |
5607 | | |
5608 | 0 | lg->AddGeneratorTarget(std::move(gtp)); |
5609 | 0 | this->SynthCxxTargets[usageHash] = syntheticTarget; |
5610 | 0 | if (!syntheticTarget->DiscoverSyntheticTargets(config, &bmiConsumer)) { |
5611 | 0 | return nullptr; |
5612 | 0 | } |
5613 | | |
5614 | 0 | return syntheticTarget; |
5615 | 0 | } |
5616 | | |
5617 | | bool cmGeneratorTarget::DiscoverSyntheticTargets( |
5618 | | std::string const& config, cmGeneratorTarget const* bmiConsumer) |
5619 | 0 | { |
5620 | 0 | auto& configInfo = this->Configs[config]; |
5621 | 0 | cmOptionalLinkImplementation impl; |
5622 | 0 | this->ComputeLinkImplementationLibraries(config, impl, UseTo::Link); |
5623 | |
|
5624 | 0 | if (!bmiConsumer) { |
5625 | 0 | bmiConsumer = this; |
5626 | 0 | } |
5627 | |
|
5628 | 0 | auto& SyntheticDeps = configInfo.SyntheticDeps; |
5629 | |
|
5630 | 0 | for (auto const& entry : impl.Libraries) { |
5631 | 0 | auto const* gt = entry.Target; |
5632 | 0 | if (!gt || !gt->HaveInterfaceCxx20ModuleSources()) { |
5633 | 0 | continue; |
5634 | 0 | } |
5635 | | |
5636 | | // Visual Studio generators do not currently support BMI-only compilation, |
5637 | | // so they can't generate synthetic targets. For consuming native modules, |
5638 | | // skip so that the native target is used directly. For imported modules, |
5639 | | // create the synth target anyway and diagnose later, in the VS generator. |
5640 | 0 | if (!gt->IsImported() && this->GlobalGenerator->IsVisualStudio()) { |
5641 | 0 | continue; |
5642 | 0 | } |
5643 | | |
5644 | 0 | auto const* dep = gt->GetTargetForCxxModules(config, *bmiConsumer); |
5645 | 0 | if (!dep) { |
5646 | 0 | return false; |
5647 | 0 | } |
5648 | 0 | if (dep->IsSynthetic()) { |
5649 | 0 | SyntheticDeps[gt].push_back(dep); |
5650 | 0 | } |
5651 | 0 | } |
5652 | | |
5653 | 0 | return true; |
5654 | 0 | } |
5655 | | |
5656 | | cmGeneratorTarget::SyntheticDepsMap const& cmGeneratorTarget::GetSyntheticDeps( |
5657 | | std::string const& config) const |
5658 | 0 | { |
5659 | 0 | return this->Configs[config].SyntheticDeps; |
5660 | 0 | } |
5661 | | |
5662 | | bool cmGeneratorTarget::HasPackageReferences() const |
5663 | 0 | { |
5664 | 0 | return this->IsInBuildSystem() && |
5665 | 0 | !this->GetProperty("VS_PACKAGE_REFERENCES")->empty(); |
5666 | 0 | } |
5667 | | |
5668 | | std::vector<std::string> cmGeneratorTarget::GetPackageReferences() const |
5669 | 0 | { |
5670 | 0 | cmList packageReferences; |
5671 | |
|
5672 | 0 | if (this->IsInBuildSystem()) { |
5673 | 0 | if (cmValue vsPackageReferences = |
5674 | 0 | this->GetProperty("VS_PACKAGE_REFERENCES")) { |
5675 | 0 | packageReferences.assign(*vsPackageReferences); |
5676 | 0 | } |
5677 | 0 | } |
5678 | |
|
5679 | 0 | return std::move(packageReferences.data()); |
5680 | 0 | } |
5681 | | |
5682 | | std::string cmGeneratorTarget::GetPDBDirectory(std::string const& config) const |
5683 | 0 | { |
5684 | 0 | if (OutputInfo const* info = this->GetOutputInfo(config)) { |
5685 | | // Return the directory in which the target will be built. |
5686 | 0 | return info->PdbDir; |
5687 | 0 | } |
5688 | 0 | return ""; |
5689 | 0 | } |
5690 | | |
5691 | | bool cmGeneratorTarget::HasImplibGNUtoMS(std::string const& config) const |
5692 | 0 | { |
5693 | 0 | return this->HasImportLibrary(config) && this->GetPropertyAsBool("GNUtoMS"); |
5694 | 0 | } |
5695 | | |
5696 | | bool cmGeneratorTarget::GetImplibGNUtoMS(std::string const& config, |
5697 | | std::string const& gnuName, |
5698 | | std::string& out, |
5699 | | char const* newExt) const |
5700 | 0 | { |
5701 | 0 | if (this->HasImplibGNUtoMS(config) && gnuName.size() > 6 && |
5702 | 0 | gnuName.substr(gnuName.size() - 6) == ".dll.a") { |
5703 | 0 | out = cmStrCat(cm::string_view(gnuName).substr(0, gnuName.size() - 6), |
5704 | 0 | newExt ? newExt : ".lib"); |
5705 | 0 | return true; |
5706 | 0 | } |
5707 | 0 | return false; |
5708 | 0 | } |
5709 | | |
5710 | | bool cmGeneratorTarget::HasContextDependentSources() const |
5711 | 0 | { |
5712 | 0 | return this->SourcesAreContextDependent == Tribool::True; |
5713 | 0 | } |
5714 | | |
5715 | | bool cmGeneratorTarget::IsExecutableWithExports() const |
5716 | 0 | { |
5717 | 0 | return this->Target->IsExecutableWithExports(); |
5718 | 0 | } |
5719 | | |
5720 | | bool cmGeneratorTarget::IsSharedLibraryWithExports() const |
5721 | 0 | { |
5722 | 0 | return this->Target->IsSharedLibraryWithExports(); |
5723 | 0 | } |
5724 | | |
5725 | | bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const |
5726 | 0 | { |
5727 | 0 | bool generate_Stubs = true; |
5728 | 0 | if (this->GetGlobalGenerator()->IsXcode()) { |
5729 | | // take care of CMAKE_XCODE_ATTRIBUTE_GENERATE_TEXT_BASED_STUBS variable |
5730 | | // as well as XCODE_ATTRIBUTE_GENERATE_TEXT_BASED_STUBS property |
5731 | 0 | if (cmValue propGenStubs = |
5732 | 0 | this->GetProperty("XCODE_ATTRIBUTE_GENERATE_TEXT_BASED_STUBS")) { |
5733 | 0 | generate_Stubs = propGenStubs == "YES"; |
5734 | 0 | } else if (cmValue varGenStubs = this->Makefile->GetDefinition( |
5735 | 0 | "CMAKE_XCODE_ATTRIBUTE_GENERATE_TEXT_BASED_STUBS")) { |
5736 | 0 | generate_Stubs = varGenStubs == "YES"; |
5737 | 0 | } |
5738 | 0 | } |
5739 | |
|
5740 | 0 | return (this->IsDLLPlatform() && |
5741 | 0 | (this->GetType() == cmStateEnums::SHARED_LIBRARY || |
5742 | 0 | this->IsExecutableWithExports()) && |
5743 | | // Assemblies which have only managed code do not have |
5744 | | // import libraries. |
5745 | 0 | this->GetManagedType(config) != ManagedType::Managed) || |
5746 | 0 | (this->IsAIX() && this->IsExecutableWithExports()) || |
5747 | 0 | (this->Makefile->PlatformSupportsAppleTextStubs() && |
5748 | 0 | this->IsSharedLibraryWithExports() && generate_Stubs); |
5749 | 0 | } |
5750 | | |
5751 | | bool cmGeneratorTarget::NeedImportLibraryName(std::string const& config) const |
5752 | 0 | { |
5753 | 0 | return this->HasImportLibrary(config) || |
5754 | | // On DLL platforms we always generate the import library name |
5755 | | // just in case the sources have export markup. |
5756 | 0 | (this->IsDLLPlatform() && |
5757 | 0 | (this->GetType() == cmStateEnums::EXECUTABLE || |
5758 | 0 | this->GetType() == cmStateEnums::MODULE_LIBRARY)); |
5759 | 0 | } |
5760 | | |
5761 | | bool cmGeneratorTarget::GetUseShortObjectNames( |
5762 | | cmStateEnums::IntermediateDirKind kind) const |
5763 | 0 | { |
5764 | 0 | return this->LocalGenerator->UseShortObjectNames(kind); |
5765 | 0 | } |
5766 | | |
5767 | | cmObjectLocations::UseShortPath |
5768 | | cmGeneratorTarget::GetUseShortObjectNamesForInstall() const |
5769 | 0 | { |
5770 | 0 | auto prop = this->Target->GetProperty("INSTALL_OBJECT_NAME_STRATEGY"); |
5771 | 0 | if (prop == "SHORT"_s) { |
5772 | 0 | return cmObjectLocations::UseShortPath::Yes; |
5773 | 0 | } |
5774 | 0 | if (prop == "FULL"_s) { |
5775 | 0 | return cmObjectLocations::UseShortPath::No; |
5776 | 0 | } |
5777 | 0 | if (prop.IsSet()) { |
5778 | 0 | this->Makefile->IssueMessage( |
5779 | 0 | MessageType::FATAL_ERROR, |
5780 | 0 | cmStrCat("Property INSTALL_OBJECT_NAME_STRATEGY of target \"", |
5781 | 0 | this->GetName(), "\" set to the unsupported strategy ", prop)); |
5782 | 0 | } |
5783 | 0 | return cmObjectLocations::UseShortPath::No; |
5784 | 0 | } |
5785 | | |
5786 | | std::string cmGeneratorTarget::GetSupportDirectory( |
5787 | | cmStateEnums::IntermediateDirKind kind) const |
5788 | 0 | { |
5789 | 0 | cmLocalGenerator* lg = this->GetLocalGenerator(); |
5790 | 0 | auto targetDir = cmStrCat(lg->GetObjectOutputRoot(kind), '/', |
5791 | 0 | lg->GetTargetDirectory(this, kind)); |
5792 | |
|
5793 | 0 | #ifndef CMAKE_BOOTSTRAP |
5794 | 0 | auto& tdr = |
5795 | 0 | this->GetGlobalGenerator()->RegisterTargetDirectory(this, targetDir); |
5796 | 0 | if (tdr.CollidesWith && !tdr.Warned) { |
5797 | 0 | this->Makefile->IssueMessage( |
5798 | 0 | MessageType::WARNING, |
5799 | 0 | cmStrCat("The '", tdr.CollidesWith->GetName(), "' and '", |
5800 | 0 | this->GetName(), |
5801 | 0 | "' targets share an intermediate directory\n ", targetDir, |
5802 | 0 | "\nwhich may cause problems with the build graph. This project " |
5803 | 0 | "is not compatible with the `SHORT` target intermediate " |
5804 | 0 | "directory strategy. Possible remedies include: moving the " |
5805 | 0 | "target into different directories or renaming a target.")); |
5806 | 0 | tdr.Warned = true; |
5807 | 0 | } |
5808 | 0 | #endif |
5809 | |
|
5810 | 0 | return targetDir; |
5811 | 0 | } |
5812 | | |
5813 | | std::string cmGeneratorTarget::GetCMFSupportDirectory( |
5814 | | cmStateEnums::IntermediateDirKind kind) const |
5815 | 0 | { |
5816 | 0 | cmLocalGenerator* lg = this->GetLocalGenerator(); |
5817 | 0 | if (!lg->AlwaysUsesCMFPaths()) { |
5818 | 0 | return cmStrCat(lg->GetCurrentBinaryDirectory(), "/CMakeFiles/", |
5819 | 0 | lg->GetTargetDirectory(this, kind)); |
5820 | 0 | } |
5821 | 0 | return cmStrCat(lg->GetObjectOutputRoot(kind), '/', |
5822 | 0 | lg->GetTargetDirectory(this, kind)); |
5823 | 0 | } |
5824 | | |
5825 | | bool cmGeneratorTarget::IsLinkable() const |
5826 | 0 | { |
5827 | 0 | return (this->GetType() == cmStateEnums::STATIC_LIBRARY || |
5828 | 0 | this->GetType() == cmStateEnums::SHARED_LIBRARY || |
5829 | 0 | this->GetType() == cmStateEnums::MODULE_LIBRARY || |
5830 | 0 | this->GetType() == cmStateEnums::UNKNOWN_LIBRARY || |
5831 | 0 | this->GetType() == cmStateEnums::OBJECT_LIBRARY || |
5832 | 0 | this->GetType() == cmStateEnums::INTERFACE_LIBRARY || |
5833 | 0 | this->IsExecutableWithExports()); |
5834 | 0 | } |
5835 | | |
5836 | | bool cmGeneratorTarget::HasLinkDependencyFile(std::string const& config) const |
5837 | 0 | { |
5838 | 0 | if (this->GetType() != cmStateEnums::EXECUTABLE && |
5839 | 0 | this->GetType() != cmStateEnums::SHARED_LIBRARY && |
5840 | 0 | this->GetType() != cmStateEnums::MODULE_LIBRARY) { |
5841 | 0 | return false; |
5842 | 0 | } |
5843 | | |
5844 | 0 | if (this->Target->GetProperty("LINK_DEPENDS_NO_SHARED").IsOn()) { |
5845 | | // Do not use the linker dependency file because it includes shared |
5846 | | // libraries as well |
5847 | 0 | return false; |
5848 | 0 | } |
5849 | | |
5850 | 0 | std::string const depsUseLinker{ "CMAKE_LINK_DEPENDS_USE_LINKER" }; |
5851 | 0 | auto linkLanguage = this->GetLinkerLanguage(config); |
5852 | 0 | std::string const langDepsUseLinker{ cmStrCat("CMAKE_", linkLanguage, |
5853 | 0 | "_LINK_DEPENDS_USE_LINKER") }; |
5854 | |
|
5855 | 0 | return (!this->Makefile->IsDefinitionSet(depsUseLinker) || |
5856 | 0 | this->Makefile->IsOn(depsUseLinker)) && |
5857 | 0 | this->Makefile->IsOn(langDepsUseLinker); |
5858 | 0 | } |
5859 | | |
5860 | | bool cmGeneratorTarget::IsFrameworkOnApple() const |
5861 | 0 | { |
5862 | 0 | return this->Target->IsFrameworkOnApple(); |
5863 | 0 | } |
5864 | | |
5865 | | bool cmGeneratorTarget::IsArchivedAIXSharedLibrary() const |
5866 | 0 | { |
5867 | 0 | return this->Target->IsArchivedAIXSharedLibrary(); |
5868 | 0 | } |
5869 | | |
5870 | | bool cmGeneratorTarget::IsImportedFrameworkFolderOnApple( |
5871 | | std::string const& config) const |
5872 | 0 | { |
5873 | 0 | if (this->IsApple() && this->IsImported() && |
5874 | 0 | (this->GetType() == cmStateEnums::STATIC_LIBRARY || |
5875 | 0 | this->GetType() == cmStateEnums::SHARED_LIBRARY || |
5876 | 0 | this->GetType() == cmStateEnums::UNKNOWN_LIBRARY)) { |
5877 | 0 | std::string cfg = config; |
5878 | 0 | if (cfg.empty() && this->GetGlobalGenerator()->IsXcode()) { |
5879 | | // FIXME(#25515): Remove the need for this workaround. |
5880 | | // The Xcode generator queries include directories without any |
5881 | | // specific configuration. Pick one in case this target does |
5882 | | // not set either IMPORTED_LOCATION or IMPORTED_CONFIGURATIONS. |
5883 | 0 | cfg = |
5884 | 0 | this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig)[0]; |
5885 | 0 | } |
5886 | 0 | return cmSystemTools::IsPathToFramework(this->GetLocation(cfg)); |
5887 | 0 | } |
5888 | | |
5889 | 0 | return false; |
5890 | 0 | } |
5891 | | |
5892 | | bool cmGeneratorTarget::IsAppBundleOnApple() const |
5893 | 0 | { |
5894 | 0 | return this->Target->IsAppBundleOnApple(); |
5895 | 0 | } |
5896 | | |
5897 | | bool cmGeneratorTarget::IsXCTestOnApple() const |
5898 | 0 | { |
5899 | 0 | return (this->IsCFBundleOnApple() && this->GetPropertyAsBool("XCTEST")); |
5900 | 0 | } |
5901 | | |
5902 | | bool cmGeneratorTarget::IsCFBundleOnApple() const |
5903 | 0 | { |
5904 | 0 | return (this->GetType() == cmStateEnums::MODULE_LIBRARY && this->IsApple() && |
5905 | 0 | this->GetPropertyAsBool("BUNDLE")); |
5906 | 0 | } |
5907 | | |
5908 | | cmGeneratorTarget::ManagedType cmGeneratorTarget::CheckManagedType( |
5909 | | std::string const& propval) const |
5910 | 0 | { |
5911 | | // The type of the managed assembly (mixed unmanaged C++ and C++/CLI, |
5912 | | // or only C++/CLI) does only depend on whether the property is an empty |
5913 | | // string or contains any value at all. In Visual Studio generators |
5914 | | // this propval is prepended with /clr[:] which results in: |
5915 | | // |
5916 | | // 1. propval does not exist: no /clr flag, unmanaged target, has import |
5917 | | // lib |
5918 | | // 2. empty propval: add /clr as flag, mixed unmanaged/managed |
5919 | | // target, has import lib |
5920 | | // 3. netcore propval: add /clr:netcore as flag, mixed |
5921 | | // unmanaged/managed target, has import lib. |
5922 | | // 4. any value (safe,pure): add /clr:[propval] as flag, target with |
5923 | | // managed code only, no import lib |
5924 | 0 | if (propval.empty() || propval == "netcore") { |
5925 | 0 | return ManagedType::Mixed; |
5926 | 0 | } |
5927 | 0 | return ManagedType::Managed; |
5928 | 0 | } |
5929 | | |
5930 | | cmGeneratorTarget::ManagedType cmGeneratorTarget::GetManagedType( |
5931 | | std::string const& config) const |
5932 | 0 | { |
5933 | | // Only libraries and executables can be managed targets. |
5934 | 0 | if (this->GetType() > cmStateEnums::SHARED_LIBRARY) { |
5935 | 0 | return ManagedType::Undefined; |
5936 | 0 | } |
5937 | | |
5938 | 0 | if (this->GetType() == cmStateEnums::STATIC_LIBRARY) { |
5939 | 0 | return ManagedType::Native; |
5940 | 0 | } |
5941 | | |
5942 | | // Check imported target. |
5943 | 0 | if (this->IsImported()) { |
5944 | 0 | if (cmGeneratorTarget::ImportInfo const* info = |
5945 | 0 | this->GetImportInfo(config)) { |
5946 | 0 | return info->Managed; |
5947 | 0 | } |
5948 | 0 | return ManagedType::Undefined; |
5949 | 0 | } |
5950 | | |
5951 | | // Check for explicitly set clr target property. |
5952 | 0 | if (cmValue clr = this->GetProperty("COMMON_LANGUAGE_RUNTIME")) { |
5953 | 0 | return this->CheckManagedType(*clr); |
5954 | 0 | } |
5955 | | |
5956 | | // C# targets are always managed. This language specific check |
5957 | | // is added to avoid that the COMMON_LANGUAGE_RUNTIME target property |
5958 | | // has to be set manually for C# targets. |
5959 | 0 | return this->IsCSharpOnly() ? ManagedType::Managed : ManagedType::Native; |
5960 | 0 | } |
5961 | | |
5962 | | std::string cmGeneratorTarget::GetImportedXcFrameworkPath( |
5963 | | std::string const& config) const |
5964 | 0 | { |
5965 | 0 | if (!(this->IsApple() && this->IsImported() && |
5966 | 0 | (this->GetType() == cmStateEnums::SHARED_LIBRARY || |
5967 | 0 | this->GetType() == cmStateEnums::STATIC_LIBRARY || |
5968 | 0 | this->GetType() == cmStateEnums::UNKNOWN_LIBRARY))) { |
5969 | 0 | return {}; |
5970 | 0 | } |
5971 | | |
5972 | 0 | std::string desiredConfig = config; |
5973 | 0 | if (config.empty()) { |
5974 | 0 | desiredConfig = "NOCONFIG"; |
5975 | 0 | } |
5976 | |
|
5977 | 0 | std::string result; |
5978 | |
|
5979 | 0 | cmValue loc = nullptr; |
5980 | 0 | cmValue imp = nullptr; |
5981 | 0 | std::string suffix; |
5982 | |
|
5983 | 0 | if (this->Target->GetMappedConfig(desiredConfig, loc, imp, suffix)) { |
5984 | 0 | if (loc) { |
5985 | 0 | result = *loc; |
5986 | 0 | } else { |
5987 | 0 | std::string impProp = cmStrCat("IMPORTED_LOCATION", suffix); |
5988 | 0 | if (cmValue configLocation = this->GetProperty(impProp)) { |
5989 | 0 | result = *configLocation; |
5990 | 0 | } else if (cmValue location = this->GetProperty("IMPORTED_LOCATION")) { |
5991 | 0 | result = *location; |
5992 | 0 | } |
5993 | 0 | } |
5994 | |
|
5995 | 0 | if (cmSystemTools::IsPathToXcFramework(result)) { |
5996 | 0 | return result; |
5997 | 0 | } |
5998 | 0 | } |
5999 | | |
6000 | 0 | return {}; |
6001 | 0 | } |
6002 | | |
6003 | | bool cmGeneratorTarget::HaveFortranSources(std::string const& config) const |
6004 | 0 | { |
6005 | 0 | auto sources = this->GetSourceFiles(config); |
6006 | 0 | bool const have_direct = std::any_of( |
6007 | 0 | sources.begin(), sources.end(), [](BT<cmSourceFile*> const& sf) -> bool { |
6008 | 0 | return sf.Value->GetLanguage() == "Fortran"_s; |
6009 | 0 | }); |
6010 | 0 | bool have_via_target_objects = false; |
6011 | 0 | if (!have_direct) { |
6012 | 0 | auto const sourceObjectLibraries = this->GetSourceObjectLibraries(config); |
6013 | 0 | have_via_target_objects = |
6014 | 0 | std::any_of(sourceObjectLibraries.begin(), sourceObjectLibraries.end(), |
6015 | 0 | [&config](cmGeneratorTarget const* tgt) -> bool { |
6016 | 0 | return tgt->HaveFortranSources(config); |
6017 | 0 | }); |
6018 | 0 | } |
6019 | 0 | return have_direct || have_via_target_objects; |
6020 | 0 | } |
6021 | | |
6022 | | bool cmGeneratorTarget::HaveFortranSources() const |
6023 | 0 | { |
6024 | 0 | auto sources = this->GetAllConfigSources(); |
6025 | 0 | bool const have_direct = std::any_of( |
6026 | 0 | sources.begin(), sources.end(), [](AllConfigSource const& sf) -> bool { |
6027 | 0 | return sf.Source->GetLanguage() == "Fortran"_s; |
6028 | 0 | }); |
6029 | 0 | bool have_via_target_objects = false; |
6030 | 0 | if (!have_direct) { |
6031 | 0 | std::vector<std::string> configs = |
6032 | 0 | this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig); |
6033 | 0 | for (auto const& config : configs) { |
6034 | 0 | auto const sourceObjectLibraries = |
6035 | 0 | this->GetSourceObjectLibraries(config); |
6036 | 0 | have_via_target_objects = |
6037 | 0 | std::any_of(sourceObjectLibraries.begin(), sourceObjectLibraries.end(), |
6038 | 0 | [&config](cmGeneratorTarget const* tgt) -> bool { |
6039 | 0 | return tgt->HaveFortranSources(config); |
6040 | 0 | }); |
6041 | 0 | if (have_via_target_objects) { |
6042 | 0 | break; |
6043 | 0 | } |
6044 | 0 | } |
6045 | 0 | } |
6046 | 0 | return have_direct || have_via_target_objects; |
6047 | 0 | } |
6048 | | |
6049 | | bool cmGeneratorTarget::HaveInterfaceCxx20ModuleSources() const |
6050 | 0 | { |
6051 | 0 | return !this->GetInterfaceFileSets(cm::FileSetMetadata::CXX_MODULES).empty(); |
6052 | 0 | } |
6053 | | bool cmGeneratorTarget::HaveCxx20ModuleSources() const |
6054 | 0 | { |
6055 | 0 | return !this->GetFileSets(cm::FileSetMetadata::CXX_MODULES).empty() || |
6056 | 0 | !this->GetInterfaceFileSets(cm::FileSetMetadata::CXX_MODULES).empty(); |
6057 | 0 | } |
6058 | | |
6059 | | cmGeneratorTarget::Cxx20SupportLevel cmGeneratorTarget::HaveCxxModuleSupport( |
6060 | | std::string const& config) const |
6061 | 0 | { |
6062 | 0 | auto const* state = this->Makefile->GetState(); |
6063 | 0 | if (!state->GetLanguageEnabled("CXX")) { |
6064 | 0 | return Cxx20SupportLevel::MissingCxx; |
6065 | 0 | } |
6066 | | |
6067 | 0 | cmValue standardDefault = |
6068 | 0 | this->Makefile->GetDefinition("CMAKE_CXX_STANDARD_DEFAULT"); |
6069 | 0 | if (!standardDefault || standardDefault->empty()) { |
6070 | | // We do not know any meaningful C++ standard levels for this compiler. |
6071 | 0 | return Cxx20SupportLevel::NoCxx20; |
6072 | 0 | } |
6073 | | |
6074 | 0 | cmStandardLevelResolver standardResolver(this->Makefile); |
6075 | 0 | cmStandardLevel const cxxStd20 = |
6076 | 0 | *standardResolver.LanguageStandardLevel("CXX", "20"); |
6077 | 0 | cm::optional<cmStandardLevel> explicitLevel = |
6078 | 0 | this->GetExplicitStandardLevel("CXX", config); |
6079 | 0 | if (!explicitLevel || *explicitLevel < cxxStd20) { |
6080 | 0 | return Cxx20SupportLevel::NoCxx20; |
6081 | 0 | } |
6082 | | |
6083 | 0 | cmValue scandepRule = |
6084 | 0 | this->Makefile->GetDefinition("CMAKE_CXX_SCANDEP_SOURCE"); |
6085 | 0 | if (!scandepRule) { |
6086 | 0 | return Cxx20SupportLevel::MissingRule; |
6087 | 0 | } |
6088 | 0 | return Cxx20SupportLevel::Supported; |
6089 | 0 | } |
6090 | | |
6091 | | void cmGeneratorTarget::CheckCxxModuleStatus(std::string const& config) const |
6092 | 0 | { |
6093 | 0 | bool haveScannableSources = false; |
6094 | | |
6095 | | // Check for `CXX_MODULE*` file sets and a lack of support. |
6096 | 0 | if (this->HaveCxx20ModuleSources()) { |
6097 | 0 | haveScannableSources = true; |
6098 | 0 | } |
6099 | |
|
6100 | 0 | if (!haveScannableSources) { |
6101 | | // Check to see if there are regular sources that have requested scanning. |
6102 | 0 | auto sources = this->GetSourceFiles(config); |
6103 | 0 | for (auto const& source : sources) { |
6104 | 0 | auto const* sf = source.Value; |
6105 | 0 | auto const& lang = sf->GetLanguage(); |
6106 | 0 | if (lang != "CXX"_s) { |
6107 | 0 | continue; |
6108 | 0 | } |
6109 | | // Ignore sources which do not need dyndep. |
6110 | 0 | if (this->NeedDyndepForSource(lang, config, sf)) { |
6111 | 0 | haveScannableSources = true; |
6112 | 0 | } |
6113 | 0 | } |
6114 | 0 | } |
6115 | | |
6116 | | // If there isn't anything scannable, ignore it. |
6117 | 0 | if (!haveScannableSources) { |
6118 | 0 | return; |
6119 | 0 | } |
6120 | | |
6121 | | // If the generator doesn't support modules at all, error that we have |
6122 | | // sources that require the support. |
6123 | 0 | if (!this->GetGlobalGenerator()->CheckCxxModuleSupport( |
6124 | 0 | cmGlobalGenerator::CxxModuleSupportQuery::Expected)) { |
6125 | 0 | this->Makefile->IssueMessage( |
6126 | 0 | MessageType::FATAL_ERROR, |
6127 | 0 | cmStrCat("The target named \"", this->GetName(), |
6128 | 0 | "\" has C++ sources that may use modules, but modules are not " |
6129 | 0 | "supported by this generator:\n ", |
6130 | 0 | this->GetGlobalGenerator()->GetName(), |
6131 | 0 | "\n" |
6132 | 0 | "Modules are supported only by Ninja, Ninja Multi-Config, " |
6133 | 0 | "and Visual Studio generators for VS 17.4 and newer. " |
6134 | 0 | "See the cmake-cxxmodules(7) manual for details. " |
6135 | 0 | "Use the CMAKE_CXX_SCAN_FOR_MODULES variable to enable or " |
6136 | 0 | "disable scanning.")); |
6137 | 0 | return; |
6138 | 0 | } |
6139 | | |
6140 | 0 | switch (this->HaveCxxModuleSupport(config)) { |
6141 | 0 | case cmGeneratorTarget::Cxx20SupportLevel::MissingCxx: |
6142 | 0 | this->Makefile->IssueMessage( |
6143 | 0 | MessageType::FATAL_ERROR, |
6144 | 0 | cmStrCat("The target named \"", this->GetName(), |
6145 | 0 | "\" has C++ sources that use modules, but the \"CXX\" " |
6146 | 0 | "language has not been enabled.")); |
6147 | 0 | break; |
6148 | 0 | case cmGeneratorTarget::Cxx20SupportLevel::NoCxx20: { |
6149 | 0 | cmStandardLevelResolver standardResolver(this->Makefile); |
6150 | 0 | auto effStandard = |
6151 | 0 | standardResolver.GetEffectiveStandard(this, "CXX", config); |
6152 | 0 | if (effStandard.empty()) { |
6153 | 0 | effStandard = "; no C++ standard found"; |
6154 | 0 | } else { |
6155 | 0 | effStandard = cmStrCat("; found \"cxx_std_", effStandard, '"'); |
6156 | 0 | } |
6157 | 0 | this->Makefile->IssueMessage( |
6158 | 0 | MessageType::FATAL_ERROR, |
6159 | 0 | cmStrCat( |
6160 | 0 | "The target named \"", this->GetName(), |
6161 | 0 | "\" has C++ sources that use modules, but does not include " |
6162 | 0 | "\"cxx_std_20\" (or newer) among its `target_compile_features`", |
6163 | 0 | effStandard, '.')); |
6164 | 0 | } break; |
6165 | 0 | case cmGeneratorTarget::Cxx20SupportLevel::MissingRule: { |
6166 | 0 | this->Makefile->IssueMessage( |
6167 | 0 | MessageType::FATAL_ERROR, |
6168 | 0 | cmStrCat("The target named \"", this->GetName(), |
6169 | 0 | "\" has C++ sources that may use modules, but the compiler " |
6170 | 0 | "does not provide a way to discover the import graph " |
6171 | 0 | "dependencies. See the cmake-cxxmodules(7) manual for " |
6172 | 0 | "details. Use the CMAKE_CXX_SCAN_FOR_MODULES variable to " |
6173 | 0 | "enable or disable scanning.")); |
6174 | 0 | } break; |
6175 | 0 | case cmGeneratorTarget::Cxx20SupportLevel::Supported: |
6176 | | // All is well. |
6177 | 0 | break; |
6178 | 0 | } |
6179 | 0 | } |
6180 | | |
6181 | | bool cmGeneratorTarget::NeedCxxModuleSupport(std::string const& lang, |
6182 | | std::string const& config) const |
6183 | 0 | { |
6184 | 0 | if (lang != "CXX"_s) { |
6185 | 0 | return false; |
6186 | 0 | } |
6187 | 0 | return this->HaveCxxModuleSupport(config) == Cxx20SupportLevel::Supported && |
6188 | 0 | this->GetGlobalGenerator()->CheckCxxModuleSupport( |
6189 | 0 | cmGlobalGenerator::CxxModuleSupportQuery::Inspect); |
6190 | 0 | } |
6191 | | |
6192 | | bool cmGeneratorTarget::NeedDyndep(std::string const& lang, |
6193 | | std::string const& config) const |
6194 | 0 | { |
6195 | 0 | return lang == "Fortran"_s || this->NeedCxxModuleSupport(lang, config); |
6196 | 0 | } |
6197 | | |
6198 | | bool cmGeneratorTarget::NeedDyndepForSource(std::string const& lang, |
6199 | | std::string const& config, |
6200 | | cmSourceFile const* sf) const |
6201 | 0 | { |
6202 | | // Fortran always needs to be scanned. |
6203 | 0 | if (lang == "Fortran"_s) { |
6204 | 0 | return true; |
6205 | 0 | } |
6206 | | // Only C++ code needs scanned otherwise. |
6207 | 0 | if (lang != "CXX"_s) { |
6208 | 0 | return false; |
6209 | 0 | } |
6210 | | |
6211 | | // Any file in `CXX_MODULES` file sets need scanned (it being `CXX` is |
6212 | | // enforced elsewhere). |
6213 | 0 | auto const* fs = this->GetFileSetForSource(config, sf); |
6214 | 0 | if (fs && fs->GetType() == cm::FileSetMetadata::CXX_MODULES) { |
6215 | 0 | return true; |
6216 | 0 | } |
6217 | | |
6218 | 0 | auto targetDyndep = this->NeedCxxDyndep(config); |
6219 | 0 | if (targetDyndep == CxxModuleSupport::Unavailable) { |
6220 | 0 | return false; |
6221 | 0 | } |
6222 | 0 | if (fs) { |
6223 | 0 | auto const fsProp = fs->GetProperty("CXX_SCAN_FOR_MODULES"); |
6224 | 0 | if (fsProp.IsSet()) { |
6225 | 0 | return fsProp.IsOn(); |
6226 | 0 | } |
6227 | 0 | } |
6228 | 0 | auto const sfProp = sf->GetProperty("CXX_SCAN_FOR_MODULES"); |
6229 | 0 | if (sfProp.IsSet()) { |
6230 | 0 | return sfProp.IsOn(); |
6231 | 0 | } |
6232 | 0 | return targetDyndep == CxxModuleSupport::Enabled; |
6233 | 0 | } |
6234 | | |
6235 | | cmGeneratorTarget::CxxModuleSupport cmGeneratorTarget::NeedCxxDyndep( |
6236 | | std::string const& config) const |
6237 | 0 | { |
6238 | 0 | bool haveRule = false; |
6239 | 0 | switch (this->HaveCxxModuleSupport(config)) { |
6240 | 0 | case Cxx20SupportLevel::MissingCxx: |
6241 | 0 | case Cxx20SupportLevel::NoCxx20: |
6242 | 0 | return CxxModuleSupport::Unavailable; |
6243 | 0 | case Cxx20SupportLevel::MissingRule: |
6244 | 0 | break; |
6245 | 0 | case Cxx20SupportLevel::Supported: |
6246 | 0 | haveRule = true; |
6247 | 0 | break; |
6248 | 0 | } |
6249 | 0 | bool haveGeneratorSupport = |
6250 | 0 | this->GetGlobalGenerator()->CheckCxxModuleSupport( |
6251 | 0 | cmGlobalGenerator::CxxModuleSupportQuery::Inspect); |
6252 | 0 | auto const tgtProp = this->GetProperty("CXX_SCAN_FOR_MODULES"); |
6253 | 0 | if (tgtProp.IsSet()) { |
6254 | 0 | return tgtProp.IsOn() ? CxxModuleSupport::Enabled |
6255 | 0 | : CxxModuleSupport::Disabled; |
6256 | 0 | } |
6257 | | |
6258 | 0 | CxxModuleSupport policyAnswer = CxxModuleSupport::Unavailable; |
6259 | 0 | switch (this->GetPolicyStatusCMP0155()) { |
6260 | 0 | case cmPolicies::WARN: |
6261 | 0 | case cmPolicies::OLD: |
6262 | | // The OLD behavior is to not scan the source. |
6263 | 0 | policyAnswer = CxxModuleSupport::Disabled; |
6264 | 0 | break; |
6265 | 0 | case cmPolicies::NEW: |
6266 | | // The NEW behavior is to scan the source if the compiler supports |
6267 | | // scanning and the generator supports it. |
6268 | 0 | if (haveRule && haveGeneratorSupport) { |
6269 | 0 | policyAnswer = CxxModuleSupport::Enabled; |
6270 | 0 | } else { |
6271 | 0 | policyAnswer = CxxModuleSupport::Disabled; |
6272 | 0 | } |
6273 | 0 | break; |
6274 | 0 | } |
6275 | 0 | return policyAnswer; |
6276 | 0 | } |
6277 | | |
6278 | | bool cmGeneratorTarget::HasFileSets() const |
6279 | 0 | { |
6280 | 0 | return !this->FileSets->Empty(); |
6281 | 0 | } |
6282 | | |
6283 | | std::vector<cmGeneratorFileSet const*> const& |
6284 | | cmGeneratorTarget::GetAllFileSets() const |
6285 | 0 | { |
6286 | 0 | return this->FileSets->GetAllFileSets(); |
6287 | 0 | } |
6288 | | |
6289 | | std::vector<cmGeneratorFileSet const*> const& cmGeneratorTarget::GetFileSets( |
6290 | | cm::string_view type) const |
6291 | 0 | { |
6292 | 0 | return this->FileSets->GetFileSets(type); |
6293 | 0 | } |
6294 | | std::vector<cmGeneratorFileSet const*> const& |
6295 | | cmGeneratorTarget::GetInterfaceFileSets(cm::string_view type) const |
6296 | 0 | { |
6297 | 0 | return this->FileSets->GetInterfaceFileSets(type); |
6298 | 0 | } |
6299 | | |
6300 | | cmGeneratorFileSet const* cmGeneratorTarget::GetFileSet( |
6301 | | std::string const& name) const |
6302 | 0 | { |
6303 | 0 | return this->FileSets->GetFileSet(name); |
6304 | 0 | } |
6305 | | |
6306 | | cmGeneratorFileSet const* cmGeneratorTarget::GetFileSetForSource( |
6307 | | std::string const& config, cmSourceFile const* sf) const |
6308 | 0 | { |
6309 | 0 | return this->FileSets->GetFileSetForSource(config, sf); |
6310 | 0 | } |
6311 | | |
6312 | | std::string cmGeneratorTarget::BuildDatabasePath( |
6313 | | std::string const& lang, std::string const& config) const |
6314 | 0 | { |
6315 | | // Check to see if the target wants it. |
6316 | 0 | if (!this->GetPropertyAsBool("EXPORT_BUILD_DATABASE")) { |
6317 | 0 | return {}; |
6318 | 0 | } |
6319 | 0 | if (!cmExperimental::HasSupportEnabled( |
6320 | 0 | *this->Makefile, cmExperimental::Feature::ExportBuildDatabase)) { |
6321 | 0 | return {}; |
6322 | 0 | } |
6323 | | // Check to see if the generator supports it. |
6324 | 0 | if (!this->GetGlobalGenerator()->SupportsBuildDatabase()) { |
6325 | 0 | return {}; |
6326 | 0 | } |
6327 | | |
6328 | 0 | if (this->GetGlobalGenerator()->IsMultiConfig()) { |
6329 | 0 | return cmStrCat(this->GetSupportDirectory(), '/', config, '/', lang, |
6330 | 0 | "_build_database.json"); |
6331 | 0 | } |
6332 | | |
6333 | 0 | return cmStrCat(this->GetSupportDirectory(), '/', lang, |
6334 | 0 | "_build_database.json"); |
6335 | 0 | } |
6336 | | |
6337 | | std::string cmGeneratorTarget::GetSwiftPackageName() const |
6338 | 0 | { |
6339 | 0 | std::string packageName; |
6340 | 0 | if (cmValue projectName = this->GetProperty("Swift_PACKAGE_NAME")) { |
6341 | 0 | packageName = *projectName; |
6342 | 0 | } else if (this->GetPolicyStatusCMP0216() == cmPolicies::NEW) { |
6343 | 0 | packageName = this->Makefile->GetSafeDefinition("PROJECT_NAME"); |
6344 | 0 | } |
6345 | 0 | return packageName; |
6346 | 0 | } |
6347 | | |
6348 | | std::string cmGeneratorTarget::GetSwiftModuleName() const |
6349 | 0 | { |
6350 | 0 | if (cmValue name = this->GetProperty("Swift_MODULE_NAME")) { |
6351 | 0 | return *name; |
6352 | 0 | } |
6353 | | // Hyphens are not valid in Swift module identifiers. |
6354 | 0 | std::string name = this->GetName(); |
6355 | 0 | std::replace(name.begin(), name.end(), '-', '_'); |
6356 | 0 | return name; |
6357 | 0 | } |
6358 | | |
6359 | | std::string cmGeneratorTarget::GetSwiftModuleFileName() const |
6360 | 0 | { |
6361 | 0 | std::string moduleFilename = this->GetPropertyOrDefault( |
6362 | 0 | "Swift_MODULE", this->GetSwiftModuleName() + ".swiftmodule"); |
6363 | 0 | if (this->GetPolicyStatusCMP0195() == cmPolicies::NEW) { |
6364 | 0 | if (cmValue moduleTriple = |
6365 | 0 | this->Makefile->GetDefinition("CMAKE_Swift_MODULE_TRIPLE")) { |
6366 | 0 | moduleFilename = cmStrCat(std::move(moduleFilename), '/', *moduleTriple, |
6367 | 0 | ".swiftmodule"); |
6368 | 0 | } |
6369 | 0 | } |
6370 | 0 | return moduleFilename; |
6371 | 0 | } |
6372 | | |
6373 | | std::string cmGeneratorTarget::GetSwiftModuleDirectory( |
6374 | | std::string const& config) const |
6375 | 0 | { |
6376 | | // This is like the *_OUTPUT_DIRECTORY properties except that we don't have a |
6377 | | // separate per-configuration target property. |
6378 | | // |
6379 | | // The property expands generator expressions. Multi-config generators append |
6380 | | // a per-configuration subdirectory to the specified directory unless a |
6381 | | // generator expression is used. |
6382 | 0 | bool appendConfigDir = true; |
6383 | 0 | std::string moduleDirectory; |
6384 | |
|
6385 | 0 | if (cmValue value = this->GetProperty("Swift_MODULE_DIRECTORY")) { |
6386 | 0 | moduleDirectory = cmGeneratorExpression::Evaluate( |
6387 | 0 | *value, this->LocalGenerator, config, this); |
6388 | 0 | appendConfigDir = *value == moduleDirectory; |
6389 | 0 | } |
6390 | 0 | if (moduleDirectory.empty()) { |
6391 | 0 | moduleDirectory = this->LocalGenerator->GetCurrentBinaryDirectory(); |
6392 | 0 | } |
6393 | 0 | if (appendConfigDir) { |
6394 | 0 | this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig( |
6395 | 0 | "/", config, "", moduleDirectory); |
6396 | 0 | } |
6397 | 0 | return moduleDirectory; |
6398 | 0 | } |
6399 | | |
6400 | | std::string cmGeneratorTarget::GetSwiftModulePath( |
6401 | | std::string const& config) const |
6402 | 0 | { |
6403 | 0 | return cmStrCat(this->GetSwiftModuleDirectory(config), '/', |
6404 | 0 | this->GetSwiftModuleFileName()); |
6405 | 0 | } |
6406 | | |
6407 | | std::string cmGeneratorTarget::GetPropertyOrDefault( |
6408 | | std::string const& property, std::string defaultValue) const |
6409 | 0 | { |
6410 | 0 | if (cmValue name = this->GetProperty(property)) { |
6411 | 0 | return *name; |
6412 | 0 | } |
6413 | 0 | return defaultValue; |
6414 | 0 | } |