1 cmake_minimum_required(VERSION 3.0)
5 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
8 set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
9 set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
10 set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
11 set(HEADER_DIR ${CATCH_DIR}/include)
14 ## We can't turn this on by default, since it breaks on travis
15 message(STATUS "Enabling C++11")
16 set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
18 message(STATUS "Enabling C++14")
19 set(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")
23 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
26 #checks that the given hard-coded list contains all headers + sources in the given folder
27 function(CheckFileList LIST_VAR FOLDER)
28 set(MESSAGE " should be added to the variable ${LIST_VAR}")
29 set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n")
30 file(GLOB GLOBBED_LIST "${FOLDER}/*.cpp"
33 list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}})
34 foreach(EXTRA_ITEM ${GLOBBED_LIST})
35 string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}")
36 message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}")
40 function(CheckFileListRec LIST_VAR FOLDER)
41 set(MESSAGE " should be added to the variable ${LIST_VAR}")
42 set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n")
43 file(GLOB_RECURSE GLOBBED_LIST "${FOLDER}/*.cpp"
46 list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}})
47 foreach(EXTRA_ITEM ${GLOBBED_LIST})
48 string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}")
49 message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}")
53 # define the sources of the self test
54 # Please keep these ordered alphabetically
56 ${SELF_TEST_DIR}/ApproxTests.cpp
57 ${SELF_TEST_DIR}/BDDTests.cpp
58 ${SELF_TEST_DIR}/ClassTests.cpp
59 ${SELF_TEST_DIR}/CmdLineTests.cpp
60 ${SELF_TEST_DIR}/CompilationTests.cpp
61 ${SELF_TEST_DIR}/ConditionTests.cpp
62 ${SELF_TEST_DIR}/DecompositionTests.cpp
63 ${SELF_TEST_DIR}/EnumToString.cpp
64 ${SELF_TEST_DIR}/ExceptionTests.cpp
65 ${SELF_TEST_DIR}/GeneratorTests.cpp
66 ${SELF_TEST_DIR}/MessageTests.cpp
67 ${SELF_TEST_DIR}/MiscTests.cpp
68 ${SELF_TEST_DIR}/PartTrackerTests.cpp
69 ${SELF_TEST_DIR}/TagAliasTests.cpp
70 ${SELF_TEST_DIR}/TestMain.cpp
71 ${SELF_TEST_DIR}/ToStringGeneralTests.cpp
72 ${SELF_TEST_DIR}/ToStringPair.cpp
73 ${SELF_TEST_DIR}/ToStringTuple.cpp
74 ${SELF_TEST_DIR}/ToStringVector.cpp
75 ${SELF_TEST_DIR}/ToStringWhich.cpp
76 ${SELF_TEST_DIR}/TrickyTests.cpp
77 ${SELF_TEST_DIR}/VariadicMacrosTests.cpp
78 ${SELF_TEST_DIR}/MatchersTests.cpp
80 CheckFileList(TEST_SOURCES ${SELF_TEST_DIR})
82 # A set of impl files that just #include a single header
83 # Please keep these ordered alphabetically
85 ${SELF_TEST_DIR}/SurrogateCpps/catch_common.cpp
86 ${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp
87 ${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp
88 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_capture.cpp
89 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_config.cpp
90 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_exception.cpp
91 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_generators.cpp
92 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_registry_hub.cpp
93 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp
94 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_runner.cpp
95 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_testcase.cpp
96 ${SELF_TEST_DIR}/SurrogateCpps/catch_message.cpp
97 ${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp
98 ${SELF_TEST_DIR}/SurrogateCpps/catch_ptr.cpp
99 ${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp
100 ${SELF_TEST_DIR}/SurrogateCpps/catch_streambuf.cpp
101 ${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp
102 ${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp
103 ${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp
105 CheckFileList(IMPL_SOURCES ${SELF_TEST_DIR}/SurrogateCpps)
108 # Please keep these ordered alphabetically
109 set(TOP_LEVEL_HEADERS
110 ${HEADER_DIR}/catch.hpp
111 ${HEADER_DIR}/catch_session.hpp
112 ${HEADER_DIR}/catch_with_main.hpp
114 CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR})
116 # Please keep these ordered alphabetically
118 ${HEADER_DIR}/external/clara.h
119 ${HEADER_DIR}/external/tbc_text_format.h
121 CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external)
124 # Please keep these ordered alphabetically
126 ${HEADER_DIR}/internal/catch_approx.hpp
127 ${HEADER_DIR}/internal/catch_assertionresult.h
128 ${HEADER_DIR}/internal/catch_assertionresult.hpp
129 ${HEADER_DIR}/internal/catch_capture.hpp
130 ${HEADER_DIR}/internal/catch_clara.h
131 ${HEADER_DIR}/internal/catch_commandline.hpp
132 ${HEADER_DIR}/internal/catch_common.h
133 ${HEADER_DIR}/internal/catch_common.hpp
134 ${HEADER_DIR}/internal/catch_compiler_capabilities.h
135 ${HEADER_DIR}/internal/catch_config.hpp
136 ${HEADER_DIR}/internal/catch_console_colour.hpp
137 ${HEADER_DIR}/internal/catch_console_colour_impl.hpp
138 ${HEADER_DIR}/internal/catch_context.h
139 ${HEADER_DIR}/internal/catch_context_impl.hpp
140 ${HEADER_DIR}/internal/catch_debugger.h
141 ${HEADER_DIR}/internal/catch_debugger.hpp
142 ${HEADER_DIR}/internal/catch_default_main.hpp
143 ${HEADER_DIR}/internal/catch_errno_guard.hpp
144 ${HEADER_DIR}/internal/catch_evaluate.hpp
145 ${HEADER_DIR}/internal/catch_exception_translator_registry.hpp
146 ${HEADER_DIR}/internal/catch_expression_lhs.hpp
147 ${HEADER_DIR}/internal/catch_fatal_condition.hpp
148 ${HEADER_DIR}/internal/catch_generators.hpp
149 ${HEADER_DIR}/internal/catch_generators_impl.hpp
150 ${HEADER_DIR}/internal/catch_impl.hpp
151 ${HEADER_DIR}/internal/catch_interfaces_capture.h
152 ${HEADER_DIR}/internal/catch_interfaces_config.h
153 ${HEADER_DIR}/internal/catch_interfaces_exception.h
154 ${HEADER_DIR}/internal/catch_interfaces_generators.h
155 ${HEADER_DIR}/internal/catch_interfaces_registry_hub.h
156 ${HEADER_DIR}/internal/catch_interfaces_reporter.h
157 ${HEADER_DIR}/internal/catch_interfaces_runner.h
158 ${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h
159 ${HEADER_DIR}/internal/catch_interfaces_testcase.h
160 ${HEADER_DIR}/internal/catch_legacy_reporter_adapter.h
161 ${HEADER_DIR}/internal/catch_legacy_reporter_adapter.hpp
162 ${HEADER_DIR}/internal/catch_list.hpp
163 ${HEADER_DIR}/internal/catch_matchers.hpp
164 ${HEADER_DIR}/internal/catch_matchers_string.h
165 ${HEADER_DIR}/internal/catch_matchers_string.hpp
166 ${HEADER_DIR}/internal/catch_matchers_vector.h
167 ${HEADER_DIR}/internal/catch_message.h
168 ${HEADER_DIR}/internal/catch_message.hpp
169 ${HEADER_DIR}/internal/catch_notimplemented_exception.h
170 ${HEADER_DIR}/internal/catch_notimplemented_exception.hpp
171 ${HEADER_DIR}/internal/catch_objc.hpp
172 ${HEADER_DIR}/internal/catch_objc_arc.hpp
173 ${HEADER_DIR}/internal/catch_option.hpp
174 ${HEADER_DIR}/internal/catch_platform.h
175 ${HEADER_DIR}/internal/catch_ptr.hpp
176 ${HEADER_DIR}/internal/catch_reenable_warnings.h
177 ${HEADER_DIR}/internal/catch_registry_hub.hpp
178 ${HEADER_DIR}/internal/catch_reporter_registrars.hpp
179 ${HEADER_DIR}/internal/catch_reporter_registry.hpp
180 ${HEADER_DIR}/internal/catch_result_builder.h
181 ${HEADER_DIR}/internal/catch_result_builder.hpp
182 ${HEADER_DIR}/internal/catch_result_type.h
183 ${HEADER_DIR}/internal/catch_run_context.hpp
184 ${HEADER_DIR}/internal/catch_section.h
185 ${HEADER_DIR}/internal/catch_section.hpp
186 ${HEADER_DIR}/internal/catch_section_info.h
187 ${HEADER_DIR}/internal/catch_section_info.hpp
188 ${HEADER_DIR}/internal/catch_stream.h
189 ${HEADER_DIR}/internal/catch_stream.hpp
190 ${HEADER_DIR}/internal/catch_streambuf.h
191 ${HEADER_DIR}/internal/catch_suppress_warnings.h
192 ${HEADER_DIR}/internal/catch_tag_alias.h
193 ${HEADER_DIR}/internal/catch_tag_alias_registry.h
194 ${HEADER_DIR}/internal/catch_tag_alias_registry.hpp
195 ${HEADER_DIR}/internal/catch_test_case_info.h
196 ${HEADER_DIR}/internal/catch_test_case_info.hpp
197 ${HEADER_DIR}/internal/catch_test_case_registry_impl.hpp
198 ${HEADER_DIR}/internal/catch_test_case_tracker.hpp
199 ${HEADER_DIR}/internal/catch_test_registry.hpp
200 ${HEADER_DIR}/internal/catch_test_spec.hpp
201 ${HEADER_DIR}/internal/catch_test_spec_parser.hpp
202 ${HEADER_DIR}/internal/catch_text.h
203 ${HEADER_DIR}/internal/catch_timer.h
204 ${HEADER_DIR}/internal/catch_timer.hpp
205 ${HEADER_DIR}/internal/catch_tostring.h
206 ${HEADER_DIR}/internal/catch_tostring.hpp
207 ${HEADER_DIR}/internal/catch_totals.hpp
208 ${HEADER_DIR}/internal/catch_type_traits.hpp
209 ${HEADER_DIR}/internal/catch_version.h
210 ${HEADER_DIR}/internal/catch_version.hpp
211 ${HEADER_DIR}/internal/catch_wildcard_pattern.hpp
212 ${HEADER_DIR}/internal/catch_windows_h_proxy.h
213 ${HEADER_DIR}/internal/catch_xmlwriter.hpp
215 CheckFileList(INTERNAL_HEADERS ${HEADER_DIR}/internal)
217 # Please keep these ordered alphabetically
219 ${HEADER_DIR}/reporters/catch_reporter_automake.hpp
220 ${HEADER_DIR}/reporters/catch_reporter_bases.hpp
221 ${HEADER_DIR}/reporters/catch_reporter_compact.hpp
222 ${HEADER_DIR}/reporters/catch_reporter_console.hpp
223 ${HEADER_DIR}/reporters/catch_reporter_junit.hpp
224 ${HEADER_DIR}/reporters/catch_reporter_multi.hpp
225 ${HEADER_DIR}/reporters/catch_reporter_tap.hpp
226 ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
227 ${HEADER_DIR}/reporters/catch_reporter_xml.hpp
229 CheckFileList(REPORTER_HEADERS ${HEADER_DIR}/reporters)
231 # Specify the headers, too, so CLion recognises them as project files
241 ${BENCHMARK_DIR}/BenchMain.cpp
242 ${BENCHMARK_DIR}/StringificationBench.cpp
244 CheckFileList(BENCH_SOURCES ${BENCHMARK_DIR})
246 # Provide some groupings for IDEs
247 SOURCE_GROUP("Tests" FILES ${TEST_SOURCES})
248 SOURCE_GROUP("Surrogates" FILES ${IMPL_SOURCES})
249 SOURCE_GROUP("Benchmarks" FILES ${BENCH_SOURCES})
251 # configure the executable
252 include_directories(${HEADER_DIR})
254 # Projects consuming Catch via ExternalProject_Add might want to use install step
255 # without building all of our selftests.
257 add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${HEADERS})
258 add_executable(Benchmark ${BENCH_SOURCES} ${HEADERS})
260 # Add desired warnings
261 if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
262 target_compile_options( SelfTest PRIVATE -Wall -Wextra )
263 target_compile_options( Benchmark PRIVATE -Wall -Wextra )
265 if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
266 target_compile_options( SelfTest PRIVATE /W4 /w44265 /WX )
267 target_compile_options( Benchmark PRIVATE /W4 )
271 # configure unit tests via CTest
273 add_test(NAME RunTests COMMAND SelfTest)
275 add_test(NAME ListTests COMMAND SelfTest --list-tests)
276 set_tests_properties(ListTests PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ test cases")
278 add_test(NAME ListTags COMMAND SelfTest --list-tags)
279 set_tests_properties(ListTags PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ tags")
281 endif() # !NO_SELFTEST
284 install(DIRECTORY "single_include/" DESTINATION "include/catch")