33# -----------------------------------------------------------------
44# Setup the basic targets
55
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 )
106
7+ # For internal common settings
118
129# For Iris-specific tests
1310add_library (iris_cxx_test INTERFACE )
1411set_target_properties (iris_cxx_test PROPERTIES CXX_EXTENSIONS OFF )
15- target_link_libraries (iris_cxx_test INTERFACE _iris_cxx_test_common )
12+ target_link_libraries (iris_cxx_test INTERFACE iris_cxx_abi )
1613
1714# For external libraries. Excludes strict warning, etc.
1815add_library (iris_cxx_test_external INTERFACE )
1916set_target_properties (iris_cxx_test_external PROPERTIES CXX_EXTENSIONS OFF )
20- target_link_libraries (iris_cxx_test_external INTERFACE _iris_cxx_test_common )
17+ target_link_libraries (iris_cxx_test_external INTERFACE iris_cxx_abi )
2118
2219if (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-
36- target_compile_options (
37- iris_cxx_test
38- INTERFACE /W4 /analyze /analyze:external-
39- )
40-
4120 target_compile_options (
4221 iris_cxx_test_external
4322 INTERFACE /analyze-
4423 )
24+ endif ()
4525
46- else () # 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-
58- target_compile_options (
59- iris_cxx_test
60- INTERFACE
61- -Wall -Wextra -pedantic
62- )
26+ #
27+ # TODO: separate sanitizer and non-sanitizer versions
28+ #
29+ option (IRIS_TEST_USE_SANITIZER "Enable ASan/UBSan" ON )
30+ if (${IRIS_TEST_USE_SANITIZER} )
31+ target_link_libraries (iris_cxx_test INTERFACE iris_cxx_sanitizer )
32+ target_link_libraries (iris_cxx_test_external INTERFACE iris_cxx_sanitizer )
6333endif ()
6434
6535
@@ -84,11 +54,33 @@ set_target_properties(Catch2 PROPERTIES CXX_EXTENSIONS OFF)
8454set_target_properties (Catch2 Catch2WithMain PROPERTIES FOLDER "_deps" )
8555
8656target_compile_definitions (Catch2 PUBLIC DO_NOT_USE_WMAIN )
57+
58+ if (MSVC )
59+ target_compile_options (Catch2 PRIVATE /wd6054 )
60+ endif ()
61+
8762target_link_libraries (Catch2 PRIVATE iris_cxx_test_external )
8863target_link_libraries (Catch2WithMain PRIVATE iris_cxx_test_external )
8964
9065target_link_libraries (iris_cxx_test INTERFACE Catch2::Catch2 )
9166
67+
68+ # -----------------------------------------------------------------
69+ # Iris internal test targets
70+
71+ add_library (_iris_internal_test INTERFACE )
72+ target_include_directories (_iris_internal_test INTERFACE ${CMAKE_CURRENT_LIST_DIR} )
73+
74+ if (MSVC )
75+ target_sources (_iris_internal_test INTERFACE "${CMAKE_CURRENT_LIST_DIR} /cpp.hint" )
76+ endif ()
77+
78+ function (iris_define_internal_test test_name )
79+ iris_define_test (${test_name} ${ARGN} )
80+ target_link_libraries (${test_name} _test PRIVATE _iris_internal_test )
81+ endfunction ()
82+
83+
9284# -----------------------------------------------------------------
9385# Common CMake utilities for testing
9486
@@ -102,9 +94,8 @@ function(_iris_define_test_impl test_name libs)
10294 message (FATAL_ERROR "IRIS_ROOT is not defined" )
10395 endif ()
10496
105- add_executable (${test_name} _test ${ARGN} )
106- target_include_directories (${test_name} _test PRIVATE ${CMAKE_CURRENT_FUNCTION_LIST_DIR} )
10797 target_include_directories (${test_name} _test PRIVATE ${CMAKE_CURRENT_LIST_DIR} )
98+ target_link_libraries (${test_name} _test PRIVATE Iris::Iris iris_cxx_test ${libs} )
10899 set_target_properties (${test_name} _test PROPERTIES CXX_EXTENSIONS OFF )
109100
110101 if (MSVC )
@@ -114,12 +105,8 @@ function(_iris_define_test_impl test_name libs)
114105 TARGET_DIRECTORY ${test_name} _test
115106 PROPERTIES VS_SETTINGS "ExcludedFromBuild=true"
116107 )
117-
118- target_sources (${test_name} _test PRIVATE "${CMAKE_CURRENT_FUNCTION_LIST_DIR} /cpp.hint" )
119108 endif ()
120109
121- target_link_libraries (${test_name} _test PRIVATE Iris::Iris iris_cxx_test ${libs} )
122- add_test (NAME ${test_name} _test COMMAND ${test_name} _test --colour-mode=ansi )
123110
124111 set_tests_properties (
125112 ${test_name} _test PROPERTIES
@@ -151,25 +138,28 @@ function(_iris_define_test_impl test_name libs)
151138 endif ()
152139endfunction ()
153140
154- function (iris_define_test test_name )
155- _iris_define_test_impl (${test_name} Catch2::Catch2WithMain ${ARGN} )
141+ function (_iris_define_executable_test test_name libs )
142+ add_executable (${test_name} _test ${ARGN} )
143+ add_test (NAME ${test_name} _test COMMAND ${test_name} _test --colour-mode=ansi )
144+ _iris_define_test_impl (${test_name} ${libs} )
156145endfunction ()
157146
158- function (iris_define_test_no_main test_name )
159- _iris_define_test_impl (${test_name} "" ${ARGN} )
147+
148+ # -----------------------------------------------------------------
149+ # Public test adder functions
150+
151+ function (iris_define_test test_name )
152+ _iris_define_executable_test (${test_name} Catch2::Catch2WithMain ${ARGN} )
160153endfunction ()
161154
162- function (iris_define_tests )
163- foreach (test_name IN LISTS ARGV)
164- iris_define_test (${test_name} ${test_name} .cpp )
165- endforeach ()
155+ function (iris_define_test_no_main test_name )
156+ _iris_define_executable_test (${test_name} Catch2::Catch2 ${ARGN} )
166157endfunction ()
167158
168- function (iris_define_sub_tests prefix )
169- foreach (test_name IN LISTS ARGN)
170- iris_define_test (${prefix} _${test_name} ${test_name} .cpp )
171- set_target_properties (${prefix} _${test_name}_test PROPERTIES FOLDER "test/${prefix} " )
172- endforeach ()
159+ function (iris_define_library_test library_type test_name srcs )
160+ add_library (${test_name} _test ${library_type} ${srcs} )
161+ add_test (NAME ${test_name} _test COMMAND ${ARGN} )
162+ _iris_define_test_impl (${test_name} Catch2::Catch2 )
173163endfunction ()
174164
175165
@@ -190,10 +180,10 @@ if(PROJECT_IS_TOP_LEVEL)
190180 preprocess
191181 )
192182
193- iris_define_sub_tests (iris ${IRIS_TEST_IRIS_TESTS} )
194-
195183 foreach (test_name IN LISTS IRIS_TEST_IRIS_TESTS)
184+ iris_define_internal_test (iris_${test_name} ${test_name} .cpp )
196185 iris_define_test_headers (iris_${test_name} iris_test.hpp )
186+ set_target_properties (iris_${test_name}_test PROPERTIES FOLDER "test/iris" )
197187 endforeach ()
198188
199189 add_subdirectory (unicode )
0 commit comments