blob: 2783af807a182b4a39da7fe1053a696677d22cf2 [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
54# This is a variant intended for the final user:
55function(llvm_map_components_to_libraries OUT_VAR)
56 explicit_map_components_to_libraries(result ${ARGN})
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000057 set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE )
58endfunction(llvm_map_components_to_libraries)
59
NAKAMURA Takumi906dad82014-02-04 14:42:04 +000060# Map LINK_COMPONENTS to actual libnames.
61function(llvm_map_components_to_libnames out_libs)
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000062 set( link_components ${ARGN} )
NAKAMURA Takumi12fedb02014-02-21 14:17:07 +000063 if(NOT LLVM_AVAILABLE_LIBS)
64 # Inside LLVM itself available libs are in a global property.
65 get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
66 endif()
67 string(TOUPPER "${LLVM_AVAILABLE_LIBS}" capitalized_libs)
Oscar Fuentese5035062011-03-09 14:44:46 +000068
69 # Expand some keywords:
Oscar Fuentes465f9362011-03-23 17:42:13 +000070 list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend)
Oscar Fuentese5035062011-03-09 14:44:46 +000071 list(FIND link_components "engine" engine_required)
Oscar Fuentes465f9362011-03-23 17:42:13 +000072 if( NOT engine_required EQUAL -1 )
73 list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" have_jit)
74 if( NOT have_native_backend EQUAL -1 AND NOT have_jit EQUAL -1 )
75 list(APPEND link_components "jit")
76 list(APPEND link_components "native")
77 else()
78 list(APPEND link_components "interpreter")
79 endif()
Oscar Fuentese5035062011-03-09 14:44:46 +000080 endif()
81 list(FIND link_components "native" native_required)
Oscar Fuentes465f9362011-03-23 17:42:13 +000082 if( NOT native_required EQUAL -1 )
83 if( NOT have_native_backend EQUAL -1 )
84 list(APPEND link_components ${LLVM_NATIVE_ARCH})
85 endif()
Oscar Fuentese5035062011-03-09 14:44:46 +000086 endif()
87
Oscar Fuentes18811d52010-09-28 22:38:39 +000088 # Translate symbolic component names to real libraries:
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000089 foreach(c ${link_components})
90 # add codegen, asmprinter, asmparser, disassembler
91 list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
92 if( NOT idx LESS 0 )
NAKAMURA Takumi1956c492014-02-21 14:16:52 +000093 if( TARGET LLVM${c}CodeGen )
NAKAMURA Takumi78293372014-02-02 16:46:35 +000094 list(APPEND expanded_components "LLVM${c}CodeGen")
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000095 else()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +000096 if( TARGET LLVM${c} )
NAKAMURA Takumi78293372014-02-02 16:46:35 +000097 list(APPEND expanded_components "LLVM${c}")
98 else()
99 message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
100 endif()
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000101 endif()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000102 if( TARGET LLVM${c}AsmPrinter )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000103 list(APPEND expanded_components "LLVM${c}AsmPrinter")
104 endif()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000105 if( TARGET LLVM${c}AsmParser )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000106 list(APPEND expanded_components "LLVM${c}AsmParser")
107 endif()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000108 if( TARGET LLVM${c}Info )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000109 list(APPEND expanded_components "LLVM${c}Info")
110 endif()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000111 if( TARGET LLVM${c}Disassembler )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000112 list(APPEND expanded_components "LLVM${c}Disassembler")
113 endif()
114 elseif( c STREQUAL "native" )
Oscar Fuentese5035062011-03-09 14:44:46 +0000115 # already processed
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000116 elseif( c STREQUAL "nativecodegen" )
117 list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
118 elseif( c STREQUAL "backend" )
119 # same case as in `native'.
120 elseif( c STREQUAL "engine" )
Oscar Fuentese5035062011-03-09 14:44:46 +0000121 # already processed
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000122 elseif( c STREQUAL "all" )
NAKAMURA Takumi12fedb02014-02-21 14:17:07 +0000123 list(APPEND expanded_components ${LLVM_AVAILABLE_LIBS})
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000124 else( NOT idx LESS 0 )
Oscar Fuentes18811d52010-09-28 22:38:39 +0000125 # Canonize the component name:
126 string(TOUPPER "${c}" capitalized)
127 list(FIND capitalized_libs LLVM${capitalized} lib_idx)
128 if( lib_idx LESS 0 )
Chandler Carruth68b23112011-07-29 23:52:01 +0000129 # The component is unknown. Maybe is an omitted target?
130 is_llvm_target_library(${c} iltl_result)
131 if( NOT iltl_result )
132 message(FATAL_ERROR "Library `${c}' not found in list of llvm libraries.")
133 endif()
Oscar Fuentes18811d52010-09-28 22:38:39 +0000134 else( lib_idx LESS 0 )
NAKAMURA Takumi12fedb02014-02-21 14:17:07 +0000135 list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib)
Chandler Carruth68b23112011-07-29 23:52:01 +0000136 list(APPEND expanded_components ${canonical_lib})
Oscar Fuentes18811d52010-09-28 22:38:39 +0000137 endif( lib_idx LESS 0 )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000138 endif( NOT idx LESS 0 )
139 endforeach(c)
NAKAMURA Takumi906dad82014-02-04 14:42:04 +0000140
141 set(${out_libs} ${expanded_components} PARENT_SCOPE)
142endfunction()
143
144# Expand dependencies while topologically sorting the list of libraries:
145function(llvm_expand_dependencies out_libs)
146 set(expanded_components ${ARGN})
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000147 list(LENGTH expanded_components lst_size)
Oscar Fuentes18811d52010-09-28 22:38:39 +0000148 set(cursor 0)
149 set(processed)
150 while( cursor LESS lst_size )
151 list(GET expanded_components ${cursor} lib)
Daniel Dunbarfaaa76d2011-11-29 01:31:52 +0000152 get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib})
Chandler Carruth68b23112011-07-29 23:52:01 +0000153 list(APPEND expanded_components ${lib_deps})
Oscar Fuentes18811d52010-09-28 22:38:39 +0000154 # Remove duplicates at the front:
155 list(REVERSE expanded_components)
156 list(REMOVE_DUPLICATES expanded_components)
157 list(REVERSE expanded_components)
158 list(APPEND processed ${lib})
159 # Find the maximum index that doesn't have to be re-processed:
160 while(NOT "${expanded_components}" MATCHES "^${processed}.*" )
161 list(REMOVE_AT processed -1)
162 endwhile()
163 list(LENGTH processed cursor)
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000164 list(LENGTH expanded_components lst_size)
Oscar Fuentes18811d52010-09-28 22:38:39 +0000165 endwhile( cursor LESS lst_size )
NAKAMURA Takumi906dad82014-02-04 14:42:04 +0000166 set(${out_libs} ${expanded_components} PARENT_SCOPE)
167endfunction()
168
169function(explicit_map_components_to_libraries out_libs)
170 llvm_map_components_to_libnames(link_libs ${ARGN})
171 llvm_expand_dependencies(expanded_components ${link_libs})
Oscar Fuentes18811d52010-09-28 22:38:39 +0000172 # Return just the libraries included in this build:
173 set(result)
174 foreach(c ${expanded_components})
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000175 if( TARGET ${c} )
Oscar Fuentes18811d52010-09-28 22:38:39 +0000176 set(result ${result} ${c})
177 endif()
178 endforeach(c)
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000179 set(${out_libs} ${result} PARENT_SCOPE)
180endfunction(explicit_map_components_to_libraries)