Skip to content

Commit 9c553d3

Browse files
committed
CMake support absolute CMAKE_INSTALL_LIBDIR values
Fixes #1390
1 parent fddf2fe commit 9c553d3

File tree

5 files changed

+51
-17
lines changed

5 files changed

+51
-17
lines changed

cub/cmake/CubInstallRules.cmake

+18-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,24 @@ install(DIRECTORY "${CUB_SOURCE_DIR}/cub/cmake/"
1616
)
1717
# Need to configure a file to store the infix specified in
1818
# CMAKE_INSTALL_INCLUDEDIR since it can be defined by the user
19-
set(install_location "${CMAKE_INSTALL_LIBDIR}/cmake/cub")
19+
set(_CCCL_RELATIVE_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
20+
if(_CCCL_RELATIVE_LIBDIR MATCHES "^${CMAKE_INSTALL_PREFIX}")
21+
# libdir is an abs string that starts with prefix
22+
string(LENGTH "${CMAKE_INSTALL_PREFIX}" to_remove)
23+
string(SUBSTRING "${_CCCL_RELATIVE_LIBDIR}" ${to_remove} -1 relative)
24+
# remove any leading "/""
25+
string(REGEX REPLACE "^/(.)" "\\1" _CCCL_RELATIVE_LIBDIR "${relative}")
26+
elseif(_CCCL_RELATIVE_LIBDIR MATCHES "^/")
27+
message(FATAL_ERROR "CMAKE_INSTALL_LIBDIR ('${CMAKE_INSTALL_LIBDIR}') must be a relative path or an absolute path under CMAKE_INSTALL_PREFIX ('${CMAKE_INSTALL_PREFIX}')")
28+
endif()
29+
set(install_location "${_CCCL_RELATIVE_LIBDIR}/cmake/cub")
30+
31+
# Transform to a list of directories, replace each directory with "../"
32+
# and convert back to a string
33+
string(REGEX REPLACE "/" ";" from_install_prefix "${install_location}")
34+
list(TRANSFORM from_install_prefix REPLACE ".+" "../")
35+
list(JOIN from_install_prefix "" from_install_prefix)
36+
2037
configure_file("${CUB_SOURCE_DIR}/cub/cmake/cub-header-search.cmake.in"
2138
"${CUB_BINARY_DIR}/cub/cmake/cub-header-search.cmake"
2239
@ONLY)

cub/cub/cmake/cub-header-search.cmake.in

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22
unset(_CUB_VERSION_INCLUDE_DIR CACHE) # Clear old result to force search
33

44
# Find CMAKE_INSTALL_INCLUDEDIR=@CMAKE_INSTALL_INCLUDEDIR@ directory"
5-
set(from_install_prefix "@install_location@")
6-
7-
# Transform to a list of directories, replace each directoy with "../"
8-
# and convert back to a string
9-
string(REGEX REPLACE "/" ";" from_install_prefix "${from_install_prefix}")
10-
list(TRANSFORM from_install_prefix REPLACE ".+" "../")
11-
list(JOIN from_install_prefix "" from_install_prefix)
5+
set(from_install_prefix "@from_install_prefix@")
126

137
find_path(_CUB_VERSION_INCLUDE_DIR cub/version.cuh
148
NO_CMAKE_FIND_ROOT_PATH # Don't allow CMake to re-root the search

libcudacxx/cmake/libcudacxxInstallRules.cmake

+12-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@ install(DIRECTORY "${libcudacxx_SOURCE_DIR}/lib/cmake/libcudacxx"
2828
# Need to configure a file to store CMAKE_INSTALL_INCLUDEDIR
2929
# since it can be defined by the user. This is common to work around collisions
3030
# with the CTK installed headers.
31-
set(install_location "${CMAKE_INSTALL_LIBDIR}/cmake/libcudacxx")
31+
set(_CCCL_RELATIVE_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
32+
if(_CCCL_RELATIVE_LIBDIR MATCHES "^${CMAKE_INSTALL_PREFIX}")
33+
# libdir is an abs string that starts with prefix
34+
string(LENGTH "${CMAKE_INSTALL_PREFIX}" to_remove)
35+
string(SUBSTRING "${_CCCL_RELATIVE_LIBDIR}" ${to_remove} -1 relative)
36+
# remove any leading "/""
37+
string(REGEX REPLACE "^/(.)" "\\1" _CCCL_RELATIVE_LIBDIR "${relative}")
38+
elseif(_CCCL_RELATIVE_LIBDIR MATCHES "^/")
39+
message(FATAL_ERROR "CMAKE_INSTALL_LIBDIR ('${CMAKE_INSTALL_LIBDIR}') must be a relative path or an absolute path under CMAKE_INSTALL_PREFIX ('${CMAKE_INSTALL_PREFIX}')")
40+
endif()
41+
set(install_location "${_CCCL_RELATIVE_LIBDIR}/cmake/libcudacxx")
42+
3243
# Transform to a list of directories, replace each directory with "../"
3344
# and convert back to a string
3445
string(REGEX REPLACE "/" ";" from_install_prefix "${install_location}")

thrust/cmake/ThrustInstallRules.cmake

+19-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,27 @@ install(DIRECTORY "${Thrust_SOURCE_DIR}/thrust/cmake/"
1515
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/thrust"
1616
REGEX .*header-search.cmake.* EXCLUDE
1717
)
18+
1819
# Need to configure a file to store the infix specified in
1920
# CMAKE_INSTALL_INCLUDEDIR since it can be defined by the user
20-
set(install_location "${CMAKE_INSTALL_LIBDIR}/cmake/thrust")
21+
set(_CCCL_RELATIVE_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
22+
if(_CCCL_RELATIVE_LIBDIR MATCHES "^${CMAKE_INSTALL_PREFIX}")
23+
# libdir is an abs string that starts with prefix
24+
string(LENGTH "${CMAKE_INSTALL_PREFIX}" to_remove)
25+
string(SUBSTRING "${_CCCL_RELATIVE_LIBDIR}" ${to_remove} -1 relative)
26+
# remove any leading "/""
27+
string(REGEX REPLACE "^/(.)" "\\1" _CCCL_RELATIVE_LIBDIR "${relative}")
28+
elseif(_CCCL_RELATIVE_LIBDIR MATCHES "^/")
29+
message(FATAL_ERROR "CMAKE_INSTALL_LIBDIR ('${CMAKE_INSTALL_LIBDIR}') must be a relative path or an absolute path under CMAKE_INSTALL_PREFIX ('${CMAKE_INSTALL_PREFIX}')")
30+
endif()
31+
set(install_location "${_CCCL_RELATIVE_LIBDIR}/cmake/thrust")
32+
33+
# Transform to a list of directories, replace each directory with "../"
34+
# and convert back to a string
35+
string(REGEX REPLACE "/" ";" from_install_prefix "${install_location}")
36+
list(TRANSFORM from_install_prefix REPLACE ".+" "../")
37+
list(JOIN from_install_prefix "" from_install_prefix)
38+
2139
configure_file("${Thrust_SOURCE_DIR}/thrust/cmake/thrust-header-search.cmake.in"
2240
"${Thrust_BINARY_DIR}/thrust/cmake/thrust-header-search.cmake"
2341
@ONLY)

thrust/thrust/cmake/thrust-header-search.cmake.in

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22
unset(_THRUST_VERSION_INCLUDE_DIR CACHE) # Clear old result to force search
33

44
# Find CMAKE_INSTALL_INCLUDEDIR=@CMAKE_INSTALL_INCLUDEDIR@ directory"
5-
set(from_install_prefix "@install_location@")
6-
7-
# Transform to a list of directories, replace each directoy with "../"
8-
# and convert back to a string
9-
string(REGEX REPLACE "/" ";" from_install_prefix "${from_install_prefix}")
10-
list(TRANSFORM from_install_prefix REPLACE ".+" "../")
11-
list(JOIN from_install_prefix "" from_install_prefix)
5+
set(from_install_prefix "@from_install_prefix@")
126

137
find_path(_THRUST_VERSION_INCLUDE_DIR thrust/version.h
148
NO_CMAKE_FIND_ROOT_PATH # Don't allow CMake to re-root the search

0 commit comments

Comments
 (0)