Reapply "Skipping host target exports during cross-compilation" (#210… (#210496)
This reverts commit42eb7db188. This reland3fbb037d03(#209922). Under CMake 4+, calling add_library(... SHARED IMPORTED) on a target platform that lacks dynamic linking support triggers a fatal error. This becomes an issue when building LLVM and runtimes for baremetal targets like armv6m-none-eabi. This patch adds the option "LLVM_OMIT_EXPORTS_FROM_CONFIG" in LLVM. When used in sub builds like LLVM runtimes, it makes CMake to skip including the LLVM and Clang exports. This mitigates the CMake 4 errors on baremetal runtimes.42eb7db188originally apply this flag on all runtimes build and causing issues on runtimes like intel-sycl-gpu, amdgpu-offload-ubuntu-22-cmake-build-only. This PR only set this flag when the target platform lacks shared library support.
This commit is contained in:
parent
a6b49df445
commit
a04f87fdd9
4 changed files with 27 additions and 3 deletions
|
|
@ -12,8 +12,11 @@ set(CLANG_INCLUDE_DIRS "@CLANG_CONFIG_INCLUDE_DIRS@")
|
|||
set(CLANG_LINK_CLANG_DYLIB "@CLANG_LINK_CLANG_DYLIB@")
|
||||
set(CLANG_DEFAULT_LINKER "@CLANG_DEFAULT_LINKER@")
|
||||
|
||||
# Provide all our library targets to users.
|
||||
@CLANG_CONFIG_INCLUDE_EXPORTS@
|
||||
# Provide all our library targets to users. Skip when
|
||||
# LLVM_OMIT_EXPORTS_FROM_CONFIG flag is set.
|
||||
if(NOT LLVM_OMIT_EXPORTS_FROM_CONFIG)
|
||||
@CLANG_CONFIG_INCLUDE_EXPORTS@
|
||||
endif()
|
||||
|
||||
# By creating clang-tablegen-targets here, subprojects that depend on Clang's
|
||||
# tablegen-generated headers can always depend on this target whether building
|
||||
|
|
|
|||
|
|
@ -313,6 +313,16 @@ macro(load_llvm_config)
|
|||
"You are not using the monorepo layout. This configuration is DEPRECATED.")
|
||||
endif()
|
||||
|
||||
# Exports from LLVM and Clang may contain shared libraries. When targeting
|
||||
# platforms that lack shared library support, importing such
|
||||
# exports unrestrictedly will trigger an error. Set
|
||||
# LLVM_OMIT_EXPORTS_FROM_CONFIG flag to skip importing these exports
|
||||
# when the target platform does not support shared libraries.
|
||||
get_property(HAS_SHARED_SUPPORT GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
|
||||
message(NOTICE "HAS_SHARED_SUPPORT is ${HAS_SHARED_SUPPORT}")
|
||||
if (NOT HAS_SHARED_SUPPORT)
|
||||
set(LLVM_OMIT_EXPORTS_FROM_CONFIG ON)
|
||||
endif()
|
||||
find_package(LLVM HINTS "${LLVM_CMAKE_DIR}")
|
||||
if (NOT LLVM_FOUND)
|
||||
message(WARNING "UNSUPPORTED COMPILER-RT CONFIGURATION DETECTED: "
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ set(LLVM_ENABLE_SHARED_LIBS @BUILD_SHARED_LIBS@)
|
|||
set(LLVM_DEFAULT_EXTERNAL_LIT "@LLVM_CONFIG_DEFAULT_EXTERNAL_LIT@")
|
||||
set(LLVM_LIT_ARGS "@LLVM_LIT_ARGS@")
|
||||
|
||||
if(NOT TARGET LLVMSupport)
|
||||
if(NOT TARGET LLVMSupport AND NOT LLVM_OMIT_EXPORTS_FROM_CONFIG)
|
||||
@LLVM_CONFIG_INCLUDE_EXPORTS@
|
||||
@llvm_config_include_buildtree_only_exports@
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -76,6 +76,17 @@ if(LLVM_BINARY_DIR)
|
|||
list(APPEND llvm_search_paths "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
|
||||
list(APPEND clang_search_paths "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/clang")
|
||||
endif()
|
||||
|
||||
# Exports from LLVM and Clang may contain shared libraries. When targeting
|
||||
# platforms that lack shared library support, importing such
|
||||
# exports unrestrictedly will trigger an error. Set
|
||||
# LLVM_OMIT_EXPORTS_FROM_CONFIG flag to skip importing these exports
|
||||
# when the target platform does not support shared libraries.
|
||||
get_property(HAS_SHARED_SUPPORT GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
|
||||
message(NOTICE "HAS_SHARED_SUPPORT is ${HAS_SHARED_SUPPORT}")
|
||||
if (NOT HAS_SHARED_SUPPORT)
|
||||
set(LLVM_OMIT_EXPORTS_FROM_CONFIG ON)
|
||||
endif()
|
||||
find_package(LLVM PATHS ${llvm_search_paths} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
|
||||
find_package(Clang PATHS ${clang_search_paths} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue