From 28e665fa054d62d4e2c777774cc83dea533dfe6e Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 16 Jan 2022 05:52:22 +0000 Subject: [PATCH] [cmake] Slight fix ups to make robust to the full range of GNUInstallDirs See https://cmake.org/cmake/help/v3.14/module/GNUInstallDirs.html#result-variables for `CMAKE_INSTALL_FULL_*` Reviewed By: sebastian-ne Differential Revision: https://reviews.llvm.org/D130545 --- clang/tools/clang-linker-wrapper/CMakeLists.txt | 4 +++- llvm-libgcc/lib/CMakeLists.txt | 5 +++-- llvm/cmake/modules/CMakeLists.txt | 1 + openmp/CMakeLists.txt | 9 +++++++-- openmp/runtime/src/CMakeLists.txt | 14 +++++++++----- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/clang/tools/clang-linker-wrapper/CMakeLists.txt b/clang/tools/clang-linker-wrapper/CMakeLists.txt index 60392c7d901f..88c19cad7b53 100644 --- a/clang/tools/clang-linker-wrapper/CMakeLists.txt +++ b/clang/tools/clang-linker-wrapper/CMakeLists.txt @@ -1,3 +1,5 @@ +include(GNUInstallDirs) + set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} BitWriter @@ -42,4 +44,4 @@ target_link_libraries(clang-linker-wrapper ${CLANG_LINKER_WRAPPER_LIB_DEPS} ) -install(TARGETS clang-linker-wrapper RUNTIME DESTINATION bin) +install(TARGETS clang-linker-wrapper RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") diff --git a/llvm-libgcc/lib/CMakeLists.txt b/llvm-libgcc/lib/CMakeLists.txt index 652af46db4cb..d895a21554b0 100644 --- a/llvm-libgcc/lib/CMakeLists.txt +++ b/llvm-libgcc/lib/CMakeLists.txt @@ -1,5 +1,6 @@ include(CheckLibraryExists) include(GNUInstallDirs) +include(ExtendPath) string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") @@ -41,13 +42,13 @@ target_link_libraries(libgcc_s PRIVATE c ) -get_filename_component(LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT "${CMAKE_INSTALL_PREFIX}/${LIBUNWIND_INSTALL_LIBRARY_DIR}" ABSOLUTE) +extend_path(LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT "${CMAKE_INSTALL_PREFIX}" "${LIBUNWIND_INSTALL_LIBRARY_DIR}") #string(REPLACE "${CMAKE_INSTALL_FULL_LIBDIR}/" "" LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT "${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}") install(TARGETS libgcc_s LIBRARY DESTINATION "${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}" COMPONENT unwind ARCHIVE DESTINATION "${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}" COMPONENT unwind - RUNTIME DESTINATION bin COMPONENT unwind) + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT unwind) get_compiler_rt_install_dir(${LLVM_LIBGCC_TARGET_ARCH} install_dir_builtins) string(REGEX REPLACE "^lib/" "" install_dir_builtins "${install_dir_builtins}") diff --git a/llvm/cmake/modules/CMakeLists.txt b/llvm/cmake/modules/CMakeLists.txt index 25c9b790b80b..d4b0ab959148 100644 --- a/llvm/cmake/modules/CMakeLists.txt +++ b/llvm/cmake/modules/CMakeLists.txt @@ -137,6 +137,7 @@ list(REMOVE_DUPLICATES LLVM_CONFIG_LIBRARY_DIRS) set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") extend_path(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}") +extend_path(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}" "${LLVM_TOOLS_INSTALL_DIR}") # Generate a default location for lit if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS) diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt index 4530281aff26..b6ddbe90516d 100644 --- a/openmp/CMakeLists.txt +++ b/openmp/CMakeLists.txt @@ -1,7 +1,12 @@ cmake_minimum_required(VERSION 3.13.4) -# Add cmake directory to search for custom cmake functions. -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) +set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) + +# Add path for custom modules +list(INSERT CMAKE_MODULE_PATH 0 + "${CMAKE_CURRENT_SOURCE_DIR}/cmake" + "${LLVM_COMMON_CMAKE_UTILS}/Modules" + ) # llvm/runtimes/ will set OPENMP_STANDALONE_BUILD. if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt index 4068a5862b4a..02f65aac0d40 100644 --- a/openmp/runtime/src/CMakeLists.txt +++ b/openmp/runtime/src/CMakeLists.txt @@ -8,6 +8,8 @@ #//===----------------------------------------------------------------------===// # +include(ExtendPath) + # Configure omp.h, kmp_config.h and omp-tools.h if necessary configure_file(${LIBOMP_INC_DIR}/omp.h.var omp.h @ONLY) configure_file(kmp_config.h.cmake kmp_config.h @ONLY) @@ -347,8 +349,8 @@ endif() add_dependencies(libomp-micro-tests libomp-test-deps) # Install rules -# We want to install libomp in DESTDIR/CMAKE_INSTALL_PREFIX/lib -# We want to install headers in DESTDIR/CMAKE_INSTALL_PREFIX/include +# We want to install libomp in ${DESTDIR}/${CMAKE_INSTALL_FULL_LIBDIR} +# We want to install headers in ${DESTDIR}/${CMAKE_INSTALL_FULL_INCLUDEDIR} if(${OPENMP_STANDALONE_BUILD}) set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}") else() @@ -362,9 +364,10 @@ if(WIN32) set(LIBOMP_ALIASES "libiomp5md") foreach(alias IN LISTS LIBOMP_ALIASES) install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_LIB_FILE}\" - \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}\")") + \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"${CMAKE_INSTALL_FULL_BINDIR}\")") + extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}") install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_IMP_LIB_FILE}\" - \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR}\")") + \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"${outdir}\")") endforeach() else() @@ -374,9 +377,10 @@ else() # Create aliases (symlinks) of the library for backwards compatibility set(LIBOMP_ALIASES "libgomp;libiomp5") foreach(alias IN LISTS LIBOMP_ALIASES) + extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}") install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\" \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY - \"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR}\")") + \"\$ENV{DESTDIR}\${outdir}\")") endforeach() endif() endif()