[lld] 8965370 - [lld][CMake] Use `GNUInstallDirs` to support custom installation dirs
John Ericson via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 31 10:58:02 PST 2021
Author: John Ericson
Date: 2021-12-31T18:57:57Z
New Revision: 896537048df70762b5b0051a0e1b065a74e8d0ce
URL: https://github.com/llvm/llvm-project/commit/896537048df70762b5b0051a0e1b065a74e8d0ce
DIFF: https://github.com/llvm/llvm-project/commit/896537048df70762b5b0051a0e1b065a74e8d0ce.diff
LOG: [lld][CMake] Use `GNUInstallDirs` to support custom installation dirs
Extracted from D99484. My new plan is to start from the outside and work
inward.
Reviewed By: stephenneuendorffer
Differential Revision: https://reviews.llvm.org/D115568
Added:
Modified:
lld/CMakeLists.txt
lld/cmake/modules/AddLLD.cmake
lld/cmake/modules/CMakeLists.txt
lld/tools/lld/CMakeLists.txt
Removed:
################################################################################
diff --git a/lld/CMakeLists.txt b/lld/CMakeLists.txt
index fb5cfd5f28a13..00f8e1bb2a779 100644
--- a/lld/CMakeLists.txt
+++ b/lld/CMakeLists.txt
@@ -1,3 +1,5 @@
+include(GNUInstallDirs)
+
# Check if lld is built as a standalone project.
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
project(lld)
@@ -34,8 +36,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(LLVM_MAIN_INCLUDE_DIR ${MAIN_INCLUDE_DIR} CACHE PATH "path to llvm/include")
set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
- file(TO_CMAKE_PATH ${LLVM_OBJ_ROOT} LLVM_BINARY_DIR)
- file(TO_CMAKE_PATH ${LLVM_CMAKE_DIR} LLVM_CMAKE_DIR)
+ file(TO_CMAKE_PATH "${LLVM_OBJ_ROOT}" LLVM_BINARY_DIR)
+ file(TO_CMAKE_PATH "${LLVM_CMAKE_DIR}" LLVM_CMAKE_DIR)
if(NOT EXISTS "${LLVM_CMAKE_DIR}/LLVMConfig.cmake")
message(FATAL_ERROR "LLVMConfig.cmake not found")
@@ -151,7 +153,11 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
"`CMakeFiles'. Please delete them.")
endif()
-list (APPEND CMAKE_MODULE_PATH "${LLD_SOURCE_DIR}/cmake/modules")
+# Add path for custom modules.
+list(INSERT CMAKE_MODULE_PATH 0
+ "${LLD_SOURCE_DIR}/cmake/modules"
+ "${LLD_SOURCE_DIR}/../cmake/Modules"
+ )
include(AddLLD)
@@ -188,7 +194,7 @@ include_directories(BEFORE
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
install(DIRECTORY include/
- DESTINATION include
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING
PATTERN "*.h"
)
diff --git a/lld/cmake/modules/AddLLD.cmake b/lld/cmake/modules/AddLLD.cmake
index 9883475d1aa58..dd2898ce62364 100644
--- a/lld/cmake/modules/AddLLD.cmake
+++ b/lld/cmake/modules/AddLLD.cmake
@@ -1,3 +1,4 @@
+include(GNUInstallDirs)
include(LLVMDistributionSupport)
macro(add_lld_library name)
@@ -19,7 +20,7 @@ macro(add_lld_library name)
${export_to_lldtargets}
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
- RUNTIME DESTINATION bin)
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES)
add_llvm_install_targets(install-${name}
@@ -46,7 +47,7 @@ macro(add_lld_tool name)
get_target_export_arg(${name} LLD export_to_lldtargets)
install(TARGETS ${name}
${export_to_lldtargets}
- RUNTIME DESTINATION bin
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT ${name})
if(NOT CMAKE_CONFIGURATION_TYPES)
diff --git a/lld/cmake/modules/CMakeLists.txt b/lld/cmake/modules/CMakeLists.txt
index 62d03fa901dd8..022824ede631d 100644
--- a/lld/cmake/modules/CMakeLists.txt
+++ b/lld/cmake/modules/CMakeLists.txt
@@ -1,3 +1,5 @@
+include(ExtendPath)
+
# 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.
@@ -40,7 +42,7 @@ 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}")
get_config_exports_includes(LLD LLD_CONFIG_INCLUDE_EXPORTS)
-set(LLD_CONFIG_INCLUDE_DIRS "\${LLD_INSTALL_PREFIX}/include")
+extend_path(LLD_CONFIG_INCLUDE_DIRS "\${LLD_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/LLDConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLDConfig.cmake
diff --git a/lld/tools/lld/CMakeLists.txt b/lld/tools/lld/CMakeLists.txt
index c5c86c604c670..df48cc0d6c51d 100644
--- a/lld/tools/lld/CMakeLists.txt
+++ b/lld/tools/lld/CMakeLists.txt
@@ -20,7 +20,7 @@ target_link_libraries(lld
)
install(TARGETS lld
- RUNTIME DESTINATION bin)
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
if(NOT LLD_SYMLINKS_TO_CREATE)
set(LLD_SYMLINKS_TO_CREATE
More information about the llvm-commits
mailing list