1*9880d681SAndroid Build Coastguard Workerfunction(get_system_libs return_var) 2*9880d681SAndroid Build Coastguard Worker message(AUTHOR_WARNING "get_system_libs no longer needed") 3*9880d681SAndroid Build Coastguard Worker set(${return_var} "" PARENT_SCOPE) 4*9880d681SAndroid Build Coastguard Workerendfunction() 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Worker 7*9880d681SAndroid Build Coastguard Workerfunction(link_system_libs target) 8*9880d681SAndroid Build Coastguard Worker message(AUTHOR_WARNING "link_system_libs no longer needed") 9*9880d681SAndroid Build Coastguard Workerendfunction() 10*9880d681SAndroid Build Coastguard Worker 11*9880d681SAndroid Build Coastguard Worker 12*9880d681SAndroid Build Coastguard Workerfunction(is_llvm_target_library library return_var) 13*9880d681SAndroid Build Coastguard Worker # Sets variable `return_var' to ON if `library' corresponds to a 14*9880d681SAndroid Build Coastguard Worker # LLVM supported target. To OFF if it doesn't. 15*9880d681SAndroid Build Coastguard Worker set(${return_var} OFF PARENT_SCOPE) 16*9880d681SAndroid Build Coastguard Worker string(TOUPPER "${library}" capitalized_lib) 17*9880d681SAndroid Build Coastguard Worker string(TOUPPER "${LLVM_ALL_TARGETS}" targets) 18*9880d681SAndroid Build Coastguard Worker foreach(t ${targets}) 19*9880d681SAndroid Build Coastguard Worker if( capitalized_lib STREQUAL t OR 20*9880d681SAndroid Build Coastguard Worker capitalized_lib STREQUAL "LLVM${t}" OR 21*9880d681SAndroid Build Coastguard Worker capitalized_lib STREQUAL "LLVM${t}CODEGEN" OR 22*9880d681SAndroid Build Coastguard Worker capitalized_lib STREQUAL "LLVM${t}ASMPARSER" OR 23*9880d681SAndroid Build Coastguard Worker capitalized_lib STREQUAL "LLVM${t}ASMPRINTER" OR 24*9880d681SAndroid Build Coastguard Worker capitalized_lib STREQUAL "LLVM${t}DISASSEMBLER" OR 25*9880d681SAndroid Build Coastguard Worker capitalized_lib STREQUAL "LLVM${t}INFO" ) 26*9880d681SAndroid Build Coastguard Worker set(${return_var} ON PARENT_SCOPE) 27*9880d681SAndroid Build Coastguard Worker break() 28*9880d681SAndroid Build Coastguard Worker endif() 29*9880d681SAndroid Build Coastguard Worker endforeach() 30*9880d681SAndroid Build Coastguard Workerendfunction(is_llvm_target_library) 31*9880d681SAndroid Build Coastguard Worker 32*9880d681SAndroid Build Coastguard Worker 33*9880d681SAndroid Build Coastguard Workermacro(llvm_config executable) 34*9880d681SAndroid Build Coastguard Worker cmake_parse_arguments(ARG "USE_SHARED" "" "" ${ARGN}) 35*9880d681SAndroid Build Coastguard Worker set(link_components ${ARG_UNPARSED_ARGUMENTS}) 36*9880d681SAndroid Build Coastguard Worker 37*9880d681SAndroid Build Coastguard Worker if(USE_SHARED) 38*9880d681SAndroid Build Coastguard Worker # If USE_SHARED is specified, then we link against libLLVM, 39*9880d681SAndroid Build Coastguard Worker # but also against the component libraries below. This is 40*9880d681SAndroid Build Coastguard Worker # done in case libLLVM does not contain all of the components 41*9880d681SAndroid Build Coastguard Worker # the target requires. 42*9880d681SAndroid Build Coastguard Worker # 43*9880d681SAndroid Build Coastguard Worker # Strip LLVM_DYLIB_COMPONENTS out of link_components. 44*9880d681SAndroid Build Coastguard Worker # To do this, we need special handling for "all", since that 45*9880d681SAndroid Build Coastguard Worker # may imply linking to libraries that are not included in 46*9880d681SAndroid Build Coastguard Worker # libLLVM. 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Worker if (DEFINED link_components AND DEFINED LLVM_DYLIB_COMPONENTS) 49*9880d681SAndroid Build Coastguard Worker if("${LLVM_DYLIB_COMPONENTS}" STREQUAL "all") 50*9880d681SAndroid Build Coastguard Worker set(link_components "") 51*9880d681SAndroid Build Coastguard Worker else() 52*9880d681SAndroid Build Coastguard Worker list(REMOVE_ITEM link_components ${LLVM_DYLIB_COMPONENTS}) 53*9880d681SAndroid Build Coastguard Worker endif() 54*9880d681SAndroid Build Coastguard Worker endif() 55*9880d681SAndroid Build Coastguard Worker 56*9880d681SAndroid Build Coastguard Worker target_link_libraries(${executable} LLVM) 57*9880d681SAndroid Build Coastguard Worker endif() 58*9880d681SAndroid Build Coastguard Worker 59*9880d681SAndroid Build Coastguard Worker explicit_llvm_config(${executable} ${link_components}) 60*9880d681SAndroid Build Coastguard Workerendmacro(llvm_config) 61*9880d681SAndroid Build Coastguard Worker 62*9880d681SAndroid Build Coastguard Worker 63*9880d681SAndroid Build Coastguard Workerfunction(explicit_llvm_config executable) 64*9880d681SAndroid Build Coastguard Worker set( link_components ${ARGN} ) 65*9880d681SAndroid Build Coastguard Worker 66*9880d681SAndroid Build Coastguard Worker llvm_map_components_to_libnames(LIBRARIES ${link_components}) 67*9880d681SAndroid Build Coastguard Worker get_target_property(t ${executable} TYPE) 68*9880d681SAndroid Build Coastguard Worker if("x${t}" STREQUAL "xSTATIC_LIBRARY") 69*9880d681SAndroid Build Coastguard Worker target_link_libraries(${executable} INTERFACE ${LIBRARIES}) 70*9880d681SAndroid Build Coastguard Worker elseif("x${t}" STREQUAL "xSHARED_LIBRARY" OR "x${t}" STREQUAL "xMODULE_LIBRARY") 71*9880d681SAndroid Build Coastguard Worker target_link_libraries(${executable} PRIVATE ${LIBRARIES}) 72*9880d681SAndroid Build Coastguard Worker else() 73*9880d681SAndroid Build Coastguard Worker # Use plain form for legacy user. 74*9880d681SAndroid Build Coastguard Worker target_link_libraries(${executable} ${LIBRARIES}) 75*9880d681SAndroid Build Coastguard Worker endif() 76*9880d681SAndroid Build Coastguard Workerendfunction(explicit_llvm_config) 77*9880d681SAndroid Build Coastguard Worker 78*9880d681SAndroid Build Coastguard Worker 79*9880d681SAndroid Build Coastguard Worker# This is Deprecated 80*9880d681SAndroid Build Coastguard Workerfunction(llvm_map_components_to_libraries OUT_VAR) 81*9880d681SAndroid Build Coastguard Worker message(AUTHOR_WARNING "Using llvm_map_components_to_libraries() is deprecated. Use llvm_map_components_to_libnames() instead") 82*9880d681SAndroid Build Coastguard Worker explicit_map_components_to_libraries(result ${ARGN}) 83*9880d681SAndroid Build Coastguard Worker set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE ) 84*9880d681SAndroid Build Coastguard Workerendfunction(llvm_map_components_to_libraries) 85*9880d681SAndroid Build Coastguard Worker 86*9880d681SAndroid Build Coastguard Worker# This is a variant intended for the final user: 87*9880d681SAndroid Build Coastguard Worker# Map LINK_COMPONENTS to actual libnames. 88*9880d681SAndroid Build Coastguard Workerfunction(llvm_map_components_to_libnames out_libs) 89*9880d681SAndroid Build Coastguard Worker set( link_components ${ARGN} ) 90*9880d681SAndroid Build Coastguard Worker if(NOT LLVM_AVAILABLE_LIBS) 91*9880d681SAndroid Build Coastguard Worker # Inside LLVM itself available libs are in a global property. 92*9880d681SAndroid Build Coastguard Worker get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS) 93*9880d681SAndroid Build Coastguard Worker endif() 94*9880d681SAndroid Build Coastguard Worker string(TOUPPER "${LLVM_AVAILABLE_LIBS}" capitalized_libs) 95*9880d681SAndroid Build Coastguard Worker 96*9880d681SAndroid Build Coastguard Worker # Expand some keywords: 97*9880d681SAndroid Build Coastguard Worker list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend) 98*9880d681SAndroid Build Coastguard Worker list(FIND link_components "engine" engine_required) 99*9880d681SAndroid Build Coastguard Worker if( NOT engine_required EQUAL -1 ) 100*9880d681SAndroid Build Coastguard Worker list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" have_jit) 101*9880d681SAndroid Build Coastguard Worker if( NOT have_native_backend EQUAL -1 AND NOT have_jit EQUAL -1 ) 102*9880d681SAndroid Build Coastguard Worker list(APPEND link_components "jit") 103*9880d681SAndroid Build Coastguard Worker list(APPEND link_components "native") 104*9880d681SAndroid Build Coastguard Worker else() 105*9880d681SAndroid Build Coastguard Worker list(APPEND link_components "interpreter") 106*9880d681SAndroid Build Coastguard Worker endif() 107*9880d681SAndroid Build Coastguard Worker endif() 108*9880d681SAndroid Build Coastguard Worker list(FIND link_components "native" native_required) 109*9880d681SAndroid Build Coastguard Worker if( NOT native_required EQUAL -1 ) 110*9880d681SAndroid Build Coastguard Worker if( NOT have_native_backend EQUAL -1 ) 111*9880d681SAndroid Build Coastguard Worker list(APPEND link_components ${LLVM_NATIVE_ARCH}) 112*9880d681SAndroid Build Coastguard Worker endif() 113*9880d681SAndroid Build Coastguard Worker endif() 114*9880d681SAndroid Build Coastguard Worker 115*9880d681SAndroid Build Coastguard Worker # Translate symbolic component names to real libraries: 116*9880d681SAndroid Build Coastguard Worker foreach(c ${link_components}) 117*9880d681SAndroid Build Coastguard Worker # add codegen, asmprinter, asmparser, disassembler 118*9880d681SAndroid Build Coastguard Worker list(FIND LLVM_TARGETS_TO_BUILD ${c} idx) 119*9880d681SAndroid Build Coastguard Worker if( NOT idx LESS 0 ) 120*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${c}CodeGen ) 121*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${c}CodeGen") 122*9880d681SAndroid Build Coastguard Worker else() 123*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${c} ) 124*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${c}") 125*9880d681SAndroid Build Coastguard Worker else() 126*9880d681SAndroid Build Coastguard Worker message(FATAL_ERROR "Target ${c} is not in the set of libraries.") 127*9880d681SAndroid Build Coastguard Worker endif() 128*9880d681SAndroid Build Coastguard Worker endif() 129*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${c}AsmPrinter ) 130*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${c}AsmPrinter") 131*9880d681SAndroid Build Coastguard Worker endif() 132*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${c}AsmParser ) 133*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${c}AsmParser") 134*9880d681SAndroid Build Coastguard Worker endif() 135*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${c}Desc ) 136*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${c}Desc") 137*9880d681SAndroid Build Coastguard Worker endif() 138*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${c}Info ) 139*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${c}Info") 140*9880d681SAndroid Build Coastguard Worker endif() 141*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${c}Disassembler ) 142*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${c}Disassembler") 143*9880d681SAndroid Build Coastguard Worker endif() 144*9880d681SAndroid Build Coastguard Worker elseif( c STREQUAL "native" ) 145*9880d681SAndroid Build Coastguard Worker # already processed 146*9880d681SAndroid Build Coastguard Worker elseif( c STREQUAL "nativecodegen" ) 147*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen") 148*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${LLVM_NATIVE_ARCH}Desc ) 149*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Desc") 150*9880d681SAndroid Build Coastguard Worker endif() 151*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${LLVM_NATIVE_ARCH}Info ) 152*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Info") 153*9880d681SAndroid Build Coastguard Worker endif() 154*9880d681SAndroid Build Coastguard Worker elseif( c STREQUAL "backend" ) 155*9880d681SAndroid Build Coastguard Worker # same case as in `native'. 156*9880d681SAndroid Build Coastguard Worker elseif( c STREQUAL "engine" ) 157*9880d681SAndroid Build Coastguard Worker # already processed 158*9880d681SAndroid Build Coastguard Worker elseif( c STREQUAL "all" ) 159*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components ${LLVM_AVAILABLE_LIBS}) 160*9880d681SAndroid Build Coastguard Worker elseif( c STREQUAL "AllTargetsAsmPrinters" ) 161*9880d681SAndroid Build Coastguard Worker # Link all the asm printers from all the targets 162*9880d681SAndroid Build Coastguard Worker foreach(t ${LLVM_TARGETS_TO_BUILD}) 163*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${t}AsmPrinter ) 164*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${t}AsmPrinter") 165*9880d681SAndroid Build Coastguard Worker endif() 166*9880d681SAndroid Build Coastguard Worker endforeach(t) 167*9880d681SAndroid Build Coastguard Worker elseif( c STREQUAL "AllTargetsAsmParsers" ) 168*9880d681SAndroid Build Coastguard Worker # Link all the asm parsers from all the targets 169*9880d681SAndroid Build Coastguard Worker foreach(t ${LLVM_TARGETS_TO_BUILD}) 170*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${t}AsmParser ) 171*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${t}AsmParser") 172*9880d681SAndroid Build Coastguard Worker endif() 173*9880d681SAndroid Build Coastguard Worker endforeach(t) 174*9880d681SAndroid Build Coastguard Worker elseif( c STREQUAL "AllTargetsDescs" ) 175*9880d681SAndroid Build Coastguard Worker # Link all the descs from all the targets 176*9880d681SAndroid Build Coastguard Worker foreach(t ${LLVM_TARGETS_TO_BUILD}) 177*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${t}Desc ) 178*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${t}Desc") 179*9880d681SAndroid Build Coastguard Worker endif() 180*9880d681SAndroid Build Coastguard Worker endforeach(t) 181*9880d681SAndroid Build Coastguard Worker elseif( c STREQUAL "AllTargetsDisassemblers" ) 182*9880d681SAndroid Build Coastguard Worker # Link all the disassemblers from all the targets 183*9880d681SAndroid Build Coastguard Worker foreach(t ${LLVM_TARGETS_TO_BUILD}) 184*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${t}Disassembler ) 185*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${t}Disassembler") 186*9880d681SAndroid Build Coastguard Worker endif() 187*9880d681SAndroid Build Coastguard Worker endforeach(t) 188*9880d681SAndroid Build Coastguard Worker elseif( c STREQUAL "AllTargetsInfos" ) 189*9880d681SAndroid Build Coastguard Worker # Link all the infos from all the targets 190*9880d681SAndroid Build Coastguard Worker foreach(t ${LLVM_TARGETS_TO_BUILD}) 191*9880d681SAndroid Build Coastguard Worker if( TARGET LLVM${t}Info ) 192*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components "LLVM${t}Info") 193*9880d681SAndroid Build Coastguard Worker endif() 194*9880d681SAndroid Build Coastguard Worker endforeach(t) 195*9880d681SAndroid Build Coastguard Worker else( NOT idx LESS 0 ) 196*9880d681SAndroid Build Coastguard Worker # Canonize the component name: 197*9880d681SAndroid Build Coastguard Worker string(TOUPPER "${c}" capitalized) 198*9880d681SAndroid Build Coastguard Worker list(FIND capitalized_libs LLVM${capitalized} lib_idx) 199*9880d681SAndroid Build Coastguard Worker if( lib_idx LESS 0 ) 200*9880d681SAndroid Build Coastguard Worker # The component is unknown. Maybe is an omitted target? 201*9880d681SAndroid Build Coastguard Worker is_llvm_target_library(${c} iltl_result) 202*9880d681SAndroid Build Coastguard Worker if( NOT iltl_result ) 203*9880d681SAndroid Build Coastguard Worker message(FATAL_ERROR "Library `${c}' not found in list of llvm libraries.") 204*9880d681SAndroid Build Coastguard Worker endif() 205*9880d681SAndroid Build Coastguard Worker else( lib_idx LESS 0 ) 206*9880d681SAndroid Build Coastguard Worker list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib) 207*9880d681SAndroid Build Coastguard Worker list(APPEND expanded_components ${canonical_lib}) 208*9880d681SAndroid Build Coastguard Worker endif( lib_idx LESS 0 ) 209*9880d681SAndroid Build Coastguard Worker endif( NOT idx LESS 0 ) 210*9880d681SAndroid Build Coastguard Worker endforeach(c) 211*9880d681SAndroid Build Coastguard Worker 212*9880d681SAndroid Build Coastguard Worker set(${out_libs} ${expanded_components} PARENT_SCOPE) 213*9880d681SAndroid Build Coastguard Workerendfunction() 214*9880d681SAndroid Build Coastguard Worker 215*9880d681SAndroid Build Coastguard Worker# Perform a post-order traversal of the dependency graph. 216*9880d681SAndroid Build Coastguard Worker# This duplicates the algorithm used by llvm-config, originally 217*9880d681SAndroid Build Coastguard Worker# in tools/llvm-config/llvm-config.cpp, function ComputeLibsForComponents. 218*9880d681SAndroid Build Coastguard Workerfunction(expand_topologically name required_libs visited_libs) 219*9880d681SAndroid Build Coastguard Worker list(FIND visited_libs ${name} found) 220*9880d681SAndroid Build Coastguard Worker if( found LESS 0 ) 221*9880d681SAndroid Build Coastguard Worker list(APPEND visited_libs ${name}) 222*9880d681SAndroid Build Coastguard Worker set(visited_libs ${visited_libs} PARENT_SCOPE) 223*9880d681SAndroid Build Coastguard Worker 224*9880d681SAndroid Build Coastguard Worker get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name}) 225*9880d681SAndroid Build Coastguard Worker foreach( lib_dep ${lib_deps} ) 226*9880d681SAndroid Build Coastguard Worker expand_topologically(${lib_dep} "${required_libs}" "${visited_libs}") 227*9880d681SAndroid Build Coastguard Worker set(required_libs ${required_libs} PARENT_SCOPE) 228*9880d681SAndroid Build Coastguard Worker set(visited_libs ${visited_libs} PARENT_SCOPE) 229*9880d681SAndroid Build Coastguard Worker endforeach() 230*9880d681SAndroid Build Coastguard Worker 231*9880d681SAndroid Build Coastguard Worker list(APPEND required_libs ${name}) 232*9880d681SAndroid Build Coastguard Worker set(required_libs ${required_libs} PARENT_SCOPE) 233*9880d681SAndroid Build Coastguard Worker endif() 234*9880d681SAndroid Build Coastguard Workerendfunction() 235*9880d681SAndroid Build Coastguard Worker 236*9880d681SAndroid Build Coastguard Worker# Expand dependencies while topologically sorting the list of libraries: 237*9880d681SAndroid Build Coastguard Workerfunction(llvm_expand_dependencies out_libs) 238*9880d681SAndroid Build Coastguard Worker set(expanded_components ${ARGN}) 239*9880d681SAndroid Build Coastguard Worker 240*9880d681SAndroid Build Coastguard Worker set(required_libs) 241*9880d681SAndroid Build Coastguard Worker set(visited_libs) 242*9880d681SAndroid Build Coastguard Worker foreach( lib ${expanded_components} ) 243*9880d681SAndroid Build Coastguard Worker expand_topologically(${lib} "${required_libs}" "${visited_libs}") 244*9880d681SAndroid Build Coastguard Worker endforeach() 245*9880d681SAndroid Build Coastguard Worker 246*9880d681SAndroid Build Coastguard Worker list(REVERSE required_libs) 247*9880d681SAndroid Build Coastguard Worker set(${out_libs} ${required_libs} PARENT_SCOPE) 248*9880d681SAndroid Build Coastguard Workerendfunction() 249*9880d681SAndroid Build Coastguard Worker 250*9880d681SAndroid Build Coastguard Workerfunction(explicit_map_components_to_libraries out_libs) 251*9880d681SAndroid Build Coastguard Worker llvm_map_components_to_libnames(link_libs ${ARGN}) 252*9880d681SAndroid Build Coastguard Worker llvm_expand_dependencies(expanded_components ${link_libs}) 253*9880d681SAndroid Build Coastguard Worker # Return just the libraries included in this build: 254*9880d681SAndroid Build Coastguard Worker set(result) 255*9880d681SAndroid Build Coastguard Worker foreach(c ${expanded_components}) 256*9880d681SAndroid Build Coastguard Worker if( TARGET ${c} ) 257*9880d681SAndroid Build Coastguard Worker set(result ${result} ${c}) 258*9880d681SAndroid Build Coastguard Worker endif() 259*9880d681SAndroid Build Coastguard Worker endforeach(c) 260*9880d681SAndroid Build Coastguard Worker set(${out_libs} ${result} PARENT_SCOPE) 261*9880d681SAndroid Build Coastguard Workerendfunction(explicit_map_components_to_libraries) 262