diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2022-01-01 20:18:27 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2022-07-25 21:02:53 +0000 |
commit | ac0d1d5c7b7e0d572e35e31e0b59be765ca42a48 (patch) | |
tree | 011a54e6042ee73873dc6922908d96474fd44ade | |
parent | 8c626fc0c8a904c0040a36561edd9b62ac3b71b4 (diff) | |
download | llvm-ac0d1d5c7b7e0d572e35e31e0b59be765ca42a48.zip llvm-ac0d1d5c7b7e0d572e35e31e0b59be765ca42a48.tar.gz llvm-ac0d1d5c7b7e0d572e35e31e0b59be765ca42a48.tar.bz2 |
[cmake] Support custom package install paths
Firstly, we we make an additional GNUInstallDirs-style variable. With
NixOS, for example, this is crucial as we want those to go in
`${dev}/lib/cmake` not `${out}/lib/cmake` as that would a cmake subdir
of the "regular" libdir, which is installed even when no one needs to do
any development.
Secondly, we make *Config.cmake robust to absolute package install
paths. We for NixOS will in fact be passing them absolute paths to make
the `${dev}` vs `${out}` distinction mentioned above, and the
GNUInstallDirs-style variables are suposed to support absolute paths in
general so it's good practice besides the NixOS use-case.
Thirdly, we make `${project}_INSTALL_PACKAGE_DIR` CACHE PATHs like other
install dirs are.
Reviewed By: sebastian-ne
Differential Revision: https://reviews.llvm.org/D117973
-rw-r--r-- | clang/cmake/modules/CMakeLists.txt | 17 | ||||
-rw-r--r-- | cmake/Modules/FindPrefixFromConfig.cmake | 32 | ||||
-rw-r--r-- | cmake/Modules/GNUInstallPackageDir.cmake | 33 | ||||
-rw-r--r-- | flang/cmake/modules/CMakeLists.txt | 17 | ||||
-rw-r--r-- | lld/cmake/modules/CMakeLists.txt | 17 | ||||
-rw-r--r-- | llvm/cmake/modules/AddLLVM.cmake | 7 | ||||
-rw-r--r-- | llvm/cmake/modules/CMakeLists.txt | 7 | ||||
-rw-r--r-- | mlir/cmake/modules/CMakeLists.txt | 17 | ||||
-rw-r--r-- | polly/cmake/CMakeLists.txt | 23 |
9 files changed, 124 insertions, 46 deletions
diff --git a/clang/cmake/modules/CMakeLists.txt b/clang/cmake/modules/CMakeLists.txt index 5d41661..6a7fa2f 100644 --- a/clang/cmake/modules/CMakeLists.txt +++ b/clang/cmake/modules/CMakeLists.txt @@ -1,3 +1,4 @@ +include(GNUInstallPackageDir) include(ExtendPath) include(LLVMDistributionSupport) include(FindPrefixFromConfig) @@ -5,12 +6,16 @@ include(FindPrefixFromConfig) # 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(CLANG_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/clang) -set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}") +set(CLANG_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/clang" CACHE STRING + "Path for CMake subdirectory for Clang (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/clang')") +# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below. +set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/clang") # 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}") +set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING + "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')") +# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below. +set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") get_property(CLANG_EXPORTS GLOBAL PROPERTY CLANG_EXPORTS) export(TARGETS ${CLANG_EXPORTS} FILE ${clang_cmake_builddir}/ClangTargets.cmake) @@ -43,8 +48,8 @@ file(COPY . # Generate ClangConfig.cmake for the install tree. find_prefix_from_config(CLANG_CONFIG_CODE CLANG_INSTALL_PREFIX "${CLANG_INSTALL_PACKAGE_DIR}") -set(CLANG_CONFIG_CMAKE_DIR "\${CLANG_INSTALL_PREFIX}/${CLANG_INSTALL_PACKAGE_DIR}") -set(CLANG_CONFIG_LLVM_CMAKE_DIR "\${CLANG_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") +extend_path(CLANG_CONFIG_CMAKE_DIR "\${CLANG_INSTALL_PREFIX}" "${CLANG_INSTALL_PACKAGE_DIR}") +extend_path(CLANG_CONFIG_LLVM_CMAKE_DIR "\${CLANG_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}") get_config_exports_includes(Clang CLANG_CONFIG_INCLUDE_EXPORTS) extend_path(base_includedir "\${CLANG_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}") set(CLANG_CONFIG_INCLUDE_DIRS diff --git a/cmake/Modules/FindPrefixFromConfig.cmake b/cmake/Modules/FindPrefixFromConfig.cmake index aa9fb0d..c583a65 100644 --- a/cmake/Modules/FindPrefixFromConfig.cmake +++ b/cmake/Modules/FindPrefixFromConfig.cmake @@ -26,16 +26,28 @@ # Path from the prefix to the config file, a relative path which we wish to # go up and out from to find the prefix directory. function(find_prefix_from_config out_var prefix_var path_to_leave) - set(config_code - "# Compute the installation prefix from this LLVMConfig.cmake file location." - "get_filename_component(${prefix_var} \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)") - # Construct the proper number of get_filename_component(... PATH) - # calls to compute the installation prefix. - string(REGEX REPLACE "/" ";" _count "${path_to_leave}") - foreach(p ${_count}) - list(APPEND config_code - "get_filename_component(${prefix_var} \"\${${prefix_var}}\" PATH)") - endforeach(p) + if(IS_ABSOLUTE "${path_to_leave}") + # Because the path is absolute, we don't care about `path_to_leave` + # because we can just "jump" to the absolute path rather than work + # our way there relatively. + set(config_code + "# Installation prefix is fixed absolute path" + "set(${prefix_var} \"${CMAKE_INSTALL_PREFIX}\"") + else() + # `path_to_leave` is relative. Relative to what? The install prefix. + # We therefore go up enough parent directories to get back to the + # install prefix, and avoid hard-coding any absolute paths. + set(config_code + "# Compute the installation prefix from this LLVMConfig.cmake file location." + "get_filename_component(${prefix_var} \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)") + # Construct the proper number of get_filename_component(... PATH) + # calls to compute the installation prefix. + string(REGEX REPLACE "/" ";" _count "${path_to_leave}") + foreach(p ${_count}) + list(APPEND config_code + "get_filename_component(${prefix_var} \"\${${prefix_var}}\" PATH)") + endforeach(p) + endif() string(REPLACE ";" "\n" config_code "${config_code}") set("${out_var}" "${config_code}" PARENT_SCOPE) endfunction() diff --git a/cmake/Modules/GNUInstallPackageDir.cmake b/cmake/Modules/GNUInstallPackageDir.cmake new file mode 100644 index 0000000..e4a058e --- /dev/null +++ b/cmake/Modules/GNUInstallPackageDir.cmake @@ -0,0 +1,33 @@ +# Mimick `GNUInstallDirs` for one more install directory, the one where +# project's installed cmake subdirs go. + +# These functions are internal functions vendored in from GNUInstallDirs (with +# new names), so we don't depend on unstable implementation details. They are +# also simplified to only handle the cases we need. +# +# The purpose would appear to be making `CACHE PATH` vars in a way that +# bypasses the legacy oddity that `-D<PATH>` gets canonicalized, despite +# non-canonical `CACHE PATH`s being perfectly valid. + +macro(_GNUInstallPackageDir_cache_convert_to_path var description) + get_property(_GNUInstallPackageDir_cache_type CACHE ${var} PROPERTY TYPE) + if(_GNUInstallPackageDir_cache_type STREQUAL "UNINITIALIZED") + file(TO_CMAKE_PATH "${${var}}" _GNUInstallPackageDir_cmakepath) + set_property(CACHE ${var} PROPERTY TYPE PATH) + set_property(CACHE ${var} PROPERTY VALUE "${_GNUInstallPackageDir_cmakepath}") + set_property(CACHE ${var} PROPERTY HELPSTRING "${description}") + unset(_GNUInstallPackageDir_cmakepath) + endif() + unset(_GNUInstallPackageDir_cache_type) +endmacro() + +# Create a cache variable with default for a path. +macro(_GNUInstallPackageDir_cache_path var default description) + if(NOT DEFINED ${var}) + set(${var} "${default}" CACHE PATH "${description}") + endif() + _GNUInstallPackageDir_cache_convert_to_path("${var}" "${description}") +endmacro() + +_GNUInstallPackageDir_cache_path(CMAKE_INSTALL_PACKAGEDIR "lib${LLVM_LIBDIR_SUFFIX}/cmake" + "Directories containing installed CMake modules (lib/cmake)") diff --git a/flang/cmake/modules/CMakeLists.txt b/flang/cmake/modules/CMakeLists.txt index 170568c..2827c2b 100644 --- a/flang/cmake/modules/CMakeLists.txt +++ b/flang/cmake/modules/CMakeLists.txt @@ -1,15 +1,20 @@ +include(GNUInstallPackageDir) include(ExtendPath) include(FindPrefixFromConfig) # 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(FLANG_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/flang) -set(flang_cmake_builddir "${CMAKE_BINARY_DIR}/${FLANG_INSTALL_PACKAGE_DIR}") +set(FLANG_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/flang" CACHE STRING + "Path for CMake subdirectory for Flang (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/flang')") +# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below. +set(flang_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/flang") # 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}") +set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING + "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')") +# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below. +set(llvm_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") get_property(FLANG_EXPORTS GLOBAL PROPERTY FLANG_EXPORTS) export(TARGETS ${FLANG_EXPORTS} FILE ${flang_cmake_builddir}/FlangTargets.cmake) @@ -32,8 +37,8 @@ set(FLANG_CONFIG_LLVM_CMAKE_DIR) # Generate FlangConfig.cmake for the install tree. find_prefix_from_config(FLANG_CONFIG_CODE FLANG_INSTALL_PREFIX "${FLANG_INSTALL_PACKAGE_DIR}") -set(FLANG_CONFIG_CMAKE_DIR "\${FLANG_INSTALL_PREFIX}/${FLANG_INSTALL_PACKAGE_DIR}") -set(FLANG_CONFIG_LLVM_CMAKE_DIR "\${FLANG_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") +extend_path(FLANG_CONFIG_CMAKE_DIR "\${FLANG_INSTALL_PREFIX}" "${FLANG_INSTALL_PACKAGE_DIR}") +extend_path(FLANG_CONFIG_LLVM_CMAKE_DIR "\${FLANG_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}") get_config_exports_includes(Flang FLANG_CONFIG_INCLUDE_EXPORTS) extend_path(FLANG_CONFIG_INCLUDE_DIRS "\${FLANG_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}") diff --git a/lld/cmake/modules/CMakeLists.txt b/lld/cmake/modules/CMakeLists.txt index 760c9d5..57140e6 100644 --- a/lld/cmake/modules/CMakeLists.txt +++ b/lld/cmake/modules/CMakeLists.txt @@ -1,15 +1,20 @@ +include(GNUInstallPackageDir) include(ExtendPath) include(FindPrefixFromConfig) # 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}") +set(LLD_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/lld" CACHE STRING + "Path for CMake subdirectory for LLD (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/lld')") +# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below. +set(lld_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/lld") # 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}") +set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING + "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')") +# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below. +set(llvm_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") get_property(LLD_EXPORTS GLOBAL PROPERTY LLD_EXPORTS) export(TARGETS ${LLD_EXPORTS} FILE ${lld_cmake_builddir}/LLDTargets.cmake) @@ -31,8 +36,8 @@ set(LLD_CONFIG_LLVM_CMAKE_DIR) # Generate LLDConfig.cmake for the install tree. find_prefix_from_config(LLD_CONFIG_CODE LLD_INSTALL_PREFIX "${LLD_INSTALL_PACKAGE_DIR}") -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}") +extend_path(LLD_CONFIG_CMAKE_DIR "\${LLD_INSTALL_PREFIX}" "${LLD_INSTALL_PACKAGE_DIR}") +extend_path(LLD_CONFIG_LLVM_CMAKE_DIR "\${LLD_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}") get_config_exports_includes(LLD LLD_CONFIG_INCLUDE_EXPORTS) extend_path(LLD_CONFIG_INCLUDE_DIRS "\${LLD_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}") configure_file( diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake index 22076d4..365742d 100644 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -1089,8 +1089,11 @@ function(process_llvm_pass_plugins) ## Part 1: Extension header to be included whenever we need extension # processing. - set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) - set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") + if(NOT DEFINED LLVM_INSTALL_PACKAGE_DIR) + message(FATAL_ERROR "LLVM_INSTALL_PACKAGE_DIR must be defined and writable. GEN_CONFIG should only be passe when building LLVM proper.") + endif() + # LLVM_INSTALL_PACKAGE_DIR might be absolute, so don't reuse below. + set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") file(WRITE "${llvm_cmake_builddir}/LLVMConfigExtensions.cmake" "set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})") diff --git a/llvm/cmake/modules/CMakeLists.txt b/llvm/cmake/modules/CMakeLists.txt index d4453f2..93f6171 100644 --- a/llvm/cmake/modules/CMakeLists.txt +++ b/llvm/cmake/modules/CMakeLists.txt @@ -1,9 +1,12 @@ +include(GNUInstallPackageDir) include(ExtendPath) include(LLVMDistributionSupport) include(FindPrefixFromConfig) -set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) -set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") +set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING + "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')") +# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below. +set(llvm_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") # First for users who use an installed LLVM, create the LLVMExports.cmake file. set(LLVM_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMExports.cmake) diff --git a/mlir/cmake/modules/CMakeLists.txt b/mlir/cmake/modules/CMakeLists.txt index 1397055..6d8ea52 100644 --- a/mlir/cmake/modules/CMakeLists.txt +++ b/mlir/cmake/modules/CMakeLists.txt @@ -1,3 +1,4 @@ +include(GNUInstallPackageDir) include(ExtendPath) include(LLVMDistributionSupport) include(FindPrefixFromConfig) @@ -5,12 +6,16 @@ include(FindPrefixFromConfig) # 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(MLIR_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir) -set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/${MLIR_INSTALL_PACKAGE_DIR}") +set(MLIR_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/mlir" CACHE STRING + "Path for CMake subdirectory for Polly (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/polly')") +# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below. +set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir") # 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}") +set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING + "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')") +# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below. +set(llvm_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") get_property(MLIR_EXPORTS GLOBAL PROPERTY MLIR_EXPORTS) export(TARGETS ${MLIR_EXPORTS} FILE ${mlir_cmake_builddir}/MLIRTargets.cmake) @@ -54,8 +59,8 @@ file(COPY . # Generate MLIRConfig.cmake for the install tree. find_prefix_from_config(MLIR_CONFIG_CODE MLIR_INSTALL_PREFIX "${MLIR_INSTALL_PACKAGE_DIR}") -set(MLIR_CONFIG_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}/${MLIR_INSTALL_PACKAGE_DIR}") -set(MLIR_CONFIG_LLVM_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") +extend_path(MLIR_CONFIG_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}" "${MLIR_INSTALL_PACKAGE_DIR}") +extend_path(MLIR_CONFIG_LLVM_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}") get_config_exports_includes(MLIR MLIR_CONFIG_INCLUDE_EXPORTS) extend_path(base_includedir "\${MLIR_INSTALL_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}") set(MLIR_CONFIG_INCLUDE_DIRS diff --git a/polly/cmake/CMakeLists.txt b/polly/cmake/CMakeLists.txt index 7a0190b..4c528d5 100644 --- a/polly/cmake/CMakeLists.txt +++ b/polly/cmake/CMakeLists.txt @@ -1,10 +1,19 @@ # Keep this in sync with llvm/cmake/CMakeLists.txt! +include(GNUInstallPackageDir) include(ExtendPath) include(FindPrefixFromConfig) -set(LLVM_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") -set(POLLY_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/polly") +set(POLLY_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/polly" CACHE STRING + "Path for CMake subdirectory for Polly (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/polly')") +# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below. +set(polly_cmake_builddir "${POLLY_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/polly") + +set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING + "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')") +# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below. +set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm") + if (CMAKE_CONFIGURATION_TYPES) set(POLLY_EXPORTS_FILE_NAME "PollyExports-$<LOWER_CASE:$<CONFIG>>.cmake") else() @@ -28,9 +37,6 @@ foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS) set(POLLY_CONFIG_TARGET_${tgt}_TYPE ${tgt_type}) endforeach() -set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") -set(POLLY_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}") - # generate the import code for bundled/undbundled libisl versions if (NOT POLLY_BUNDLED_ISL) get_property(incl TARGET ISL PROPERTY INTERFACE_INCLUDE_DIRECTORIES) @@ -50,7 +56,8 @@ endif() # Generate PollyConfig.cmake for the build tree. set(POLLY_CONFIG_CODE "") -set(POLLY_CONFIG_CMAKE_DIR "${CMAKE_BINARY_DIR}/${POLLY_INSTALL_PACKAGE_DIR}") +set(POLLY_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}") +set(POLLY_CONFIG_CMAKE_DIR "${polly_cmake_builddir}") set(POLLY_CONFIG_INCLUDE_DIRS ${POLLY_SOURCE_DIR}/include ${ISL_INCLUDE_DIRS} @@ -73,11 +80,11 @@ endforeach(tgt) # the imported locations configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in - ${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake + ${polly_cmake_builddir}/PollyConfig.cmake @ONLY) file(GENERATE - OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME} + OUTPUT ${polly_cmake_builddir}/${POLLY_EXPORTS_FILE_NAME} CONTENT "${POLLY_EXPORTS}") |