diff --git a/cmake/Modules/ExtendInstallPath.cmake b/cmake/Modules/ExtendInstallPath.cmake --- a/cmake/Modules/ExtendInstallPath.cmake +++ b/cmake/Modules/ExtendInstallPath.cmake @@ -14,3 +14,18 @@ endif() set(${joined_path} "${temp_path}" PARENT_SCOPE) endfunction() + +# Like extend_install_path, but quotes the ${prefix_var} expansion. This is +# typically for generating the contents of `*Config.cmake` modules to be +# installed. +function(extend_delayed_install_path prefix_var joined_path current_segment) + if("${current_segment}" STREQUAL "") + set(temp_path "\${${refix_name}}") + elseif(IS_ABSOLUTE "${current_segment}") + message(WARNING "Since \"${current_segment}\" is absolute, it overrides ${prefix_var}") + set(temp_path "${current_segment}") + else() + set(temp_path "\${${prefix_var}}/${current_segment}") + endif() + set(${joined_path} "${temp_path}" PARENT_SCOPE) +endfunction() diff --git a/lld/CMakeLists.txt b/lld/CMakeLists.txt --- 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) @@ -188,7 +190,7 @@ 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 --- 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 @@ ${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 @@ 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 --- a/lld/cmake/modules/CMakeLists.txt +++ b/lld/cmake/modules/CMakeLists.txt @@ -1,3 +1,5 @@ +include(ExtendInstallPath) + # 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 @@ 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_delayed_install_path(LLD_INSTALL_PREFIX LLD_CONFIG_INCLUDE_DIRS "${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 --- a/lld/tools/lld/CMakeLists.txt +++ b/lld/tools/lld/CMakeLists.txt @@ -20,7 +20,7 @@ ) install(TARGETS lld - RUNTIME DESTINATION bin) + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") if(NOT LLD_SYMLINKS_TO_CREATE) set(LLD_SYMLINKS_TO_CREATE