Oscar Fuentes | e32d0ec | 2009-08-12 03:32:44 +0000 | [diff] [blame] | 1 | include(LLVMLibDeps) |
Oscar Fuentes | fd6daa8 | 2009-05-27 15:49:33 +0000 | [diff] [blame] | 2 | |
| 3 | function(get_system_libs return_var) |
| 4 | # Returns in `return_var' a list of system libraries used by LLVM. |
| 5 | if( NOT MSVC ) |
| 6 | if( MINGW ) |
| 7 | set(system_libs ${system_libs} imagehlp psapi) |
| 8 | elseif( CMAKE_HOST_UNIX ) |
| 9 | if( HAVE_LIBDL ) |
| 10 | set(system_libs ${system_libs} dl) |
| 11 | endif() |
| 12 | if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD ) |
| 13 | set(system_libs ${system_libs} pthread) |
| 14 | endif() |
| 15 | endif( MINGW ) |
| 16 | endif( NOT MSVC ) |
| 17 | set(${return_var} ${system_libs} PARENT_SCOPE) |
| 18 | endfunction(get_system_libs) |
| 19 | |
| 20 | |
Oscar Fuentes | 0b2bdff | 2008-11-16 04:13:19 +0000 | [diff] [blame] | 21 | macro(llvm_config executable) |
Douglas Gregor | 5d3c4e1 | 2009-06-23 18:30:17 +0000 | [diff] [blame] | 22 | explicit_llvm_config(${executable} ${ARGN}) |
Oscar Fuentes | 0b2bdff | 2008-11-16 04:13:19 +0000 | [diff] [blame] | 23 | endmacro(llvm_config) |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 24 | |
| 25 | |
Douglas Gregor | 92aa978 | 2009-06-04 19:53:37 +0000 | [diff] [blame] | 26 | function(explicit_llvm_config executable) |
Oscar Fuentes | 0b2bdff | 2008-11-16 04:13:19 +0000 | [diff] [blame] | 27 | set( link_components ${ARGN} ) |
Oscar Fuentes | 827283f | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 28 | |
Douglas Gregor | 92aa978 | 2009-06-04 19:53:37 +0000 | [diff] [blame] | 29 | explicit_map_components_to_libraries(LIBRARIES ${link_components}) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 30 | target_link_libraries(${executable} ${LIBRARIES}) |
Douglas Gregor | 92aa978 | 2009-06-04 19:53:37 +0000 | [diff] [blame] | 31 | endfunction(explicit_llvm_config) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 32 | |
| 33 | |
Douglas Gregor | 92aa978 | 2009-06-04 19:53:37 +0000 | [diff] [blame] | 34 | function(explicit_map_components_to_libraries out_libs) |
Oscar Fuentes | 0b2bdff | 2008-11-16 04:13:19 +0000 | [diff] [blame] | 35 | set( link_components ${ARGN} ) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 36 | foreach(c ${link_components}) |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 37 | # add codegen, asmprinter, asmparser |
Oscar Fuentes | 827283f | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 38 | list(FIND LLVM_TARGETS_TO_BUILD ${c} idx) |
| 39 | if( NOT idx LESS 0 ) |
Oscar Fuentes | 0b2bdff | 2008-11-16 04:13:19 +0000 | [diff] [blame] | 40 | list(FIND llvm_libs "LLVM${c}CodeGen" idx) |
| 41 | if( NOT idx LESS 0 ) |
| 42 | list(APPEND expanded_components "LLVM${c}CodeGen") |
| 43 | else() |
| 44 | list(FIND llvm_libs "LLVM${c}" idx) |
| 45 | if( NOT idx LESS 0 ) |
| 46 | list(APPEND expanded_components "LLVM${c}") |
| 47 | else() |
| 48 | message(FATAL_ERROR "Target ${c} is not in the set of libraries.") |
| 49 | endif() |
| 50 | endif() |
Oscar Fuentes | 827283f | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 51 | list(FIND llvm_libs "LLVM${c}AsmPrinter" asmidx) |
| 52 | if( NOT asmidx LESS 0 ) |
| 53 | list(APPEND expanded_components "LLVM${c}AsmPrinter") |
| 54 | endif() |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 55 | list(FIND llvm_libs "LLVM${c}AsmParser" asmidx) |
| 56 | if( NOT asmidx LESS 0 ) |
| 57 | list(APPEND expanded_components "LLVM${c}AsmParser") |
| 58 | endif() |
Daniel Dunbar | 1258e70 | 2009-07-15 07:52:36 +0000 | [diff] [blame] | 59 | list(FIND llvm_libs "LLVM${c}Info" asmidx) |
| 60 | if( NOT asmidx LESS 0 ) |
| 61 | list(APPEND expanded_components "LLVM${c}Info") |
| 62 | endif() |
Oscar Fuentes | 827283f | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 63 | elseif( c STREQUAL "native" ) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 64 | # TODO: we assume ARCH is X86. In this case, we must use nativecodegen |
| 65 | # component instead. Do nothing, as in llvm-config script. |
| 66 | elseif( c STREQUAL "nativecodegen" ) |
| 67 | # TODO: we assume ARCH is X86. |
| 68 | list(APPEND expanded_components "LLVMX86CodeGen") |
| 69 | elseif( c STREQUAL "backend" ) |
| 70 | # same case as in `native'. |
| 71 | elseif( c STREQUAL "engine" ) |
| 72 | # TODO: as we assume we are on X86, this is `jit'. |
| 73 | list(APPEND expanded_components "LLVMJIT") |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 74 | elseif( c STREQUAL "all" ) |
| 75 | list(APPEND expanded_components ${llvm_libs}) |
Oscar Fuentes | 827283f | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 76 | else( NOT idx LESS 0 ) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 77 | list(APPEND expanded_components LLVM${c}) |
Oscar Fuentes | 827283f | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 78 | endif( NOT idx LESS 0 ) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 79 | endforeach(c) |
| 80 | # We must match capitalization. |
| 81 | string(TOUPPER "${llvm_libs}" capitalized_libs) |
Oscar Fuentes | 0b2bdff | 2008-11-16 04:13:19 +0000 | [diff] [blame] | 82 | list(REMOVE_DUPLICATES expanded_components) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 83 | list(LENGTH expanded_components lst_size) |
Oscar Fuentes | 9f2e0e2 | 2009-08-12 04:05:26 +0000 | [diff] [blame] | 84 | set(result "") |
| 85 | while( 0 LESS ${lst_size} ) |
| 86 | list(GET expanded_components 0 c) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 87 | string(TOUPPER "${c}" capitalized) |
| 88 | list(FIND capitalized_libs ${capitalized} idx) |
| 89 | if( idx LESS 0 ) |
| 90 | message(FATAL_ERROR "Library ${c} not found in list of llvm libraries.") |
| 91 | endif( idx LESS 0 ) |
| 92 | list(GET llvm_libs ${idx} canonical_lib) |
Oscar Fuentes | 9f2e0e2 | 2009-08-12 04:05:26 +0000 | [diff] [blame] | 93 | list(REMOVE_ITEM result ${canonical_lib}) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 94 | list(APPEND result ${canonical_lib}) |
Oscar Fuentes | 9f2e0e2 | 2009-08-12 04:05:26 +0000 | [diff] [blame] | 95 | foreach(c ${MSVC_LIB_DEPS_${canonical_lib}}) |
| 96 | list(REMOVE_ITEM expanded_components ${c}) |
| 97 | endforeach() |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 98 | list(APPEND expanded_components ${MSVC_LIB_DEPS_${canonical_lib}}) |
Oscar Fuentes | 9f2e0e2 | 2009-08-12 04:05:26 +0000 | [diff] [blame] | 99 | list(REMOVE_AT expanded_components 0) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 100 | list(LENGTH expanded_components lst_size) |
Oscar Fuentes | 9f2e0e2 | 2009-08-12 04:05:26 +0000 | [diff] [blame] | 101 | endwhile( 0 LESS ${lst_size} ) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 102 | set(${out_libs} ${result} PARENT_SCOPE) |
Douglas Gregor | 92aa978 | 2009-06-04 19:53:37 +0000 | [diff] [blame] | 103 | endfunction(explicit_map_components_to_libraries) |