blob: 1d8d090986dcaadd9194abf1ddfe6239039e4b4c [file] [log] [blame]
Oscar Fuentesfd6daa82009-05-27 15:49:33 +00001function(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)
16endfunction(get_system_libs)
17
18
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000019macro(llvm_config executable)
Douglas Gregor5d3c4e12009-06-23 18:30:17 +000020 explicit_llvm_config(${executable} ${ARGN})
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000021endmacro(llvm_config)
Oscar Fuentes00905d52008-09-22 01:08:49 +000022
23
Douglas Gregor92aa9782009-06-04 19:53:37 +000024function(explicit_llvm_config executable)
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000025 set( link_components ${ARGN} )
Oscar Fuentes827283f2008-11-15 22:51:03 +000026
Douglas Gregor92aa9782009-06-04 19:53:37 +000027 explicit_map_components_to_libraries(LIBRARIES ${link_components})
Oscar Fuentes4688b412008-10-31 01:24:51 +000028 target_link_libraries(${executable} ${LIBRARIES})
Douglas Gregor92aa9782009-06-04 19:53:37 +000029endfunction(explicit_llvm_config)
Oscar Fuentes4688b412008-10-31 01:24:51 +000030
31
Douglas Gregor92aa9782009-06-04 19:53:37 +000032function(explicit_map_components_to_libraries out_libs)
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000033 set( link_components ${ARGN} )
Oscar Fuentes4688b412008-10-31 01:24:51 +000034 foreach(c ${link_components})
Daniel Dunbarc7df3cb2009-07-17 20:42:00 +000035 # add codegen, asmprinter, asmparser
Oscar Fuentes827283f2008-11-15 22:51:03 +000036 list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
37 if( NOT idx LESS 0 )
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000038 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 Fuentes827283f2008-11-15 22:51:03 +000049 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 Dunbarc7df3cb2009-07-17 20:42:00 +000053 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 Dunbar1258e702009-07-15 07:52:36 +000057 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 Fuentes827283f2008-11-15 22:51:03 +000061 elseif( c STREQUAL "native" )
Oscar Fuentes4688b412008-10-31 01:24:51 +000062 # TODO: we assume ARCH is X86. In this case, we must use nativecodegen
63 # component instead. Do nothing, as in llvm-config script.
64 elseif( c STREQUAL "nativecodegen" )
65 # TODO: we assume ARCH is X86.
66 list(APPEND expanded_components "LLVMX86CodeGen")
67 elseif( c STREQUAL "backend" )
68 # same case as in `native'.
69 elseif( c STREQUAL "engine" )
70 # TODO: as we assume we are on X86, this is `jit'.
71 list(APPEND expanded_components "LLVMJIT")
Oscar Fuentes4688b412008-10-31 01:24:51 +000072 elseif( c STREQUAL "all" )
73 list(APPEND expanded_components ${llvm_libs})
Oscar Fuentes827283f2008-11-15 22:51:03 +000074 else( NOT idx LESS 0 )
Oscar Fuentes4688b412008-10-31 01:24:51 +000075 list(APPEND expanded_components LLVM${c})
Oscar Fuentes827283f2008-11-15 22:51:03 +000076 endif( NOT idx LESS 0 )
Oscar Fuentes4688b412008-10-31 01:24:51 +000077 endforeach(c)
78 # We must match capitalization.
79 string(TOUPPER "${llvm_libs}" capitalized_libs)
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000080 list(REMOVE_DUPLICATES expanded_components)
Oscar Fuentes4688b412008-10-31 01:24:51 +000081 list(LENGTH expanded_components lst_size)
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +000082 set(result "")
83 while( 0 LESS ${lst_size} )
84 list(GET expanded_components 0 c)
Oscar Fuentes4688b412008-10-31 01:24:51 +000085 string(TOUPPER "${c}" capitalized)
86 list(FIND capitalized_libs ${capitalized} idx)
87 if( idx LESS 0 )
88 message(FATAL_ERROR "Library ${c} not found in list of llvm libraries.")
89 endif( idx LESS 0 )
90 list(GET llvm_libs ${idx} canonical_lib)
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +000091 list(REMOVE_ITEM result ${canonical_lib})
Oscar Fuentes4688b412008-10-31 01:24:51 +000092 list(APPEND result ${canonical_lib})
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +000093 foreach(c ${MSVC_LIB_DEPS_${canonical_lib}})
94 list(REMOVE_ITEM expanded_components ${c})
95 endforeach()
Oscar Fuentes4688b412008-10-31 01:24:51 +000096 list(APPEND expanded_components ${MSVC_LIB_DEPS_${canonical_lib}})
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +000097 list(REMOVE_AT expanded_components 0)
Oscar Fuentes4688b412008-10-31 01:24:51 +000098 list(LENGTH expanded_components lst_size)
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +000099 endwhile( 0 LESS ${lst_size} )
Oscar Fuentes4688b412008-10-31 01:24:51 +0000100 set(${out_libs} ${result} PARENT_SCOPE)
Douglas Gregor92aa9782009-06-04 19:53:37 +0000101endfunction(explicit_map_components_to_libraries)
Oscar Fuentesac552472009-08-14 16:59:41 +0000102
103
104# The library dependency data is contained in the file
105# LLVMLibDeps.cmake on this directory. It is automatically generated
106# by tools/llvm-config/CMakeLists.txt when the build comprises all the
107# targets and we are on a environment Posix enough to build the
108# llvm-config script. This, in practice, just excludes MSVC.
109
110# When you remove or rename a library from the build, be sure to
111# remove its file from lib/ as well, or the GenLibDeps.pl script will
112# include it on its analysis!
113
114# The format generated by GenLibDeps.pl
115
116# LLVMARMAsmPrinter.o: LLVMARMCodeGen.o libLLVMAsmPrinter.a libLLVMCodeGen.a libLLVMCore.a libLLVMSupport.a libLLVMTarget.a
117
118# is translated to:
119
120# set(MSVC_LIB_DEPS_LLVMARMAsmPrinter LLVMARMCodeGen LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget)
121
122# It is necessary to remove the `lib' prefix and the `.a'.
123
124# This 'sed' script should do the trick:
125# 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
126
127include(LLVMLibDeps)