From 0356bad534c756de20ea6f297339c5d500f37e83 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Fri, 17 Dec 2021 12:10:36 -0500 Subject: [PATCH] Support custom infix directories when installing thrust --- cmake/ThrustInstallRules.cmake | 18 ++++++++++++++++-- thrust/cmake/thrust-config-version.cmake | 10 ++-------- thrust/cmake/thrust-header-search.cmake | 8 ++++++++ thrust/cmake/thrust-header-search.cmake.in | 8 ++++++++ 4 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 thrust/cmake/thrust-header-search.cmake create mode 100644 thrust/cmake/thrust-header-search.cmake.in diff --git a/cmake/ThrustInstallRules.cmake b/cmake/ThrustInstallRules.cmake index 4f4f4d0115..3cecc7a8df 100644 --- a/cmake/ThrustInstallRules.cmake +++ b/cmake/ThrustInstallRules.cmake @@ -5,15 +5,22 @@ include(GNUInstallDirs) set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE) install(DIRECTORY "${Thrust_SOURCE_DIR}/thrust" - TYPE INCLUDE + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h" PATTERN "*.inl" ) +# Need to configure a file to store THRUST_INSTALL_HEADER_INFIX install(DIRECTORY "${Thrust_SOURCE_DIR}/thrust/cmake/" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/thrust" + PATTERN thrust-header-search EXCLUDE ) +configure_file("${Thrust_SOURCE_DIR}/thrust/cmake/thrust-header-search.cmake.in" + "${Thrust_BINARY_DIR}/thrust/cmake/thrust-header-search.cmake" + @ONLY) +install(FILES "${Thrust_BINARY_DIR}/thrust/cmake/thrust-header-search.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/thrust") # Depending on how Thrust is configured, CUB's CMake scripts may or may not be # included, so maintain a set of CUB install rules in both projects. By default @@ -22,12 +29,19 @@ install(DIRECTORY "${Thrust_SOURCE_DIR}/thrust/cmake/" option(THRUST_INSTALL_CUB_HEADERS "Include cub headers when installing." ON) if (THRUST_INSTALL_CUB_HEADERS) install(DIRECTORY "${Thrust_SOURCE_DIR}/dependencies/cub/cub" - TYPE INCLUDE + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.cuh" ) + # Need to configure a file to store THRUST_INSTALL_HEADER_INFIX install(DIRECTORY "${Thrust_SOURCE_DIR}/dependencies/cub/cub/cmake/" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cub" + PATTERN cub-header-search EXCLUDE ) + configure_file("${Thrust_SOURCE_DIR}/dependencies/cub/cub/cmake/cub-header-search.cmake.in" + "${Thrust_BINARY_DIR}/dependencies/cub/cub/cmake/cub-header-search.cmake" + @ONLY) + install(FILES "${Thrust_BINARY_DIR}/dependencies/cub/cub/cmake/cub-header-search.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/cub") endif() diff --git a/thrust/cmake/thrust-config-version.cmake b/thrust/cmake/thrust-config-version.cmake index 28d68bbce3..34fbc64689 100644 --- a/thrust/cmake/thrust-config-version.cmake +++ b/thrust/cmake/thrust-config-version.cmake @@ -1,12 +1,6 @@ # Parse version information from version.h: -unset(_THRUST_VERSION_INCLUDE_DIR CACHE) # Clear old result to force search -find_path(_THRUST_VERSION_INCLUDE_DIR thrust/version.h - NO_DEFAULT_PATH # Only search explicit paths below: - PATHS - ${CMAKE_CURRENT_LIST_DIR}/../.. # Source tree - ${CMAKE_CURRENT_LIST_DIR}/../../../include # Install tree -) -set_property(CACHE _THRUST_VERSION_INCLUDE_DIR PROPERTY TYPE INTERNAL) +include(${CMAKE_CURRENT_LIST_DIR}/thrust-header-search.cmake) + file(READ "${_THRUST_VERSION_INCLUDE_DIR}/thrust/version.h" THRUST_VERSION_HEADER) string(REGEX MATCH "#define[ \t]+THRUST_VERSION[ \t]+([0-9]+)" DUMMY "${THRUST_VERSION_HEADER}") set(THRUST_VERSION_FLAT ${CMAKE_MATCH_1}) diff --git a/thrust/cmake/thrust-header-search.cmake b/thrust/cmake/thrust-header-search.cmake new file mode 100644 index 0000000000..75f8e2f1f1 --- /dev/null +++ b/thrust/cmake/thrust-header-search.cmake @@ -0,0 +1,8 @@ +# Parse version information from version.h: +unset(_THRUST_VERSION_INCLUDE_DIR CACHE) # Clear old result to force search +find_path(_THRUST_VERSION_INCLUDE_DIR thrust/version.h + NO_DEFAULT_PATH # Only search explicit paths below: + PATHS + ${CMAKE_CURRENT_LIST_DIR}/../.. # Source tree +) +set_property(CACHE _THRUST_VERSION_INCLUDE_DIR PROPERTY TYPE INTERNAL) \ No newline at end of file diff --git a/thrust/cmake/thrust-header-search.cmake.in b/thrust/cmake/thrust-header-search.cmake.in new file mode 100644 index 0000000000..f95b7c1f9c --- /dev/null +++ b/thrust/cmake/thrust-header-search.cmake.in @@ -0,0 +1,8 @@ +# Parse version information from version.h: +unset(_THRUST_VERSION_INCLUDE_DIR CACHE) # Clear old result to force search +find_path(_THRUST_VERSION_INCLUDE_DIR thrust/version.h + NO_DEFAULT_PATH # Only search explicit paths below: + PATHS + ${CMAKE_CURRENT_LIST_DIR}/../../../@CMAKE_INSTALL_INCLUDEDIR@ +) +set_property(CACHE _THRUST_VERSION_INCLUDE_DIR PROPERTY TYPE INTERNAL)