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