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)
|
|
|
|
|
|
|
|
|
2010-08-02 20:48:01 +00:00
|
|
|
function(is_llvm_target_library library return_var)
|
|
|
|
# Sets variable `return_var' to ON if `library' corresponds to a
|
|
|
|
# LLVM supported target. To OFF if it doesn't.
|
|
|
|
set(${return_var} OFF PARENT_SCOPE)
|
|
|
|
string(TOUPPER "${library}" capitalized_lib)
|
|
|
|
string(TOUPPER "${LLVM_ALL_TARGETS}" targets)
|
|
|
|
foreach(t ${targets})
|
2010-08-02 21:24:12 +00:00
|
|
|
if( capitalized_lib STREQUAL "LLVM${t}" OR
|
|
|
|
capitalized_lib STREQUAL "LLVM${t}CODEGEN" OR
|
2010-08-02 20:48:01 +00:00
|
|
|
capitalized_lib STREQUAL "LLVM${t}ASMPARSER" OR
|
2010-08-02 21:24:12 +00:00
|
|
|
capitalized_lib STREQUAL "LLVM${t}ASMPRINTER" OR
|
2010-08-02 20:48:01 +00:00
|
|
|
capitalized_lib STREQUAL "LLVM${t}DISASSEMBLER" OR
|
|
|
|
capitalized_lib STREQUAL "LLVM${t}INFO" )
|
|
|
|
set(${return_var} ON PARENT_SCOPE)
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endfunction(is_llvm_target_library)
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2010-08-09 03:26:43 +00:00
|
|
|
# This is a variant intended for the final user:
|
|
|
|
function(llvm_map_components_to_libraries OUT_VAR)
|
|
|
|
explicit_map_components_to_libraries(result ${ARGN})
|
2010-08-09 03:47:11 +00:00
|
|
|
get_system_libs(sys_result)
|
2010-08-11 00:51:32 +00:00
|
|
|
set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE )
|
2010-08-09 03:26:43 +00:00
|
|
|
endfunction(llvm_map_components_to_libraries)
|
|
|
|
|
|
|
|
|
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)
|
2010-08-02 21:24:12 +00:00
|
|
|
set(add_it ON)
|
2008-10-31 01:24:51 +00:00
|
|
|
if( idx LESS 0 )
|
2010-08-02 20:48:01 +00:00
|
|
|
# The library is unkown. Maybe is an ommitted target?
|
|
|
|
is_llvm_target_library(${c} iltl_result)
|
2010-08-02 21:24:12 +00:00
|
|
|
if( NOT iltl_result )
|
2010-08-02 20:48:01 +00:00
|
|
|
message(FATAL_ERROR "Library ${c} not found in list of llvm libraries.")
|
|
|
|
endif()
|
2010-08-02 21:24:12 +00:00
|
|
|
set(add_it OFF)
|
2008-10-31 01:24:51 +00:00
|
|
|
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})
|
|
|
|
foreach(c ${MSVC_LIB_DEPS_${canonical_lib}})
|
|
|
|
list(REMOVE_ITEM expanded_components ${c})
|
|
|
|
endforeach()
|
2010-08-02 21:24:12 +00:00
|
|
|
if( add_it )
|
|
|
|
list(APPEND result ${canonical_lib})
|
|
|
|
list(APPEND expanded_components ${MSVC_LIB_DEPS_${canonical_lib}})
|
|
|
|
endif()
|
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
|
|
|
|
|
2010-08-15 15:08:27 +00:00
|
|
|
# libLLVMARMAsmPrinter.a: libLLVMMC.a libLLVMSupport.a
|
2009-08-14 16:59:41 +00:00
|
|
|
|
|
|
|
# is translated to:
|
|
|
|
|
2010-08-15 15:08:27 +00:00
|
|
|
# set(MSVC_LIB_DEPS_LLVMARMAsmPrinter LLVMMC LLVMSupport)
|
2009-08-14 16:59:41 +00:00
|
|
|
|
2010-08-15 15:08:27 +00:00
|
|
|
# It is necessary to remove the `lib' prefix and the `.a' suffix.
|
2009-08-14 16:59:41 +00:00
|
|
|
|
|
|
|
# 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)
|