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