Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake support absolute CMAKE_INSTALL_LIBDIR values #1393

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion cub/cmake/CubInstallRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,24 @@ 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")
set(_CCCL_RELATIVE_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
if(_CCCL_RELATIVE_LIBDIR MATCHES "^${CMAKE_INSTALL_PREFIX}")
alliepiper marked this conversation as resolved.
Show resolved Hide resolved
# libdir is an abs string that starts with prefix
string(LENGTH "${CMAKE_INSTALL_PREFIX}" to_remove)
string(SUBSTRING "${_CCCL_RELATIVE_LIBDIR}" ${to_remove} -1 relative)
# remove any leading "/""
string(REGEX REPLACE "^/(.)" "\\1" _CCCL_RELATIVE_LIBDIR "${relative}")
elseif(_CCCL_RELATIVE_LIBDIR MATCHES "^/")
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}')")
endif()
set(install_location "${_CCCL_RELATIVE_LIBDIR}/cmake/cub")

# Transform to a list of directories, replace each directory with "../"
# and convert back to a string
string(REGEX REPLACE "/" ";" from_install_prefix "${install_location}")
list(TRANSFORM from_install_prefix REPLACE ".+" "../")
list(JOIN from_install_prefix "" from_install_prefix)

configure_file("${CUB_SOURCE_DIR}/cub/cmake/cub-header-search.cmake.in"
"${CUB_BINARY_DIR}/cub/cmake/cub-header-search.cmake"
@ONLY)
Expand Down
8 changes: 1 addition & 7 deletions cub/cub/cmake/cub-header-search.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
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)
set(from_install_prefix "@from_install_prefix@")

find_path(_CUB_VERSION_INCLUDE_DIR cub/version.cuh
NO_CMAKE_FIND_ROOT_PATH # Don't allow CMake to re-root the search
Expand Down
13 changes: 12 additions & 1 deletion libcudacxx/cmake/libcudacxxInstallRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ install(DIRECTORY "${libcudacxx_SOURCE_DIR}/lib/cmake/libcudacxx"
# Need to configure a file to store CMAKE_INSTALL_INCLUDEDIR
# since it can be defined by the user. This is common to work around collisions
# with the CTK installed headers.
set(install_location "${CMAKE_INSTALL_LIBDIR}/cmake/libcudacxx")
set(_CCCL_RELATIVE_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
if(_CCCL_RELATIVE_LIBDIR MATCHES "^${CMAKE_INSTALL_PREFIX}")
# libdir is an abs string that starts with prefix
string(LENGTH "${CMAKE_INSTALL_PREFIX}" to_remove)
string(SUBSTRING "${_CCCL_RELATIVE_LIBDIR}" ${to_remove} -1 relative)
# remove any leading "/""
string(REGEX REPLACE "^/(.)" "\\1" _CCCL_RELATIVE_LIBDIR "${relative}")
elseif(_CCCL_RELATIVE_LIBDIR MATCHES "^/")
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}')")
endif()
set(install_location "${_CCCL_RELATIVE_LIBDIR}/cmake/libcudacxx")

# Transform to a list of directories, replace each directory with "../"
# and convert back to a string
string(REGEX REPLACE "/" ";" from_install_prefix "${install_location}")
Expand Down
20 changes: 19 additions & 1 deletion thrust/cmake/ThrustInstallRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,27 @@ install(DIRECTORY "${Thrust_SOURCE_DIR}/thrust/cmake/"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/thrust"
REGEX .*header-search.cmake.* EXCLUDE
)

# 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/thrust")
set(_CCCL_RELATIVE_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
if(_CCCL_RELATIVE_LIBDIR MATCHES "^${CMAKE_INSTALL_PREFIX}")
# libdir is an abs string that starts with prefix
string(LENGTH "${CMAKE_INSTALL_PREFIX}" to_remove)
string(SUBSTRING "${_CCCL_RELATIVE_LIBDIR}" ${to_remove} -1 relative)
# remove any leading "/""
string(REGEX REPLACE "^/(.)" "\\1" _CCCL_RELATIVE_LIBDIR "${relative}")
elseif(_CCCL_RELATIVE_LIBDIR MATCHES "^/")
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}')")
endif()
set(install_location "${_CCCL_RELATIVE_LIBDIR}/cmake/thrust")

# Transform to a list of directories, replace each directory with "../"
# and convert back to a string
string(REGEX REPLACE "/" ";" from_install_prefix "${install_location}")
list(TRANSFORM from_install_prefix REPLACE ".+" "../")
list(JOIN from_install_prefix "" from_install_prefix)

configure_file("${Thrust_SOURCE_DIR}/thrust/cmake/thrust-header-search.cmake.in"
"${Thrust_BINARY_DIR}/thrust/cmake/thrust-header-search.cmake"
@ONLY)
Expand Down
8 changes: 1 addition & 7 deletions thrust/thrust/cmake/thrust-header-search.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
unset(_THRUST_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)
set(from_install_prefix "@from_install_prefix@")

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