Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit ea48955

Browse files
committed
Update CUB CMake to match recent changes to Thrust.
Specifically, this ports the following PRs to CUB: - NVIDIA/thrust#1297 Add install rule option for add_subdirectory users. - NVIDIA/thrust#1298 Enforce semantic versioning in CMake version configs. - NVIDIA/thrust#1300 Use FindPackageHandleStandardArgs in CMake config.
1 parent 52d58a8 commit ea48955

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed

CMakeLists.txt

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
# Support adding CUB to a parent project via add_subdirectory.
2-
# See examples/cmake/add_subdir/CMakeLists.txt for details.
3-
if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}" AND
4-
NOT CUB_IN_THRUST)
5-
include(cmake/CubAddSubdir.cmake)
6-
return()
7-
endif()
8-
91
# Will be increased to 3.18 when C++17 is enabled:
102
cmake_minimum_required(VERSION 3.15)
113

@@ -17,11 +9,36 @@ endif()
179
# CXX is only needed for AppendOptionIfAvailable.
1810
project(CUB CUDA CXX)
1911

12+
# Determine whether CUB is the top-level project or included into
13+
# another project via add_subdirectory().
14+
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}")
15+
set(CUB_TOPLEVEL_PROJECT ON)
16+
else()
17+
set(CUB_TOPLEVEL_PROJECT OFF)
18+
endif()
19+
20+
# Thrust has its own copy of CUB install rules to handle packaging usecases
21+
# where we want to install CUB headers but aren't actually building anything.
22+
# In these cases the add_subdirectory(dependencies/cub) line in Thrust won't get
23+
# called so we can't rely on CUB providing its own rules.
24+
if (NOT CUB_IN_THRUST)
25+
option(CUB_ENABLE_INSTALL_RULES "Enable installation of CUB" ${CUB_TOPLEVEL_PROJECT})
26+
if (CUB_ENABLE_INSTALL_RULES)
27+
include(cmake/CubInstallRules.cmake)
28+
endif()
29+
endif()
30+
31+
# Support adding CUB to a parent project via add_subdirectory.
32+
# See examples/cmake/add_subdir/CMakeLists.txt for details.
33+
if (NOT CUB_TOPLEVEL_PROJECT AND NOT CUB_IN_THRUST)
34+
include(cmake/CubAddSubdir.cmake)
35+
return()
36+
endif()
37+
2038
include(cmake/AppendOptionIfAvailable.cmake)
2139
include(cmake/CubBuildCompilerTargets.cmake)
2240
include(cmake/CubBuildTargetList.cmake)
2341
include(cmake/CubCudaConfig.cmake)
24-
include(cmake/CubInstallRules.cmake)
2542

2643
option(CUB_ENABLE_HEADER_TESTING "Test that all public headers compile." ON)
2744
option(CUB_ENABLE_TESTING "Build CUB testing suite." ON)

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ The configuration options for CUB are:
290290
- `CUB_ENABLE_EXAMPLES_WITH_RDC={ON, OFF}`
291291
- Whether to enable Relocatable Device Code when building examples.
292292
Default is `OFF`.
293+
- `CUB_ENABLE_INSTALL_RULES={ON, OFF}`
294+
- If true, installation rules will be generated for CUB. Default is `ON` when
295+
building CUB alone, and `OFF` when CUB is a subproject added via CMake's
296+
`add_subdirectory`.
293297

294298
# Development Model
295299

cub/cmake/cub-config-version.cmake

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Parse version information from version.cuh:
1+
# Parse version information from version.h:
22
file(READ "${CMAKE_CURRENT_LIST_DIR}/../version.cuh" CUB_VERSION_HEADER)
33
string(REGEX MATCH "#define[ \t]+CUB_VERSION[ \t]+([0-9]+)" DUMMY "${CUB_VERSION_HEADER}")
44
set(CUB_VERSION_FLAT ${CMAKE_MATCH_1})
@@ -10,24 +10,19 @@ math(EXPR CUB_VERSION_MAJOR "${CUB_VERSION_FLAT} / 100000")
1010
math(EXPR CUB_VERSION_MINOR "(${CUB_VERSION_FLAT} / 100) % 1000")
1111
math(EXPR CUB_VERSION_PATCH "${CUB_VERSION_FLAT} % 100") # CUB: "subminor" CMake: "patch"
1212

13-
# Build comparison versions:
14-
set(CUB_COMPAT "${CUB_VERSION_MAJOR}.${CUB_VERSION_MINOR}.${CUB_VERSION_PATCH}")
15-
set(CUB_EXACT "${CUB_COMPAT}.${CUB_VERSION_TWEAK}")
16-
set(FIND_COMPAT "${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}.${PACKAGE_FIND_VERSION_PATCH}")
17-
set(FIND_EXACT "${FIND_COMPAT}.${PACKAGE_FIND_VERSION_TWEAK}")
13+
set(CUB_VERSION "${CUB_VERSION_MAJOR}.${CUB_VERSION_MINOR}.${CUB_VERSION_PATCH}.${CUB_VERSION_TWEAK}")
1814

19-
# Set default results
20-
set(PACKAGE_VERSION ${CUB_EXACT})
21-
set(PACKAGE_VERSION_UNSUITABLE FALSE)
15+
set(PACKAGE_VERSION ${CUB_VERSION})
2216
set(PACKAGE_VERSION_COMPATIBLE FALSE)
2317
set(PACKAGE_VERSION_EXACT FALSE)
18+
set(PACKAGE_VERSION_UNSUITABLE FALSE)
2419

25-
# Test for compatibility (ignores tweak)
26-
if (FIND_COMPAT VERSION_EQUAL CUB_COMPAT)
27-
set(PACKAGE_VERSION_COMPATIBLE TRUE)
28-
endif()
20+
if(PACKAGE_VERSION VERSION_GREATER_EQUAL PACKAGE_FIND_VERSION)
21+
if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CUB_VERSION_MAJOR)
22+
set(PACKAGE_VERSION_COMPATIBLE TRUE)
23+
endif()
2924

30-
# Test for exact (does not ignore tweak)
31-
if (FIND_EXACT VERSION_EQUAL CUB_EXACT)
32-
set(PACKAGE_VERSION_EXACT TRUE)
25+
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
26+
set(PACKAGE_VERSION_EXACT TRUE)
27+
endif()
3328
endif()

cub/cmake/cub-config.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,9 @@ set(CUB_VERSION_MINOR ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_MINOR} CACHE INTERNAL
6060
set(CUB_VERSION_PATCH ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_PATCH} CACHE INTERNAL "")
6161
set(CUB_VERSION_TWEAK ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_TWEAK} CACHE INTERNAL "")
6262
set(CUB_VERSION_COUNT ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_COUNT} CACHE INTERNAL "")
63+
64+
include(FindPackageHandleStandardArgs)
65+
if (NOT CUB_CONFIG)
66+
set(CUB_CONFIG "${CMAKE_CURRENT_LIST_FILE}")
67+
endif()
68+
find_package_handle_standard_args(CUB CONFIG_MODE)

0 commit comments

Comments
 (0)