2009-05-27 15:49:33 +00:00
|
|
|
function(get_system_libs return_var)
|
|
|
|
# Returns in `return_var' a list of system libraries used by LLVM.
|
|
|
|
if( NOT MSVC )
|
|
|
|
if( MINGW )
|
|
|
|
set(system_libs ${system_libs} imagehlp psapi)
|
|
|
|
elseif( CMAKE_HOST_UNIX )
|
|
|
|
if( HAVE_LIBDL )
|
2009-11-19 23:21:43 +00:00
|
|
|
set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
|
2009-05-27 15:49:33 +00:00
|
|
|
endif()
|
|
|
|
if( LLVM_ENABLE_THREADS AND HAVE_LIBPTHREAD )
|
|
|
|
set(system_libs ${system_libs} pthread)
|
|
|
|
endif()
|
|
|
|
endif( MINGW )
|
|
|
|
endif( NOT MSVC )
|
|
|
|
set(${return_var} ${system_libs} PARENT_SCOPE)
|
|
|
|
endfunction(get_system_libs)
|
|
|
|
|
|
|
|
|
2008-11-16 04:13:19 +00:00
|
|
|
macro(llvm_config executable)
|
2009-06-23 18:30:17 +00:00
|
|
|
explicit_llvm_config(${executable} ${ARGN})
|
2008-11-16 04:13:19 +00:00
|
|
|
endmacro(llvm_config)
|
2008-09-22 01:08:49 +00:00
|
|
|
|
|
|
|
|
2009-06-04 19:53:37 +00:00
|
|
|
function(explicit_llvm_config executable)
|
2008-11-16 04:13:19 +00:00
|
|
|
set( link_components ${ARGN} )
|
2009-06-04 19:53:37 +00:00
|
|
|
|
|
|
|
explicit_map_components_to_libraries(LIBRARIES ${link_components})
|
2008-10-31 01:24:51 +00:00
|
|
|
target_link_libraries(${executable} ${LIBRARIES})
|
2009-06-04 19:53:37 +00:00
|
|
|
endfunction(explicit_llvm_config)
|
2008-10-31 01:24:51 +00:00
|
|
|
|
|
|
|
|
2009-06-04 19:53:37 +00:00
|
|
|
function(explicit_map_components_to_libraries out_libs)
|
2008-11-16 04:13:19 +00:00
|
|
|
set( link_components ${ARGN} )
|
2008-10-31 01:24:51 +00:00
|
|
|
foreach(c ${link_components})
|
2009-11-25 04:46:58 +00:00
|
|
|
# add codegen, asmprinter, asmparser, disassembler
|
2008-11-15 22:51:03 +00:00
|
|
|
list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
|
|
|
|
if( NOT idx LESS 0 )
|
2008-11-16 04:13:19 +00:00
|
|
|
list(FIND llvm_libs "LLVM${c}CodeGen" idx)
|
|
|
|
if( NOT idx LESS 0 )
|
|
|
|
list(APPEND expanded_components "LLVM${c}CodeGen")
|
|
|
|
else()
|
|
|
|
list(FIND llvm_libs "LLVM${c}" idx)
|
|
|
|
if( NOT idx LESS 0 )
|
|
|
|
list(APPEND expanded_components "LLVM${c}")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
|
|
|
|
endif()
|
|
|
|
endif()
|
2008-11-15 22:51:03 +00:00
|
|
|
list(FIND llvm_libs "LLVM${c}AsmPrinter" asmidx)
|
|
|
|
if( NOT asmidx LESS 0 )
|
|
|
|
list(APPEND expanded_components "LLVM${c}AsmPrinter")
|
|
|
|
endif()
|
2009-07-17 20:42:00 +00:00
|
|
|
list(FIND llvm_libs "LLVM${c}AsmParser" asmidx)
|
|
|
|
if( NOT asmidx LESS 0 )
|
|
|
|
list(APPEND expanded_components "LLVM${c}AsmParser")
|
|
|
|
endif()
|
2009-07-15 07:52:36 +00:00
|
|
|
list(FIND llvm_libs "LLVM${c}Info" asmidx)
|
|
|
|
if( NOT asmidx LESS 0 )
|
|
|
|
list(APPEND expanded_components "LLVM${c}Info")
|
|
|
|
endif()
|
2009-11-25 04:46:58 +00:00
|
|
|
list(FIND llvm_libs "LLVM${c}Disassembler" asmidx)
|
|
|
|
if( NOT asmidx LESS 0 )
|
|
|
|
list(APPEND expanded_components "LLVM${c}Disassembler")
|
|
|
|
endif()
|
2008-11-15 22:51:03 +00:00
|
|
|
elseif( c STREQUAL "native" )
|
2009-08-19 12:41:52 +00:00
|
|
|
list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
|
2008-10-31 01:24:51 +00:00
|
|
|
elseif( c STREQUAL "nativecodegen" )
|
2009-08-19 12:41:52 +00:00
|
|
|
list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
|
2008-10-31 01:24:51 +00:00
|
|
|
elseif( c STREQUAL "backend" )
|
|
|
|
# same case as in `native'.
|
|
|
|
elseif( c STREQUAL "engine" )
|
|
|
|
# TODO: as we assume we are on X86, this is `jit'.
|
|
|
|
list(APPEND expanded_components "LLVMJIT")
|
|
|
|
elseif( c STREQUAL "all" )
|
|
|
|
list(APPEND expanded_components ${llvm_libs})
|
2008-11-15 22:51:03 +00:00
|
|
|
else( NOT idx LESS 0 )
|
2008-10-31 01:24:51 +00:00
|
|
|
list(APPEND expanded_components LLVM${c})
|
2008-11-15 22:51:03 +00:00
|
|
|
endif( NOT idx LESS 0 )
|
2008-10-31 01:24:51 +00:00
|
|
|
endforeach(c)
|
|
|
|
# We must match capitalization.
|
|
|
|
string(TOUPPER "${llvm_libs}" capitalized_libs)
|
2008-11-16 04:13:19 +00:00
|
|
|
list(REMOVE_DUPLICATES expanded_components)
|
2008-10-31 01:24:51 +00:00
|
|
|
list(LENGTH expanded_components lst_size)
|
2009-08-12 04:05:26 +00:00
|
|
|
set(result "")
|
|
|
|
while( 0 LESS ${lst_size} )
|
|
|
|
list(GET expanded_components 0 c)
|
2008-10-31 01:24:51 +00:00
|
|
|
string(TOUPPER "${c}" capitalized)
|
|
|
|
list(FIND capitalized_libs ${capitalized} idx)
|
|
|
|
if( idx LESS 0 )
|
|
|
|
message(FATAL_ERROR "Library ${c} not found in list of llvm libraries.")
|
|
|
|
endif( idx LESS 0 )
|
|
|
|
list(GET llvm_libs ${idx} canonical_lib)
|
2009-08-12 04:05:26 +00:00
|
|
|
list(REMOVE_ITEM result ${canonical_lib})
|
2008-10-31 01:24:51 +00:00
|
|
|
list(APPEND result ${canonical_lib})
|
2009-08-12 04:05:26 +00:00
|
|
|
foreach(c ${MSVC_LIB_DEPS_${canonical_lib}})
|
|
|
|
list(REMOVE_ITEM expanded_components ${c})
|
|
|
|
endforeach()
|
2008-10-31 01:24:51 +00:00
|
|
|
list(APPEND expanded_components ${MSVC_LIB_DEPS_${canonical_lib}})
|
2009-08-12 04:05:26 +00:00
|
|
|
list(REMOVE_AT expanded_components 0)
|
2008-10-31 01:24:51 +00:00
|
|
|
list(LENGTH expanded_components lst_size)
|
2009-08-12 04:05:26 +00:00
|
|
|
endwhile( 0 LESS ${lst_size} )
|
2008-10-31 01:24:51 +00:00
|
|
|
set(${out_libs} ${result} PARENT_SCOPE)
|
2009-06-04 19:53:37 +00:00
|
|
|
endfunction(explicit_map_components_to_libraries)
|
2009-08-14 16:59:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
# The library dependency data is contained in the file
|
|
|
|
# LLVMLibDeps.cmake on this directory. It is automatically generated
|
|
|
|
# by tools/llvm-config/CMakeLists.txt when the build comprises all the
|
|
|
|
# targets and we are on a environment Posix enough to build the
|
|
|
|
# llvm-config script. This, in practice, just excludes MSVC.
|
|
|
|
|
|
|
|
# When you remove or rename a library from the build, be sure to
|
|
|
|
# remove its file from lib/ as well, or the GenLibDeps.pl script will
|
|
|
|
# include it on its analysis!
|
|
|
|
|
|
|
|
# The format generated by GenLibDeps.pl
|
|
|
|
|
|
|
|
# LLVMARMAsmPrinter.o: LLVMARMCodeGen.o libLLVMAsmPrinter.a libLLVMCodeGen.a libLLVMCore.a libLLVMSupport.a libLLVMTarget.a
|
|
|
|
|
|
|
|
# is translated to:
|
|
|
|
|
|
|
|
# set(MSVC_LIB_DEPS_LLVMARMAsmPrinter LLVMARMCodeGen LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget)
|
|
|
|
|
|
|
|
# It is necessary to remove the `lib' prefix and the `.a'.
|
|
|
|
|
|
|
|
# This 'sed' script should do the trick:
|
|
|
|
# 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
|
|
|
|
|
|
|
|
include(LLVMLibDeps)
|