2010-09-14 01:59:48 +02:00
|
|
|
function(get_system_libs return_var)
|
2014-02-23 07:27:04 +01:00
|
|
|
message(AUTHOR_WARNING "get_system_libs no longer needed")
|
|
|
|
set(${return_var} "" PARENT_SCOPE)
|
|
|
|
endfunction()
|
2010-09-14 01:59:48 +02:00
|
|
|
|
|
|
|
|
2011-03-29 22:51:08 +02:00
|
|
|
function(link_system_libs target)
|
2014-02-23 07:27:04 +01:00
|
|
|
message(AUTHOR_WARNING "link_system_libs no longer needed")
|
|
|
|
endfunction()
|
2011-03-29 22:51:08 +02:00
|
|
|
|
2017-02-08 21:58:37 +01:00
|
|
|
# is_llvm_target_library(
|
|
|
|
# library
|
|
|
|
# Name of the LLVM library to check
|
|
|
|
# return_var
|
|
|
|
# Output variable name
|
|
|
|
# ALL_TARGETS;INCLUDED_TARGETS;OMITTED_TARGETS
|
|
|
|
# ALL_TARGETS - default looks at the full list of known targets
|
|
|
|
# INCLUDED_TARGETS - looks only at targets being configured
|
|
|
|
# OMITTED_TARGETS - looks only at targets that are not being configured
|
|
|
|
# )
|
2010-09-14 01:59:48 +02:00
|
|
|
function(is_llvm_target_library library return_var)
|
2017-02-08 21:58:37 +01:00
|
|
|
cmake_parse_arguments(ARG "ALL_TARGETS;INCLUDED_TARGETS;OMITTED_TARGETS" "" "" ${ARGN})
|
2010-09-14 01:59:48 +02:00
|
|
|
# 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)
|
2017-02-08 21:58:37 +01:00
|
|
|
if(ARG_INCLUDED_TARGETS)
|
|
|
|
string(TOUPPER "${LLVM_TARGETS_TO_BUILD}" targets)
|
|
|
|
elseif(ARG_OMITTED_TARGETS)
|
|
|
|
set(omitted_targets ${LLVM_ALL_TARGETS})
|
2019-11-13 10:29:10 +01:00
|
|
|
list(REMOVE_ITEM omitted_targets "${LLVM_TARGETS_TO_BUILD}")
|
2017-02-08 21:58:37 +01:00
|
|
|
string(TOUPPER "${omitted_targets}" targets)
|
|
|
|
else()
|
|
|
|
string(TOUPPER "${LLVM_ALL_TARGETS}" targets)
|
|
|
|
endif()
|
2010-09-14 01:59:48 +02:00
|
|
|
foreach(t ${targets})
|
2011-03-15 15:53:53 +01:00
|
|
|
if( capitalized_lib STREQUAL t OR
|
2017-02-08 21:58:37 +01:00
|
|
|
capitalized_lib STREQUAL "${t}" OR
|
|
|
|
capitalized_lib STREQUAL "${t}DESC" OR
|
|
|
|
capitalized_lib STREQUAL "${t}CODEGEN" OR
|
|
|
|
capitalized_lib STREQUAL "${t}ASMPARSER" OR
|
|
|
|
capitalized_lib STREQUAL "${t}ASMPRINTER" OR
|
|
|
|
capitalized_lib STREQUAL "${t}DISASSEMBLER" OR
|
|
|
|
capitalized_lib STREQUAL "${t}INFO" OR
|
|
|
|
capitalized_lib STREQUAL "${t}UTILS" )
|
2010-09-14 01:59:48 +02:00
|
|
|
set(${return_var} ON PARENT_SCOPE)
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endfunction(is_llvm_target_library)
|
|
|
|
|
2017-02-08 21:58:37 +01:00
|
|
|
function(is_llvm_target_specifier library return_var)
|
|
|
|
is_llvm_target_library(${library} ${return_var} ${ARGN})
|
|
|
|
string(TOUPPER "${library}" capitalized_lib)
|
|
|
|
if(NOT ${return_var})
|
|
|
|
if( capitalized_lib STREQUAL "ALLTARGETSASMPARSERS" OR
|
|
|
|
capitalized_lib STREQUAL "ALLTARGETSDESCS" OR
|
|
|
|
capitalized_lib STREQUAL "ALLTARGETSDISASSEMBLERS" OR
|
|
|
|
capitalized_lib STREQUAL "ALLTARGETSINFOS" OR
|
|
|
|
capitalized_lib STREQUAL "NATIVE" OR
|
|
|
|
capitalized_lib STREQUAL "NATIVECODEGEN" )
|
|
|
|
set(${return_var} ON PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2010-09-14 01:59:48 +02:00
|
|
|
|
|
|
|
macro(llvm_config executable)
|
2015-09-05 10:27:33 +02:00
|
|
|
cmake_parse_arguments(ARG "USE_SHARED" "" "" ${ARGN})
|
|
|
|
set(link_components ${ARG_UNPARSED_ARGUMENTS})
|
|
|
|
|
2018-06-06 12:07:08 +02:00
|
|
|
if(ARG_USE_SHARED)
|
2015-09-05 10:27:33 +02:00
|
|
|
# If USE_SHARED is specified, then we link against libLLVM,
|
|
|
|
# but also against the component libraries below. This is
|
|
|
|
# done in case libLLVM does not contain all of the components
|
|
|
|
# the target requires.
|
|
|
|
#
|
2016-02-12 02:42:43 +01:00
|
|
|
# Strip LLVM_DYLIB_COMPONENTS out of link_components.
|
2015-09-05 10:27:33 +02:00
|
|
|
# To do this, we need special handling for "all", since that
|
|
|
|
# may imply linking to libraries that are not included in
|
|
|
|
# libLLVM.
|
2016-02-12 02:42:43 +01:00
|
|
|
|
|
|
|
if (DEFINED link_components AND DEFINED LLVM_DYLIB_COMPONENTS)
|
|
|
|
if("${LLVM_DYLIB_COMPONENTS}" STREQUAL "all")
|
|
|
|
set(link_components "")
|
|
|
|
else()
|
|
|
|
list(REMOVE_ITEM link_components ${LLVM_DYLIB_COMPONENTS})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
[CMake] Use PRIVATE in target_link_libraries for executables
We currently use target_link_libraries without an explicit scope
specifier (INTERFACE, PRIVATE or PUBLIC) when linking executables.
Dependencies added in this way apply to both the target and its
dependencies, i.e. they become part of the executable's link interface
and are transitive.
Transitive dependencies generally don't make sense for executables,
since you wouldn't normally be linking against an executable. This also
causes issues for generating install export files when using
LLVM_DISTRIBUTION_COMPONENTS. For example, clang has a lot of LLVM
library dependencies, which are currently added as interface
dependencies. If clang is in the distribution components but the LLVM
libraries it depends on aren't (which is a perfectly legitimate use case
if the LLVM libraries are being built static and there are therefore no
run-time dependencies on them), CMake will complain about the LLVM
libraries not being in export set when attempting to generate the
install export file for clang. This is reasonable behavior on CMake's
part, and the right thing is for LLVM's build system to explicitly use
PRIVATE dependencies for executables.
Unfortunately, CMake doesn't allow you to mix and match the keyword and
non-keyword target_link_libraries signatures for a single target; i.e.,
if a single call to target_link_libraries for a particular target uses
one of the INTERFACE, PRIVATE, or PUBLIC keywords, all other calls must
also be updated to use those keywords. This means we must do this change
in a single shot. I also fully expect to have missed some instances; I
tested by enabling all the projects in the monorepo (except dragonegg),
and configuring both with and without shared libraries, on both Darwin
and Linux, but I'm planning to rely on the buildbots for other
configurations (since it should be pretty easy to fix those).
Even after this change, we still have a lot of target_link_libraries
calls that don't specify a scope keyword, mostly for shared libraries.
I'm thinking about addressing those in a follow-up, but that's a
separate change IMO.
Differential Revision: https://reviews.llvm.org/D40823
llvm-svn: 319840
2017-12-05 22:49:56 +01:00
|
|
|
target_link_libraries(${executable} PRIVATE LLVM)
|
2015-09-05 10:27:33 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
explicit_llvm_config(${executable} ${link_components})
|
2010-09-14 01:59:48 +02:00
|
|
|
endmacro(llvm_config)
|
|
|
|
|
|
|
|
|
|
|
|
function(explicit_llvm_config executable)
|
|
|
|
set( link_components ${ARGN} )
|
|
|
|
|
2014-02-10 04:24:19 +01:00
|
|
|
llvm_map_components_to_libnames(LIBRARIES ${link_components})
|
2014-02-26 07:53:16 +01:00
|
|
|
get_target_property(t ${executable} TYPE)
|
2017-12-05 02:19:48 +01:00
|
|
|
if(t STREQUAL "STATIC_LIBRARY")
|
2015-03-23 21:03:57 +01:00
|
|
|
target_link_libraries(${executable} INTERFACE ${LIBRARIES})
|
[CMake] Use PRIVATE in target_link_libraries for executables
We currently use target_link_libraries without an explicit scope
specifier (INTERFACE, PRIVATE or PUBLIC) when linking executables.
Dependencies added in this way apply to both the target and its
dependencies, i.e. they become part of the executable's link interface
and are transitive.
Transitive dependencies generally don't make sense for executables,
since you wouldn't normally be linking against an executable. This also
causes issues for generating install export files when using
LLVM_DISTRIBUTION_COMPONENTS. For example, clang has a lot of LLVM
library dependencies, which are currently added as interface
dependencies. If clang is in the distribution components but the LLVM
libraries it depends on aren't (which is a perfectly legitimate use case
if the LLVM libraries are being built static and there are therefore no
run-time dependencies on them), CMake will complain about the LLVM
libraries not being in export set when attempting to generate the
install export file for clang. This is reasonable behavior on CMake's
part, and the right thing is for LLVM's build system to explicitly use
PRIVATE dependencies for executables.
Unfortunately, CMake doesn't allow you to mix and match the keyword and
non-keyword target_link_libraries signatures for a single target; i.e.,
if a single call to target_link_libraries for a particular target uses
one of the INTERFACE, PRIVATE, or PUBLIC keywords, all other calls must
also be updated to use those keywords. This means we must do this change
in a single shot. I also fully expect to have missed some instances; I
tested by enabling all the projects in the monorepo (except dragonegg),
and configuring both with and without shared libraries, on both Darwin
and Linux, but I'm planning to rely on the buildbots for other
configurations (since it should be pretty easy to fix those).
Even after this change, we still have a lot of target_link_libraries
calls that don't specify a scope keyword, mostly for shared libraries.
I'm thinking about addressing those in a follow-up, but that's a
separate change IMO.
Differential Revision: https://reviews.llvm.org/D40823
llvm-svn: 319840
2017-12-05 22:49:56 +01:00
|
|
|
elseif(t STREQUAL "EXECUTABLE" OR t STREQUAL "SHARED_LIBRARY" OR t STREQUAL "MODULE_LIBRARY")
|
2015-03-23 21:03:57 +01:00
|
|
|
target_link_libraries(${executable} PRIVATE ${LIBRARIES})
|
2014-02-26 07:53:16 +01:00
|
|
|
else()
|
|
|
|
# Use plain form for legacy user.
|
|
|
|
target_link_libraries(${executable} ${LIBRARIES})
|
|
|
|
endif()
|
2010-09-14 01:59:48 +02:00
|
|
|
endfunction(explicit_llvm_config)
|
|
|
|
|
|
|
|
|
2014-07-28 15:36:50 +02:00
|
|
|
# This is Deprecated
|
2010-09-14 01:59:48 +02:00
|
|
|
function(llvm_map_components_to_libraries OUT_VAR)
|
2014-07-28 15:36:50 +02:00
|
|
|
message(AUTHOR_WARNING "Using llvm_map_components_to_libraries() is deprecated. Use llvm_map_components_to_libnames() instead")
|
2010-09-14 01:59:48 +02:00
|
|
|
explicit_map_components_to_libraries(result ${ARGN})
|
|
|
|
set( ${OUT_VAR} ${result} ${sys_result} PARENT_SCOPE )
|
|
|
|
endfunction(llvm_map_components_to_libraries)
|
|
|
|
|
2019-07-20 00:46:47 +02:00
|
|
|
# Expand pseudo-components into real components.
|
|
|
|
# Does not cover 'native', 'backend', or 'engine' as these require special
|
|
|
|
# handling. Also does not cover 'all' as we only have a list of the libnames
|
|
|
|
# available and not a list of the components.
|
|
|
|
function(llvm_expand_pseudo_components out_components)
|
2010-09-14 01:59:48 +02:00
|
|
|
set( link_components ${ARGN} )
|
|
|
|
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 15:16:52 +01:00
|
|
|
if( TARGET LLVM${c}CodeGen )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${c}CodeGen")
|
2010-09-14 01:59:48 +02:00
|
|
|
else()
|
2014-02-21 15:16:52 +01:00
|
|
|
if( TARGET LLVM${c} )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${c}")
|
2014-02-02 17:46:35 +01:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Target ${c} is not in the set of libraries.")
|
|
|
|
endif()
|
2010-09-14 01:59:48 +02:00
|
|
|
endif()
|
2019-07-19 23:11:05 +02:00
|
|
|
if( TARGET LLVM${c}AsmPrinter )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${c}AsmPrinter")
|
|
|
|
endif()
|
|
|
|
if( TARGET LLVM${c}AsmParser )
|
|
|
|
list(APPEND expanded_components "${c}AsmParser")
|
2017-08-10 15:37:58 +02:00
|
|
|
endif()
|
2014-07-14 07:07:07 +02:00
|
|
|
if( TARGET LLVM${c}Desc )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${c}Desc")
|
2014-07-14 07:07:07 +02:00
|
|
|
endif()
|
2014-02-21 15:16:52 +01:00
|
|
|
if( TARGET LLVM${c}Disassembler )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${c}Disassembler")
|
2010-09-14 01:59:48 +02:00
|
|
|
endif()
|
2017-02-08 21:58:37 +01:00
|
|
|
if( TARGET LLVM${c}Info )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${c}Info")
|
2017-02-08 21:58:37 +01:00
|
|
|
endif()
|
|
|
|
if( TARGET LLVM${c}Utils )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${c}Utils")
|
2017-02-08 21:58:37 +01:00
|
|
|
endif()
|
2010-09-14 01:59:48 +02:00
|
|
|
elseif( c STREQUAL "nativecodegen" )
|
2019-07-20 00:46:47 +02:00
|
|
|
if( TARGET LLVM${LLVM_NATIVE_ARCH}CodeGen )
|
|
|
|
list(APPEND expanded_components "${LLVM_NATIVE_ARCH}CodeGen")
|
|
|
|
endif()
|
2014-07-14 07:07:07 +02:00
|
|
|
if( TARGET LLVM${LLVM_NATIVE_ARCH}Desc )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${LLVM_NATIVE_ARCH}Desc")
|
2014-07-14 07:07:07 +02:00
|
|
|
endif()
|
|
|
|
if( TARGET LLVM${LLVM_NATIVE_ARCH}Info )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${LLVM_NATIVE_ARCH}Info")
|
2014-07-14 07:07:07 +02:00
|
|
|
endif()
|
2019-05-24 01:02:56 +02:00
|
|
|
elseif( c STREQUAL "AllTargetsCodeGens" )
|
2019-05-24 04:15:27 +02:00
|
|
|
# Link all the codegens from all the targets
|
2019-05-24 01:02:56 +02:00
|
|
|
foreach(t ${LLVM_TARGETS_TO_BUILD})
|
|
|
|
if( TARGET LLVM${t}CodeGen)
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${t}CodeGen")
|
2019-05-24 01:02:56 +02:00
|
|
|
endif()
|
|
|
|
endforeach(t)
|
2015-04-20 20:22:05 +02:00
|
|
|
elseif( c STREQUAL "AllTargetsAsmParsers" )
|
|
|
|
# Link all the asm parsers from all the targets
|
|
|
|
foreach(t ${LLVM_TARGETS_TO_BUILD})
|
|
|
|
if( TARGET LLVM${t}AsmParser )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${t}AsmParser")
|
2015-04-20 20:22:05 +02:00
|
|
|
endif()
|
|
|
|
endforeach(t)
|
|
|
|
elseif( c STREQUAL "AllTargetsDescs" )
|
|
|
|
# Link all the descs from all the targets
|
|
|
|
foreach(t ${LLVM_TARGETS_TO_BUILD})
|
|
|
|
if( TARGET LLVM${t}Desc )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${t}Desc")
|
2015-04-20 20:22:05 +02:00
|
|
|
endif()
|
|
|
|
endforeach(t)
|
|
|
|
elseif( c STREQUAL "AllTargetsDisassemblers" )
|
|
|
|
# Link all the disassemblers from all the targets
|
|
|
|
foreach(t ${LLVM_TARGETS_TO_BUILD})
|
|
|
|
if( TARGET LLVM${t}Disassembler )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${t}Disassembler")
|
2015-04-20 20:22:05 +02:00
|
|
|
endif()
|
|
|
|
endforeach(t)
|
|
|
|
elseif( c STREQUAL "AllTargetsInfos" )
|
|
|
|
# Link all the infos from all the targets
|
|
|
|
foreach(t ${LLVM_TARGETS_TO_BUILD})
|
|
|
|
if( TARGET LLVM${t}Info )
|
2019-07-20 00:46:47 +02:00
|
|
|
list(APPEND expanded_components "${t}Info")
|
2015-04-20 20:22:05 +02:00
|
|
|
endif()
|
|
|
|
endforeach(t)
|
2019-07-20 00:46:47 +02:00
|
|
|
else()
|
|
|
|
list(APPEND expanded_components "${c}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set(${out_components} ${expanded_components} PARENT_SCOPE)
|
|
|
|
endfunction(llvm_expand_pseudo_components out_components)
|
|
|
|
|
|
|
|
# This is a variant intended for the final user:
|
|
|
|
# Map LINK_COMPONENTS to actual libnames.
|
|
|
|
function(llvm_map_components_to_libnames out_libs)
|
|
|
|
set( link_components ${ARGN} )
|
|
|
|
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)
|
|
|
|
|
|
|
|
get_property(LLVM_TARGETS_CONFIGURED GLOBAL PROPERTY LLVM_TARGETS_CONFIGURED)
|
|
|
|
|
|
|
|
# Generally in our build system we avoid order-dependence. Unfortunately since
|
|
|
|
# not all targets create the same set of libraries we actually need to ensure
|
|
|
|
# that all build targets associated with a target are added before we can
|
|
|
|
# process target dependencies.
|
|
|
|
if(NOT LLVM_TARGETS_CONFIGURED)
|
|
|
|
foreach(c ${link_components})
|
|
|
|
is_llvm_target_specifier(${c} iltl_result ALL_TARGETS)
|
|
|
|
if(iltl_result)
|
|
|
|
message(FATAL_ERROR "Specified target library before target registration is complete.")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Expand some keywords:
|
|
|
|
list(FIND LLVM_TARGETS_TO_BUILD "${LLVM_NATIVE_ARCH}" have_native_backend)
|
|
|
|
list(FIND link_components "engine" engine_required)
|
|
|
|
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()
|
|
|
|
endif()
|
|
|
|
list(FIND link_components "native" native_required)
|
|
|
|
if( NOT native_required EQUAL -1 )
|
|
|
|
if( NOT have_native_backend EQUAL -1 )
|
|
|
|
list(APPEND link_components ${LLVM_NATIVE_ARCH})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Translate symbolic component names to real libraries:
|
|
|
|
llvm_expand_pseudo_components(link_components ${link_components})
|
|
|
|
foreach(c ${link_components})
|
2020-10-09 18:41:21 +02:00
|
|
|
get_property(c_rename GLOBAL PROPERTY LLVM_COMPONENT_NAME_${c})
|
|
|
|
if(c_rename)
|
|
|
|
set(c ${c_rename})
|
|
|
|
endif()
|
2019-07-20 00:46:47 +02:00
|
|
|
if( c STREQUAL "native" )
|
|
|
|
# already processed
|
|
|
|
elseif( c STREQUAL "backend" )
|
|
|
|
# same case as in `native'.
|
|
|
|
elseif( c STREQUAL "engine" )
|
|
|
|
# already processed
|
|
|
|
elseif( c STREQUAL "all" )
|
[cmake] Explicitly mark libraries defined in lib/ as "Component Libraries"
Summary:
Most libraries are defined in the lib/ directory but there are also a
few libraries defined in tools/ e.g. libLLVM, libLTO. I'm defining
"Component Libraries" as libraries defined in lib/ that may be included in
libLLVM.so. Explicitly marking the libraries in lib/ as component
libraries allows us to remove some fragile checks that attempt to
differentiate between lib/ libraries and tools/ libraires:
1. In tools/llvm-shlib, because
llvm_map_components_to_libnames(LIB_NAMES "all") returned a list of
all libraries defined in the whole project, there was custom code
needed to filter out libraries defined in tools/, none of which should
be included in libLLVM.so. This code assumed that any library
defined as static was from lib/ and everything else should be
excluded.
With this change, llvm_map_components_to_libnames(LIB_NAMES, "all")
only returns libraries that have been added to the LLVM_COMPONENT_LIBS
global cmake property, so this custom filtering logic can be removed.
Doing this also fixes the build with BUILD_SHARED_LIBS=ON
and LLVM_BUILD_LLVM_DYLIB=ON.
2. There was some code in llvm_add_library that assumed that
libraries defined in lib/ would not have LLVM_LINK_COMPONENTS or
ARG_LINK_COMPONENTS set. This is only true because libraries
defined lib lib/ use LLVMBuild.txt and don't set these values.
This code has been fixed now to check if the library has been
explicitly marked as a component library, which should now make it
easier to remove LLVMBuild at some point in the future.
I have tested this patch on Windows, MacOS and Linux with release builds
and the following combinations of CMake options:
- "" (No options)
- -DLLVM_BUILD_LLVM_DYLIB=ON
- -DLLVM_LINK_LLVM_DYLIB=ON
- -DBUILD_SHARED_LIBS=ON
- -DBUILD_SHARED_LIBS=ON -DLLVM_BUILD_LLVM_DYLIB=ON
- -DBUILD_SHARED_LIBS=ON -DLLVM_LINK_LLVM_DYLIB=ON
Reviewers: beanz, smeenai, compnerd, phosek
Reviewed By: beanz
Subscribers: wuzish, jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, mgorny, mehdi_amini, sbc100, jgravelle-google, hiraditya, aheejin, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, steven_wu, rogfer01, MartinMosbeck, brucehoult, the_o, dexonsmith, PkmX, jocewei, jsji, dang, Jim, lenary, s.egerton, pzheng, sameer.abuasal, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70179
2019-11-14 06:39:58 +01:00
|
|
|
get_property(all_components GLOBAL PROPERTY LLVM_COMPONENT_LIBS)
|
|
|
|
list(APPEND expanded_components ${all_components})
|
2019-11-14 01:01:33 +01:00
|
|
|
else()
|
2010-09-29 00:38:39 +02:00
|
|
|
# Canonize the component name:
|
|
|
|
string(TOUPPER "${c}" capitalized)
|
|
|
|
list(FIND capitalized_libs LLVM${capitalized} lib_idx)
|
|
|
|
if( lib_idx LESS 0 )
|
2011-07-30 01:52:01 +02:00
|
|
|
# The component is unknown. Maybe is an omitted target?
|
2017-02-08 21:58:37 +01:00
|
|
|
is_llvm_target_library(${c} iltl_result OMITTED_TARGETS)
|
|
|
|
if(iltl_result)
|
|
|
|
# A missing library to a directly referenced omitted target would be bad.
|
|
|
|
message(FATAL_ERROR "Library '${c}' is a direct reference to a target library for an omitted target.")
|
|
|
|
else()
|
|
|
|
# If it is not an omitted target we should assume it is a component
|
|
|
|
# that hasn't yet been processed by CMake. Missing components will
|
|
|
|
# cause errors later in the configuration, so we can safely assume
|
|
|
|
# that this is valid here.
|
|
|
|
list(APPEND expanded_components LLVM${c})
|
2011-07-30 01:52:01 +02:00
|
|
|
endif()
|
2010-09-29 00:38:39 +02:00
|
|
|
else( lib_idx LESS 0 )
|
2014-02-21 15:17:07 +01:00
|
|
|
list(GET LLVM_AVAILABLE_LIBS ${lib_idx} canonical_lib)
|
2011-07-30 01:52:01 +02:00
|
|
|
list(APPEND expanded_components ${canonical_lib})
|
2010-09-29 00:38:39 +02:00
|
|
|
endif( lib_idx LESS 0 )
|
2019-07-20 00:46:47 +02:00
|
|
|
endif( c STREQUAL "native" )
|
2010-09-14 01:59:48 +02:00
|
|
|
endforeach(c)
|
2014-02-04 15:42:04 +01:00
|
|
|
|
|
|
|
set(${out_libs} ${expanded_components} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2014-12-19 00:56:52 +01: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 15:42:04 +01:00
|
|
|
# Expand dependencies while topologically sorting the list of libraries:
|
|
|
|
function(llvm_expand_dependencies out_libs)
|
|
|
|
set(expanded_components ${ARGN})
|
2014-12-19 00:56:52 +01:00
|
|
|
|
|
|
|
set(required_libs)
|
|
|
|
set(visited_libs)
|
|
|
|
foreach( lib ${expanded_components} )
|
|
|
|
expand_topologically(${lib} "${required_libs}" "${visited_libs}")
|
|
|
|
endforeach()
|
|
|
|
|
2018-09-26 12:14:10 +02:00
|
|
|
if(required_libs)
|
|
|
|
list(REVERSE required_libs)
|
|
|
|
endif()
|
2014-12-19 00:56:52 +01:00
|
|
|
set(${out_libs} ${required_libs} PARENT_SCOPE)
|
2014-02-04 15:42:04 +01: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-29 00:38:39 +02:00
|
|
|
# Return just the libraries included in this build:
|
|
|
|
set(result)
|
|
|
|
foreach(c ${expanded_components})
|
2014-02-21 15:16:52 +01:00
|
|
|
if( TARGET ${c} )
|
2010-09-29 00:38:39 +02:00
|
|
|
set(result ${result} ${c})
|
|
|
|
endif()
|
|
|
|
endforeach(c)
|
2010-09-14 01:59:48 +02:00
|
|
|
set(${out_libs} ${result} PARENT_SCOPE)
|
|
|
|
endfunction(explicit_map_components_to_libraries)
|