blob: cfb0db893309667309d478525eae592ac2d5bb4e [file] [log] [blame]
Oscar Fuentesa4a0ee22009-01-22 01:20:31 +00001include(FindPerl)
Oscar Fuentese32d0ec2009-08-12 03:32:44 +00002include(LLVMLibDeps)
Oscar Fuentesfd6daa82009-05-27 15:49:33 +00003
4function(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)
19endfunction(get_system_libs)
20
21
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000022macro(llvm_config executable)
Douglas Gregor5d3c4e12009-06-23 18:30:17 +000023 explicit_llvm_config(${executable} ${ARGN})
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000024endmacro(llvm_config)
Oscar Fuentes00905d52008-09-22 01:08:49 +000025
26
Douglas Gregor92aa9782009-06-04 19:53:37 +000027function(explicit_llvm_config executable)
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000028 set( link_components ${ARGN} )
Oscar Fuentes827283f2008-11-15 22:51:03 +000029
Douglas Gregor92aa9782009-06-04 19:53:37 +000030 explicit_map_components_to_libraries(LIBRARIES ${link_components})
Oscar Fuentes4688b412008-10-31 01:24:51 +000031 target_link_libraries(${executable} ${LIBRARIES})
Douglas Gregor92aa9782009-06-04 19:53:37 +000032endfunction(explicit_llvm_config)
Oscar Fuentes4688b412008-10-31 01:24:51 +000033
34
Douglas Gregor92aa9782009-06-04 19:53:37 +000035function(explicit_map_components_to_libraries out_libs)
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000036 set( link_components ${ARGN} )
Oscar Fuentes4688b412008-10-31 01:24:51 +000037 foreach(c ${link_components})
Daniel Dunbarc7df3cb2009-07-17 20:42:00 +000038 # add codegen, asmprinter, asmparser
Oscar Fuentes827283f2008-11-15 22:51:03 +000039 list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
40 if( NOT idx LESS 0 )
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000041 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 Fuentes827283f2008-11-15 22:51:03 +000052 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 Dunbarc7df3cb2009-07-17 20:42:00 +000056 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 Dunbar1258e702009-07-15 07:52:36 +000060 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 Fuentes827283f2008-11-15 22:51:03 +000064 elseif( c STREQUAL "native" )
Oscar Fuentes4688b412008-10-31 01:24:51 +000065 # 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 Fuentes4688b412008-10-31 01:24:51 +000075 elseif( c STREQUAL "all" )
76 list(APPEND expanded_components ${llvm_libs})
Oscar Fuentes827283f2008-11-15 22:51:03 +000077 else( NOT idx LESS 0 )
Oscar Fuentes4688b412008-10-31 01:24:51 +000078 list(APPEND expanded_components LLVM${c})
Oscar Fuentes827283f2008-11-15 22:51:03 +000079 endif( NOT idx LESS 0 )
Oscar Fuentes4688b412008-10-31 01:24:51 +000080 endforeach(c)
81 # We must match capitalization.
82 string(TOUPPER "${llvm_libs}" capitalized_libs)
Oscar Fuentes0b2bdff2008-11-16 04:13:19 +000083 list(REMOVE_DUPLICATES expanded_components)
Oscar Fuentes4688b412008-10-31 01:24:51 +000084 list(LENGTH expanded_components lst_size)
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +000085 set(result "")
86 while( 0 LESS ${lst_size} )
87 list(GET expanded_components 0 c)
Oscar Fuentes4688b412008-10-31 01:24:51 +000088 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 Fuentes9f2e0e22009-08-12 04:05:26 +000094 list(REMOVE_ITEM result ${canonical_lib})
Oscar Fuentes4688b412008-10-31 01:24:51 +000095 list(APPEND result ${canonical_lib})
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +000096 foreach(c ${MSVC_LIB_DEPS_${canonical_lib}})
97 list(REMOVE_ITEM expanded_components ${c})
98 endforeach()
Oscar Fuentes4688b412008-10-31 01:24:51 +000099 list(APPEND expanded_components ${MSVC_LIB_DEPS_${canonical_lib}})
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +0000100 list(REMOVE_AT expanded_components 0)
Oscar Fuentes4688b412008-10-31 01:24:51 +0000101 list(LENGTH expanded_components lst_size)
Oscar Fuentes9f2e0e22009-08-12 04:05:26 +0000102 endwhile( 0 LESS ${lst_size} )
Oscar Fuentes4688b412008-10-31 01:24:51 +0000103 set(${out_libs} ${result} PARENT_SCOPE)
Douglas Gregor92aa9782009-06-04 19:53:37 +0000104endfunction(explicit_map_components_to_libraries)