blob: 4a05e32b2acedd73b62ca1b6509db1d10dfa2e1d [file] [log] [blame]
Oscar Fuentese32d0ec2009-08-12 03:32:44 +00001include(LLVMLibDeps)
Oscar Fuentesfd6daa82009-05-27 15:49:33 +00002
3function(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)
18endfunction(get_system_libs)
19
20
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000021macro(llvm_config executable)
Douglas Gregor5d3c4e12009-06-23 18:30:17 +000022 explicit_llvm_config(${executable} ${ARGN})
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000023endmacro(llvm_config)
Oscar Fuentes00905d52008-09-22 01:08:49 +000024
25
Douglas Gregor92aa9782009-06-04 19:53:37 +000026function(explicit_llvm_config executable)
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000027 set( link_components ${ARGN} )
Oscar Fuentes827283f2008-11-15 22:51:03 +000028
Douglas Gregor92aa9782009-06-04 19:53:37 +000029 explicit_map_components_to_libraries(LIBRARIES ${link_components})
Oscar Fuentes4688b412008-10-31 01:24:51 +000030 target_link_libraries(${executable} ${LIBRARIES})
Douglas Gregor92aa9782009-06-04 19:53:37 +000031endfunction(explicit_llvm_config)
Oscar Fuentes4688b412008-10-31 01:24:51 +000032
33
Douglas Gregor92aa9782009-06-04 19:53:37 +000034function(explicit_map_components_to_libraries out_libs)
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000035 set( link_components ${ARGN} )
Oscar Fuentes4688b412008-10-31 01:24:51 +000036 foreach(c ${link_components})
Daniel Dunbarc7df3cb2009-07-17 20:42:00 +000037 # add codegen, asmprinter, asmparser
Oscar Fuentes827283f2008-11-15 22:51:03 +000038 list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
39 if( NOT idx LESS 0 )
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000040 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 Fuentes827283f2008-11-15 22:51:03 +000051 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 Dunbarc7df3cb2009-07-17 20:42:00 +000055 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 Dunbar1258e702009-07-15 07:52:36 +000059 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 Fuentes827283f2008-11-15 22:51:03 +000063 elseif( c STREQUAL "native" )
Oscar Fuentes4688b412008-10-31 01:24:51 +000064 # 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 Fuentes4688b412008-10-31 01:24:51 +000074 elseif( c STREQUAL "all" )
75 list(APPEND expanded_components ${llvm_libs})
Oscar Fuentes827283f2008-11-15 22:51:03 +000076 else( NOT idx LESS 0 )
Oscar Fuentes4688b412008-10-31 01:24:51 +000077 list(APPEND expanded_components LLVM${c})
Oscar Fuentes827283f2008-11-15 22:51:03 +000078 endif( NOT idx LESS 0 )
Oscar Fuentes4688b412008-10-31 01:24:51 +000079 endforeach(c)
80 # We must match capitalization.
81 string(TOUPPER "${llvm_libs}" capitalized_libs)
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000082 list(REMOVE_DUPLICATES expanded_components)
Oscar Fuentes4688b412008-10-31 01:24:51 +000083 list(LENGTH expanded_components lst_size)
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +000084 set(result "")
85 while( 0 LESS ${lst_size} )
86 list(GET expanded_components 0 c)
Oscar Fuentes4688b412008-10-31 01:24:51 +000087 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 Fuentes9f2e0e22009-08-12 04:05:26 +000093 list(REMOVE_ITEM result ${canonical_lib})
Oscar Fuentes4688b412008-10-31 01:24:51 +000094 list(APPEND result ${canonical_lib})
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +000095 foreach(c ${MSVC_LIB_DEPS_${canonical_lib}})
96 list(REMOVE_ITEM expanded_components ${c})
97 endforeach()
Oscar Fuentes4688b412008-10-31 01:24:51 +000098 list(APPEND expanded_components ${MSVC_LIB_DEPS_${canonical_lib}})
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +000099 list(REMOVE_AT expanded_components 0)
Oscar Fuentes4688b412008-10-31 01:24:51 +0000100 list(LENGTH expanded_components lst_size)
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +0000101 endwhile( 0 LESS ${lst_size} )
Oscar Fuentes4688b412008-10-31 01:24:51 +0000102 set(${out_libs} ${result} PARENT_SCOPE)
Douglas Gregor92aa9782009-06-04 19:53:37 +0000103endfunction(explicit_map_components_to_libraries)