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