mirror of
https://github.com/intel/llvm.git
synced 2026-01-24 00:20:25 +08:00
lld: Let find_package(LLD) work
Install a cmake config file. Copied exactly from how clang exports. I also wasn't sure whether the canonical capitalization is "lld" or "LLD". The project() is still calling this lld, but most places seemed to capitalize it.
This commit is contained in:
@@ -226,3 +226,5 @@ add_subdirectory(ELF)
|
||||
add_subdirectory(MachO)
|
||||
add_subdirectory(MinGW)
|
||||
add_subdirectory(wasm)
|
||||
|
||||
add_subdirectory(cmake/modules)
|
||||
|
||||
@@ -13,7 +13,7 @@ macro(add_lld_library name)
|
||||
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
||||
if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
|
||||
NOT LLVM_DISTRIBUTION_COMPONENTS)
|
||||
set(export_to_lldtargets EXPORT lldTargets)
|
||||
set(export_to_lldtargets EXPORT LLDTargets)
|
||||
set_property(GLOBAL PROPERTY LLD_HAS_EXPORTS True)
|
||||
endif()
|
||||
|
||||
@@ -48,7 +48,7 @@ macro(add_lld_tool name)
|
||||
if (LLD_BUILD_TOOLS)
|
||||
if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
|
||||
NOT LLVM_DISTRIBUTION_COMPONENTS)
|
||||
set(export_to_lldtargets EXPORT lldTargets)
|
||||
set(export_to_lldtargets EXPORT LLDTargets)
|
||||
set_property(GLOBAL PROPERTY LLD_HAS_EXPORTS True)
|
||||
endif()
|
||||
|
||||
|
||||
71
lld/cmake/modules/CMakeLists.txt
Normal file
71
lld/cmake/modules/CMakeLists.txt
Normal file
@@ -0,0 +1,71 @@
|
||||
# Generate a list of CMake library targets so that other CMake projects can
|
||||
# link against them. LLVM calls its version of this file LLVMExports.cmake, but
|
||||
# the usual CMake convention seems to be ${Project}Targets.cmake.
|
||||
set(LLD_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/lld)
|
||||
set(lld_cmake_builddir "${CMAKE_BINARY_DIR}/${LLD_INSTALL_PACKAGE_DIR}")
|
||||
|
||||
# Keep this in sync with llvm/cmake/CMakeLists.txt!
|
||||
set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
|
||||
set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
|
||||
|
||||
get_property(LLD_EXPORTS GLOBAL PROPERTY LLD_EXPORTS)
|
||||
export(TARGETS ${LLD_EXPORTS} FILE ${lld_cmake_builddir}/LLDTargets.cmake)
|
||||
|
||||
# Generate LLDConfig.cmake for the build tree.
|
||||
set(LLD_CONFIG_CMAKE_DIR "${lld_cmake_builddir}")
|
||||
set(LLD_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
|
||||
set(LLD_CONFIG_EXPORTS_FILE "${lld_cmake_builddir}/LLDTargets.cmake")
|
||||
set(LLD_CONFIG_INCLUDE_DIRS
|
||||
"${LLD_SOURCE_DIR}/include"
|
||||
"${LLD_BINARY_DIR}/include"
|
||||
)
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/LLDConfig.cmake.in
|
||||
${lld_cmake_builddir}/LLDConfig.cmake
|
||||
@ONLY)
|
||||
set(LLD_CONFIG_CMAKE_DIR)
|
||||
set(LLD_CONFIG_LLVM_CMAKE_DIR)
|
||||
set(LLD_CONFIG_EXPORTS_FILE)
|
||||
|
||||
# Generate LLDConfig.cmake for the install tree.
|
||||
set(LLD_CONFIG_CODE "
|
||||
# Compute the installation prefix from this LLVMConfig.cmake file location.
|
||||
get_filename_component(LLD_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
|
||||
# Construct the proper number of get_filename_component(... PATH)
|
||||
# calls to compute the installation prefix.
|
||||
string(REGEX REPLACE "/" ";" _count "${LLD_INSTALL_PACKAGE_DIR}")
|
||||
foreach(p ${_count})
|
||||
set(LLD_CONFIG_CODE "${LLD_CONFIG_CODE}
|
||||
get_filename_component(LLD_INSTALL_PREFIX \"\${LLD_INSTALL_PREFIX}\" PATH)")
|
||||
endforeach(p)
|
||||
set(LLD_CONFIG_CMAKE_DIR "\${LLD_INSTALL_PREFIX}/${LLD_INSTALL_PACKAGE_DIR}")
|
||||
set(LLD_CONFIG_LLVM_CMAKE_DIR "\${LLD_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
|
||||
set(LLD_CONFIG_EXPORTS_FILE "\${LLD_CMAKE_DIR}/LLDTargets.cmake")
|
||||
set(LLD_CONFIG_INCLUDE_DIRS "\${LLD_INSTALL_PREFIX}/include")
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/LLDConfig.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLDConfig.cmake
|
||||
@ONLY)
|
||||
set(LLD_CONFIG_CODE)
|
||||
set(LLD_CONFIG_CMAKE_DIR)
|
||||
set(LLD_CONFIG_EXPORTS_FILE)
|
||||
|
||||
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
|
||||
get_property(lld_has_exports GLOBAL PROPERTY LLD_HAS_EXPORTS)
|
||||
if(lld_has_exports)
|
||||
install(EXPORT LLDTargets DESTINATION ${LLD_INSTALL_PACKAGE_DIR}
|
||||
COMPONENT lld-cmake-exports)
|
||||
endif()
|
||||
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLDConfig.cmake
|
||||
DESTINATION ${LLD_INSTALL_PACKAGE_DIR}
|
||||
COMPONENT lld-cmake-exports)
|
||||
|
||||
if(NOT LLVM_ENABLE_IDE)
|
||||
# Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
|
||||
add_custom_target(lld-cmake-exports)
|
||||
add_llvm_install_targets(install-lld-cmake-exports
|
||||
COMPONENT lld-cmake-exports)
|
||||
endif()
|
||||
endif()
|
||||
13
lld/cmake/modules/LLDConfig.cmake.in
Normal file
13
lld/cmake/modules/LLDConfig.cmake.in
Normal file
@@ -0,0 +1,13 @@
|
||||
# This file allows users to call find_package(LLD) and pick up our targets.
|
||||
|
||||
@LLD_CONFIG_CODE@
|
||||
|
||||
find_package(LLVM REQUIRED CONFIG
|
||||
HINTS "@LLD_CONFIG_LLVM_CMAKE_DIR@")
|
||||
|
||||
set(LLD_EXPORTED_TARGETS "@LLD_EXPORTS@")
|
||||
set(LLD_CMAKE_DIR "@LLD_CONFIG_CMAKE_DIR@")
|
||||
set(LLD_INCLUDE_DIRS "@LLD_CONFIG_INCLUDE_DIRS@")
|
||||
|
||||
# Provide all our library targets to users.
|
||||
include("@LLD_CONFIG_EXPORTS_FILE@")
|
||||
Reference in New Issue
Block a user