1 function(get_system_libs return_var)
2 # Returns in `return_var' a list of system libraries used by LLVM.
5 set(system_libs ${system_libs} imagehlp psapi)
6 elseif( CMAKE_HOST_UNIX )
8 set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
10 if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
11 set(system_libs ${system_libs} pthread)
15 set(${return_var} ${system_libs} PARENT_SCOPE)
16 endfunction(get_system_libs)
19 macro(llvm_config executable)
20 explicit_llvm_config(${executable} ${ARGN})
24 function(explicit_llvm_config executable)
25 set( link_components ${ARGN} )
27 explicit_map_components_to_libraries(LIBRARIES ${link_components})
28 target_link_libraries(${executable} ${LIBRARIES})
29 endfunction(explicit_llvm_config)
32 function(explicit_map_components_to_libraries out_libs)
33 set( link_components ${ARGN} )
34 foreach(c ${link_components})
35 # add codegen, asmprinter, asmparser, disassembler
36 list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
38 list(FIND llvm_libs "LLVM${c}CodeGen" idx)
40 list(APPEND expanded_components "LLVM${c}CodeGen")
42 list(FIND llvm_libs "LLVM${c}" idx)
44 list(APPEND expanded_components "LLVM${c}")
46 message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
49 list(FIND llvm_libs "LLVM${c}AsmPrinter" asmidx)
50 if( NOT asmidx LESS 0 )
51 list(APPEND expanded_components "LLVM${c}AsmPrinter")
53 list(FIND llvm_libs "LLVM${c}AsmParser" asmidx)
54 if( NOT asmidx LESS 0 )
55 list(APPEND expanded_components "LLVM${c}AsmParser")
57 list(FIND llvm_libs "LLVM${c}Info" asmidx)
58 if( NOT asmidx LESS 0 )
59 list(APPEND expanded_components "LLVM${c}Info")
61 list(FIND llvm_libs "LLVM${c}Disassembler" asmidx)
62 if( NOT asmidx LESS 0 )
63 list(APPEND expanded_components "LLVM${c}Disassembler")
65 elseif( c STREQUAL "native" )
66 list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
67 elseif( c STREQUAL "nativecodegen" )
68 list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
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")
74 elseif( c STREQUAL "all" )
75 list(APPEND expanded_components ${llvm_libs})
76 else( NOT idx LESS 0 )
77 list(APPEND expanded_components LLVM${c})
78 endif( NOT idx LESS 0 )
80 # We must match capitalization.
81 string(TOUPPER "${llvm_libs}" capitalized_libs)
82 list(REMOVE_DUPLICATES expanded_components)
83 list(LENGTH expanded_components lst_size)
85 while( 0 LESS ${lst_size} )
86 list(GET expanded_components 0 c)
87 string(TOUPPER "${c}" capitalized)
88 list(FIND capitalized_libs ${capitalized} idx)
90 message(FATAL_ERROR "Library ${c} not found in list of llvm libraries.")
92 list(GET llvm_libs ${idx} canonical_lib)
93 list(REMOVE_ITEM result ${canonical_lib})
94 list(APPEND result ${canonical_lib})
95 foreach(c ${MSVC_LIB_DEPS_${canonical_lib}})
96 list(REMOVE_ITEM expanded_components ${c})
98 list(APPEND expanded_components ${MSVC_LIB_DEPS_${canonical_lib}})
99 list(REMOVE_AT expanded_components 0)
100 list(LENGTH expanded_components lst_size)
101 endwhile( 0 LESS ${lst_size} )
102 set(${out_libs} ${result} PARENT_SCOPE)
103 endfunction(explicit_map_components_to_libraries)
106 # The library dependency data is contained in the file
107 # LLVMLibDeps.cmake on this directory. It is automatically generated
108 # by tools/llvm-config/CMakeLists.txt when the build comprises all the
109 # targets and we are on a environment Posix enough to build the
110 # llvm-config script. This, in practice, just excludes MSVC.
112 # When you remove or rename a library from the build, be sure to
113 # remove its file from lib/ as well, or the GenLibDeps.pl script will
114 # include it on its analysis!
116 # The format generated by GenLibDeps.pl
118 # LLVMARMAsmPrinter.o: LLVMARMCodeGen.o libLLVMAsmPrinter.a libLLVMCodeGen.a libLLVMCore.a libLLVMSupport.a libLLVMTarget.a
122 # set(MSVC_LIB_DEPS_LLVMARMAsmPrinter LLVMARMCodeGen LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget)
124 # It is necessary to remove the `lib' prefix and the `.a'.
126 # This 'sed' script should do the trick:
127 # 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