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

Commit

Permalink
Add cub-config.cmake file for CMake's find_package.
Browse files Browse the repository at this point in the history
  • Loading branch information
alliepiper committed May 12, 2020
1 parent 3bfe495 commit d106ddb
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cub/cmake/cub-config-version.cmake
@@ -0,0 +1,33 @@
# Parse version information from version.cuh:
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})
# Note that CUB calls this the PATCH number, CMake calls it the TWEAK number:
string(REGEX MATCH "#define[ \t]+CUB_PATCH_NUMBER[ \t]+([0-9]+)" DUMMY "${CUB_VERSION_HEADER}")
set(CUB_VERSION_TWEAK ${CMAKE_MATCH_1})

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 default results
set(PACKAGE_VERSION ${CUB_EXACT})
set(PACKAGE_VERSION_UNSUITABLE FALSE)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
set(PACKAGE_VERSION_EXACT FALSE)

# Test for compatibility (ignores tweak)
if (FIND_COMPAT VERSION_EQUAL CUB_COMPAT)
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)
endif()
55 changes: 55 additions & 0 deletions cub/cmake/cub-config.cmake
@@ -0,0 +1,55 @@
#
# find_package(CUB) config file.
#
# Defines a CUB::CUB target that may be linked from user projects to include
# CUB.

function(_cub_declare_interface_alias alias_name ugly_name)
# 1) Only IMPORTED and ALIAS targets can be placed in a namespace.
# 2) When an IMPORTED library is linked to another target, its include
# directories are treated as SYSTEM includes.
# 3) nvcc will automatically check the CUDA Toolkit include path *before* the
# system includes. This means that the Toolkit CUB will *always* be used
# during compilation, and the include paths of an IMPORTED CUB::CUB
# target will never have any effect.
# 4) This behavior can be fixed by setting the property NO_SYSTEM_FROM_IMPORTED
# on EVERY target that links to CUB::CUB. This would be a burden and a
# footgun for our users. Forgetting this would silently pull in the wrong CUB!
# 5) A workaround is to make a non-IMPORTED library outside of the namespace,
# configure it, and then ALIAS it into the namespace (or ALIAS and then
# configure, that seems to work too).
add_library(${ugly_name} INTERFACE)
add_library(${alias_name} ALIAS ${ugly_name})
endfunction()

#
# Setup targets
#

_cub_declare_interface_alias(CUB::CUB _CUB_CUB)
# Strip out the 'cub/cmake/' from 'cub/cmake/cub-config.cmake':
get_filename_component(_CUB_INCLUDE_DIR "../.." ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")
target_include_directories(_CUB_CUB INTERFACE "${_CUB_INCLUDE_DIR}")

if (CUB_IGNORE_DEPRECATED_CPP_DIALECT)
target_compile_definitions(_CUB_CUB INTERFACE "CUB_IGNORE_DEPRECATED_CPP_DIALECT")
endif()

if (CUB_IGNORE_DEPRECATED_CPP_11)
target_compile_definitions(_CUB_CUB INTERFACE "CUB_IGNORE_DEPRECATED_CPP_11")
endif()

if (CUB_IGNORE_DEPRECATED_COMPILER)
target_compile_definitions(_CUB_CUB INTERFACE "CUB_IGNORE_DEPRECATED_COMPILER")
endif()

#
# Standardize version info
#

set(CUB_VERSION ${${CMAKE_FIND_PACKAGE_NAME}_VERSION} CACHE INTERNAL "")
set(CUB_VERSION_MAJOR ${${CMAKE_FIND_PACKAGE_NAME}_VERSION_MAJOR} CACHE INTERNAL "")
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 "")

0 comments on commit d106ddb

Please sign in to comment.