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 | |
Chris Bieneman | e7a9820 | 2017-02-08 20:58:37 +0000 | [diff] [blame] | 11 | # is_llvm_target_library( |
| 12 | # library |
| 13 | # Name of the LLVM library to check |
| 14 | # return_var |
| 15 | # Output variable name |
| 16 | # ALL_TARGETS;INCLUDED_TARGETS;OMITTED_TARGETS |
| 17 | # ALL_TARGETS - default looks at the full list of known targets |
| 18 | # INCLUDED_TARGETS - looks only at targets being configured |
| 19 | # OMITTED_TARGETS - looks only at targets that are not being configured |
| 20 | # ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 21 | function(is_llvm_target_library library return_var) |
Chris Bieneman | e7a9820 | 2017-02-08 20:58:37 +0000 | [diff] [blame] | 22 | cmake_parse_arguments(ARG "ALL_TARGETS;INCLUDED_TARGETS;OMITTED_TARGETS" "" "" ${ARGN}) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 23 | # Sets variable `return_var' to ON if `library' corresponds to a |
| 24 | # LLVM supported target. To OFF if it doesn't. |
| 25 | set(${return_var} OFF PARENT_SCOPE) |
| 26 | string(TOUPPER "${library}" capitalized_lib) |
Chris Bieneman | e7a9820 | 2017-02-08 20:58:37 +0000 | [diff] [blame] | 27 | if(ARG_INCLUDED_TARGETS) |
| 28 | string(TOUPPER "${LLVM_TARGETS_TO_BUILD}" targets) |
| 29 | elseif(ARG_OMITTED_TARGETS) |
| 30 | set(omitted_targets ${LLVM_ALL_TARGETS}) |
| 31 | list(REMOVE_ITEM omitted_targets ${LLVM_TARGETS_TO_BUILD}) |
| 32 | string(TOUPPER "${omitted_targets}" targets) |
| 33 | else() |
| 34 | string(TOUPPER "${LLVM_ALL_TARGETS}" targets) |
| 35 | endif() |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 36 | foreach(t ${targets}) |
Oscar Fuentes | 638b8b7 | 2011-03-15 14:53:53 +0000 | [diff] [blame] | 37 | if( capitalized_lib STREQUAL t OR |
Chris Bieneman | e7a9820 | 2017-02-08 20:58:37 +0000 | [diff] [blame] | 38 | capitalized_lib STREQUAL "${t}" OR |
| 39 | capitalized_lib STREQUAL "${t}DESC" OR |
| 40 | capitalized_lib STREQUAL "${t}CODEGEN" OR |
| 41 | capitalized_lib STREQUAL "${t}ASMPARSER" OR |
| 42 | capitalized_lib STREQUAL "${t}ASMPRINTER" OR |
| 43 | capitalized_lib STREQUAL "${t}DISASSEMBLER" OR |
| 44 | capitalized_lib STREQUAL "${t}INFO" OR |
| 45 | capitalized_lib STREQUAL "${t}UTILS" ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 46 | set(${return_var} ON PARENT_SCOPE) |
| 47 | break() |
| 48 | endif() |
| 49 | endforeach() |
| 50 | endfunction(is_llvm_target_library) |
| 51 | |
Chris Bieneman | e7a9820 | 2017-02-08 20:58:37 +0000 | [diff] [blame] | 52 | function(is_llvm_target_specifier library return_var) |
| 53 | is_llvm_target_library(${library} ${return_var} ${ARGN}) |
| 54 | string(TOUPPER "${library}" capitalized_lib) |
| 55 | if(NOT ${return_var}) |
| 56 | if( capitalized_lib STREQUAL "ALLTARGETSASMPARSERS" OR |
| 57 | capitalized_lib STREQUAL "ALLTARGETSDESCS" OR |
| 58 | capitalized_lib STREQUAL "ALLTARGETSDISASSEMBLERS" OR |
| 59 | capitalized_lib STREQUAL "ALLTARGETSINFOS" OR |
| 60 | capitalized_lib STREQUAL "NATIVE" OR |
| 61 | capitalized_lib STREQUAL "NATIVECODEGEN" ) |
| 62 | set(${return_var} ON PARENT_SCOPE) |
| 63 | endif() |
| 64 | endif() |
| 65 | endfunction() |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 66 | |
| 67 | macro(llvm_config executable) |
Andrew Wilkins | bb6d95f | 2015-09-05 08:27:33 +0000 | [diff] [blame] | 68 | cmake_parse_arguments(ARG "USE_SHARED" "" "" ${ARGN}) |
| 69 | set(link_components ${ARG_UNPARSED_ARGUMENTS}) |
| 70 | |
| 71 | if(USE_SHARED) |
| 72 | # If USE_SHARED is specified, then we link against libLLVM, |
| 73 | # but also against the component libraries below. This is |
| 74 | # done in case libLLVM does not contain all of the components |
| 75 | # the target requires. |
| 76 | # |
Andrew Wilkins | 095e22d | 2016-02-12 01:42:43 +0000 | [diff] [blame] | 77 | # Strip LLVM_DYLIB_COMPONENTS out of link_components. |
Andrew Wilkins | bb6d95f | 2015-09-05 08:27:33 +0000 | [diff] [blame] | 78 | # To do this, we need special handling for "all", since that |
| 79 | # may imply linking to libraries that are not included in |
| 80 | # libLLVM. |
Andrew Wilkins | 095e22d | 2016-02-12 01:42:43 +0000 | [diff] [blame] | 81 | |
| 82 | if (DEFINED link_components AND DEFINED LLVM_DYLIB_COMPONENTS) |
| 83 | if("${LLVM_DYLIB_COMPONENTS}" STREQUAL "all") |
| 84 | set(link_components "") |
| 85 | else() |
| 86 | list(REMOVE_ITEM link_components ${LLVM_DYLIB_COMPONENTS}) |
| 87 | endif() |
| 88 | endif() |
| 89 | |
Andrew Wilkins | bb6d95f | 2015-09-05 08:27:33 +0000 | [diff] [blame] | 90 | target_link_libraries(${executable} LLVM) |
| 91 | endif() |
| 92 | |
| 93 | explicit_llvm_config(${executable} ${link_components}) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 94 | endmacro(llvm_config) |
| 95 | |
| 96 | |
| 97 | function(explicit_llvm_config executable) |
| 98 | set( link_components ${ARGN} ) |
| 99 | |
NAKAMURA Takumi | 623055b | 2014-02-10 03:24:19 +0000 | [diff] [blame] | 100 | llvm_map_components_to_libnames(LIBRARIES ${link_components}) |
NAKAMURA Takumi | 955d27a | 2014-02-26 06:53:16 +0000 | [diff] [blame] | 101 | get_target_property(t ${executable} TYPE) |
Richard Smith | 571b0b9 | 2014-09-26 21:33:05 +0000 | [diff] [blame] | 102 | if("x${t}" STREQUAL "xSTATIC_LIBRARY") |
Chris Bieneman | 6a1b54a | 2015-03-23 20:03:57 +0000 | [diff] [blame] | 103 | target_link_libraries(${executable} INTERFACE ${LIBRARIES}) |
Richard Smith | 571b0b9 | 2014-09-26 21:33:05 +0000 | [diff] [blame] | 104 | elseif("x${t}" STREQUAL "xSHARED_LIBRARY" OR "x${t}" STREQUAL "xMODULE_LIBRARY") |
Chris Bieneman | 6a1b54a | 2015-03-23 20:03:57 +0000 | [diff] [blame] | 105 | target_link_libraries(${executable} PRIVATE ${LIBRARIES}) |
NAKAMURA Takumi | 955d27a | 2014-02-26 06:53:16 +0000 | [diff] [blame] | 106 | else() |
| 107 | # Use plain form for legacy user. |
| 108 | target_link_libraries(${executable} ${LIBRARIES}) |
| 109 | endif() |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 110 | endfunction(explicit_llvm_config) |
| 111 | |
| 112 | |
Dan Liew | 544f45b | 2014-07-28 13:36:50 +0000 | [diff] [blame] | 113 | # This is Deprecated |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 114 | function(llvm_map_components_to_libraries OUT_VAR) |
Dan Liew | 544f45b | 2014-07-28 13:36:50 +0000 | [diff] [blame] | 115 | 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] | 116 | explicit_map_components_to_libraries(result ${ARGN}) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 117 | set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE ) |
| 118 | endfunction(llvm_map_components_to_libraries) |
| 119 | |
Dan Liew | 544f45b | 2014-07-28 13:36:50 +0000 | [diff] [blame] | 120 | # This is a variant intended for the final user: |
NAKAMURA Takumi | 906dad8 | 2014-02-04 14:42:04 +0000 | [diff] [blame] | 121 | # Map LINK_COMPONENTS to actual libnames. |
| 122 | function(llvm_map_components_to_libnames out_libs) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 123 | set( link_components ${ARGN} ) |
NAKAMURA Takumi | 12fedb0 | 2014-02-21 14:17:07 +0000 | [diff] [blame] | 124 | if(NOT LLVM_AVAILABLE_LIBS) |
| 125 | # Inside LLVM itself available libs are in a global property. |
| 126 | get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS) |
| 127 | endif() |
| 128 | string(TOUPPER "${LLVM_AVAILABLE_LIBS}" capitalized_libs) |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 129 | |
Chris Bieneman | e7a9820 | 2017-02-08 20:58:37 +0000 | [diff] [blame] | 130 | get_property(LLVM_TARGETS_CONFIGURED GLOBAL PROPERTY LLVM_TARGETS_CONFIGURED) |
| 131 | |
| 132 | # Generally in our build system we avoid order-dependence. Unfortunately since |
| 133 | # not all targets create the same set of libraries we actually need to ensure |
| 134 | # that all build targets associated with a target are added before we can |
| 135 | # process target dependencies. |
| 136 | if(NOT LLVM_TARGETS_CONFIGURED) |
| 137 | foreach(c ${link_components}) |
| 138 | is_llvm_target_specifier(${c} iltl_result ALL_TARGETS) |
| 139 | if(iltl_result) |
| 140 | message(FATAL_ERROR "Specified target library before target registration is complete.") |
| 141 | endif() |
| 142 | endforeach() |
| 143 | endif() |
| 144 | |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 145 | # Expand some keywords: |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 146 | list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend) |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 147 | list(FIND link_components "engine" engine_required) |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 148 | if( NOT engine_required EQUAL -1 ) |
| 149 | list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" have_jit) |
| 150 | if( NOT have_native_backend EQUAL -1 AND NOT have_jit EQUAL -1 ) |
| 151 | list(APPEND link_components "jit") |
| 152 | list(APPEND link_components "native") |
| 153 | else() |
| 154 | list(APPEND link_components "interpreter") |
| 155 | endif() |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 156 | endif() |
| 157 | list(FIND link_components "native" native_required) |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 158 | if( NOT native_required EQUAL -1 ) |
| 159 | if( NOT have_native_backend EQUAL -1 ) |
| 160 | list(APPEND link_components ${LLVM_NATIVE_ARCH}) |
| 161 | endif() |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 162 | endif() |
| 163 | |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 164 | # Translate symbolic component names to real libraries: |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 165 | foreach(c ${link_components}) |
| 166 | # add codegen, asmprinter, asmparser, disassembler |
| 167 | list(FIND LLVM_TARGETS_TO_BUILD ${c} idx) |
| 168 | if( NOT idx LESS 0 ) |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 169 | if( TARGET LLVM${c}CodeGen ) |
NAKAMURA Takumi | 7829337 | 2014-02-02 16:46:35 +0000 | [diff] [blame] | 170 | list(APPEND expanded_components "LLVM${c}CodeGen") |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 171 | else() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 172 | if( TARGET LLVM${c} ) |
NAKAMURA Takumi | 7829337 | 2014-02-02 16:46:35 +0000 | [diff] [blame] | 173 | list(APPEND expanded_components "LLVM${c}") |
| 174 | else() |
| 175 | message(FATAL_ERROR "Target ${c} is not in the set of libraries.") |
| 176 | endif() |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 177 | endif() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 178 | if( TARGET LLVM${c}AsmPrinter ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 179 | list(APPEND expanded_components "LLVM${c}AsmPrinter") |
| 180 | endif() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 181 | if( TARGET LLVM${c}AsmParser ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 182 | list(APPEND expanded_components "LLVM${c}AsmParser") |
| 183 | endif() |
NAKAMURA Takumi | 5c40508 | 2014-07-14 05:07:07 +0000 | [diff] [blame] | 184 | if( TARGET LLVM${c}Desc ) |
| 185 | list(APPEND expanded_components "LLVM${c}Desc") |
| 186 | endif() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 187 | if( TARGET LLVM${c}Info ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 188 | list(APPEND expanded_components "LLVM${c}Info") |
| 189 | endif() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 190 | if( TARGET LLVM${c}Disassembler ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 191 | list(APPEND expanded_components "LLVM${c}Disassembler") |
| 192 | endif() |
Chris Bieneman | e7a9820 | 2017-02-08 20:58:37 +0000 | [diff] [blame] | 193 | if( TARGET LLVM${c}Info ) |
| 194 | list(APPEND expanded_components "LLVM${c}Info") |
| 195 | endif() |
| 196 | if( TARGET LLVM${c}Utils ) |
| 197 | list(APPEND expanded_components "LLVM${c}Utils") |
| 198 | endif() |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 199 | elseif( c STREQUAL "native" ) |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 200 | # already processed |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 201 | elseif( c STREQUAL "nativecodegen" ) |
| 202 | list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen") |
NAKAMURA Takumi | 5c40508 | 2014-07-14 05:07:07 +0000 | [diff] [blame] | 203 | if( TARGET LLVM${LLVM_NATIVE_ARCH}Desc ) |
| 204 | list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Desc") |
| 205 | endif() |
| 206 | if( TARGET LLVM${LLVM_NATIVE_ARCH}Info ) |
| 207 | list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Info") |
| 208 | endif() |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 209 | elseif( c STREQUAL "backend" ) |
| 210 | # same case as in `native'. |
| 211 | elseif( c STREQUAL "engine" ) |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 212 | # already processed |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 213 | elseif( c STREQUAL "all" ) |
NAKAMURA Takumi | 12fedb0 | 2014-02-21 14:17:07 +0000 | [diff] [blame] | 214 | list(APPEND expanded_components ${LLVM_AVAILABLE_LIBS}) |
Pete Cooper | 468d6d7 | 2015-04-20 18:22:05 +0000 | [diff] [blame] | 215 | elseif( c STREQUAL "AllTargetsAsmPrinters" ) |
| 216 | # Link all the asm printers from all the targets |
| 217 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 218 | if( TARGET LLVM${t}AsmPrinter ) |
| 219 | list(APPEND expanded_components "LLVM${t}AsmPrinter") |
| 220 | endif() |
| 221 | endforeach(t) |
| 222 | elseif( c STREQUAL "AllTargetsAsmParsers" ) |
| 223 | # Link all the asm parsers from all the targets |
| 224 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 225 | if( TARGET LLVM${t}AsmParser ) |
| 226 | list(APPEND expanded_components "LLVM${t}AsmParser") |
| 227 | endif() |
| 228 | endforeach(t) |
| 229 | elseif( c STREQUAL "AllTargetsDescs" ) |
| 230 | # Link all the descs from all the targets |
| 231 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 232 | if( TARGET LLVM${t}Desc ) |
| 233 | list(APPEND expanded_components "LLVM${t}Desc") |
| 234 | endif() |
| 235 | endforeach(t) |
| 236 | elseif( c STREQUAL "AllTargetsDisassemblers" ) |
| 237 | # Link all the disassemblers from all the targets |
| 238 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 239 | if( TARGET LLVM${t}Disassembler ) |
| 240 | list(APPEND expanded_components "LLVM${t}Disassembler") |
| 241 | endif() |
| 242 | endforeach(t) |
| 243 | elseif( c STREQUAL "AllTargetsInfos" ) |
| 244 | # Link all the infos from all the targets |
| 245 | foreach(t ${LLVM_TARGETS_TO_BUILD}) |
| 246 | if( TARGET LLVM${t}Info ) |
| 247 | list(APPEND expanded_components "LLVM${t}Info") |
| 248 | endif() |
| 249 | endforeach(t) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 250 | else( NOT idx LESS 0 ) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 251 | # Canonize the component name: |
| 252 | string(TOUPPER "${c}" capitalized) |
| 253 | list(FIND capitalized_libs LLVM${capitalized} lib_idx) |
| 254 | if( lib_idx LESS 0 ) |
Chandler Carruth | 68b2311 | 2011-07-29 23:52:01 +0000 | [diff] [blame] | 255 | # The component is unknown. Maybe is an omitted target? |
Chris Bieneman | e7a9820 | 2017-02-08 20:58:37 +0000 | [diff] [blame] | 256 | is_llvm_target_library(${c} iltl_result OMITTED_TARGETS) |
| 257 | if(iltl_result) |
| 258 | # A missing library to a directly referenced omitted target would be bad. |
| 259 | message(FATAL_ERROR "Library '${c}' is a direct reference to a target library for an omitted target.") |
| 260 | else() |
| 261 | # If it is not an omitted target we should assume it is a component |
| 262 | # that hasn't yet been processed by CMake. Missing components will |
| 263 | # cause errors later in the configuration, so we can safely assume |
| 264 | # that this is valid here. |
| 265 | list(APPEND expanded_components LLVM${c}) |
Chandler Carruth | 68b2311 | 2011-07-29 23:52:01 +0000 | [diff] [blame] | 266 | endif() |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 267 | else( lib_idx LESS 0 ) |
NAKAMURA Takumi | 12fedb0 | 2014-02-21 14:17:07 +0000 | [diff] [blame] | 268 | list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib) |
Chandler Carruth | 68b2311 | 2011-07-29 23:52:01 +0000 | [diff] [blame] | 269 | list(APPEND expanded_components ${canonical_lib}) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 270 | endif( lib_idx LESS 0 ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 271 | endif( NOT idx LESS 0 ) |
| 272 | endforeach(c) |
NAKAMURA Takumi | 906dad8 | 2014-02-04 14:42:04 +0000 | [diff] [blame] | 273 | |
| 274 | set(${out_libs} ${expanded_components} PARENT_SCOPE) |
| 275 | endfunction() |
| 276 | |
Peter Zotov | f94eed6 | 2014-12-18 23:56:52 +0000 | [diff] [blame] | 277 | # Perform a post-order traversal of the dependency graph. |
| 278 | # This duplicates the algorithm used by llvm-config, originally |
| 279 | # in tools/llvm-config/llvm-config.cpp, function ComputeLibsForComponents. |
| 280 | function(expand_topologically name required_libs visited_libs) |
| 281 | list(FIND visited_libs ${name} found) |
| 282 | if( found LESS 0 ) |
| 283 | list(APPEND visited_libs ${name}) |
| 284 | set(visited_libs ${visited_libs} PARENT_SCOPE) |
| 285 | |
| 286 | get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) |
| 287 | foreach( lib_dep ${lib_deps} ) |
| 288 | expand_topologically(${lib_dep} "${required_libs}" "${visited_libs}") |
| 289 | set(required_libs ${required_libs} PARENT_SCOPE) |
| 290 | set(visited_libs ${visited_libs} PARENT_SCOPE) |
| 291 | endforeach() |
| 292 | |
| 293 | list(APPEND required_libs ${name}) |
| 294 | set(required_libs ${required_libs} PARENT_SCOPE) |
| 295 | endif() |
| 296 | endfunction() |
| 297 | |
NAKAMURA Takumi | 906dad8 | 2014-02-04 14:42:04 +0000 | [diff] [blame] | 298 | # Expand dependencies while topologically sorting the list of libraries: |
| 299 | function(llvm_expand_dependencies out_libs) |
| 300 | set(expanded_components ${ARGN}) |
Peter Zotov | f94eed6 | 2014-12-18 23:56:52 +0000 | [diff] [blame] | 301 | |
| 302 | set(required_libs) |
| 303 | set(visited_libs) |
| 304 | foreach( lib ${expanded_components} ) |
| 305 | expand_topologically(${lib} "${required_libs}" "${visited_libs}") |
| 306 | endforeach() |
| 307 | |
| 308 | list(REVERSE required_libs) |
| 309 | set(${out_libs} ${required_libs} PARENT_SCOPE) |
NAKAMURA Takumi | 906dad8 | 2014-02-04 14:42:04 +0000 | [diff] [blame] | 310 | endfunction() |
| 311 | |
| 312 | function(explicit_map_components_to_libraries out_libs) |
| 313 | llvm_map_components_to_libnames(link_libs ${ARGN}) |
| 314 | llvm_expand_dependencies(expanded_components ${link_libs}) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 315 | # Return just the libraries included in this build: |
| 316 | set(result) |
| 317 | foreach(c ${expanded_components}) |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame] | 318 | if( TARGET ${c} ) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 319 | set(result ${result} ${c}) |
| 320 | endif() |
| 321 | endforeach(c) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 322 | set(${out_libs} ${result} PARENT_SCOPE) |
| 323 | endfunction(explicit_map_components_to_libraries) |