Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 1 | function(get_system_libs return_var) |
| 2 | # Returns in `return_var' a list of system libraries used by LLVM. |
| 3 | if( NOT MSVC ) |
| 4 | if( MINGW ) |
David Majnemer | 61eae2e | 2013-10-07 01:00:07 +0000 | [diff] [blame] | 5 | set(system_libs ${system_libs} imagehlp psapi shell32) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 6 | elseif( CMAKE_HOST_UNIX ) |
Chandler Carruth | ef7f968 | 2013-01-04 23:19:55 +0000 | [diff] [blame] | 7 | if( HAVE_LIBRT ) |
| 8 | set(system_libs ${system_libs} rt) |
| 9 | endif() |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 10 | if( HAVE_LIBDL ) |
Chandler Carruth | ef7f968 | 2013-01-04 23:19:55 +0000 | [diff] [blame] | 11 | set(system_libs ${system_libs} ${CMAKE_DL_LIBS}) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 12 | endif() |
Chandler Carruth | f11f1e4 | 2013-08-12 09:49:17 +0000 | [diff] [blame] | 13 | if(LLVM_ENABLE_TERMINFO) |
| 14 | if(HAVE_TERMINFO) |
| 15 | set(system_libs ${system_libs} ${TERMINFO_LIBS}) |
Chandler Carruth | cad7e5e | 2013-08-07 08:47:36 +0000 | [diff] [blame] | 16 | endif() |
| 17 | endif() |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 18 | if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD ) |
Chandler Carruth | ef7f968 | 2013-01-04 23:19:55 +0000 | [diff] [blame] | 19 | set(system_libs ${system_libs} pthread) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 20 | endif() |
Alexey Samsonov | 2fb337e | 2013-04-23 08:28:39 +0000 | [diff] [blame] | 21 | if ( LLVM_ENABLE_ZLIB AND HAVE_LIBZ ) |
| 22 | set(system_libs ${system_libs} z) |
| 23 | endif() |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 24 | endif( MINGW ) |
| 25 | endif( NOT MSVC ) |
| 26 | set(${return_var} ${system_libs} PARENT_SCOPE) |
| 27 | endfunction(get_system_libs) |
| 28 | |
| 29 | |
Oscar Fuentes | 978e528 | 2011-03-29 20:51:08 +0000 | [diff] [blame] | 30 | function(link_system_libs target) |
| 31 | get_system_libs(llvm_system_libs) |
| 32 | target_link_libraries(${target} ${llvm_system_libs}) |
| 33 | endfunction(link_system_libs) |
| 34 | |
| 35 | |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 36 | function(is_llvm_target_library library return_var) |
| 37 | # Sets variable `return_var' to ON if `library' corresponds to a |
| 38 | # LLVM supported target. To OFF if it doesn't. |
| 39 | set(${return_var} OFF PARENT_SCOPE) |
| 40 | string(TOUPPER "${library}" capitalized_lib) |
| 41 | string(TOUPPER "${LLVM_ALL_TARGETS}" targets) |
| 42 | foreach(t ${targets}) |
Oscar Fuentes | 638b8b7 | 2011-03-15 14:53:53 +0000 | [diff] [blame] | 43 | if( capitalized_lib STREQUAL t OR |
NAKAMURA Takumi | 7829337 | 2014-02-02 16:46:35 +0000 | [diff] [blame] | 44 | capitalized_lib STREQUAL "LLVM${t}" OR |
| 45 | capitalized_lib STREQUAL "LLVM${t}CODEGEN" OR |
| 46 | capitalized_lib STREQUAL "LLVM${t}ASMPARSER" OR |
| 47 | capitalized_lib STREQUAL "LLVM${t}ASMPRINTER" OR |
| 48 | capitalized_lib STREQUAL "LLVM${t}DISASSEMBLER" OR |
| 49 | capitalized_lib STREQUAL "LLVM${t}INFO" ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 50 | set(${return_var} ON PARENT_SCOPE) |
| 51 | break() |
| 52 | endif() |
| 53 | endforeach() |
| 54 | endfunction(is_llvm_target_library) |
| 55 | |
| 56 | |
| 57 | macro(llvm_config executable) |
| 58 | explicit_llvm_config(${executable} ${ARGN}) |
| 59 | endmacro(llvm_config) |
| 60 | |
| 61 | |
| 62 | function(explicit_llvm_config executable) |
| 63 | set( link_components ${ARGN} ) |
| 64 | |
NAKAMURA Takumi | 623055b | 2014-02-10 03:24:19 +0000 | [diff] [blame] | 65 | llvm_map_components_to_libnames(LIBRARIES ${link_components}) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 66 | target_link_libraries(${executable} ${LIBRARIES}) |
| 67 | endfunction(explicit_llvm_config) |
| 68 | |
| 69 | |
| 70 | # This is a variant intended for the final user: |
| 71 | function(llvm_map_components_to_libraries OUT_VAR) |
| 72 | explicit_map_components_to_libraries(result ${ARGN}) |
| 73 | get_system_libs(sys_result) |
| 74 | set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE ) |
| 75 | endfunction(llvm_map_components_to_libraries) |
| 76 | |
NAKAMURA Takumi | 906dad8 | 2014-02-04 14:42:04 +0000 | [diff] [blame] | 77 | # Map LINK_COMPONENTS to actual libnames. |
| 78 | function(llvm_map_components_to_libnames out_libs) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 79 | set( link_components ${ARGN} ) |
Oscar Fuentes | 5ed9626 | 2011-02-18 22:06:14 +0000 | [diff] [blame] | 80 | get_property(llvm_libs GLOBAL PROPERTY LLVM_LIBS) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 81 | string(TOUPPER "${llvm_libs}" capitalized_libs) |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 82 | |
| 83 | # Expand some keywords: |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 84 | list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend) |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 85 | list(FIND link_components "engine" engine_required) |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 86 | if( NOT engine_required EQUAL -1 ) |
| 87 | list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" have_jit) |
| 88 | if( NOT have_native_backend EQUAL -1 AND NOT have_jit EQUAL -1 ) |
| 89 | list(APPEND link_components "jit") |
| 90 | list(APPEND link_components "native") |
| 91 | else() |
| 92 | list(APPEND link_components "interpreter") |
| 93 | endif() |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 94 | endif() |
| 95 | list(FIND link_components "native" native_required) |
Oscar Fuentes | 465f936 | 2011-03-23 17:42:13 +0000 | [diff] [blame] | 96 | if( NOT native_required EQUAL -1 ) |
| 97 | if( NOT have_native_backend EQUAL -1 ) |
| 98 | list(APPEND link_components ${LLVM_NATIVE_ARCH}) |
| 99 | endif() |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 100 | endif() |
| 101 | |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 102 | # Translate symbolic component names to real libraries: |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 103 | foreach(c ${link_components}) |
| 104 | # add codegen, asmprinter, asmparser, disassembler |
| 105 | list(FIND LLVM_TARGETS_TO_BUILD ${c} idx) |
| 106 | if( NOT idx LESS 0 ) |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame^] | 107 | if( TARGET LLVM${c}CodeGen ) |
NAKAMURA Takumi | 7829337 | 2014-02-02 16:46:35 +0000 | [diff] [blame] | 108 | list(APPEND expanded_components "LLVM${c}CodeGen") |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 109 | else() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame^] | 110 | if( TARGET LLVM${c} ) |
NAKAMURA Takumi | 7829337 | 2014-02-02 16:46:35 +0000 | [diff] [blame] | 111 | list(APPEND expanded_components "LLVM${c}") |
| 112 | else() |
| 113 | message(FATAL_ERROR "Target ${c} is not in the set of libraries.") |
| 114 | endif() |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 115 | endif() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame^] | 116 | if( TARGET LLVM${c}AsmPrinter ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 117 | list(APPEND expanded_components "LLVM${c}AsmPrinter") |
| 118 | endif() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame^] | 119 | if( TARGET LLVM${c}AsmParser ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 120 | list(APPEND expanded_components "LLVM${c}AsmParser") |
| 121 | endif() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame^] | 122 | if( TARGET LLVM${c}Info ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 123 | list(APPEND expanded_components "LLVM${c}Info") |
| 124 | endif() |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame^] | 125 | if( TARGET LLVM${c}Disassembler ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 126 | list(APPEND expanded_components "LLVM${c}Disassembler") |
| 127 | endif() |
| 128 | elseif( c STREQUAL "native" ) |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 129 | # already processed |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 130 | elseif( c STREQUAL "nativecodegen" ) |
| 131 | list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen") |
| 132 | elseif( c STREQUAL "backend" ) |
| 133 | # same case as in `native'. |
| 134 | elseif( c STREQUAL "engine" ) |
Oscar Fuentes | e503506 | 2011-03-09 14:44:46 +0000 | [diff] [blame] | 135 | # already processed |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 136 | elseif( c STREQUAL "all" ) |
| 137 | list(APPEND expanded_components ${llvm_libs}) |
| 138 | else( NOT idx LESS 0 ) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 139 | # Canonize the component name: |
| 140 | string(TOUPPER "${c}" capitalized) |
| 141 | list(FIND capitalized_libs LLVM${capitalized} lib_idx) |
| 142 | if( lib_idx LESS 0 ) |
Chandler Carruth | 68b2311 | 2011-07-29 23:52:01 +0000 | [diff] [blame] | 143 | # The component is unknown. Maybe is an omitted target? |
| 144 | is_llvm_target_library(${c} iltl_result) |
| 145 | if( NOT iltl_result ) |
| 146 | message(FATAL_ERROR "Library `${c}' not found in list of llvm libraries.") |
| 147 | endif() |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 148 | else( lib_idx LESS 0 ) |
Chandler Carruth | 68b2311 | 2011-07-29 23:52:01 +0000 | [diff] [blame] | 149 | list(GET llvm_libs ${lib_idx} canonical_lib) |
| 150 | list(APPEND expanded_components ${canonical_lib}) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 151 | endif( lib_idx LESS 0 ) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 152 | endif( NOT idx LESS 0 ) |
| 153 | endforeach(c) |
NAKAMURA Takumi | 906dad8 | 2014-02-04 14:42:04 +0000 | [diff] [blame] | 154 | |
| 155 | set(${out_libs} ${expanded_components} PARENT_SCOPE) |
| 156 | endfunction() |
| 157 | |
| 158 | # Expand dependencies while topologically sorting the list of libraries: |
| 159 | function(llvm_expand_dependencies out_libs) |
| 160 | set(expanded_components ${ARGN}) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 161 | list(LENGTH expanded_components lst_size) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 162 | set(cursor 0) |
| 163 | set(processed) |
| 164 | while( cursor LESS lst_size ) |
| 165 | list(GET expanded_components ${cursor} lib) |
Daniel Dunbar | faaa76d | 2011-11-29 01:31:52 +0000 | [diff] [blame] | 166 | get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib}) |
Chandler Carruth | 68b2311 | 2011-07-29 23:52:01 +0000 | [diff] [blame] | 167 | list(APPEND expanded_components ${lib_deps}) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 168 | # Remove duplicates at the front: |
| 169 | list(REVERSE expanded_components) |
| 170 | list(REMOVE_DUPLICATES expanded_components) |
| 171 | list(REVERSE expanded_components) |
| 172 | list(APPEND processed ${lib}) |
| 173 | # Find the maximum index that doesn't have to be re-processed: |
| 174 | while(NOT "${expanded_components}" MATCHES "^${processed}.*" ) |
| 175 | list(REMOVE_AT processed -1) |
| 176 | endwhile() |
| 177 | list(LENGTH processed cursor) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 178 | list(LENGTH expanded_components lst_size) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 179 | endwhile( cursor LESS lst_size ) |
NAKAMURA Takumi | 906dad8 | 2014-02-04 14:42:04 +0000 | [diff] [blame] | 180 | set(${out_libs} ${expanded_components} PARENT_SCOPE) |
| 181 | endfunction() |
| 182 | |
| 183 | function(explicit_map_components_to_libraries out_libs) |
| 184 | llvm_map_components_to_libnames(link_libs ${ARGN}) |
| 185 | llvm_expand_dependencies(expanded_components ${link_libs}) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 186 | # Return just the libraries included in this build: |
| 187 | set(result) |
| 188 | foreach(c ${expanded_components}) |
NAKAMURA Takumi | 1956c49 | 2014-02-21 14:16:52 +0000 | [diff] [blame^] | 189 | if( TARGET ${c} ) |
Oscar Fuentes | 18811d5 | 2010-09-28 22:38:39 +0000 | [diff] [blame] | 190 | set(result ${result} ${c}) |
| 191 | endif() |
| 192 | endforeach(c) |
Michael J. Spencer | 93c9b2e | 2010-09-13 23:59:48 +0000 | [diff] [blame] | 193 | set(${out_libs} ${result} PARENT_SCOPE) |
| 194 | endfunction(explicit_map_components_to_libraries) |