Add bogus conditional branch before stlx
[oota-llvm.git] / cmake / modules / LLVM-Config.cmake
1 function(get_system_libs return_var)
2   message(AUTHOR_WARNING "get_system_libs no longer needed")
3   set(${return_var} "" PARENT_SCOPE)
4 endfunction()
5
6
7 function(link_system_libs target)
8   message(AUTHOR_WARNING "link_system_libs no longer needed")
9 endfunction()
10
11
12 function(is_llvm_target_library library return_var)
13   # Sets variable `return_var' to ON if `library' corresponds to a
14   # LLVM supported target. To OFF if it doesn't.
15   set(${return_var} OFF PARENT_SCOPE)
16   string(TOUPPER "${library}" capitalized_lib)
17   string(TOUPPER "${LLVM_ALL_TARGETS}" targets)
18   foreach(t ${targets})
19     if( capitalized_lib STREQUAL t OR
20         capitalized_lib STREQUAL "LLVM${t}" OR
21         capitalized_lib STREQUAL "LLVM${t}CODEGEN" OR
22         capitalized_lib STREQUAL "LLVM${t}ASMPARSER" OR
23         capitalized_lib STREQUAL "LLVM${t}ASMPRINTER" OR
24         capitalized_lib STREQUAL "LLVM${t}DISASSEMBLER" OR
25         capitalized_lib STREQUAL "LLVM${t}INFO" )
26       set(${return_var} ON PARENT_SCOPE)
27       break()
28     endif()
29   endforeach()
30 endfunction(is_llvm_target_library)
31
32
33 macro(llvm_config executable)
34   cmake_parse_arguments(ARG "USE_SHARED" "" "" ${ARGN})
35   set(link_components ${ARG_UNPARSED_ARGUMENTS})
36
37   if(USE_SHARED)
38     # If USE_SHARED is specified, then we link against libLLVM,
39     # but also against the component libraries below. This is
40     # done in case libLLVM does not contain all of the components
41     # the target requires.
42     #
43     # Strip LLVM_DYLIB_COMPONENTS out of link_components.
44     # To do this, we need special handling for "all", since that
45     # may imply linking to libraries that are not included in
46     # libLLVM.
47
48     if (DEFINED link_components AND DEFINED LLVM_DYLIB_COMPONENTS)
49       if("${LLVM_DYLIB_COMPONENTS}" STREQUAL "all")
50         set(link_components "")
51       else()
52         list(REMOVE_ITEM link_components ${LLVM_DYLIB_COMPONENTS})
53       endif()
54     endif()
55
56     target_link_libraries(${executable} LLVM)
57   endif()
58
59   explicit_llvm_config(${executable} ${link_components})
60 endmacro(llvm_config)
61
62
63 function(explicit_llvm_config executable)
64   set( link_components ${ARGN} )
65
66   llvm_map_components_to_libnames(LIBRARIES ${link_components})
67   get_target_property(t ${executable} TYPE)
68   if("x${t}" STREQUAL "xSTATIC_LIBRARY")
69     target_link_libraries(${executable} INTERFACE ${LIBRARIES})
70   elseif("x${t}" STREQUAL "xSHARED_LIBRARY" OR "x${t}" STREQUAL "xMODULE_LIBRARY")
71     target_link_libraries(${executable} PRIVATE ${LIBRARIES})
72   else()
73     # Use plain form for legacy user.
74     target_link_libraries(${executable} ${LIBRARIES})
75   endif()
76 endfunction(explicit_llvm_config)
77
78
79 # This is Deprecated
80 function(llvm_map_components_to_libraries OUT_VAR)
81   message(AUTHOR_WARNING "Using llvm_map_components_to_libraries() is deprecated. Use llvm_map_components_to_libnames() instead")
82   explicit_map_components_to_libraries(result ${ARGN})
83   set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE )
84 endfunction(llvm_map_components_to_libraries)
85
86 # This is a variant intended for the final user:
87 # Map LINK_COMPONENTS to actual libnames.
88 function(llvm_map_components_to_libnames out_libs)
89   set( link_components ${ARGN} )
90   if(NOT LLVM_AVAILABLE_LIBS)
91     # Inside LLVM itself available libs are in a global property.
92     get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
93   endif()
94   string(TOUPPER "${LLVM_AVAILABLE_LIBS}" capitalized_libs)
95
96   # Expand some keywords:
97   list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend)
98   list(FIND link_components "engine" engine_required)
99   if( NOT engine_required EQUAL -1 )
100     list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" have_jit)
101     if( NOT have_native_backend EQUAL -1 AND NOT have_jit EQUAL -1 )
102       list(APPEND link_components "jit")
103       list(APPEND link_components "native")
104     else()
105       list(APPEND link_components "interpreter")
106     endif()
107   endif()
108   list(FIND link_components "native" native_required)
109   if( NOT native_required EQUAL -1 )
110     if( NOT have_native_backend EQUAL -1 )
111       list(APPEND link_components ${LLVM_NATIVE_ARCH})
112     endif()
113   endif()
114
115   # Translate symbolic component names to real libraries:
116   foreach(c ${link_components})
117     # add codegen, asmprinter, asmparser, disassembler
118     list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
119     if( NOT idx LESS 0 )
120       if( TARGET LLVM${c}CodeGen )
121         list(APPEND expanded_components "LLVM${c}CodeGen")
122       else()
123         if( TARGET LLVM${c} )
124           list(APPEND expanded_components "LLVM${c}")
125         else()
126           message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
127         endif()
128       endif()
129       if( TARGET LLVM${c}AsmPrinter )
130         list(APPEND expanded_components "LLVM${c}AsmPrinter")
131       endif()
132       if( TARGET LLVM${c}AsmParser )
133         list(APPEND expanded_components "LLVM${c}AsmParser")
134       endif()
135       if( TARGET LLVM${c}Desc )
136         list(APPEND expanded_components "LLVM${c}Desc")
137       endif()
138       if( TARGET LLVM${c}Info )
139         list(APPEND expanded_components "LLVM${c}Info")
140       endif()
141       if( TARGET LLVM${c}Disassembler )
142         list(APPEND expanded_components "LLVM${c}Disassembler")
143       endif()
144     elseif( c STREQUAL "native" )
145       # already processed
146     elseif( c STREQUAL "nativecodegen" )
147       list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
148       if( TARGET LLVM${LLVM_NATIVE_ARCH}Desc )
149         list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Desc")
150       endif()
151       if( TARGET LLVM${LLVM_NATIVE_ARCH}Info )
152         list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Info")
153       endif()
154     elseif( c STREQUAL "backend" )
155       # same case as in `native'.
156     elseif( c STREQUAL "engine" )
157       # already processed
158     elseif( c STREQUAL "all" )
159       list(APPEND expanded_components ${LLVM_AVAILABLE_LIBS})
160     elseif( c STREQUAL "AllTargetsAsmPrinters" )
161       # Link all the asm printers from all the targets
162       foreach(t ${LLVM_TARGETS_TO_BUILD})
163         if( TARGET LLVM${t}AsmPrinter )
164           list(APPEND expanded_components "LLVM${t}AsmPrinter")
165         endif()
166       endforeach(t)
167     elseif( c STREQUAL "AllTargetsAsmParsers" )
168       # Link all the asm parsers from all the targets
169       foreach(t ${LLVM_TARGETS_TO_BUILD})
170         if( TARGET LLVM${t}AsmParser )
171           list(APPEND expanded_components "LLVM${t}AsmParser")
172         endif()
173       endforeach(t)
174     elseif( c STREQUAL "AllTargetsDescs" )
175       # Link all the descs from all the targets
176       foreach(t ${LLVM_TARGETS_TO_BUILD})
177         if( TARGET LLVM${t}Desc )
178           list(APPEND expanded_components "LLVM${t}Desc")
179         endif()
180       endforeach(t)
181     elseif( c STREQUAL "AllTargetsDisassemblers" )
182       # Link all the disassemblers from all the targets
183       foreach(t ${LLVM_TARGETS_TO_BUILD})
184         if( TARGET LLVM${t}Disassembler )
185           list(APPEND expanded_components "LLVM${t}Disassembler")
186         endif()
187       endforeach(t)
188     elseif( c STREQUAL "AllTargetsInfos" )
189       # Link all the infos from all the targets
190       foreach(t ${LLVM_TARGETS_TO_BUILD})
191         if( TARGET LLVM${t}Info )
192           list(APPEND expanded_components "LLVM${t}Info")
193         endif()
194       endforeach(t)
195     else( NOT idx LESS 0 )
196       # Canonize the component name:
197       string(TOUPPER "${c}" capitalized)
198       list(FIND capitalized_libs LLVM${capitalized} lib_idx)
199       if( lib_idx LESS 0 )
200         # The component is unknown. Maybe is an omitted target?
201         is_llvm_target_library(${c} iltl_result)
202         if( NOT iltl_result )
203           message(FATAL_ERROR "Library `${c}' not found in list of llvm libraries.")
204         endif()
205       else( lib_idx LESS 0 )
206         list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib)
207         list(APPEND expanded_components ${canonical_lib})
208       endif( lib_idx LESS 0 )
209     endif( NOT idx LESS 0 )
210   endforeach(c)
211
212   set(${out_libs} ${expanded_components} PARENT_SCOPE)
213 endfunction()
214
215 # Perform a post-order traversal of the dependency graph.
216 # This duplicates the algorithm used by llvm-config, originally
217 # in tools/llvm-config/llvm-config.cpp, function ComputeLibsForComponents.
218 function(expand_topologically name required_libs visited_libs)
219   list(FIND visited_libs ${name} found)
220   if( found LESS 0 )
221     list(APPEND visited_libs ${name})
222     set(visited_libs ${visited_libs} PARENT_SCOPE)
223
224     get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
225     foreach( lib_dep ${lib_deps} )
226       expand_topologically(${lib_dep} "${required_libs}" "${visited_libs}")
227       set(required_libs ${required_libs} PARENT_SCOPE)
228       set(visited_libs ${visited_libs} PARENT_SCOPE)
229     endforeach()
230
231     list(APPEND required_libs ${name})
232     set(required_libs ${required_libs} PARENT_SCOPE)
233   endif()
234 endfunction()
235
236 # Expand dependencies while topologically sorting the list of libraries:
237 function(llvm_expand_dependencies out_libs)
238   set(expanded_components ${ARGN})
239
240   set(required_libs)
241   set(visited_libs)
242   foreach( lib ${expanded_components} )
243     expand_topologically(${lib} "${required_libs}" "${visited_libs}")
244   endforeach()
245
246   list(REVERSE required_libs)
247   set(${out_libs} ${required_libs} PARENT_SCOPE)
248 endfunction()
249
250 function(explicit_map_components_to_libraries out_libs)
251   llvm_map_components_to_libnames(link_libs ${ARGN})
252   llvm_expand_dependencies(expanded_components ${link_libs})
253   # Return just the libraries included in this build:
254   set(result)
255   foreach(c ${expanded_components})
256     if( TARGET ${c} )
257       set(result ${result} ${c})
258     endif()
259   endforeach(c)
260   set(${out_libs} ${result} PARENT_SCOPE)
261 endfunction(explicit_map_components_to_libraries)