2010-09-13 23:59:48 +00:00
|
|
|
function(get_system_libs return_var)
|
2014-02-23 06:27:04 +00:00
|
|
|
message(AUTHOR_WARNING "get_system_libs no longer needed")
|
|
|
|
set(${return_var} "" PARENT_SCOPE)
|
|
|
|
endfunction()
|
2010-09-13 23:59:48 +00:00
|
|
|
|
|
|
|
|
2011-03-29 20:51:08 +00:00
|
|
|
function(link_system_libs target)
|
2014-02-23 06:27:04 +00:00
|
|
|
message(AUTHOR_WARNING "link_system_libs no longer needed")
|
|
|
|
endfunction()
|
2011-03-29 20:51:08 +00:00
|
|
|
|
|
|
|
|
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
|
2014-02-02 16:46:35 +00:00
|
|
|
capitalized_lib STREQUAL "LLVM${t}" OR
|
|
|
|
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" )
|
2010-09-13 23:59:48 +00:00
|
|
|
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} )
|
|
|
|
|
2014-02-10 03:24:19 +00:00
|
|
|
llvm_map_components_to_libnames(LIBRARIES ${link_components})
|
2014-02-26 06:53:16 +00:00
|
|
|
get_target_property(t ${executable} TYPE)
|
2014-09-26 21:33:05 +00:00
|
|
|
if("x${t}" STREQUAL "xSTATIC_LIBRARY")
|
2015-02-20 21:28:18 +00:00
|
|
|
target_link_libraries(${executable} INTERFACE ${LIBRARIES})
|
2014-09-26 21:33:05 +00:00
|
|
|
elseif("x${t}" STREQUAL "xSHARED_LIBRARY" OR "x${t}" STREQUAL "xMODULE_LIBRARY")
|
2015-02-20 21:28:18 +00:00
|
|
|
target_link_libraries(${executable} PRIVATE ${LIBRARIES})
|
2014-02-26 06:53:16 +00:00
|
|
|
else()
|
|
|
|
# Use plain form for legacy user.
|
|
|
|
target_link_libraries(${executable} ${LIBRARIES})
|
|
|
|
endif()
|
2010-09-13 23:59:48 +00:00
|
|
|
endfunction(explicit_llvm_config)
|
|
|
|
|
|
|
|
|
2014-07-28 13:36:50 +00:00
|
|
|
# This is Deprecated
|
2010-09-13 23:59:48 +00:00
|
|
|
function(llvm_map_components_to_libraries OUT_VAR)
|
2014-07-28 13:36:50 +00:00
|
|
|
message(AUTHOR_WARNING "Using llvm_map_components_to_libraries() is deprecated. Use llvm_map_components_to_libnames() instead")
|
2010-09-13 23:59:48 +00:00
|
|
|
explicit_map_components_to_libraries(result ${ARGN})
|
|
|
|
set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE )
|
|
|
|
endfunction(llvm_map_components_to_libraries)
|
|
|
|
|
2014-07-28 13:36:50 +00:00
|
|
|
# This is a variant intended for the final user:
|
2014-02-04 14:42:04 +00:00
|
|
|
# Map LINK_COMPONENTS to actual libnames.
|
|
|
|
function(llvm_map_components_to_libnames out_libs)
|
2010-09-13 23:59:48 +00:00
|
|
|
set( link_components ${ARGN} )
|
2014-02-21 14:17:07 +00:00
|
|
|
if(NOT LLVM_AVAILABLE_LIBS)
|
|
|
|
# Inside LLVM itself available libs are in a global property.
|
|
|
|
get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
|
|
|
|
endif()
|
|
|
|
string(TOUPPER "${LLVM_AVAILABLE_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 )
|
2014-02-21 14:16:52 +00:00
|
|
|
if( TARGET LLVM${c}CodeGen )
|
2014-02-02 16:46:35 +00:00
|
|
|
list(APPEND expanded_components "LLVM${c}CodeGen")
|
2010-09-13 23:59:48 +00:00
|
|
|
else()
|
2014-02-21 14:16:52 +00:00
|
|
|
if( TARGET LLVM${c} )
|
2014-02-02 16:46:35 +00:00
|
|
|
list(APPEND expanded_components "LLVM${c}")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
|
|
|
|
endif()
|
2010-09-13 23:59:48 +00:00
|
|
|
endif()
|
2014-02-21 14:16:52 +00:00
|
|
|
if( TARGET LLVM${c}AsmPrinter )
|
2010-09-13 23:59:48 +00:00
|
|
|
list(APPEND expanded_components "LLVM${c}AsmPrinter")
|
|
|
|
endif()
|
2014-02-21 14:16:52 +00:00
|
|
|
if( TARGET LLVM${c}AsmParser )
|
2010-09-13 23:59:48 +00:00
|
|
|
list(APPEND expanded_components "LLVM${c}AsmParser")
|
|
|
|
endif()
|
2014-07-14 05:07:07 +00:00
|
|
|
if( TARGET LLVM${c}Desc )
|
|
|
|
list(APPEND expanded_components "LLVM${c}Desc")
|
|
|
|
endif()
|
2014-02-21 14:16:52 +00:00
|
|
|
if( TARGET LLVM${c}Info )
|
2010-09-13 23:59:48 +00:00
|
|
|
list(APPEND expanded_components "LLVM${c}Info")
|
|
|
|
endif()
|
2014-02-21 14:16:52 +00:00
|
|
|
if( TARGET LLVM${c}Disassembler )
|
2010-09-13 23:59:48 +00:00
|
|
|
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")
|
2014-07-14 05:07:07 +00:00
|
|
|
if( TARGET LLVM${LLVM_NATIVE_ARCH}Desc )
|
|
|
|
list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Desc")
|
|
|
|
endif()
|
|
|
|
if( TARGET LLVM${LLVM_NATIVE_ARCH}Info )
|
|
|
|
list(APPEND expanded_components "LLVM${LLVM_NATIVE_ARCH}Info")
|
|
|
|
endif()
|
2010-09-13 23:59:48 +00:00
|
|
|
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" )
|
2014-02-21 14:17:07 +00:00
|
|
|
list(APPEND expanded_components ${LLVM_AVAILABLE_LIBS})
|
2010-09-13 23:59:48 +00:00
|
|
|
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 )
|
2011-07-29 23:52:01 +00:00
|
|
|
# The component is unknown. Maybe is an omitted 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()
|
2010-09-28 22:38:39 +00:00
|
|
|
else( lib_idx LESS 0 )
|
2014-02-21 14:17:07 +00:00
|
|
|
list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib)
|
2011-07-29 23:52:01 +00:00
|
|
|
list(APPEND expanded_components ${canonical_lib})
|
2010-09-28 22:38:39 +00:00
|
|
|
endif( lib_idx LESS 0 )
|
2010-09-13 23:59:48 +00:00
|
|
|
endif( NOT idx LESS 0 )
|
|
|
|
endforeach(c)
|
2014-02-04 14:42:04 +00:00
|
|
|
|
|
|
|
set(${out_libs} ${expanded_components} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2014-12-18 23:56:52 +00:00
|
|
|
# Perform a post-order traversal of the dependency graph.
|
|
|
|
# This duplicates the algorithm used by llvm-config, originally
|
|
|
|
# in tools/llvm-config/llvm-config.cpp, function ComputeLibsForComponents.
|
|
|
|
function(expand_topologically name required_libs visited_libs)
|
|
|
|
list(FIND visited_libs ${name} found)
|
|
|
|
if( found LESS 0 )
|
|
|
|
list(APPEND visited_libs ${name})
|
|
|
|
set(visited_libs ${visited_libs} PARENT_SCOPE)
|
|
|
|
|
|
|
|
get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
|
|
|
|
foreach( lib_dep ${lib_deps} )
|
|
|
|
expand_topologically(${lib_dep} "${required_libs}" "${visited_libs}")
|
|
|
|
set(required_libs ${required_libs} PARENT_SCOPE)
|
|
|
|
set(visited_libs ${visited_libs} PARENT_SCOPE)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
list(APPEND required_libs ${name})
|
|
|
|
set(required_libs ${required_libs} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2014-02-04 14:42:04 +00:00
|
|
|
# Expand dependencies while topologically sorting the list of libraries:
|
|
|
|
function(llvm_expand_dependencies out_libs)
|
|
|
|
set(expanded_components ${ARGN})
|
2014-12-18 23:56:52 +00:00
|
|
|
|
|
|
|
set(required_libs)
|
|
|
|
set(visited_libs)
|
|
|
|
foreach( lib ${expanded_components} )
|
|
|
|
expand_topologically(${lib} "${required_libs}" "${visited_libs}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
list(REVERSE required_libs)
|
|
|
|
set(${out_libs} ${required_libs} PARENT_SCOPE)
|
2014-02-04 14:42:04 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(explicit_map_components_to_libraries out_libs)
|
|
|
|
llvm_map_components_to_libnames(link_libs ${ARGN})
|
|
|
|
llvm_expand_dependencies(expanded_components ${link_libs})
|
2010-09-28 22:38:39 +00:00
|
|
|
# Return just the libraries included in this build:
|
|
|
|
set(result)
|
|
|
|
foreach(c ${expanded_components})
|
2014-02-21 14:16:52 +00:00
|
|
|
if( TARGET ${c} )
|
2010-09-28 22:38:39 +00:00
|
|
|
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)
|