Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 1 | function(get_system_libs return_var) |
NAKAMURA Takumi | af2c113 | 2014-02-23 06:27:04 +0000 | [diff] [blame] | 2 | message(AUTHOR_WARNING "get_system_libs no longer needed") |
| 3 | set(${return_var} "" PARENT_SCOPE) |
| 4 | endfunction() |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 5 | |
| 6 | |
Oscar Fuentes | 978e528 | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 7 | function(link_system_libs target) |
NAKAMURA Takumi | af2c113 | 2014-02-23 06:27:04 +0000 | [diff] [blame] | 8 | message(AUTHOR_WARNING "link_system_libs no longer needed") |
| 9 | endfunction() |
Oscar Fuentes | 978e528 | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 10 | |
| 11 | |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 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}) |
Oscar Fuentes | 638b8b7 | 2011-03-15 14:53:53 +0000 | [diff] [blame] | 19 | if( capitalized_lib STREQUAL t OR |
NAKAMURA Takumi | 7829337 | 2014-02-02 16:46:35 +0000 | [diff] [blame] | 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" ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 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 | explicit_llvm_config(${executable} ${ARGN}) |
| 35 | endmacro(llvm_config) |
| 36 | |
| 37 | |
| 38 | function(explicit_llvm_config executable) |
| 39 | set( link_components ${ARGN} ) |
| 40 | |
NAKAMURA Takumi | 623055b | 2014-02-10 03:24:19 +0000 | [diff] [blame] | 41 | llvm_map_components_to_libnames(LIBRARIES ${link_components}) |
NAKAMURA Takumi | 955d27a | 2014-02-26 06:53:16 +0000 | [diff] [blame] | 42 | get_target_property(t ${executable} TYPE) |
Richard Smith | 571b0b9 | 2014-09-26 21:33:05 +0000 | [diff] [blame] | 43 | if("x${t}" STREQUAL "xSTATIC_LIBRARY") |
Chris Bieneman | 6a1b54a | 2015-03-23 20:03:57 +0000 | [diff] [blame] | 44 | target_link_libraries(${executable} INTERFACE ${LIBRARIES}) |
Richard Smith | 571b0b9 | 2014-09-26 21:33:05 +0000 | [diff] [blame] | 45 | elseif("x${t}" STREQUAL "xSHARED_LIBRARY" OR "x${t}" STREQUAL "xMODULE_LIBRARY") |
Chris Bieneman | 6a1b54a | 2015-03-23 20:03:57 +0000 | [diff] [blame] | 46 | target_link_libraries(${executable} PRIVATE ${LIBRARIES}) |
NAKAMURA Takumi | 955d27a | 2014-02-26 06:53:16 +0000 | [diff] [blame] | 47 | else() |
| 48 | # Use plain form for legacy user. |
| 49 | target_link_libraries(${executable} ${LIBRARIES}) |
| 50 | endif() |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 51 | endfunction(explicit_llvm_config) |
| 52 | |
| 53 | |
Dan Liew | 544f45b | 2014-07-28 13:36:50 +0000 | [diff] [blame] | 54 | # This is Deprecated |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 55 | function(llvm_map_components_to_libraries OUT_VAR) |
Dan Liew | 544f45b | 2014-07-28 13:36:50 +0000 | [diff] [blame] | 56 | message(AUTHOR_WARNING "Using llvm_map_components_to_libraries() is deprecated. Use llvm_map_components_to_libnames() instead") |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 57 | explicit_map_components_to_libraries(result ${ARGN}) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 58 | set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE ) |
| 59 | endfunction(llvm_map_components_to_libraries) |
| 60 | |
Dan Liew | 544f45b | 2014-07-28 13:36:50 +0000 | [diff] [blame] | 61 | # This is a variant intended for the final user: |
NAKAMURA Takumi | 906dad8 | 2014-02-04 14:42:04 +0000 | [diff] [blame] | 62 | # Map LINK_COMPONENTS to actual libnames. |
| 63 | function(llvm_map_components_to_libnames out_libs) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 64 | set( link_components ${ARGN} ) |
NAKAMURA Takumi | 12fedb0 | 2014-02-21 14:17:07 +0000 | [diff] [blame] | 65 | 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 Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 70 | |
| 71 | # Expand some keywords: |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 72 | list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend) |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 73 | list(FIND link_components "engine" engine_required) |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 74 | 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 Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 82 | endif() |
| 83 | list(FIND link_components "native" native_required) |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 84 | 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 Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 88 | endif() |
| 89 | |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 90 | # Translate symbolic component names to real libraries: |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 91 | 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 Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 95 | if( TARGET LLVM${c}CodeGen ) |
NAKAMURA Takumi | 7829337 | 2014-02-02 16:46:35 +0000 | [diff] [blame] | 96 | list(APPEND expanded_components "LLVM${c}CodeGen") |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 97 | else() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 98 | if( TARGET LLVM${c} ) |
NAKAMURA Takumi | 7829337 | 2014-02-02 16:46:35 +0000 | [diff] [blame] | 99 | 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. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 103 | endif() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 104 | if( TARGET LLVM${c}AsmPrinter ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 105 | list(APPEND expanded_components "LLVM${c}AsmPrinter") |
| 106 | endif() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 107 | if( TARGET LLVM${c}AsmParser ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 108 | list(APPEND expanded_components "LLVM${c}AsmParser") |
| 109 | endif() |
NAKAMURA Takumi | 5c40508 | 2014-07-14 05:07:07 +0000 | [diff] [blame] | 110 | if( TARGET LLVM${c}Desc ) |
| 111 | list(APPEND expanded_components "LLVM${c}Desc") |
| 112 | endif() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 113 | if( TARGET LLVM${c}Info ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 114 | list(APPEND expanded_components "LLVM${c}Info") |
| 115 | endif() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 116 | if( TARGET LLVM${c}Disassembler ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 117 | list(APPEND expanded_components "LLVM${c}Disassembler") |
| 118 | endif() |
| 119 | elseif( c STREQUAL "native" ) |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 120 | # already processed |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 121 | elseif( c STREQUAL "nativecodegen" ) |
| 122 | list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen") |
NAKAMURA Takumi | 5c40508 | 2014-07-14 05:07:07 +0000 | [diff] [blame] | 123 | 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. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 129 | elseif( c STREQUAL "backend" ) |
| 130 | # same case as in `native'. |
| 131 | elseif( c STREQUAL "engine" ) |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 132 | # already processed |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 133 | elseif( c STREQUAL "all" ) |
NAKAMURA Takumi | 12fedb0 | 2014-02-21 14:17:07 +0000 | [diff] [blame] | 134 | list(APPEND expanded_components ${LLVM_AVAILABLE_LIBS}) |
Pete Cooper | 468d6d7 | 2015-04-20 18:22:05 +0000 | [diff] [blame] | 135 | elseif( c STREQUAL "AllTargetsAsmPrinters" ) |
| 136 | # Link all the asm printers from all the targets |
| 137 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 138 | if( TARGET LLVM${t}AsmPrinter ) |
| 139 | list(APPEND expanded_components "LLVM${t}AsmPrinter") |
| 140 | endif() |
| 141 | endforeach(t) |
| 142 | elseif( c STREQUAL "AllTargetsAsmParsers" ) |
| 143 | # Link all the asm parsers from all the targets |
| 144 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 145 | if( TARGET LLVM${t}AsmParser ) |
| 146 | list(APPEND expanded_components "LLVM${t}AsmParser") |
| 147 | endif() |
| 148 | endforeach(t) |
| 149 | elseif( c STREQUAL "AllTargetsDescs" ) |
| 150 | # Link all the descs from all the targets |
| 151 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 152 | if( TARGET LLVM${t}Desc ) |
| 153 | list(APPEND expanded_components "LLVM${t}Desc") |
| 154 | endif() |
| 155 | endforeach(t) |
| 156 | elseif( c STREQUAL "AllTargetsDisassemblers" ) |
| 157 | # Link all the disassemblers from all the targets |
| 158 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 159 | if( TARGET LLVM${t}Disassembler ) |
| 160 | list(APPEND expanded_components "LLVM${t}Disassembler") |
| 161 | endif() |
| 162 | endforeach(t) |
| 163 | elseif( c STREQUAL "AllTargetsInfos" ) |
| 164 | # Link all the infos from all the targets |
| 165 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 166 | if( TARGET LLVM${t}Info ) |
| 167 | list(APPEND expanded_components "LLVM${t}Info") |
| 168 | endif() |
| 169 | endforeach(t) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 170 | else( NOT idx LESS 0 ) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 171 | # Canonize the component name: |
| 172 | string(TOUPPER "${c}" capitalized) |
| 173 | list(FIND capitalized_libs LLVM${capitalized} lib_idx) |
| 174 | if( lib_idx LESS 0 ) |
Chandler Carruth | 68b2311 | 2011-07-29 23:52:01 +0000 | [diff] [blame] | 175 | # The component is unknown. Maybe is an omitted target? |
| 176 | is_llvm_target_library(${c} iltl_result) |
| 177 | if( NOT iltl_result ) |
| 178 | message(FATAL_ERROR "Library `${c}' not found in list of llvm libraries.") |
| 179 | endif() |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 180 | else( lib_idx LESS 0 ) |
NAKAMURA Takumi | 12fedb0 | 2014-02-21 14:17:07 +0000 | [diff] [blame] | 181 | list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib) |
Chandler Carruth | 68b2311 | 2011-07-29 23:52:01 +0000 | [diff] [blame] | 182 | list(APPEND expanded_components ${canonical_lib}) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 183 | endif( lib_idx LESS 0 ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 184 | endif( NOT idx LESS 0 ) |
| 185 | endforeach(c) |
NAKAMURA Takumi | 906dad8 | 2014-02-04 14:42:04 +0000 | [diff] [blame] | 186 | |
| 187 | set(${out_libs} ${expanded_components} PARENT_SCOPE) |
| 188 | endfunction() |
| 189 | |
Peter Zotov | f94eed6 | 2014-12-18 23:56:52 +0000 | [diff] [blame] | 190 | # Perform a post-order traversal of the dependency graph. |
| 191 | # This duplicates the algorithm used by llvm-config, originally |
| 192 | # in tools/llvm-config/llvm-config.cpp, function ComputeLibsForComponents. |
| 193 | function(expand_topologically name required_libs visited_libs) |
| 194 | list(FIND visited_libs ${name} found) |
| 195 | if( found LESS 0 ) |
| 196 | list(APPEND visited_libs ${name}) |
| 197 | set(visited_libs ${visited_libs} PARENT_SCOPE) |
| 198 | |
| 199 | get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) |
| 200 | foreach( lib_dep ${lib_deps} ) |
| 201 | expand_topologically(${lib_dep} "${required_libs}" "${visited_libs}") |
| 202 | set(required_libs ${required_libs} PARENT_SCOPE) |
| 203 | set(visited_libs ${visited_libs} PARENT_SCOPE) |
| 204 | endforeach() |
| 205 | |
| 206 | list(APPEND required_libs ${name}) |
| 207 | set(required_libs ${required_libs} PARENT_SCOPE) |
| 208 | endif() |
| 209 | endfunction() |
| 210 | |
NAKAMURA Takumi | 906dad8 | 2014-02-04 14:42:04 +0000 | [diff] [blame] | 211 | # Expand dependencies while topologically sorting the list of libraries: |
| 212 | function(llvm_expand_dependencies out_libs) |
| 213 | set(expanded_components ${ARGN}) |
Peter Zotov | f94eed6 | 2014-12-18 23:56:52 +0000 | [diff] [blame] | 214 | |
| 215 | set(required_libs) |
| 216 | set(visited_libs) |
| 217 | foreach( lib ${expanded_components} ) |
| 218 | expand_topologically(${lib} "${required_libs}" "${visited_libs}") |
| 219 | endforeach() |
| 220 | |
| 221 | list(REVERSE required_libs) |
| 222 | set(${out_libs} ${required_libs} PARENT_SCOPE) |
NAKAMURA Takumi | 906dad8 | 2014-02-04 14:42:04 +0000 | [diff] [blame] | 223 | endfunction() |
| 224 | |
| 225 | function(explicit_map_components_to_libraries out_libs) |
| 226 | llvm_map_components_to_libnames(link_libs ${ARGN}) |
| 227 | llvm_expand_dependencies(expanded_components ${link_libs}) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 228 | # Return just the libraries included in this build: |
| 229 | set(result) |
| 230 | foreach(c ${expanded_components}) |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 231 | if( TARGET ${c} ) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 232 | set(result ${result} ${c}) |
| 233 | endif() |
| 234 | endforeach(c) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 235 | set(${out_libs} ${result} PARENT_SCOPE) |
| 236 | endfunction(explicit_map_components_to_libraries) |