blob: 8ae1d23e4eea0df524dd056e4c3b711465e597c1 [file] [log] [blame]
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +00001function(get_system_libs return_var)
NAKAMURA Takumiaf2c1132014-02-23 06:27:04 +00002 message(AUTHOR_WARNING "get_system_libs no longer needed")
3 set(${return_var} "" PARENT_SCOPE)
4endfunction()
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +00005
6
Oscar Fuentes978e5282011-03-29 20:51:08 +00007function(link_system_libs target)
NAKAMURA Takumiaf2c1132014-02-23 06:27:04 +00008 message(AUTHOR_WARNING "link_system_libs no longer needed")
9endfunction()
Oscar Fuentes978e5282011-03-29 20:51:08 +000010
11
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000012function(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})
Oscar Fuentes638b8b72011-03-15 14:53:53 +000019 if( capitalized_lib STREQUAL t OR
NAKAMURA Takumi78293372014-02-02 16:46:35 +000020 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" )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000026 set(${return_var} ON PARENT_SCOPE)
27 break()
28 endif()
29 endforeach()
30endfunction(is_llvm_target_library)
31
32
33macro(llvm_config executable)
34 explicit_llvm_config(${executable} ${ARGN})
35endmacro(llvm_config)
36
37
38function(explicit_llvm_config executable)
39 set( link_components ${ARGN} )
40
NAKAMURA Takumi623055b2014-02-10 03:24:19 +000041 llvm_map_components_to_libnames(LIBRARIES ${link_components})
NAKAMURA Takumi955d27a2014-02-26 06:53:16 +000042 get_target_property(t ${executable} TYPE)
43 if("${t}" STREQUAL "STATIC_LIBRARY")
44 target_link_libraries(${executable} ${cmake_2_8_12_INTERFACE} ${LIBRARIES})
45 elseif("${t}" STREQUAL "SHARED_LIBRARY" OR "${t}" STREQUAL "MODULE_LIBRARY")
46 target_link_libraries(${executable} ${cmake_2_8_12_PRIVATE} ${LIBRARIES})
47 else()
48 # Use plain form for legacy user.
49 target_link_libraries(${executable} ${LIBRARIES})
50 endif()
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000051endfunction(explicit_llvm_config)
52
53
Dan Liew544f45b2014-07-28 13:36:50 +000054# This is Deprecated
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000055function(llvm_map_components_to_libraries OUT_VAR)
Dan Liew544f45b2014-07-28 13:36:50 +000056 message(AUTHOR_WARNING "Using llvm_map_components_to_libraries() is deprecated. Use llvm_map_components_to_libnames() instead")
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000057 explicit_map_components_to_libraries(result ${ARGN})
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000058 set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE )
59endfunction(llvm_map_components_to_libraries)
60
Dan Liew544f45b2014-07-28 13:36:50 +000061# This is a variant intended for the final user:
NAKAMURA Takumi906dad82014-02-04 14:42:04 +000062# Map LINK_COMPONENTS to actual libnames.
63function(llvm_map_components_to_libnames out_libs)
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000064 set( link_components ${ARGN} )
NAKAMURA Takumi12fedb02014-02-21 14:17:07 +000065 if(NOT LLVM_AVAILABLE_LIBS)
66 # Inside LLVM itself available libs are in a global property.
67 get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
68 endif()
69 string(TOUPPER "${LLVM_AVAILABLE_LIBS}" capitalized_libs)
Oscar Fuentese5035062011-03-09 14:44:46 +000070
71 # Expand some keywords:
Oscar Fuentes465f9362011-03-23 17:42:13 +000072 list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend)
Oscar Fuentese5035062011-03-09 14:44:46 +000073 list(FIND link_components "engine" engine_required)
Oscar Fuentes465f9362011-03-23 17:42:13 +000074 if( NOT engine_required EQUAL -1 )
75 list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" have_jit)
76 if( NOT have_native_backend EQUAL -1 AND NOT have_jit EQUAL -1 )
77 list(APPEND link_components "jit")
78 list(APPEND link_components "native")
79 else()
80 list(APPEND link_components "interpreter")
81 endif()
Oscar Fuentese5035062011-03-09 14:44:46 +000082 endif()
83 list(FIND link_components "native" native_required)
Oscar Fuentes465f9362011-03-23 17:42:13 +000084 if( NOT native_required EQUAL -1 )
85 if( NOT have_native_backend EQUAL -1 )
86 list(APPEND link_components ${LLVM_NATIVE_ARCH})
87 endif()
Oscar Fuentese5035062011-03-09 14:44:46 +000088 endif()
89
Oscar Fuentes18811d52010-09-28 22:38:39 +000090 # Translate symbolic component names to real libraries:
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000091 foreach(c ${link_components})
92 # add codegen, asmprinter, asmparser, disassembler
93 list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
94 if( NOT idx LESS 0 )
NAKAMURA Takumi1956c492014-02-21 14:16:52 +000095 if( TARGET LLVM${c}CodeGen )
NAKAMURA Takumi78293372014-02-02 16:46:35 +000096 list(APPEND expanded_components "LLVM${c}CodeGen")
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000097 else()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +000098 if( TARGET LLVM${c} )
NAKAMURA Takumi78293372014-02-02 16:46:35 +000099 list(APPEND expanded_components "LLVM${c}")
100 else()
101 message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
102 endif()
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000103 endif()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000104 if( TARGET LLVM${c}AsmPrinter )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000105 list(APPEND expanded_components "LLVM${c}AsmPrinter")
106 endif()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000107 if( TARGET LLVM${c}AsmParser )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000108 list(APPEND expanded_components "LLVM${c}AsmParser")
109 endif()
NAKAMURA Takumi5c405082014-07-14 05:07:07 +0000110 if( TARGET LLVM${c}Desc )
111 list(APPEND expanded_components "LLVM${c}Desc")
112 endif()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000113 if( TARGET LLVM${c}Info )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000114 list(APPEND expanded_components "LLVM${c}Info")
115 endif()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000116 if( TARGET LLVM${c}Disassembler )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000117 list(APPEND expanded_components "LLVM${c}Disassembler")
118 endif()
119 elseif( c STREQUAL "native" )
Oscar Fuentese5035062011-03-09 14:44:46 +0000120 # already processed
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000121 elseif( c STREQUAL "nativecodegen" )
122 list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
NAKAMURA Takumi5c405082014-07-14 05:07:07 +0000123 if( TARGET LLVM${LLVM_NATIVE_ARCH}Desc )
124 list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Desc")
125 endif()
126 if( TARGET LLVM${LLVM_NATIVE_ARCH}Info )
127 list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Info")
128 endif()
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000129 elseif( c STREQUAL "backend" )
130 # same case as in `native'.
131 elseif( c STREQUAL "engine" )
Oscar Fuentese5035062011-03-09 14:44:46 +0000132 # already processed
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000133 elseif( c STREQUAL "all" )
NAKAMURA Takumi12fedb02014-02-21 14:17:07 +0000134 list(APPEND expanded_components ${LLVM_AVAILABLE_LIBS})
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000135 else( NOT idx LESS 0 )
Oscar Fuentes18811d52010-09-28 22:38:39 +0000136 # Canonize the component name:
137 string(TOUPPER "${c}" capitalized)
138 list(FIND capitalized_libs LLVM${capitalized} lib_idx)
139 if( lib_idx LESS 0 )
Chandler Carruth68b23112011-07-29 23:52:01 +0000140 # The component is unknown. Maybe is an omitted target?
141 is_llvm_target_library(${c} iltl_result)
142 if( NOT iltl_result )
143 message(FATAL_ERROR "Library `${c}' not found in list of llvm libraries.")
144 endif()
Oscar Fuentes18811d52010-09-28 22:38:39 +0000145 else( lib_idx LESS 0 )
NAKAMURA Takumi12fedb02014-02-21 14:17:07 +0000146 list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib)
Chandler Carruth68b23112011-07-29 23:52:01 +0000147 list(APPEND expanded_components ${canonical_lib})
Oscar Fuentes18811d52010-09-28 22:38:39 +0000148 endif( lib_idx LESS 0 )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000149 endif( NOT idx LESS 0 )
150 endforeach(c)
NAKAMURA Takumi906dad82014-02-04 14:42:04 +0000151
152 set(${out_libs} ${expanded_components} PARENT_SCOPE)
153endfunction()
154
155# Expand dependencies while topologically sorting the list of libraries:
156function(llvm_expand_dependencies out_libs)
157 set(expanded_components ${ARGN})
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000158 list(LENGTH expanded_components lst_size)
Oscar Fuentes18811d52010-09-28 22:38:39 +0000159 set(cursor 0)
160 set(processed)
161 while( cursor LESS lst_size )
162 list(GET expanded_components ${cursor} lib)
Daniel Dunbarfaaa76d2011-11-29 01:31:52 +0000163 get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib})
Chandler Carruth68b23112011-07-29 23:52:01 +0000164 list(APPEND expanded_components ${lib_deps})
Oscar Fuentes18811d52010-09-28 22:38:39 +0000165 # Remove duplicates at the front:
166 list(REVERSE expanded_components)
167 list(REMOVE_DUPLICATES expanded_components)
168 list(REVERSE expanded_components)
169 list(APPEND processed ${lib})
170 # Find the maximum index that doesn't have to be re-processed:
171 while(NOT "${expanded_components}" MATCHES "^${processed}.*" )
172 list(REMOVE_AT processed -1)
173 endwhile()
174 list(LENGTH processed cursor)
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000175 list(LENGTH expanded_components lst_size)
Oscar Fuentes18811d52010-09-28 22:38:39 +0000176 endwhile( cursor LESS lst_size )
NAKAMURA Takumi906dad82014-02-04 14:42:04 +0000177 set(${out_libs} ${expanded_components} PARENT_SCOPE)
178endfunction()
179
180function(explicit_map_components_to_libraries out_libs)
181 llvm_map_components_to_libnames(link_libs ${ARGN})
182 llvm_expand_dependencies(expanded_components ${link_libs})
Oscar Fuentes18811d52010-09-28 22:38:39 +0000183 # Return just the libraries included in this build:
184 set(result)
185 foreach(c ${expanded_components})
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000186 if( TARGET ${c} )
Oscar Fuentes18811d52010-09-28 22:38:39 +0000187 set(result ${result} ${c})
188 endif()
189 endforeach(c)
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000190 set(${out_libs} ${result} PARENT_SCOPE)
191endfunction(explicit_map_components_to_libraries)