diff --git a/cmake/CubInstallRules.cmake b/cmake/CubInstallRules.cmake index 3617c8331d..3547718ffe 100644 --- a/cmake/CubInstallRules.cmake +++ b/cmake/CubInstallRules.cmake @@ -22,8 +22,9 @@ install(DIRECTORY "${CUB_SOURCE_DIR}/cub/cmake/" ) # Need to configure a file to store the infix specified in # CMAKE_INSTALL_INCLUDEDIR since it can be defined by the user +set(install_location "${CMAKE_INSTALL_LIBDIR}/cmake/cub") configure_file("${CUB_SOURCE_DIR}/cub/cmake/cub-header-search.cmake.in" "${CUB_BINARY_DIR}/cub/cmake/cub-header-search.cmake" @ONLY) install(FILES "${CUB_BINARY_DIR}/cub/cmake/cub-header-search.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cub") + DESTINATION "${install_location}") diff --git a/cub/cmake/cub-header-search.cmake.in b/cub/cmake/cub-header-search.cmake.in index 2a46606508..271b1b27bd 100644 --- a/cub/cmake/cub-header-search.cmake.in +++ b/cub/cmake/cub-header-search.cmake.in @@ -1,8 +1,18 @@ # Parse version information from version.h: unset(_CUB_VERSION_INCLUDE_DIR CACHE) # Clear old result to force search + +# Find CMAKE_INSTALL_INCLUDEDIR=@CMAKE_INSTALL_INCLUDEDIR@ directory" +set(from_install_prefix "@install_location@") + +# Transform to a list of directories, replace each directoy with "../" +# and convert back to a string +string(REGEX REPLACE "/" ";" from_install_prefix "${from_install_prefix}") +list(TRANSFORM from_install_prefix REPLACE ".+" "../") +list(JOIN from_install_prefix "" from_install_prefix) + find_path(_CUB_VERSION_INCLUDE_DIR cub/version.cuh NO_DEFAULT_PATH # Only search explicit paths below: PATHS - "${CMAKE_CURRENT_LIST_DIR}/../../../@CMAKE_INSTALL_INCLUDEDIR@" # Install tree + "${CMAKE_CURRENT_LIST_DIR}/${from_install_prefix}/@CMAKE_INSTALL_INCLUDEDIR@" ) set_property(CACHE _CUB_VERSION_INCLUDE_DIR PROPERTY TYPE INTERNAL)