blob: 0bd7dd1fa10d2dc76ac0f145a16ff9a3aee78821 [file] [log] [blame]
Martin Hořeňovský50c95a02017-01-31 20:21:03 +01001cmake_minimum_required(VERSION 3.0)
Kostace441a92013-08-05 12:40:33 +02002
Phil Nash0bcae642017-01-09 17:32:57 +00003project(CatchSelfTest)
Kostace441a92013-08-05 12:40:33 +02004
Phil Nash8abe17a2017-01-09 16:27:06 +00005set_property(GLOBAL PROPERTY USE_FOLDERS ON)
6
Kostace441a92013-08-05 12:40:33 +02007# define some folders
Phil Nashc8fefc42017-01-06 16:19:20 +00008set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Kostace441a92013-08-05 12:40:33 +02009set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +010010set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
Phil Nashe1fbbe12017-01-06 16:59:18 +000011set(HEADER_DIR ${CATCH_DIR}/include)
12
Andy Sawyer13cbdf72014-09-04 00:32:05 +010013if(USE_CPP11)
Phil Nash30cebd62016-11-09 22:55:32 +000014 ## 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}")
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010017elseif(USE_CPP14)
18 message(STATUS "Enabling C++14")
19 set(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")
Andy Sawyer13cbdf72014-09-04 00:32:05 +010020endif()
Kostace441a92013-08-05 12:40:33 +020021
Antonio Di Monacob8443e62017-05-11 13:00:03 +020022if(USE_WMAIN)
23 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
24endif()
25
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010026#checks that the given hard-coded list contains all headers + sources in the given folder
27function(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"
31 "${FOLDER}/*.hpp"
32 "${FOLDER}/*.h")
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}")
37 endforeach()
38endfunction()
39
40function(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"
44 "${FOLDER}/*.hpp"
45 "${FOLDER}/*.h")
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}")
50 endforeach()
51endfunction()
52
Kostace441a92013-08-05 12:40:33 +020053# define the sources of the self test
Phil Nashd5360e82017-01-12 11:54:53 +000054# Please keep these ordered alphabetically
Phil Nash8abe17a2017-01-09 16:27:06 +000055set(TEST_SOURCES
Phil Nash30cebd62016-11-09 22:55:32 +000056 ${SELF_TEST_DIR}/ApproxTests.cpp
57 ${SELF_TEST_DIR}/BDDTests.cpp
58 ${SELF_TEST_DIR}/ClassTests.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000059 ${SELF_TEST_DIR}/CmdLineTests.cpp
Martin Hořeňovský7db4d8d2017-02-07 13:32:48 +010060 ${SELF_TEST_DIR}/CompilationTests.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000061 ${SELF_TEST_DIR}/ConditionTests.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000062 ${SELF_TEST_DIR}/EnumToString.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000063 ${SELF_TEST_DIR}/ExceptionTests.cpp
64 ${SELF_TEST_DIR}/GeneratorTests.cpp
65 ${SELF_TEST_DIR}/MessageTests.cpp
66 ${SELF_TEST_DIR}/MiscTests.cpp
67 ${SELF_TEST_DIR}/PartTrackerTests.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000068 ${SELF_TEST_DIR}/TagAliasTests.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000069 ${SELF_TEST_DIR}/TestMain.cpp
Martin Hořeňovský7db4d8d2017-02-07 13:32:48 +010070 ${SELF_TEST_DIR}/ToStringGeneralTests.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000071 ${SELF_TEST_DIR}/ToStringPair.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000072 ${SELF_TEST_DIR}/ToStringTuple.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000073 ${SELF_TEST_DIR}/ToStringVector.cpp
74 ${SELF_TEST_DIR}/ToStringWhich.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000075 ${SELF_TEST_DIR}/TrickyTests.cpp
76 ${SELF_TEST_DIR}/VariadicMacrosTests.cpp
Phil Nash4e6938d2017-02-21 14:19:09 +000077 ${SELF_TEST_DIR}/MatchersTests.cpp
Phil Nash8abe17a2017-01-09 16:27:06 +000078 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010079CheckFileList(TEST_SOURCES ${SELF_TEST_DIR})
Phil Nashd5360e82017-01-12 11:54:53 +000080
81# A set of impl files that just #include a single header
82# Please keep these ordered alphabetically
Phil Nash8abe17a2017-01-09 16:27:06 +000083set(IMPL_SOURCES
Phil Nash30cebd62016-11-09 22:55:32 +000084 ${SELF_TEST_DIR}/SurrogateCpps/catch_common.cpp
85 ${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp
86 ${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp
87 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_capture.cpp
88 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_config.cpp
89 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_exception.cpp
90 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_generators.cpp
91 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_registry_hub.cpp
92 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp
93 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_runner.cpp
94 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_testcase.cpp
95 ${SELF_TEST_DIR}/SurrogateCpps/catch_message.cpp
96 ${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp
97 ${SELF_TEST_DIR}/SurrogateCpps/catch_ptr.cpp
98 ${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp
99 ${SELF_TEST_DIR}/SurrogateCpps/catch_streambuf.cpp
100 ${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp
101 ${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp
Phil Nash876af872017-01-23 15:18:23 +0000102 ${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp
Phil Nash30cebd62016-11-09 22:55:32 +0000103 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100104CheckFileList(IMPL_SOURCES ${SELF_TEST_DIR}/SurrogateCpps)
Kostace441a92013-08-05 12:40:33 +0200105
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100106
Phil Nashd5360e82017-01-12 11:54:53 +0000107# Please keep these ordered alphabetically
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100108set(TOP_LEVEL_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000109 ${HEADER_DIR}/catch.hpp
110 ${HEADER_DIR}/catch_session.hpp
111 ${HEADER_DIR}/catch_with_main.hpp
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100112 )
113CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR})
Martin Hořeňovskýdab1d9d2017-01-25 23:02:25 +0100114
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100115# Please keep these ordered alphabetically
116set(EXTERNAL_HEADERS
Phil Nashd5360e82017-01-12 11:54:53 +0000117 ${HEADER_DIR}/external/clara.h
118 ${HEADER_DIR}/external/tbc_text_format.h
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100119 )
120CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external)
121
Martin Hořeňovskýdab1d9d2017-01-25 23:02:25 +0100122
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100123# Please keep these ordered alphabetically
124set(INTERNAL_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000125 ${HEADER_DIR}/internal/catch_approx.hpp
126 ${HEADER_DIR}/internal/catch_assertionresult.h
127 ${HEADER_DIR}/internal/catch_assertionresult.hpp
128 ${HEADER_DIR}/internal/catch_capture.hpp
129 ${HEADER_DIR}/internal/catch_clara.h
130 ${HEADER_DIR}/internal/catch_commandline.hpp
131 ${HEADER_DIR}/internal/catch_common.h
132 ${HEADER_DIR}/internal/catch_common.hpp
133 ${HEADER_DIR}/internal/catch_compiler_capabilities.h
134 ${HEADER_DIR}/internal/catch_config.hpp
135 ${HEADER_DIR}/internal/catch_console_colour.hpp
136 ${HEADER_DIR}/internal/catch_console_colour_impl.hpp
137 ${HEADER_DIR}/internal/catch_context.h
138 ${HEADER_DIR}/internal/catch_context_impl.hpp
139 ${HEADER_DIR}/internal/catch_debugger.h
140 ${HEADER_DIR}/internal/catch_debugger.hpp
141 ${HEADER_DIR}/internal/catch_default_main.hpp
Martin Hořeňovský613e1462017-03-06 21:51:22 +0100142 ${HEADER_DIR}/internal/catch_errno_guard.hpp
Phil Nashe1fbbe12017-01-06 16:59:18 +0000143 ${HEADER_DIR}/internal/catch_evaluate.hpp
144 ${HEADER_DIR}/internal/catch_exception_translator_registry.hpp
145 ${HEADER_DIR}/internal/catch_expression_lhs.hpp
146 ${HEADER_DIR}/internal/catch_fatal_condition.hpp
147 ${HEADER_DIR}/internal/catch_generators.hpp
148 ${HEADER_DIR}/internal/catch_generators_impl.hpp
149 ${HEADER_DIR}/internal/catch_impl.hpp
150 ${HEADER_DIR}/internal/catch_interfaces_capture.h
151 ${HEADER_DIR}/internal/catch_interfaces_config.h
152 ${HEADER_DIR}/internal/catch_interfaces_exception.h
153 ${HEADER_DIR}/internal/catch_interfaces_generators.h
154 ${HEADER_DIR}/internal/catch_interfaces_registry_hub.h
155 ${HEADER_DIR}/internal/catch_interfaces_reporter.h
156 ${HEADER_DIR}/internal/catch_interfaces_runner.h
157 ${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h
158 ${HEADER_DIR}/internal/catch_interfaces_testcase.h
159 ${HEADER_DIR}/internal/catch_legacy_reporter_adapter.h
160 ${HEADER_DIR}/internal/catch_legacy_reporter_adapter.hpp
161 ${HEADER_DIR}/internal/catch_list.hpp
162 ${HEADER_DIR}/internal/catch_matchers.hpp
Phil Nash14001272017-02-08 15:14:51 +0000163 ${HEADER_DIR}/internal/catch_matchers_string.h
Phil Nash7fed25a2017-02-08 14:17:17 +0000164 ${HEADER_DIR}/internal/catch_matchers_string.hpp
Phil Nash10dfca32017-02-21 16:05:04 +0000165 ${HEADER_DIR}/internal/catch_matchers_vector.h
Phil Nashe1fbbe12017-01-06 16:59:18 +0000166 ${HEADER_DIR}/internal/catch_message.h
167 ${HEADER_DIR}/internal/catch_message.hpp
168 ${HEADER_DIR}/internal/catch_notimplemented_exception.h
169 ${HEADER_DIR}/internal/catch_notimplemented_exception.hpp
170 ${HEADER_DIR}/internal/catch_objc.hpp
171 ${HEADER_DIR}/internal/catch_objc_arc.hpp
172 ${HEADER_DIR}/internal/catch_option.hpp
173 ${HEADER_DIR}/internal/catch_platform.h
174 ${HEADER_DIR}/internal/catch_ptr.hpp
175 ${HEADER_DIR}/internal/catch_reenable_warnings.h
176 ${HEADER_DIR}/internal/catch_registry_hub.hpp
177 ${HEADER_DIR}/internal/catch_reporter_registrars.hpp
178 ${HEADER_DIR}/internal/catch_reporter_registry.hpp
179 ${HEADER_DIR}/internal/catch_result_builder.h
180 ${HEADER_DIR}/internal/catch_result_builder.hpp
181 ${HEADER_DIR}/internal/catch_result_type.h
182 ${HEADER_DIR}/internal/catch_run_context.hpp
183 ${HEADER_DIR}/internal/catch_section.h
184 ${HEADER_DIR}/internal/catch_section.hpp
185 ${HEADER_DIR}/internal/catch_section_info.h
186 ${HEADER_DIR}/internal/catch_section_info.hpp
187 ${HEADER_DIR}/internal/catch_stream.h
188 ${HEADER_DIR}/internal/catch_stream.hpp
189 ${HEADER_DIR}/internal/catch_streambuf.h
190 ${HEADER_DIR}/internal/catch_suppress_warnings.h
191 ${HEADER_DIR}/internal/catch_tag_alias.h
192 ${HEADER_DIR}/internal/catch_tag_alias_registry.h
193 ${HEADER_DIR}/internal/catch_tag_alias_registry.hpp
194 ${HEADER_DIR}/internal/catch_test_case_info.h
195 ${HEADER_DIR}/internal/catch_test_case_info.hpp
196 ${HEADER_DIR}/internal/catch_test_case_registry_impl.hpp
197 ${HEADER_DIR}/internal/catch_test_case_tracker.hpp
198 ${HEADER_DIR}/internal/catch_test_registry.hpp
199 ${HEADER_DIR}/internal/catch_test_spec.hpp
200 ${HEADER_DIR}/internal/catch_test_spec_parser.hpp
201 ${HEADER_DIR}/internal/catch_text.h
202 ${HEADER_DIR}/internal/catch_timer.h
203 ${HEADER_DIR}/internal/catch_timer.hpp
204 ${HEADER_DIR}/internal/catch_tostring.h
205 ${HEADER_DIR}/internal/catch_tostring.hpp
206 ${HEADER_DIR}/internal/catch_totals.hpp
Martin Hořeňovský73159ac2017-02-09 12:57:01 +0100207 ${HEADER_DIR}/internal/catch_type_traits.hpp
Phil Nashe1fbbe12017-01-06 16:59:18 +0000208 ${HEADER_DIR}/internal/catch_version.h
209 ${HEADER_DIR}/internal/catch_version.hpp
210 ${HEADER_DIR}/internal/catch_wildcard_pattern.hpp
Martin Hořeňovský531d2672017-01-16 19:56:57 +0100211 ${HEADER_DIR}/internal/catch_windows_h_proxy.h
Phil Nashe1fbbe12017-01-06 16:59:18 +0000212 ${HEADER_DIR}/internal/catch_xmlwriter.hpp
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100213 )
214CheckFileList(INTERNAL_HEADERS ${HEADER_DIR}/internal)
215
216# Please keep these ordered alphabetically
217set(REPORTER_HEADERS
Justin Wilsonb753f052017-02-22 04:17:25 -0600218 ${HEADER_DIR}/reporters/catch_reporter_automake.hpp
Phil Nashe1fbbe12017-01-06 16:59:18 +0000219 ${HEADER_DIR}/reporters/catch_reporter_bases.hpp
220 ${HEADER_DIR}/reporters/catch_reporter_compact.hpp
221 ${HEADER_DIR}/reporters/catch_reporter_console.hpp
222 ${HEADER_DIR}/reporters/catch_reporter_junit.hpp
223 ${HEADER_DIR}/reporters/catch_reporter_multi.hpp
Martin Hořeňovskýb0260c62017-02-22 13:28:13 +0100224 ${HEADER_DIR}/reporters/catch_reporter_tap.hpp
Phil Nashe1fbbe12017-01-06 16:59:18 +0000225 ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
226 ${HEADER_DIR}/reporters/catch_reporter_xml.hpp
227 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100228CheckFileList(REPORTER_HEADERS ${HEADER_DIR}/reporters)
229
230# Specify the headers, too, so CLion recognises them as project files
231set(HEADERS
232 ${TOP_LEVEL_HEADERS}
233 ${EXTERNAL_HEADERS}
234 ${INTERNAL_HEADERS}
235 ${REPORTER_HEADERS}
236 )
237
Phil Nashe1fbbe12017-01-06 16:59:18 +0000238
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +0100239set(BENCH_SOURCES
240 ${BENCHMARK_DIR}/BenchMain.cpp
241 ${BENCHMARK_DIR}/StringificationBench.cpp
242 )
Martin Hořeňovskýdab1d9d2017-01-25 23:02:25 +0100243CheckFileList(BENCH_SOURCES ${BENCHMARK_DIR})
244
Phil Nashd5360e82017-01-12 11:54:53 +0000245# Provide some groupings for IDEs
Phil Nash8abe17a2017-01-09 16:27:06 +0000246SOURCE_GROUP("Tests" FILES ${TEST_SOURCES})
247SOURCE_GROUP("Surrogates" FILES ${IMPL_SOURCES})
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +0100248SOURCE_GROUP("Benchmarks" FILES ${BENCH_SOURCES})
Phil Nash8abe17a2017-01-09 16:27:06 +0000249
Kostace441a92013-08-05 12:40:33 +0200250# configure the executable
Phil Nashe1fbbe12017-01-06 16:59:18 +0000251include_directories(${HEADER_DIR})
Kostace441a92013-08-05 12:40:33 +0200252
Martin Hořeňovský9ceae8f2017-04-28 20:27:10 +0200253# Projects consuming Catch via ExternalProject_Add might want to use install step
254# without building all of our selftests.
255if (NOT NO_SELFTEST)
256 add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${HEADERS})
257 add_executable(Benchmark ${BENCH_SOURCES} ${HEADERS})
258
259 # Add desired warnings
260 if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
261 target_compile_options( SelfTest PRIVATE -Wall -Wextra )
262 target_compile_options( Benchmark PRIVATE -Wall -Wextra )
263 endif()
264 if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
265 target_compile_options( SelfTest PRIVATE /W4 /w44265 /WX )
266 target_compile_options( Benchmark PRIVATE /W4 )
267 endif()
Martin Hořeňovský7ae96c72017-01-31 17:37:27 +0100268
269
Martin Hořeňovský9ceae8f2017-04-28 20:27:10 +0200270 # configure unit tests via CTest
271 enable_testing()
272 add_test(NAME RunTests COMMAND SelfTest)
Fraser Hutchison69a3f162013-10-24 02:57:46 +0100273
Martin Hořeňovský9ceae8f2017-04-28 20:27:10 +0200274 add_test(NAME ListTests COMMAND SelfTest --list-tests)
275 set_tests_properties(ListTests PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ test cases")
Fraser Hutchison69a3f162013-10-24 02:57:46 +0100276
Martin Hořeňovský9ceae8f2017-04-28 20:27:10 +0200277 add_test(NAME ListTags COMMAND SelfTest --list-tags)
278 set_tests_properties(ListTags PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ tags")
279
280endif() # !NO_SELFTEST
281
Saad K7dd4f292017-01-31 14:22:45 -0500282
Rian Quinn79ce6932017-03-22 14:19:51 -0600283install(DIRECTORY "single_include/" DESTINATION "include/catch")