1 function(get_system_libs return_var)
2 message(AUTHOR_WARNING "get_system_libs no longer needed")
3 set(${return_var} "" PARENT_SCOPE)
7 function(link_system_libs target)
8 message(AUTHOR_WARNING "link_system_libs no longer needed")
11 # is_llvm_target_library(
13 # Name of the LLVM library to check
15 # Output variable name
16 # ALL_TARGETS;INCLUDED_TARGETS;OMITTED_TARGETS
17 # ALL_TARGETS - default looks at the full list of known targets
18 # INCLUDED_TARGETS - looks only at targets being configured
19 # OMITTED_TARGETS - looks only at targets that are not being configured
21 function(is_llvm_target_library library return_var)
22 cmake_parse_arguments(ARG "ALL_TARGETS;INCLUDED_TARGETS;OMITTED_TARGETS" "" "" ${ARGN})
23 # Sets variable `return_var' to ON if `library' corresponds to a
24 # LLVM supported target. To OFF if it doesn't.
25 set(${return_var} OFF PARENT_SCOPE)
26 string(TOUPPER "${library}" capitalized_lib)
27 if(ARG_INCLUDED_TARGETS)
28 string(TOUPPER "${LLVM_TARGETS_TO_BUILD}" targets)
29 elseif(ARG_OMITTED_TARGETS)
30 set(omitted_targets ${LLVM_ALL_TARGETS})
31 list(REMOVE_ITEM omitted_targets "${LLVM_TARGETS_TO_BUILD}")
32 string(TOUPPER "${omitted_targets}" targets)
34 string(TOUPPER "${LLVM_ALL_TARGETS}" targets)
37 if( capitalized_lib STREQUAL t OR
38 capitalized_lib STREQUAL "${t}" OR
39 capitalized_lib STREQUAL "${t}DESC" OR
40 capitalized_lib STREQUAL "${t}CODEGEN" OR
41 capitalized_lib STREQUAL "${t}ASMPARSER" OR
42 capitalized_lib STREQUAL "${t}ASMPRINTER" OR
43 capitalized_lib STREQUAL "${t}DISASSEMBLER" OR
44 capitalized_lib STREQUAL "${t}INFO" OR
45 capitalized_lib STREQUAL "${t}UTILS" )
46 set(${return_var} ON PARENT_SCOPE)
50 endfunction(is_llvm_target_library)
52 function(is_llvm_target_specifier library return_var)
53 is_llvm_target_library(${library} ${return_var} ${ARGN})
54 string(TOUPPER "${library}" capitalized_lib)
56 if( capitalized_lib STREQUAL "ALLTARGETSASMPARSERS" OR
57 capitalized_lib STREQUAL "ALLTARGETSDESCS" OR
58 capitalized_lib STREQUAL "ALLTARGETSDISASSEMBLERS" OR
59 capitalized_lib STREQUAL "ALLTARGETSINFOS" OR
60 capitalized_lib STREQUAL "NATIVE" OR
61 capitalized_lib STREQUAL "NATIVECODEGEN" )
62 set(${return_var} ON PARENT_SCOPE)
67 macro(llvm_config executable)
68 cmake_parse_arguments(ARG "USE_SHARED" "" "" ${ARGN})
69 set(link_components ${ARG_UNPARSED_ARGUMENTS})
72 # If USE_SHARED is specified, then we link against libLLVM,
73 # but also against the component libraries below. This is
74 # done in case libLLVM does not contain all of the components
75 # the target requires.
77 # Strip LLVM_DYLIB_COMPONENTS out of link_components.
78 # To do this, we need special handling for "all", since that
79 # may imply linking to libraries that are not included in
82 if (DEFINED link_components AND DEFINED LLVM_DYLIB_COMPONENTS)
83 if("${LLVM_DYLIB_COMPONENTS}" STREQUAL "all")
84 set(link_components "")
86 list(REMOVE_ITEM link_components ${LLVM_DYLIB_COMPONENTS})
90 target_link_libraries(${executable} PRIVATE LLVM)
93 explicit_llvm_config(${executable} ${link_components})
97 function(explicit_llvm_config executable)
98 set( link_components ${ARGN} )
100 llvm_map_components_to_libnames(LIBRARIES ${link_components})
101 get_target_property(t ${executable} TYPE)
102 if(t STREQUAL "STATIC_LIBRARY")
103 target_link_libraries(${executable} INTERFACE ${LIBRARIES})
104 elseif(t STREQUAL "EXECUTABLE" OR t STREQUAL "SHARED_LIBRARY" OR t STREQUAL "MODULE_LIBRARY")
105 target_link_libraries(${executable} PRIVATE ${LIBRARIES})
107 # Use plain form for legacy user.
108 target_link_libraries(${executable} ${LIBRARIES})
110 endfunction(explicit_llvm_config)
114 function(llvm_map_components_to_libraries OUT_VAR)
115 message(AUTHOR_WARNING "Using llvm_map_components_to_libraries() is deprecated. Use llvm_map_components_to_libnames() instead")
116 explicit_map_components_to_libraries(result ${ARGN})
117 set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE )
118 endfunction(llvm_map_components_to_libraries)
120 # Expand pseudo-components into real components.
121 # Does not cover 'native', 'backend', or 'engine' as these require special
122 # handling. Also does not cover 'all' as we only have a list of the libnames
123 # available and not a list of the components.
124 function(llvm_expand_pseudo_components out_components)
125 set( link_components ${ARGN} )
126 foreach(c ${link_components})
127 # add codegen, asmprinter, asmparser, disassembler
128 list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
130 if( TARGET LLVM${c}CodeGen )
131 list(APPEND expanded_components "${c}CodeGen")
133 if( TARGET LLVM${c} )
134 list(APPEND expanded_components "${c}")
136 message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
139 if( TARGET LLVM${c}AsmPrinter )
140 list(APPEND expanded_components "${c}AsmPrinter")
142 if( TARGET LLVM${c}AsmParser )
143 list(APPEND expanded_components "${c}AsmParser")
145 if( TARGET LLVM${c}Desc )
146 list(APPEND expanded_components "${c}Desc")
148 if( TARGET LLVM${c}Disassembler )
149 list(APPEND expanded_components "${c}Disassembler")
151 if( TARGET LLVM${c}Info )
152 list(APPEND expanded_components "${c}Info")
154 if( TARGET LLVM${c}Utils )
155 list(APPEND expanded_components "${c}Utils")
157 elseif( c STREQUAL "nativecodegen" )
158 if( TARGET LLVM${LLVM_NATIVE_ARCH}CodeGen )
159 list(APPEND expanded_components "${LLVM_NATIVE_ARCH}CodeGen")
161 if( TARGET LLVM${LLVM_NATIVE_ARCH}Desc )
162 list(APPEND expanded_components "${LLVM_NATIVE_ARCH}Desc")
164 if( TARGET LLVM${LLVM_NATIVE_ARCH}Info )
165 list(APPEND expanded_components "${LLVM_NATIVE_ARCH}Info")
167 elseif( c STREQUAL "AllTargetsCodeGens" )
168 # Link all the codegens from all the targets
169 foreach(t ${LLVM_TARGETS_TO_BUILD})
170 if( TARGET LLVM${t}CodeGen)
171 list(APPEND expanded_components "${t}CodeGen")
174 elseif( c STREQUAL "AllTargetsAsmParsers" )
175 # Link all the asm parsers from all the targets
176 foreach(t ${LLVM_TARGETS_TO_BUILD})
177 if( TARGET LLVM${t}AsmParser )
178 list(APPEND expanded_components "${t}AsmParser")
181 elseif( c STREQUAL "AllTargetsDescs" )
182 # Link all the descs from all the targets
183 foreach(t ${LLVM_TARGETS_TO_BUILD})
184 if( TARGET LLVM${t}Desc )
185 list(APPEND expanded_components "${t}Desc")
188 elseif( c STREQUAL "AllTargetsDisassemblers" )
189 # Link all the disassemblers from all the targets
190 foreach(t ${LLVM_TARGETS_TO_BUILD})
191 if( TARGET LLVM${t}Disassembler )
192 list(APPEND expanded_components "${t}Disassembler")
195 elseif( c STREQUAL "AllTargetsInfos" )
196 # Link all the infos from all the targets
197 foreach(t ${LLVM_TARGETS_TO_BUILD})
198 if( TARGET LLVM${t}Info )
199 list(APPEND expanded_components "${t}Info")
203 list(APPEND expanded_components "${c}")
206 set(${out_components} ${expanded_components} PARENT_SCOPE)
207 endfunction(llvm_expand_pseudo_components out_components)
209 # This is a variant intended for the final user:
210 # Map LINK_COMPONENTS to actual libnames.
211 function(llvm_map_components_to_libnames out_libs)
212 set( link_components ${ARGN} )
213 if(NOT LLVM_AVAILABLE_LIBS)
214 # Inside LLVM itself available libs are in a global property.
215 get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
217 string(TOUPPER "${LLVM_AVAILABLE_LIBS}" capitalized_libs)
219 get_property(LLVM_TARGETS_CONFIGURED GLOBAL PROPERTY LLVM_TARGETS_CONFIGURED)
221 # Generally in our build system we avoid order-dependence. Unfortunately since
222 # not all targets create the same set of libraries we actually need to ensure
223 # that all build targets associated with a target are added before we can
224 # process target dependencies.
225 if(NOT LLVM_TARGETS_CONFIGURED)
226 foreach(c ${link_components})
227 is_llvm_target_specifier(${c} iltl_result ALL_TARGETS)
229 message(FATAL_ERROR "Specified target library before target registration is complete.")
234 # Expand some keywords:
235 list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend)
236 list(FIND link_components "engine" engine_required)
237 if( NOT engine_required EQUAL -1 )
238 list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" have_jit)
239 if( NOT have_native_backend EQUAL -1 AND NOT have_jit EQUAL -1 )
240 list(APPEND link_components "jit")
241 list(APPEND link_components "native")
243 list(APPEND link_components "interpreter")
246 list(FIND link_components "native" native_required)
247 if( NOT native_required EQUAL -1 )
248 if( NOT have_native_backend EQUAL -1 )
249 list(APPEND link_components ${LLVM_NATIVE_ARCH})
253 # Translate symbolic component names to real libraries:
254 llvm_expand_pseudo_components(link_components ${link_components})
255 foreach(c ${link_components})
256 if( c STREQUAL "native" )
258 elseif( c STREQUAL "backend" )
259 # same case as in `native'.
260 elseif( c STREQUAL "engine" )
262 elseif( c STREQUAL "all" )
263 get_property(all_components GLOBAL PROPERTY LLVM_COMPONENT_LIBS)
264 list(APPEND expanded_components ${all_components})
266 # Canonize the component name:
267 string(TOUPPER "${c}" capitalized)
268 list(FIND capitalized_libs LLVM${capitalized} lib_idx)
270 # The component is unknown. Maybe is an omitted target?
271 is_llvm_target_library(${c} iltl_result OMITTED_TARGETS)
273 # A missing library to a directly referenced omitted target would be bad.
274 message(FATAL_ERROR "Library '${c}' is a direct reference to a target library for an omitted target.")
276 # If it is not an omitted target we should assume it is a component
277 # that hasn't yet been processed by CMake. Missing components will
278 # cause errors later in the configuration, so we can safely assume
279 # that this is valid here.
280 list(APPEND expanded_components LLVM${c})
282 else( lib_idx LESS 0 )
283 list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib)
284 list(APPEND expanded_components ${canonical_lib})
285 endif( lib_idx LESS 0 )
286 endif( c STREQUAL "native" )
289 set(${out_libs} ${expanded_components} PARENT_SCOPE)
292 # Perform a post-order traversal of the dependency graph.
293 # This duplicates the algorithm used by llvm-config, originally
294 # in tools/llvm-config/llvm-config.cpp, function ComputeLibsForComponents.
295 function(expand_topologically name required_libs visited_libs)
296 list(FIND visited_libs ${name} found)
298 list(APPEND visited_libs ${name})
299 set(visited_libs ${visited_libs} PARENT_SCOPE)
301 get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
302 foreach( lib_dep ${lib_deps} )
303 expand_topologically(${lib_dep} "${required_libs}" "${visited_libs}")
304 set(required_libs ${required_libs} PARENT_SCOPE)
305 set(visited_libs ${visited_libs} PARENT_SCOPE)
308 list(APPEND required_libs ${name})
309 set(required_libs ${required_libs} PARENT_SCOPE)
313 # Expand dependencies while topologically sorting the list of libraries:
314 function(llvm_expand_dependencies out_libs)
315 set(expanded_components ${ARGN})
319 foreach( lib ${expanded_components} )
320 expand_topologically(${lib} "${required_libs}" "${visited_libs}")
324 list(REVERSE required_libs)
326 set(${out_libs} ${required_libs} PARENT_SCOPE)
329 function(explicit_map_components_to_libraries out_libs)
330 llvm_map_components_to_libnames(link_libs ${ARGN})
331 llvm_expand_dependencies(expanded_components ${link_libs})
332 # Return just the libraries included in this build:
334 foreach(c ${expanded_components})
336 set(result ${result} ${c})
339 set(${out_libs} ${result} PARENT_SCOPE)
340 endfunction(explicit_map_components_to_libraries)