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

Commit

Permalink
Update CUB CMake to match recent changes to Thrust.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alliepiper committed Oct 19, 2020
1 parent 52d58a8 commit ea48955
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 25 deletions.
35 changes: 26 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# Support adding CUB to a parent project via add_subdirectory.
# See examples/cmake/add_subdir/CMakeLists.txt for details.
if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}" AND
NOT CUB_IN_THRUST)
include(cmake/CubAddSubdir.cmake)
return()
endif()

# Will be increased to 3.18 when C++17 is enabled:
cmake_minimum_required(VERSION 3.15)

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

# Determine whether CUB is the top-level project or included into
# another project via add_subdirectory().
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_LIST_DIR}")
set(CUB_TOPLEVEL_PROJECT ON)
else()
set(CUB_TOPLEVEL_PROJECT OFF)
endif()

# Thrust has its own copy of CUB install rules to handle packaging usecases
# where we want to install CUB headers but aren't actually building anything.
# In these cases the add_subdirectory(dependencies/cub) line in Thrust won't get
# called so we can't rely on CUB providing its own rules.
if (NOT CUB_IN_THRUST)
option(CUB_ENABLE_INSTALL_RULES "Enable installation of CUB" ${CUB_TOPLEVEL_PROJECT})
if (CUB_ENABLE_INSTALL_RULES)
include(cmake/CubInstallRules.cmake)
endif()
endif()

# Support adding CUB to a parent project via add_subdirectory.
# See examples/cmake/add_subdir/CMakeLists.txt for details.
if (NOT CUB_TOPLEVEL_PROJECT AND NOT CUB_IN_THRUST)
include(cmake/CubAddSubdir.cmake)
return()
endif()

include(cmake/AppendOptionIfAvailable.cmake)
include(cmake/CubBuildCompilerTargets.cmake)
include(cmake/CubBuildTargetList.cmake)
include(cmake/CubCudaConfig.cmake)
include(cmake/CubInstallRules.cmake)

option(CUB_ENABLE_HEADER_TESTING "Test that all public headers compile." ON)
option(CUB_ENABLE_TESTING "Build CUB testing suite." ON)
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ The configuration options for CUB are:
- `CUB_ENABLE_EXAMPLES_WITH_RDC={ON, OFF}`
- Whether to enable Relocatable Device Code when building examples.
Default is `OFF`.
- `CUB_ENABLE_INSTALL_RULES={ON, OFF}`
- If true, installation rules will be generated for CUB. Default is `ON` when
building CUB alone, and `OFF` when CUB is a subproject added via CMake's
`add_subdirectory`.

# Development Model

Expand Down
27 changes: 11 additions & 16 deletions cub/cmake/cub-config-version.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Parse version information from version.cuh:
# Parse version information from version.h:
file(READ "${CMAKE_CURRENT_LIST_DIR}/../version.cuh" CUB_VERSION_HEADER)
string(REGEX MATCH "#define[ \t]+CUB_VERSION[ \t]+([0-9]+)" DUMMY "${CUB_VERSION_HEADER}")
set(CUB_VERSION_FLAT ${CMAKE_MATCH_1})
Expand All @@ -10,24 +10,19 @@ math(EXPR CUB_VERSION_MAJOR "${CUB_VERSION_FLAT} / 100000")
math(EXPR CUB_VERSION_MINOR "(${CUB_VERSION_FLAT} / 100) % 1000")
math(EXPR CUB_VERSION_PATCH "${CUB_VERSION_FLAT} % 100") # CUB: "subminor" CMake: "patch"

# Build comparison versions:
set(CUB_COMPAT "${CUB_VERSION_MAJOR}.${CUB_VERSION_MINOR}.${CUB_VERSION_PATCH}")
set(CUB_EXACT "${CUB_COMPAT}.${CUB_VERSION_TWEAK}")
set(FIND_COMPAT "${PACKAGE_FIND_VERSION_MAJOR}.${PACKAGE_FIND_VERSION_MINOR}.${PACKAGE_FIND_VERSION_PATCH}")
set(FIND_EXACT "${FIND_COMPAT}.${PACKAGE_FIND_VERSION_TWEAK}")
set(CUB_VERSION "${CUB_VERSION_MAJOR}.${CUB_VERSION_MINOR}.${CUB_VERSION_PATCH}.${CUB_VERSION_TWEAK}")

# Set default results
set(PACKAGE_VERSION ${CUB_EXACT})
set(PACKAGE_VERSION_UNSUITABLE FALSE)
set(PACKAGE_VERSION ${CUB_VERSION})
set(PACKAGE_VERSION_COMPATIBLE FALSE)
set(PACKAGE_VERSION_EXACT FALSE)
set(PACKAGE_VERSION_UNSUITABLE FALSE)

# Test for compatibility (ignores tweak)
if (FIND_COMPAT VERSION_EQUAL CUB_COMPAT)
set(PACKAGE_VERSION_COMPATIBLE TRUE)
endif()
if(PACKAGE_VERSION VERSION_GREATER_EQUAL PACKAGE_FIND_VERSION)
if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CUB_VERSION_MAJOR)
set(PACKAGE_VERSION_COMPATIBLE TRUE)
endif()

# Test for exact (does not ignore tweak)
if (FIND_EXACT VERSION_EQUAL CUB_EXACT)
set(PACKAGE_VERSION_EXACT TRUE)
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
6 changes: 6 additions & 0 deletions cub/cmake/cub-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ set(CUB_VERSION_MINOR ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_MINOR} CACHE INTERNAL
set(CUB_VERSION_PATCH ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_PATCH} CACHE INTERNAL "")
set(CUB_VERSION_TWEAK ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_TWEAK} CACHE INTERNAL "")
set(CUB_VERSION_COUNT ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_COUNT} CACHE INTERNAL "")

include(FindPackageHandleStandardArgs)
if (NOT CUB_CONFIG)
set(CUB_CONFIG "${CMAKE_CURRENT_LIST_FILE}")
endif()
find_package_handle_standard_args(CUB CONFIG_MODE)

0 comments on commit ea48955

Please sign in to comment.