Skip to content

Commit

Permalink
Setup header tests, add C++20 header tests + examples.
Browse files Browse the repository at this point in the history
The core library will always be built with C++17, but
we test our headers / examples under 17 and 20.
  • Loading branch information
alliepiper committed Apr 6, 2024
1 parent 4b24f26 commit 38657a8
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 123 deletions.
10 changes: 1 addition & 9 deletions .github/actions/compute-matrix/compute-matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,13 @@ write_output() {
echo "$key=$value" | tee --append "${GITHUB_OUTPUT:-/dev/null}"
}

explode_std_versions() {
jq -cr 'map(. as $o | {std: $o.std[]} + del($o.std))'
}

explode_libs() {
jq -cr 'map(. as $o | {lib: $o.lib[]} + del($o.lib))'
}

extract_matrix() {
local file="$1"
local type="$2"
local matrix=$(yq -o=json "$file" | jq -cr ".$type")
write_output "DEVCONTAINER_VERSION" "$(yq -o json "$file" | jq -cr '.devcontainer_version')"

local nvcc_full_matrix="$(echo "$matrix" | jq -cr '.nvcc' | explode_std_versions )"
local nvcc_full_matrix="$(echo "$matrix" | jq -cr '.nvcc')"
local per_cuda_compiler_matrix="$(echo "$nvcc_full_matrix" | jq -cr ' group_by(.cuda + .compiler.name) | map({(.[0].cuda + "-" + .[0].compiler.name): .}) | add')"
write_output "PER_CUDA_COMPILER_MATRIX" "$per_cuda_compiler_matrix"
write_output "PER_CUDA_COMPILER_KEYS" "$(echo "$per_cuda_compiler_matrix" | jq -r 'keys | @json')"
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/dispatch-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
include: ${{ fromJSON(inputs.per_cuda_compiler_matrix) }}
with:
cpu: ${{ matrix.cpu }}
test_name: ${{matrix.cpu}}/${{matrix.compiler.name}}${{matrix.compiler.version}}/C++${{matrix.std}} ${{matrix.extra_build_args}}
build_script: "./ci/build_${{ inputs.project_name }}.sh -cxx ${{matrix.compiler.exe}} -std ${{matrix.std}} ${{matrix.extra_build_args}}"
test_script: "./ci/test_${{ inputs.project_name }}.sh -cxx ${{matrix.compiler.exe}} -std ${{matrix.std}} ${{matrix.extra_build_args}}"
test_name: ${{matrix.cpu}}/${{matrix.compiler.name}}${{matrix.compiler.version}} ${{matrix.extra_build_args}}
build_script: "./ci/build_${{ inputs.project_name }}.sh -cxx ${{matrix.compiler.exe}} ${{matrix.extra_build_args}}"
test_script: "./ci/test_${{ inputs.project_name }}.sh -cxx ${{matrix.compiler.exe}} ${{matrix.extra_build_args}}"
container_image: rapidsai/devcontainers:${{inputs.devcontainer_version}}-cpp-${{matrix.compiler.name}}${{matrix.compiler.version}}-cuda${{matrix.cuda}}-${{matrix.os}}

build_and_test_windows:
Expand All @@ -45,7 +45,7 @@ jobs:
matrix:
include: ${{ fromJSON(inputs.per_cuda_compiler_matrix) }}
with:
test_name: ${{matrix.cpu}}/${{matrix.compiler.name}}${{matrix.compiler.version}}/C++${{matrix.std}}
build_script: "./ci/windows/build_${{ inputs.project_name }}.ps1 -std ${{matrix.std}} ${{matrix.extra_build_args}}"
test_script: "./ci/windows/test_${{ inputs.project_name }}.ps1 -std ${{matrix.std}} ${{matrix.extra_build_args}}"
test_name: ${{matrix.cpu}}/${{matrix.compiler.name}}${{matrix.compiler.version}}
build_script: "./ci/windows/build_${{ inputs.project_name }}.ps1 ${{matrix.extra_build_args}}"
test_script: "./ci/windows/test_${{ inputs.project_name }}.ps1 ${{matrix.extra_build_args}}"
container_image: rapidsai/devcontainers:${{inputs.devcontainer_version}}-cuda${{matrix.cuda}}-${{matrix.compiler.name}}${{matrix.compiler.version}}-${{matrix.os}}
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ project(NVBench

nvbench_init_rapids_cmake()

# Define NVBench_DETECTED_${LANG}_STANDARDS
include(cmake/DetectSupportedStandards.cmake)
detect_supported_standards(NVBench CXX 17 20)
detect_supported_standards(NVBench CUDA 17 20)

# See NVIDIA/NVBench#52
find_package(CUDAToolkit REQUIRED)
set(cupti_default ON)
Expand All @@ -34,6 +39,7 @@ option(NVBench_ENABLE_NVML "Build with NVML support from the Cuda Toolkit." ON)
option(NVBench_ENABLE_CUPTI "Build NVBench with CUPTI." ${cupti_default})

option(NVBench_ENABLE_TESTING "Build NVBench testing suite." OFF)
option(NVBench_ENABLE_HEADER_TESTING "Build NVBench testing suite." OFF)
option(NVBench_ENABLE_DEVICE_TESTING
"Include tests that require a GPU (with locked clocks)."
OFF
Expand All @@ -55,7 +61,10 @@ message(STATUS "NVBench CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}")

add_subdirectory(nvbench)

if (NVBench_ENABLE_EXAMPLES OR NVBench_ENABLE_TESTING)
if (NVBench_ENABLE_EXAMPLES OR
NVBench_ENABLE_TESTING OR
NVBench_ENABLE_HEADER_TESTING)
include(CTest)
enable_testing()
endif()

Expand All @@ -69,4 +78,8 @@ if (NVBench_ENABLE_TESTING)
add_subdirectory(testing)
endif()

if (NVBench_ENABLE_HEADER_TESTING)
include(cmake/NVBenchHeaderTesting.cmake)
endif()

nvbench_generate_exports()
30 changes: 14 additions & 16 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,35 @@
"NVBench_ENABLE_CUPTI": true,
"NVBench_ENABLE_DEVICE_TESTING": false,
"NVBench_ENABLE_EXAMPLES": true,
"NVBench_ENABLE_HEADER_TESTING": true,
"NVBench_ENABLE_INSTALL_RULES": true,
"NVBench_ENABLE_NVML": true,
"NVBench_ENABLE_TESTING": true,
"NVBench_ENABLE_WERROR": true
}
},
{
"name": "all-dev",
"name": "nvbench-dev",
"displayName": "Developer Build",
"inherits": "base",
"cacheVariables": {
"NVBench_ENABLE_DEVICE_TESTING": true
}
},
{
"name": "nvbench-cpp17",
"displayName": "nvbench_c++17",
"inherits": "base",
"cacheVariables": {
"CMAKE_CXX_STANDARD": "17",
"CMAKE_CUDA_STANDARD": "17"
}
"name": "nvbench-ci",
"displayName": "NVBench CI",
"inherits": "base"
}
],
"buildPresets": [
{
"name": "all-dev",
"configurePreset": "all-dev"
"name": "nvbench-dev",
"configurePreset": "nvbench-dev"
},
{
"name": "nvbench-cpp17",
"configurePreset": "nvbench-cpp17"
"name": "nvbench-ci",
"configurePreset": "nvbench-ci"
}
],
"testPresets": [
Expand All @@ -63,13 +61,13 @@
}
},
{
"name": "all-dev",
"configurePreset": "all-dev",
"name": "nvbench-dev",
"configurePreset": "nvbench-dev",
"inherits": "base"
},
{
"name": "nvbench-cpp17",
"configurePreset": "nvbench-cpp17",
"name": "nvbench-ci",
"configurePreset": "nvbench-ci",
"inherits": "base"
}
]
Expand Down
2 changes: 1 addition & 1 deletion ci/build_nvbench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source "$(dirname "$0")/build_common.sh"

print_environment_details

PRESET="nvbench-cpp$CXX_STANDARD"
PRESET="nvbench-ci"

CMAKE_OPTIONS=""

Expand Down
73 changes: 37 additions & 36 deletions ci/matrix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,40 @@ msvc2022: &msvc2022 { name: 'cl', version: '14.39', exe: 'cl++' }
# Configurations that will run for every PR
pull_request:
nvcc:
- {cuda: *cuda_prev_min, os: 'ubuntu18.04', cpu: 'amd64', compiler: *gcc7, std: [17], extra_build_args: "-cmake-options '-DNVBench_ENABLE_CUPTI=OFF'"}
- {cuda: *cuda_prev_min, os: 'ubuntu18.04', cpu: 'amd64', compiler: *gcc8, std: [17], extra_build_args: "-cmake-options '-DNVBench_ENABLE_CUPTI=OFF'"}
- {cuda: *cuda_prev_min, os: 'ubuntu18.04', cpu: 'amd64', compiler: *gcc9, std: [17], extra_build_args: "-cmake-options '-DNVBench_ENABLE_CUPTI=OFF'"}
- {cuda: *cuda_prev_min, os: 'ubuntu18.04', cpu: 'amd64', compiler: *llvm9, std: [17], extra_build_args: "-cmake-options '-DNVBench_ENABLE_CUPTI=OFF'"}
- {cuda: *cuda_prev_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *gcc11, std: [17]}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc7, std: [17]}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc8, std: [17]}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc9, std: [17]}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc10, std: [17]}
- {cuda: *cuda_curr_min, os: 'ubuntu22.04', cpu: 'amd64', compiler: *gcc11, std: [17]}
- {cuda: *cuda_curr_min, os: 'ubuntu22.04', cpu: 'amd64', compiler: *gcc12, std: [17]}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm9, std: [17]}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm10, std: [17]}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm11, std: [17]}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm12, std: [17]}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm13, std: [17]}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm14, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc7, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc8, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc9, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc10, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *gcc11, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *gcc12, std: [17]}
# Fails on CTK12.4: {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *gcc13, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm9, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm10, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm11, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm12, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm13, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm14, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *llvm15, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *llvm16, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *llvm17, std: [17]}
- {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *llvm18, std: [17], extra_build_args: "-cmake-options '-DCMAKE_CUDA_FLAGS=-allow-unsupported-compiler'"}
- {cuda: *cuda_curr_max, os: 'windows2022', cpu: 'amd64', compiler: *msvc2019, std: [17], extra_build_args: "-cmake-options '-DNVBench_ENABLE_CUPTI=OFF -DNVBench_ENABLE_NVML=OFF'"}
- {cuda: *cuda_curr_max, os: 'windows2022', cpu: 'amd64', compiler: *msvc2022, std: [17], extra_build_args: "-cmake-options '-DNVBench_ENABLE_CUPTI=OFF -DNVBench_ENABLE_NVML=OFF'"}
- {cuda: *cuda_prev_min, os: 'ubuntu18.04', cpu: 'amd64', compiler: *gcc7, extra_build_args: "-cmake-options '-DNVBench_ENABLE_CUPTI=OFF'"}
- {cuda: *cuda_prev_min, os: 'ubuntu18.04', cpu: 'amd64', compiler: *gcc8, extra_build_args: "-cmake-options '-DNVBench_ENABLE_CUPTI=OFF'"}
- {cuda: *cuda_prev_min, os: 'ubuntu18.04', cpu: 'amd64', compiler: *gcc9, extra_build_args: "-cmake-options '-DNVBench_ENABLE_CUPTI=OFF'"}
- {cuda: *cuda_prev_min, os: 'ubuntu18.04', cpu: 'amd64', compiler: *llvm9, extra_build_args: "-cmake-options '-DNVBench_ENABLE_CUPTI=OFF'"}
- {cuda: *cuda_prev_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *gcc11}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc7}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc8}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc9}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc10}
- {cuda: *cuda_curr_min, os: 'ubuntu22.04', cpu: 'amd64', compiler: *gcc11}
- {cuda: *cuda_curr_min, os: 'ubuntu22.04', cpu: 'amd64', compiler: *gcc12}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm9}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm10}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm11}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm12}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm13}
- {cuda: *cuda_curr_min, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm14}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc7}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc8}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc9}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *gcc10}
- {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *gcc11}
- {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *gcc12}
# Fails to compile simple input on CTK12.4. Try to add later.
# {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *gcc13}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm9}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm10}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm11}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm12}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm13}
- {cuda: *cuda_curr_max, os: 'ubuntu20.04', cpu: 'amd64', compiler: *llvm14}
- {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *llvm15}
- {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *llvm16}
- {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *llvm17}
- {cuda: *cuda_curr_max, os: 'ubuntu22.04', cpu: 'amd64', compiler: *llvm18, extra_build_args: "-cmake-options '-DCMAKE_CUDA_FLAGS=-allow-unsupported-compiler'"}
- {cuda: *cuda_curr_max, os: 'windows2022', cpu: 'amd64', compiler: *msvc2019, extra_build_args: "-cmake-options '-DNVBench_ENABLE_CUPTI=OFF -DNVBench_ENABLE_NVML=OFF'"}
- {cuda: *cuda_curr_max, os: 'windows2022', cpu: 'amd64', compiler: *msvc2022, extra_build_args: "-cmake-options '-DNVBench_ENABLE_CUPTI=OFF -DNVBench_ENABLE_NVML=OFF'"}
2 changes: 1 addition & 1 deletion ci/test_nvbench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ print_environment_details

./build_nvbench.sh "$@"

PRESET="nvbench-cpp$CXX_STANDARD"
PRESET="nvbench-ci"

test_preset "NVBench" ${PRESET}

Expand Down
9 changes: 2 additions & 7 deletions ci/windows/build_nvbench.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@

Param(
[Parameter(Mandatory = $true)]
[Alias("std")]
[ValidateNotNullOrEmpty()]
[ValidateSet(17)]
[int]$CXX_STANDARD = 17,
[Parameter(Mandatory = $false)]
[Alias("cmake-options")]
[ValidateNotNullOrEmpty()]
Expand All @@ -18,9 +13,9 @@ If($CURRENT_PATH -ne "ci") {
}

Remove-Module -Name build_common
Import-Module $PSScriptRoot/build_common.psm1 -ArgumentList $CXX_STANDARD
Import-Module $PSScriptRoot/build_common.psm1 -ArgumentList 17

$PRESET = "nvbench-cpp$CXX_STANDARD"
$PRESET = "nvbench-ci"
$CMAKE_OPTIONS = ""

# Append any arguments pass in on the command line
Expand Down
9 changes: 2 additions & 7 deletions ci/windows/test_nvbench.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@

Param(
[Parameter(Mandatory = $true)]
[Alias("std")]
[ValidateNotNullOrEmpty()]
[ValidateSet(17)]
[int]$CXX_STANDARD = 17,
[Parameter(Mandatory = $false)]
[Alias("cmake-options")]
[ValidateNotNullOrEmpty()]
Expand All @@ -18,9 +13,9 @@ If($CURRENT_PATH -ne "ci") {
}

Remove-Module -Name build_common
Import-Module $PSScriptRoot/build_common.psm1 -ArgumentList $CXX_STANDARD
Import-Module $PSScriptRoot/build_common.psm1 -ArgumentList 17

$PRESET = "nvbench-cpp$CXX_STANDARD"
$PRESET = "nvbench-ci"
$CMAKE_OPTIONS = ""

# Append any arguments pass in on the command line
Expand Down
62 changes: 62 additions & 0 deletions cmake/DetectSupportedStandards.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Detect the langauge standards supported by the current compilers.
#
# Usage: detect_supported_cxx_standards(<var_prefix> <lang> <standards>)
#
# - var_prefix: Used to name result variables,
# e.g. ${var_prefix}_${lang}_XX_SUPPORTED will be TRUE or FALSE. Defined for
# each XX in ${standards}.
# - lang: The language to test: C, CXX, or CUDA.
# - standards: List of any standard versions.
#
# Example: detect_supported_standards(PROJ CXX 11 14 17)
# - Sets the following variables in the parent scope to TRUE or FALSE:
# - PROJ_CXX_11_SUPPORTED
# - PROJ_CXX_14_SUPPORTED
# - PROJ_CXX_17_SUPPORTED
# - Sets `PROJ_DETECTED_CXX_STANDARDS` to a list of supported standards (e.g. "11;14;17").
function(detect_supported_standards prefix lang)
string(TOLOWER "${lang}_std" feature_prefix)
set(all_stds)
foreach(standard IN LISTS ARGN)
set(var_name "${prefix}_${lang}_${standard}_SUPPORTED")
if ("${feature_prefix}_${standard}" IN_LIST CMAKE_${lang}_COMPILE_FEATURES)
set(${var_name} TRUE)
list(APPEND all_stds ${standard})
else()
set(${var_name} FALSE)
endif()

# Special cases:
if (standard EQUAL 17 AND
(lang STREQUAL "CXX" OR lang STREQUAL "CUDA") AND
((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7) OR
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8)))
# gcc < 7 and clang < 8 don't fully support C++17.
# They accept the flag and have partial support, but nvcc will refuse
# to enable it and falls back to the default dialect for the current
# CXX compiler version. This breaks our CI.
# CMake's COMPILE_FEATURES var reports that these compilers support C++17,
# but we can't rely on it, so manually disable the dialect in these cases.
set(${var_name} FALSE)
endif()

if (standard EQUAL 20 AND
(lang STREQUAL "CXX" OR lang STREQUAL "CUDA") AND
((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10) OR
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10) OR
(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 1930)))
# Similar to the above, but for C++20.
set(${var_name} FALSE)
endif()

message(STATUS "Testing ${lang}${standard} Support: ${${var_name}}")
set(${var_name} ${${var_name}} PARENT_SCOPE)
endforeach()

set(${prefix}_DETECTED_${lang}_STANDARDS "${all_stds}" PARENT_SCOPE)
endfunction()
40 changes: 40 additions & 0 deletions cmake/NVBenchHeaderTesting.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# For every public header, build a translation unit containing `#include <header>`
# with some various checks.

set(excluded_headers_regexes
# Should never be used externally.
"^detail"
"^internal"
)

# Meta target for all configs' header builds:
add_custom_target(nvbench.headers.all)
add_dependencies(nvbench.all nvbench.headers.all)

file(GLOB_RECURSE header_files
RELATIVE "${NVBench_SOURCE_DIR}/nvbench/"
CONFIGURE_DEPENDS
"${NVBench_SOURCE_DIR}/nvbench/*.cuh"
)

foreach (exclusion IN LISTS excluded_headers_regexes)
list(FILTER header_files EXCLUDE REGEX "${exclusion}")
endforeach()

function (nvbench_add_header_target target_name cuda_std)
foreach (header IN LISTS header_files)
set(headertest_src "headers/${target_name}/${header}.cu")
set(header_str "nvbench/${header}") # Substitution used by configure_file:
configure_file("${NVBench_SOURCE_DIR}/cmake/header_test.in.cxx" "${headertest_src}")
list(APPEND headertest_srcs "${headertest_src}")
endforeach()

add_library(${target_name} OBJECT ${headertest_srcs})
target_link_libraries(${target_name} PUBLIC nvbench::nvbench)
set_target_properties(${target_name} PROPERTIES COMPILE_FEATURES cuda_std_${cuda_std})
add_dependencies(nvbench.headers.all ${target_name})
endfunction()

foreach (std IN LISTS NVBench_DETECTED_CUDA_STANDARDS)
nvbench_add_header_target(nvbench.headers.cpp${std} ${std})
endforeach()
Loading

0 comments on commit 38657a8

Please sign in to comment.