Skip to content

Commit 2ecf767

Browse files
committed
c++23 check in case of older compiler
1 parent 3f185a5 commit 2ecf767

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

tests/CMakeLists.txt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ include(compiler_warnings.cmake)
22
find_package(Catch2 3 REQUIRED)
33
include(CTest)
44
include(Catch)
5+
include(CheckSourceCompiles)
56

67
set(cxx_17_files
78
${CMAKE_CURRENT_SOURCE_DIR}/add_noexcept.cpp
@@ -35,6 +36,20 @@ set(cxx_23_files
3536
${CMAKE_CURRENT_SOURCE_DIR}/traced_error.cpp
3637
)
3738

39+
block(SCOPE_FOR VARIABLES)
40+
if(MSVC)
41+
set(CMAKE_REQUIRED_FLAGS /Zc:__cplusplus /std:c++latest)
42+
else()
43+
set(CMAKE_REQUIRED_FLAGS -std=c++23)
44+
endif()
45+
check_source_compiles(CXX "
46+
int main(void){
47+
static_assert(__cplusplus >= 202302L);
48+
}
49+
"
50+
HAS_CXX_23)
51+
endblock()
52+
3853
function(setup_target target)
3954
target_link_libraries(${target} PRIVATE UT::all)
4055
set_target_warnings(${target})
@@ -59,7 +74,11 @@ target_compile_features(libut_tests_23 PUBLIC cxx_std_23)
5974

6075
setup_target(libut_tests_17)
6176
setup_target(libut_tests_20)
62-
setup_target(libut_tests_23)
63-
if(NOT MSVC)
64-
target_link_libraries(libut_tests_23 PUBLIC stdc++exp)
77+
if(HAS_CXX_23)
78+
setup_target(libut_tests_23)
79+
if(NOT MSVC)
80+
target_link_libraries(libut_tests_23 PUBLIC stdc++exp)
81+
endif()
82+
else()
83+
message(WARNING "${CMAKE_CXX_COMPILER} does not support C++23, tests will not run")
6584
endif()

0 commit comments

Comments
 (0)