Oscar Fuentes | fd6daa8 | 2009-05-27 15:49:33 +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 ) |
| 7 | if( HAVE_LIBDL ) |
| 8 | set(system_libs ${system_libs} dl) |
| 9 | endif() |
| 10 | if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD ) |
| 11 | set(system_libs ${system_libs} pthread) |
| 12 | endif() |
| 13 | endif( MINGW ) |
| 14 | endif( NOT MSVC ) |
| 15 | set(${return_var} ${system_libs} PARENT_SCOPE) |
| 16 | endfunction(get_system_libs) |
| 17 | |
| 18 | |
Oscar Fuentes | 0b2bdff | 2008-11-16 04:13:19 +0000 | [diff] [blame] | 19 | macro(llvm_config executable) |
Douglas Gregor | 5d3c4e1 | 2009-06-23 18:30:17 +0000 | [diff] [blame] | 20 | explicit_llvm_config(${executable} ${ARGN}) |
Oscar Fuentes | 0b2bdff | 2008-11-16 04:13:19 +0000 | [diff] [blame] | 21 | endmacro(llvm_config) |
Oscar Fuentes | 00905d5 | 2008-09-22 01:08:49 +0000 | [diff] [blame] | 22 | |
| 23 | |
Douglas Gregor | 92aa978 | 2009-06-04 19:53:37 +0000 | [diff] [blame] | 24 | function(explicit_llvm_config executable) |
Oscar Fuentes | 0b2bdff | 2008-11-16 04:13:19 +0000 | [diff] [blame] | 25 | set( link_components ${ARGN} ) |
Oscar Fuentes | 827283f | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 26 | |
Douglas Gregor | 92aa978 | 2009-06-04 19:53:37 +0000 | [diff] [blame] | 27 | explicit_map_components_to_libraries(LIBRARIES ${link_components}) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 28 | target_link_libraries(${executable} ${LIBRARIES}) |
Douglas Gregor | 92aa978 | 2009-06-04 19:53:37 +0000 | [diff] [blame] | 29 | endfunction(explicit_llvm_config) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 30 | |
| 31 | |
Douglas Gregor | 92aa978 | 2009-06-04 19:53:37 +0000 | [diff] [blame] | 32 | function(explicit_map_components_to_libraries out_libs) |
Oscar Fuentes | 0b2bdff | 2008-11-16 04:13:19 +0000 | [diff] [blame] | 33 | set( link_components ${ARGN} ) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 34 | foreach(c ${link_components}) |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 35 | # add codegen, asmprinter, asmparser |
Oscar Fuentes | 827283f | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 36 | list(FIND LLVM_TARGETS_TO_BUILD ${c} idx) |
| 37 | if( NOT idx LESS 0 ) |
Oscar Fuentes | 0b2bdff | 2008-11-16 04:13:19 +0000 | [diff] [blame] | 38 | list(FIND llvm_libs "LLVM${c}CodeGen" idx) |
| 39 | if( NOT idx LESS 0 ) |
| 40 | list(APPEND expanded_components "LLVM${c}CodeGen") |
| 41 | else() |
| 42 | list(FIND llvm_libs "LLVM${c}" idx) |
| 43 | if( NOT idx LESS 0 ) |
| 44 | list(APPEND expanded_components "LLVM${c}") |
| 45 | else() |
| 46 | message(FATAL_ERROR "Target ${c} is not in the set of libraries.") |
| 47 | endif() |
| 48 | endif() |
Oscar Fuentes | 827283f | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 49 | list(FIND llvm_libs "LLVM${c}AsmPrinter" asmidx) |
| 50 | if( NOT asmidx LESS 0 ) |
| 51 | list(APPEND expanded_components "LLVM${c}AsmPrinter") |
| 52 | endif() |
Daniel Dunbar | c7df3cb | 2009-07-17 20:42:00 +0000 | [diff] [blame] | 53 | list(FIND llvm_libs "LLVM${c}AsmParser" asmidx) |
| 54 | if( NOT asmidx LESS 0 ) |
| 55 | list(APPEND expanded_components "LLVM${c}AsmParser") |
| 56 | endif() |
Daniel Dunbar | 1258e70 | 2009-07-15 07:52:36 +0000 | [diff] [blame] | 57 | list(FIND llvm_libs "LLVM${c}Info" asmidx) |
| 58 | if( NOT asmidx LESS 0 ) |
| 59 | list(APPEND expanded_components "LLVM${c}Info") |
| 60 | endif() |
Oscar Fuentes | 827283f | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 61 | elseif( c STREQUAL "native" ) |
Duncan Sands | 42bbd4a | 2009-08-19 12:41:52 +0000 | [diff] [blame] | 62 | list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen") |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 63 | elseif( c STREQUAL "nativecodegen" ) |
Duncan Sands | 42bbd4a | 2009-08-19 12:41:52 +0000 | [diff] [blame] | 64 | list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen") |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 65 | elseif( c STREQUAL "backend" ) |
| 66 | # same case as in `native'. |
| 67 | elseif( c STREQUAL "engine" ) |
| 68 | # TODO: as we assume we are on X86, this is `jit'. |
| 69 | list(APPEND expanded_components "LLVMJIT") |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 70 | elseif( c STREQUAL "all" ) |
| 71 | list(APPEND expanded_components ${llvm_libs}) |
Oscar Fuentes | 827283f | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 72 | else( NOT idx LESS 0 ) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 73 | list(APPEND expanded_components LLVM${c}) |
Oscar Fuentes | 827283f | 2008-11-15 22:51:03 +0000 | [diff] [blame] | 74 | endif( NOT idx LESS 0 ) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 75 | endforeach(c) |
| 76 | # We must match capitalization. |
| 77 | string(TOUPPER "${llvm_libs}" capitalized_libs) |
Oscar Fuentes | 0b2bdff | 2008-11-16 04:13:19 +0000 | [diff] [blame] | 78 | list(REMOVE_DUPLICATES expanded_components) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 79 | list(LENGTH expanded_components lst_size) |
Oscar Fuentes | 9f2e0e2 | 2009-08-12 04:05:26 +0000 | [diff] [blame] | 80 | set(result "") |
| 81 | while( 0 LESS ${lst_size} ) |
| 82 | list(GET expanded_components 0 c) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 83 | string(TOUPPER "${c}" capitalized) |
| 84 | list(FIND capitalized_libs ${capitalized} idx) |
| 85 | if( idx LESS 0 ) |
| 86 | message(FATAL_ERROR "Library ${c} not found in list of llvm libraries.") |
| 87 | endif( idx LESS 0 ) |
| 88 | list(GET llvm_libs ${idx} canonical_lib) |
Oscar Fuentes | 9f2e0e2 | 2009-08-12 04:05:26 +0000 | [diff] [blame] | 89 | list(REMOVE_ITEM result ${canonical_lib}) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 90 | list(APPEND result ${canonical_lib}) |
Oscar Fuentes | 9f2e0e2 | 2009-08-12 04:05:26 +0000 | [diff] [blame] | 91 | foreach(c ${MSVC_LIB_DEPS_${canonical_lib}}) |
| 92 | list(REMOVE_ITEM expanded_components ${c}) |
| 93 | endforeach() |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 94 | list(APPEND expanded_components ${MSVC_LIB_DEPS_${canonical_lib}}) |
Oscar Fuentes | 9f2e0e2 | 2009-08-12 04:05:26 +0000 | [diff] [blame] | 95 | list(REMOVE_AT expanded_components 0) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 96 | list(LENGTH expanded_components lst_size) |
Oscar Fuentes | 9f2e0e2 | 2009-08-12 04:05:26 +0000 | [diff] [blame] | 97 | endwhile( 0 LESS ${lst_size} ) |
Oscar Fuentes | 4688b41 | 2008-10-31 01:24:51 +0000 | [diff] [blame] | 98 | set(${out_libs} ${result} PARENT_SCOPE) |
Douglas Gregor | 92aa978 | 2009-06-04 19:53:37 +0000 | [diff] [blame] | 99 | endfunction(explicit_map_components_to_libraries) |
Oscar Fuentes | ac55247 | 2009-08-14 16:59:41 +0000 | [diff] [blame] | 100 | |
| 101 | |
| 102 | # The library dependency data is contained in the file |
| 103 | # LLVMLibDeps.cmake on this directory. It is automatically generated |
| 104 | # by tools/llvm-config/CMakeLists.txt when the build comprises all the |
| 105 | # targets and we are on a environment Posix enough to build the |
| 106 | # llvm-config script. This, in practice, just excludes MSVC. |
| 107 | |
| 108 | # When you remove or rename a library from the build, be sure to |
| 109 | # remove its file from lib/ as well, or the GenLibDeps.pl script will |
| 110 | # include it on its analysis! |
| 111 | |
| 112 | # The format generated by GenLibDeps.pl |
| 113 | |
| 114 | # LLVMARMAsmPrinter.o: LLVMARMCodeGen.o libLLVMAsmPrinter.a libLLVMCodeGen.a libLLVMCore.a libLLVMSupport.a libLLVMTarget.a |
| 115 | |
| 116 | # is translated to: |
| 117 | |
| 118 | # set(MSVC_LIB_DEPS_LLVMARMAsmPrinter LLVMARMCodeGen LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget) |
| 119 | |
| 120 | # It is necessary to remove the `lib' prefix and the `.a'. |
| 121 | |
| 122 | # This 'sed' script should do the trick: |
| 123 | # sed -e s'#\.a##g' -e 's#libLLVM#LLVM#g' -e 's#: # #' -e 's#\(.*\)#set(MSVC_LIB_DEPS_\1)#' ~/llvm/tools/llvm-config/LibDeps.txt |
| 124 | |
| 125 | include(LLVMLibDeps) |