diff --git a/CMakeLists.txt b/CMakeLists.txt index 410efba90f..7d71285cbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 353217e8fa..4faaa9e7b6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/cub/cmake/cub-config-version.cmake b/cub/cmake/cub-config-version.cmake index 4260ba66f5..1debbb4dd2 100644 --- a/cub/cmake/cub-config-version.cmake +++ b/cub/cmake/cub-config-version.cmake @@ -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}) @@ -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() diff --git a/cub/cmake/cub-config.cmake b/cub/cmake/cub-config.cmake index 0900becd8f..44b139f47d 100644 --- a/cub/cmake/cub-config.cmake +++ b/cub/cmake/cub-config.cmake @@ -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)