/src/CMake/Source/cmLinkItem.h
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 | | #pragma once |
4 | | |
5 | | #include "cmConfigure.h" // IWYU pragma: keep |
6 | | |
7 | | #include <map> |
8 | | #include <ostream> |
9 | | #include <string> |
10 | | #include <unordered_map> |
11 | | #include <vector> |
12 | | |
13 | | #include <cm/optional> |
14 | | #include <cmext/algorithm> |
15 | | |
16 | | #include "cmListFileCache.h" |
17 | | #include "cmSystemTools.h" |
18 | | #include "cmTargetLinkLibraryType.h" |
19 | | |
20 | | class cmGeneratorTarget; |
21 | | class cmSourceFile; |
22 | | |
23 | | // Basic information about each link item. |
24 | | class cmLinkItem |
25 | | { |
26 | | std::string String; |
27 | | |
28 | | public: |
29 | | // default feature: link library without decoration |
30 | | static std::string const DEFAULT; |
31 | | |
32 | 4 | cmLinkItem() = default; |
33 | | cmLinkItem(std::string s, bool c, cmListFileBacktrace bt, |
34 | | std::string feature = DEFAULT); |
35 | | cmLinkItem(cmGeneratorTarget const* t, bool c, cmListFileBacktrace bt, |
36 | | std::string feature = DEFAULT); |
37 | | std::string const& AsStr() const; |
38 | | cmGeneratorTarget const* Target = nullptr; |
39 | | // The source file representing the external object (used when linking |
40 | | // `$<TARGET_OBJECTS>`) |
41 | | cmSourceFile const* ObjectSource = nullptr; |
42 | | std::string Feature; |
43 | | bool Cross = false; |
44 | | // When the item was the result of a target's INTERFACE_LINK_LIBRARIES_DIRECT |
45 | | // property, that originating target is provided here |
46 | | cmGeneratorTarget const* InterfaceDirectFrom = nullptr; |
47 | | cmListFileBacktrace Backtrace; |
48 | | friend bool operator<(cmLinkItem const& l, cmLinkItem const& r); |
49 | | friend bool operator==(cmLinkItem const& l, cmLinkItem const& r); |
50 | | friend std::ostream& operator<<(std::ostream& os, cmLinkItem const& item); |
51 | | }; |
52 | | |
53 | | /** The link implementation specifies the direct library |
54 | | dependencies needed by the object files of the target. */ |
55 | | struct cmLinkImplementationLibraries |
56 | | { |
57 | | // Libraries linked directly in this configuration. |
58 | | std::vector<cmLinkItem> Libraries; |
59 | | |
60 | | // Object files linked directly in this configuration. |
61 | | std::vector<cmLinkItem> Objects; |
62 | | |
63 | | // Whether the list depends on a genex referencing the configuration. |
64 | | bool HadContextSensitiveCondition = false; |
65 | | }; |
66 | | |
67 | | struct cmLinkInterfaceLibraries |
68 | | { |
69 | | // Libraries listed in the interface. |
70 | | std::vector<cmLinkItem> Libraries; |
71 | | |
72 | | // Object files listed in the interface. |
73 | | std::vector<cmLinkItem> Objects; |
74 | | |
75 | | // Items to be included as if directly linked by the head target. |
76 | | std::vector<cmLinkItem> HeadInclude; |
77 | | |
78 | | // Items to be excluded from direct linking by the head target. |
79 | | std::vector<cmLinkItem> HeadExclude; |
80 | | |
81 | | // Whether the list depends on a genex referencing the head target. |
82 | | bool HadHeadSensitiveCondition = false; |
83 | | |
84 | | // Whether the list depends on a genex referencing the configuration. |
85 | | bool HadContextSensitiveCondition = false; |
86 | | }; |
87 | | |
88 | | struct cmLinkInterface : public cmLinkInterfaceLibraries |
89 | | { |
90 | | // Languages whose runtime libraries must be linked. |
91 | | std::vector<std::string> Languages; |
92 | | std::unordered_map<std::string, std::vector<cmLinkItem>> |
93 | | LanguageRuntimeLibraries; |
94 | | |
95 | | // Shared library dependencies needed for linking on some platforms. |
96 | | std::vector<cmLinkItem> SharedDeps; |
97 | | |
98 | | // Number of repetitions of a strongly connected component of two |
99 | | // or more static libraries. |
100 | | unsigned int Multiplicity = 0; |
101 | | |
102 | | // Whether the list depends on a link language genex. |
103 | | bool HadLinkLanguageSensitiveCondition = false; |
104 | | }; |
105 | | |
106 | | struct cmOptionalLinkInterface : public cmLinkInterface |
107 | | { |
108 | | bool LibrariesDone = false; |
109 | | bool AllDone = false; |
110 | | bool Exists = false; |
111 | | bool CheckLinkLibraries = false; |
112 | | }; |
113 | | |
114 | | struct cmHeadToLinkInterfaceMap |
115 | | : public std::map<cmGeneratorTarget const*, cmOptionalLinkInterface> |
116 | | { |
117 | | }; |
118 | | |
119 | | struct cmLinkImplementation : public cmLinkImplementationLibraries |
120 | | { |
121 | | // Languages whose runtime libraries must be linked. |
122 | | std::vector<std::string> Languages; |
123 | | std::unordered_map<std::string, std::vector<cmLinkItem>> |
124 | | LanguageRuntimeLibraries; |
125 | | |
126 | | // Whether the list depends on a link language genex. |
127 | | bool HadLinkLanguageSensitiveCondition = false; |
128 | | }; |
129 | | |
130 | | // Cache link implementation computation from each configuration. |
131 | | struct cmOptionalLinkImplementation : public cmLinkImplementation |
132 | | { |
133 | | bool LibrariesDone = false; |
134 | | bool LanguagesDone = false; |
135 | | bool HadHeadSensitiveCondition = false; |
136 | | bool CheckLinkLibraries = false; |
137 | | }; |
138 | | |
139 | | /** Compute the link type to use for the given configuration. */ |
140 | | inline cmTargetLinkLibraryType ComputeLinkType( |
141 | | std::string const& config, std::vector<std::string> const& debugConfigs) |
142 | 0 | { |
143 | | // No configuration is always optimized. |
144 | 0 | if (config.empty()) { |
145 | 0 | return OPTIMIZED_LibraryType; |
146 | 0 | } |
147 | | |
148 | | // Check if any entry in the list matches this configuration. |
149 | 0 | std::string configUpper = cmSystemTools::UpperCase(config); |
150 | 0 | if (cm::contains(debugConfigs, configUpper)) { |
151 | 0 | return DEBUG_LibraryType; |
152 | 0 | } |
153 | | // The current configuration is not a debug configuration. |
154 | 0 | return OPTIMIZED_LibraryType; |
155 | 0 | } |
156 | | |
157 | | // Parse LINK_LIBRARY genex markers. |
158 | | cm::optional<std::string> ParseLinkFeature(std::string const& item); |