blob: 451fc56c6bfafb14a4d75c454e2f14a187b4b20c [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})
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000042 target_link_libraries(${executable} ${LIBRARIES})
43endfunction(explicit_llvm_config)
44
45
46# This is a variant intended for the final user:
47function(llvm_map_components_to_libraries OUT_VAR)
48 explicit_map_components_to_libraries(result ${ARGN})
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000049 set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE )
50endfunction(llvm_map_components_to_libraries)
51
NAKAMURA Takumi906dad82014-02-04 14:42:04 +000052# Map LINK_COMPONENTS to actual libnames.
53function(llvm_map_components_to_libnames out_libs)
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000054 set( link_components ${ARGN} )
NAKAMURA Takumi12fedb02014-02-21 14:17:07 +000055 if(NOT LLVM_AVAILABLE_LIBS)
56 # Inside LLVM itself available libs are in a global property.
57 get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
58 endif()
59 string(TOUPPER "${LLVM_AVAILABLE_LIBS}" capitalized_libs)
Oscar Fuentese5035062011-03-09 14:44:46 +000060
61 # Expand some keywords:
Oscar Fuentes465f9362011-03-23 17:42:13 +000062 list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend)
Oscar Fuentese5035062011-03-09 14:44:46 +000063 list(FIND link_components "engine" engine_required)
Oscar Fuentes465f9362011-03-23 17:42:13 +000064 if( NOT engine_required EQUAL -1 )
65 list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" have_jit)
66 if( NOT have_native_backend EQUAL -1 AND NOT have_jit EQUAL -1 )
67 list(APPEND link_components "jit")
68 list(APPEND link_components "native")
69 else()
70 list(APPEND link_components "interpreter")
71 endif()
Oscar Fuentese5035062011-03-09 14:44:46 +000072 endif()
73 list(FIND link_components "native" native_required)
Oscar Fuentes465f9362011-03-23 17:42:13 +000074 if( NOT native_required EQUAL -1 )
75 if( NOT have_native_backend EQUAL -1 )
76 list(APPEND link_components ${LLVM_NATIVE_ARCH})
77 endif()
Oscar Fuentese5035062011-03-09 14:44:46 +000078 endif()
79
Oscar Fuentes18811d52010-09-28 22:38:39 +000080 # Translate symbolic component names to real libraries:
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000081 foreach(c ${link_components})
82 # add codegen, asmprinter, asmparser, disassembler
83 list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
84 if( NOT idx LESS 0 )
NAKAMURA Takumi1956c492014-02-21 14:16:52 +000085 if( TARGET LLVM${c}CodeGen )
NAKAMURA Takumi78293372014-02-02 16:46:35 +000086 list(APPEND expanded_components "LLVM${c}CodeGen")
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000087 else()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +000088 if( TARGET LLVM${c} )
NAKAMURA Takumi78293372014-02-02 16:46:35 +000089 list(APPEND expanded_components "LLVM${c}")
90 else()
91 message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
92 endif()
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000093 endif()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +000094 if( TARGET LLVM${c}AsmPrinter )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000095 list(APPEND expanded_components "LLVM${c}AsmPrinter")
96 endif()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +000097 if( TARGET LLVM${c}AsmParser )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +000098 list(APPEND expanded_components "LLVM${c}AsmParser")
99 endif()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000100 if( TARGET LLVM${c}Info )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000101 list(APPEND expanded_components "LLVM${c}Info")
102 endif()
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000103 if( TARGET LLVM${c}Disassembler )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000104 list(APPEND expanded_components "LLVM${c}Disassembler")
105 endif()
106 elseif( c STREQUAL "native" )
Oscar Fuentese5035062011-03-09 14:44:46 +0000107 # already processed
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000108 elseif( c STREQUAL "nativecodegen" )
109 list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
110 elseif( c STREQUAL "backend" )
111 # same case as in `native'.
112 elseif( c STREQUAL "engine" )
Oscar Fuentese5035062011-03-09 14:44:46 +0000113 # already processed
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000114 elseif( c STREQUAL "all" )
NAKAMURA Takumi12fedb02014-02-21 14:17:07 +0000115 list(APPEND expanded_components ${LLVM_AVAILABLE_LIBS})
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000116 else( NOT idx LESS 0 )
Oscar Fuentes18811d52010-09-28 22:38:39 +0000117 # Canonize the component name:
118 string(TOUPPER "${c}" capitalized)
119 list(FIND capitalized_libs LLVM${capitalized} lib_idx)
120 if( lib_idx LESS 0 )
Chandler Carruth68b23112011-07-29 23:52:01 +0000121 # The component is unknown. Maybe is an omitted target?
122 is_llvm_target_library(${c} iltl_result)
123 if( NOT iltl_result )
124 message(FATAL_ERROR "Library `${c}' not found in list of llvm libraries.")
125 endif()
Oscar Fuentes18811d52010-09-28 22:38:39 +0000126 else( lib_idx LESS 0 )
NAKAMURA Takumi12fedb02014-02-21 14:17:07 +0000127 list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib)
Chandler Carruth68b23112011-07-29 23:52:01 +0000128 list(APPEND expanded_components ${canonical_lib})
Oscar Fuentes18811d52010-09-28 22:38:39 +0000129 endif( lib_idx LESS 0 )
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000130 endif( NOT idx LESS 0 )
131 endforeach(c)
NAKAMURA Takumi906dad82014-02-04 14:42:04 +0000132
133 set(${out_libs} ${expanded_components} PARENT_SCOPE)
134endfunction()
135
136# Expand dependencies while topologically sorting the list of libraries:
137function(llvm_expand_dependencies out_libs)
138 set(expanded_components ${ARGN})
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000139 list(LENGTH expanded_components lst_size)
Oscar Fuentes18811d52010-09-28 22:38:39 +0000140 set(cursor 0)
141 set(processed)
142 while( cursor LESS lst_size )
143 list(GET expanded_components ${cursor} lib)
Daniel Dunbarfaaa76d2011-11-29 01:31:52 +0000144 get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib})
Chandler Carruth68b23112011-07-29 23:52:01 +0000145 list(APPEND expanded_components ${lib_deps})
Oscar Fuentes18811d52010-09-28 22:38:39 +0000146 # Remove duplicates at the front:
147 list(REVERSE expanded_components)
148 list(REMOVE_DUPLICATES expanded_components)
149 list(REVERSE expanded_components)
150 list(APPEND processed ${lib})
151 # Find the maximum index that doesn't have to be re-processed:
152 while(NOT "${expanded_components}" MATCHES "^${processed}.*" )
153 list(REMOVE_AT processed -1)
154 endwhile()
155 list(LENGTH processed cursor)
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000156 list(LENGTH expanded_components lst_size)
Oscar Fuentes18811d52010-09-28 22:38:39 +0000157 endwhile( cursor LESS lst_size )
NAKAMURA Takumi906dad82014-02-04 14:42:04 +0000158 set(${out_libs} ${expanded_components} PARENT_SCOPE)
159endfunction()
160
161function(explicit_map_components_to_libraries out_libs)
162 llvm_map_components_to_libnames(link_libs ${ARGN})
163 llvm_expand_dependencies(expanded_components ${link_libs})
Oscar Fuentes18811d52010-09-28 22:38:39 +0000164 # Return just the libraries included in this build:
165 set(result)
166 foreach(c ${expanded_components})
NAKAMURA Takumi1956c492014-02-21 14:16:52 +0000167 if( TARGET ${c} )
Oscar Fuentes18811d52010-09-28 22:38:39 +0000168 set(result ${result} ${c})
169 endif()
170 endforeach(c)
Michael J. Spencer93c9b2e2010-09-13 23:59:48 +0000171 set(${out_libs} ${result} PARENT_SCOPE)
172endfunction(explicit_map_components_to_libraries)