2010-09-13 23:59:48 +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 )
|
|
|
|
set(system_libs ${system_libs} ${CMAKE_DL_LIBS})
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2011-03-29 20:51:08 +00:00
|
|
|
function(link_system_libs target)
|
|
|
|
get_system_libs(llvm_system_libs)
|
|
|
|
target_link_libraries(${target} ${llvm_system_libs})
|
|
|
|
endfunction(link_system_libs)
|
|
|
|
|
|
|
|
|
2010-09-13 23:59:48 +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})
|
2011-03-15 14:53:53 +00:00
|
|
|
if( capitalized_lib STREQUAL t OR
|
|
|
|
capitalized_lib STREQUAL "LLVM${t}" OR
|
2010-09-13 23:59:48 +00:00
|
|
|
capitalized_lib STREQUAL "LLVM${t}CODEGEN" OR
|
|
|
|
capitalized_lib STREQUAL "LLVM${t}ASMPARSER" OR
|
|
|
|
capitalized_lib STREQUAL "LLVM${t}ASMPRINTER" OR
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
macro(llvm_config executable)
|
|
|
|
explicit_llvm_config(${executable} ${ARGN})
|
|
|
|
endmacro(llvm_config)
|
|
|
|
|
|
|
|
|
|
|
|
function(explicit_llvm_config executable)
|
|
|
|
set( link_components ${ARGN} )
|
|
|
|
|
|
|
|
explicit_map_components_to_libraries(LIBRARIES ${link_components})
|
|
|
|
target_link_libraries(${executable} ${LIBRARIES})
|
|
|
|
endfunction(explicit_llvm_config)
|
|
|
|
|
|
|
|
|
|
|
|
# This is a variant intended for the final user:
|
|
|
|
function(llvm_map_components_to_libraries OUT_VAR)
|
|
|
|
explicit_map_components_to_libraries(result ${ARGN})
|
|
|
|
get_system_libs(sys_result)
|
|
|
|
set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE )
|
|
|
|
endfunction(llvm_map_components_to_libraries)
|
|
|
|
|
|
|
|
|
|
|
|
function(explicit_map_components_to_libraries out_libs)
|
|
|
|
set( link_components ${ARGN} )
|
2011-02-18 22:06:14 +00:00
|
|
|
get_property(llvm_libs GLOBAL PROPERTY LLVM_LIBS)
|
2010-09-28 22:38:39 +00:00
|
|
|
string(TOUPPER "${llvm_libs}" capitalized_libs)
|
2011-03-09 14:44:46 +00:00
|
|
|
|
|
|
|
# Expand some keywords:
|
2011-03-23 17:42:13 +00:00
|
|
|
list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend)
|
2011-03-09 14:44:46 +00:00
|
|
|
list(FIND link_components "engine" engine_required)
|
2011-03-23 17:42:13 +00:00
|
|
|
if( NOT engine_required EQUAL -1 )
|
|
|
|
list(FIND LLVM_TARGETS_WITH_JIT "${LLVM_NATIVE_ARCH}" have_jit)
|
|
|
|
if( NOT have_native_backend EQUAL -1 AND NOT have_jit EQUAL -1 )
|
|
|
|
list(APPEND link_components "jit")
|
|
|
|
list(APPEND link_components "native")
|
|
|
|
else()
|
|
|
|
list(APPEND link_components "interpreter")
|
|
|
|
endif()
|
2011-03-09 14:44:46 +00:00
|
|
|
endif()
|
|
|
|
list(FIND link_components "native" native_required)
|
2011-03-23 17:42:13 +00:00
|
|
|
if( NOT native_required EQUAL -1 )
|
|
|
|
if( NOT have_native_backend EQUAL -1 )
|
|
|
|
list(APPEND link_components ${LLVM_NATIVE_ARCH})
|
|
|
|
endif()
|
2011-03-09 14:44:46 +00:00
|
|
|
endif()
|
|
|
|
|
2010-09-28 22:38:39 +00:00
|
|
|
# Translate symbolic component names to real libraries:
|
2010-09-13 23:59:48 +00:00
|
|
|
foreach(c ${link_components})
|
|
|
|
# add codegen, asmprinter, asmparser, disassembler
|
|
|
|
list(FIND LLVM_TARGETS_TO_BUILD ${c} idx)
|
|
|
|
if( NOT idx LESS 0 )
|
|
|
|
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()
|
|
|
|
list(FIND llvm_libs "LLVM${c}AsmPrinter" asmidx)
|
|
|
|
if( NOT asmidx LESS 0 )
|
|
|
|
list(APPEND expanded_components "LLVM${c}AsmPrinter")
|
|
|
|
endif()
|
|
|
|
list(FIND llvm_libs "LLVM${c}AsmParser" asmidx)
|
|
|
|
if( NOT asmidx LESS 0 )
|
|
|
|
list(APPEND expanded_components "LLVM${c}AsmParser")
|
|
|
|
endif()
|
|
|
|
list(FIND llvm_libs "LLVM${c}Info" asmidx)
|
|
|
|
if( NOT asmidx LESS 0 )
|
|
|
|
list(APPEND expanded_components "LLVM${c}Info")
|
|
|
|
endif()
|
|
|
|
list(FIND llvm_libs "LLVM${c}Disassembler" asmidx)
|
|
|
|
if( NOT asmidx LESS 0 )
|
|
|
|
list(APPEND expanded_components "LLVM${c}Disassembler")
|
|
|
|
endif()
|
|
|
|
elseif( c STREQUAL "native" )
|
2011-03-09 14:44:46 +00:00
|
|
|
# already processed
|
2010-09-13 23:59:48 +00:00
|
|
|
elseif( c STREQUAL "nativecodegen" )
|
|
|
|
list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}CodeGen")
|
|
|
|
elseif( c STREQUAL "backend" )
|
|
|
|
# same case as in `native'.
|
|
|
|
elseif( c STREQUAL "engine" )
|
2011-03-09 14:44:46 +00:00
|
|
|
# already processed
|
2010-09-13 23:59:48 +00:00
|
|
|
elseif( c STREQUAL "all" )
|
|
|
|
list(APPEND expanded_components ${llvm_libs})
|
|
|
|
else( NOT idx LESS 0 )
|
2010-09-28 22:38:39 +00:00
|
|
|
# Canonize the component name:
|
|
|
|
string(TOUPPER "${c}" capitalized)
|
|
|
|
list(FIND capitalized_libs LLVM${capitalized} lib_idx)
|
|
|
|
if( lib_idx LESS 0 )
|
|
|
|
# The component is unkown. Maybe is an ommitted target?
|
|
|
|
is_llvm_target_library(${c} iltl_result)
|
|
|
|
if( NOT iltl_result )
|
|
|
|
message(FATAL_ERROR "Library `${c}' not found in list of llvm libraries.")
|
|
|
|
endif()
|
|
|
|
else( lib_idx LESS 0 )
|
|
|
|
list(GET llvm_libs ${lib_idx} canonical_lib)
|
|
|
|
list(APPEND expanded_components ${canonical_lib})
|
|
|
|
endif( lib_idx LESS 0 )
|
2010-09-13 23:59:48 +00:00
|
|
|
endif( NOT idx LESS 0 )
|
|
|
|
endforeach(c)
|
2010-09-28 22:38:39 +00:00
|
|
|
# Expand dependencies while topologically sorting the list of libraries:
|
2010-09-13 23:59:48 +00:00
|
|
|
list(LENGTH expanded_components lst_size)
|
2010-09-28 22:38:39 +00:00
|
|
|
set(cursor 0)
|
|
|
|
set(processed)
|
|
|
|
while( cursor LESS lst_size )
|
|
|
|
list(GET expanded_components ${cursor} lib)
|
|
|
|
list(APPEND expanded_components ${MSVC_LIB_DEPS_${lib}})
|
|
|
|
# Remove duplicates at the front:
|
|
|
|
list(REVERSE expanded_components)
|
|
|
|
list(REMOVE_DUPLICATES expanded_components)
|
|
|
|
list(REVERSE expanded_components)
|
|
|
|
list(APPEND processed ${lib})
|
|
|
|
# Find the maximum index that doesn't have to be re-processed:
|
|
|
|
while(NOT "${expanded_components}" MATCHES "^${processed}.*" )
|
|
|
|
list(REMOVE_AT processed -1)
|
|
|
|
endwhile()
|
|
|
|
list(LENGTH processed cursor)
|
2010-09-13 23:59:48 +00:00
|
|
|
list(LENGTH expanded_components lst_size)
|
2010-09-28 22:38:39 +00:00
|
|
|
endwhile( cursor LESS lst_size )
|
|
|
|
# Return just the libraries included in this build:
|
|
|
|
set(result)
|
|
|
|
foreach(c ${expanded_components})
|
|
|
|
list(FIND llvm_libs ${c} lib_idx)
|
|
|
|
if( NOT lib_idx LESS 0 )
|
|
|
|
set(result ${result} ${c})
|
|
|
|
endif()
|
|
|
|
endforeach(c)
|
2010-09-13 23:59:48 +00:00
|
|
|
set(${out_libs} ${result} PARENT_SCOPE)
|
|
|
|
endfunction(explicit_map_components_to_libraries)
|
|
|
|
|
|
|
|
|
|
|
|
# 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-09-28 22:38:39 +00:00
|
|
|
# LLVMARMAsmPrinter.o: LLVMARMCodeGen.o libLLVMAsmPrinter.a libLLVMCodeGen.a libLLVMCore.a libLLVMSupport.a libLLVMTarget.a
|
2010-09-13 23:59:48 +00:00
|
|
|
|
|
|
|
# is translated to:
|
|
|
|
|
2010-09-28 22:38:39 +00:00
|
|
|
# set(MSVC_LIB_DEPS_LLVMARMAsmPrinter LLVMARMCodeGen LLVMAsmPrinter LLVMCodeGen LLVMCore LLVMSupport LLVMTarget)
|
2010-09-13 23:59:48 +00:00
|
|
|
|
2010-09-28 22:38:39 +00:00
|
|
|
# It is necessary to remove the `lib' prefix and the `.a'.
|
2010-09-13 23:59:48 +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)
|