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