-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup header tests, add C++20 header tests + examples.
The core library will always be built with C++17, but we test our headers / examples under 17 and 20.
- Loading branch information
1 parent
4b24f26
commit 38657a8
Showing
13 changed files
with
287 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.