11# SPDX-License-Identifier: MIT
22
3- # For Iris-specific tests.
3+ # -----------------------------------------------------------------
4+ # Setup the basic targets
5+
6+ # For internal common settings
7+ add_library (_iris_cxx_test_common INTERFACE )
8+ set_target_properties (_iris_cxx_test_common PROPERTIES CXX_EXTENSIONS OFF )
9+ target_link_libraries (_iris_cxx_test_common INTERFACE _iris_cxx_common )
10+
11+
12+ # For Iris-specific tests
413add_library (iris_cxx_test INTERFACE )
514set_target_properties (iris_cxx_test PROPERTIES CXX_EXTENSIONS OFF )
6- target_link_libraries (iris_cxx_test INTERFACE _iris_cxx_common )
15+ target_link_libraries (iris_cxx_test INTERFACE _iris_cxx_test_common )
716
817# For external libraries. Excludes strict warning, etc.
918add_library (iris_cxx_test_external INTERFACE )
1019set_target_properties (iris_cxx_test_external PROPERTIES CXX_EXTENSIONS OFF )
11- target_link_libraries (iris_cxx_test_external INTERFACE _iris_cxx_common )
20+ target_link_libraries (iris_cxx_test_external INTERFACE _iris_cxx_test_common )
1221
1322if (MSVC )
23+ target_compile_options (
24+ _iris_cxx_test_common
25+ INTERFACE
26+ /wd5072 # ASan intentionally enabled on Release build
27+ /fsanitize=address
28+ )
29+ target_link_options (
30+ _iris_cxx_test_common
31+ INTERFACE
32+ /ignore:4302 # ASan intentionally enabled on Release build
33+ /INCREMENTAL:NO # required for ASan
34+ )
35+
1436 target_compile_options (
1537 iris_cxx_test
1638 INTERFACE /W4 /analyze /analyze:external-
1739 )
40+
1841 target_compile_options (
1942 iris_cxx_test_external
2043 INTERFACE /analyze-
2144 )
2245
2346else () # non-MSVC
47+ target_compile_options (
48+ _iris_cxx_test_common
49+ INTERFACE
50+ -fsanitize=undefined,address
51+ )
52+ target_link_options (
53+ _iris_cxx_test_common
54+ INTERFACE
55+ -fsanitize=undefined,address
56+ )
57+
2458 target_compile_options (
2559 iris_cxx_test
2660 INTERFACE
2761 -Wall -Wextra -pedantic
2862 )
2963endif ()
3064
31- # --------------------------------------------
65+
66+ # -----------------------------------------------------------------
67+ # Catch2
3268
3369# https://github.com/catchorg/Catch2/blob/devel/docs/configuration.md
3470set (CATCH_CONFIG_FAST_COMPILE ON )
@@ -44,28 +80,32 @@ FetchContent_Declare(
4480FetchContent_MakeAvailable (Catch2)
4581
4682set_target_properties (Catch2 PROPERTIES CXX_EXTENSIONS OFF )
83+ set_target_properties (Catch2 Catch2WithMain PROPERTIES FOLDER "_deps" )
84+
4785target_compile_definitions (Catch2 PUBLIC DO_NOT_USE_WMAIN )
4886target_link_libraries (Catch2 PRIVATE iris_cxx_test_external )
4987target_link_libraries (Catch2WithMain PRIVATE iris_cxx_test_external )
5088
5189target_link_libraries (iris_cxx_test INTERFACE Catch2::Catch2WithMain )
5290
53- # --------------------------------------------
91+
92+ # -----------------------------------------------------------------
93+ # Common CMake utilities for testing
5494
5595function (iris_define_test_headers test_name )
5696 target_sources (${test_name} _test PRIVATE FILE_SET HEADERS FILES ${ARGN} )
5797endfunction ()
5898
5999function (iris_define_test test_name )
60100 add_executable (${test_name} _test ${ARGN} )
101+ target_include_directories (${test_name} _test PRIVATE ${CMAKE_CURRENT_FUNCTION_LIST_DIR} )
61102 target_include_directories (${test_name} _test PRIVATE ${CMAKE_CURRENT_LIST_DIR} )
62- iris_define_test_headers (${test_name} test .hpp )
63103 set_target_properties (${test_name} _test PROPERTIES CXX_EXTENSIONS OFF )
64104
65105 if (MSVC )
66106 # Prevent "Warning: Conflicting <Type> entries detected" error
67107 set_source_files_properties (
68- "${PROJECT_SOURCE_DIR } /iris.natvis"
108+ "${IRIS_ROOT } /iris.natvis"
69109 TARGET_DIRECTORY ${test_name} _test
70110 PROPERTIES VS_SETTINGS "ExcludedFromBuild=true"
71111 )
@@ -83,12 +123,30 @@ function(iris_define_tests)
83123 endforeach ()
84124endfunction ()
85125
86- # --------------------------------------------
126+ function (iris_define_sub_tests prefix )
127+ foreach (test_name IN LISTS ARGN)
128+ iris_define_test (${prefix} _${test_name} ${test_name} .cpp )
129+ set_target_properties (${prefix} _${test_name}_test PROPERTIES FOLDER "test/${prefix} " )
130+ endforeach ()
131+ endfunction ()
132+
133+
134+ # -----------------------------------------------------------------
135+ # Iris tests
87136
88137if (PROJECT_IS_TOP_LEVEL)
89138 add_subdirectory (rvariant )
90139
91- iris_define_tests (
140+ set (
141+ IRIS_TEST_IRIS_TESTS
92142 type_traits
143+ core
144+ indirect
93145 )
146+
147+ iris_define_sub_tests (iris ${IRIS_TEST_IRIS_TESTS} )
148+
149+ foreach (test_name IN LISTS IRIS_TEST_IRIS_TESTS)
150+ iris_define_test_headers (iris_${test_name} iris_test.hpp )
151+ endforeach ()
94152endif ()
0 commit comments