blob: 4f99aa1d30d4e5dcbef601f5730ea3daa7f7a601 [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
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010022#checks that the given hard-coded list contains all headers + sources in the given folder
23function(CheckFileList LIST_VAR FOLDER)
24 set(MESSAGE " should be added to the variable ${LIST_VAR}")
25 set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n")
26 file(GLOB GLOBBED_LIST "${FOLDER}/*.cpp"
27 "${FOLDER}/*.hpp"
28 "${FOLDER}/*.h")
29 list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}})
30 foreach(EXTRA_ITEM ${GLOBBED_LIST})
31 string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}")
32 message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}")
33 endforeach()
34endfunction()
35
36function(CheckFileListRec LIST_VAR FOLDER)
37 set(MESSAGE " should be added to the variable ${LIST_VAR}")
38 set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n")
39 file(GLOB_RECURSE GLOBBED_LIST "${FOLDER}/*.cpp"
40 "${FOLDER}/*.hpp"
41 "${FOLDER}/*.h")
42 list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}})
43 foreach(EXTRA_ITEM ${GLOBBED_LIST})
44 string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}")
45 message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}")
46 endforeach()
47endfunction()
48
Kostace441a92013-08-05 12:40:33 +020049# define the sources of the self test
Phil Nashd5360e82017-01-12 11:54:53 +000050# Please keep these ordered alphabetically
Phil Nash8abe17a2017-01-09 16:27:06 +000051set(TEST_SOURCES
Phil Nash30cebd62016-11-09 22:55:32 +000052 ${SELF_TEST_DIR}/ApproxTests.cpp
53 ${SELF_TEST_DIR}/BDDTests.cpp
54 ${SELF_TEST_DIR}/ClassTests.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000055 ${SELF_TEST_DIR}/CmdLineTests.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000056 ${SELF_TEST_DIR}/ConditionTests.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000057 ${SELF_TEST_DIR}/EnumToString.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000058 ${SELF_TEST_DIR}/ExceptionTests.cpp
59 ${SELF_TEST_DIR}/GeneratorTests.cpp
60 ${SELF_TEST_DIR}/MessageTests.cpp
61 ${SELF_TEST_DIR}/MiscTests.cpp
62 ${SELF_TEST_DIR}/PartTrackerTests.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000063 ${SELF_TEST_DIR}/TagAliasTests.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000064 ${SELF_TEST_DIR}/TestMain.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000065 ${SELF_TEST_DIR}/ToStringPair.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000066 ${SELF_TEST_DIR}/ToStringTuple.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000067 ${SELF_TEST_DIR}/ToStringVector.cpp
68 ${SELF_TEST_DIR}/ToStringWhich.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000069 ${SELF_TEST_DIR}/TrickyTests.cpp
70 ${SELF_TEST_DIR}/VariadicMacrosTests.cpp
Phil Nash8abe17a2017-01-09 16:27:06 +000071 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010072CheckFileList(TEST_SOURCES ${SELF_TEST_DIR})
Phil Nashd5360e82017-01-12 11:54:53 +000073
74# A set of impl files that just #include a single header
75# Please keep these ordered alphabetically
Phil Nash8abe17a2017-01-09 16:27:06 +000076set(IMPL_SOURCES
Phil Nash30cebd62016-11-09 22:55:32 +000077 ${SELF_TEST_DIR}/SurrogateCpps/catch_common.cpp
78 ${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp
79 ${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp
80 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_capture.cpp
81 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_config.cpp
82 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_exception.cpp
83 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_generators.cpp
84 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_registry_hub.cpp
85 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp
86 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_runner.cpp
87 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_testcase.cpp
88 ${SELF_TEST_DIR}/SurrogateCpps/catch_message.cpp
89 ${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp
90 ${SELF_TEST_DIR}/SurrogateCpps/catch_ptr.cpp
91 ${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp
92 ${SELF_TEST_DIR}/SurrogateCpps/catch_streambuf.cpp
93 ${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp
94 ${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp
Phil Nash876af872017-01-23 15:18:23 +000095 ${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000096 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010097CheckFileList(IMPL_SOURCES ${SELF_TEST_DIR}/SurrogateCpps)
Kostace441a92013-08-05 12:40:33 +020098
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010099
Phil Nashd5360e82017-01-12 11:54:53 +0000100# Please keep these ordered alphabetically
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100101set(TOP_LEVEL_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000102 ${HEADER_DIR}/catch.hpp
103 ${HEADER_DIR}/catch_session.hpp
104 ${HEADER_DIR}/catch_with_main.hpp
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100105 )
106CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR})
Martin Hořeňovskýdab1d9d2017-01-25 23:02:25 +0100107
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100108# Please keep these ordered alphabetically
109set(EXTERNAL_HEADERS
Phil Nashd5360e82017-01-12 11:54:53 +0000110 ${HEADER_DIR}/external/clara.h
111 ${HEADER_DIR}/external/tbc_text_format.h
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100112 )
113CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external)
114
Martin Hořeňovskýdab1d9d2017-01-25 23:02:25 +0100115
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100116# Please keep these ordered alphabetically
117set(INTERNAL_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000118 ${HEADER_DIR}/internal/catch_approx.hpp
119 ${HEADER_DIR}/internal/catch_assertionresult.h
120 ${HEADER_DIR}/internal/catch_assertionresult.hpp
121 ${HEADER_DIR}/internal/catch_capture.hpp
122 ${HEADER_DIR}/internal/catch_clara.h
123 ${HEADER_DIR}/internal/catch_commandline.hpp
124 ${HEADER_DIR}/internal/catch_common.h
125 ${HEADER_DIR}/internal/catch_common.hpp
126 ${HEADER_DIR}/internal/catch_compiler_capabilities.h
127 ${HEADER_DIR}/internal/catch_config.hpp
128 ${HEADER_DIR}/internal/catch_console_colour.hpp
129 ${HEADER_DIR}/internal/catch_console_colour_impl.hpp
130 ${HEADER_DIR}/internal/catch_context.h
131 ${HEADER_DIR}/internal/catch_context_impl.hpp
132 ${HEADER_DIR}/internal/catch_debugger.h
133 ${HEADER_DIR}/internal/catch_debugger.hpp
134 ${HEADER_DIR}/internal/catch_default_main.hpp
135 ${HEADER_DIR}/internal/catch_evaluate.hpp
136 ${HEADER_DIR}/internal/catch_exception_translator_registry.hpp
137 ${HEADER_DIR}/internal/catch_expression_lhs.hpp
138 ${HEADER_DIR}/internal/catch_fatal_condition.hpp
139 ${HEADER_DIR}/internal/catch_generators.hpp
140 ${HEADER_DIR}/internal/catch_generators_impl.hpp
141 ${HEADER_DIR}/internal/catch_impl.hpp
142 ${HEADER_DIR}/internal/catch_interfaces_capture.h
143 ${HEADER_DIR}/internal/catch_interfaces_config.h
144 ${HEADER_DIR}/internal/catch_interfaces_exception.h
145 ${HEADER_DIR}/internal/catch_interfaces_generators.h
146 ${HEADER_DIR}/internal/catch_interfaces_registry_hub.h
147 ${HEADER_DIR}/internal/catch_interfaces_reporter.h
148 ${HEADER_DIR}/internal/catch_interfaces_runner.h
149 ${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h
150 ${HEADER_DIR}/internal/catch_interfaces_testcase.h
151 ${HEADER_DIR}/internal/catch_legacy_reporter_adapter.h
152 ${HEADER_DIR}/internal/catch_legacy_reporter_adapter.hpp
153 ${HEADER_DIR}/internal/catch_list.hpp
154 ${HEADER_DIR}/internal/catch_matchers.hpp
155 ${HEADER_DIR}/internal/catch_message.h
156 ${HEADER_DIR}/internal/catch_message.hpp
157 ${HEADER_DIR}/internal/catch_notimplemented_exception.h
158 ${HEADER_DIR}/internal/catch_notimplemented_exception.hpp
159 ${HEADER_DIR}/internal/catch_objc.hpp
160 ${HEADER_DIR}/internal/catch_objc_arc.hpp
161 ${HEADER_DIR}/internal/catch_option.hpp
162 ${HEADER_DIR}/internal/catch_platform.h
163 ${HEADER_DIR}/internal/catch_ptr.hpp
164 ${HEADER_DIR}/internal/catch_reenable_warnings.h
165 ${HEADER_DIR}/internal/catch_registry_hub.hpp
166 ${HEADER_DIR}/internal/catch_reporter_registrars.hpp
167 ${HEADER_DIR}/internal/catch_reporter_registry.hpp
168 ${HEADER_DIR}/internal/catch_result_builder.h
169 ${HEADER_DIR}/internal/catch_result_builder.hpp
170 ${HEADER_DIR}/internal/catch_result_type.h
171 ${HEADER_DIR}/internal/catch_run_context.hpp
172 ${HEADER_DIR}/internal/catch_section.h
173 ${HEADER_DIR}/internal/catch_section.hpp
174 ${HEADER_DIR}/internal/catch_section_info.h
175 ${HEADER_DIR}/internal/catch_section_info.hpp
176 ${HEADER_DIR}/internal/catch_stream.h
177 ${HEADER_DIR}/internal/catch_stream.hpp
178 ${HEADER_DIR}/internal/catch_streambuf.h
179 ${HEADER_DIR}/internal/catch_suppress_warnings.h
180 ${HEADER_DIR}/internal/catch_tag_alias.h
181 ${HEADER_DIR}/internal/catch_tag_alias_registry.h
182 ${HEADER_DIR}/internal/catch_tag_alias_registry.hpp
183 ${HEADER_DIR}/internal/catch_test_case_info.h
184 ${HEADER_DIR}/internal/catch_test_case_info.hpp
185 ${HEADER_DIR}/internal/catch_test_case_registry_impl.hpp
186 ${HEADER_DIR}/internal/catch_test_case_tracker.hpp
187 ${HEADER_DIR}/internal/catch_test_registry.hpp
188 ${HEADER_DIR}/internal/catch_test_spec.hpp
189 ${HEADER_DIR}/internal/catch_test_spec_parser.hpp
190 ${HEADER_DIR}/internal/catch_text.h
191 ${HEADER_DIR}/internal/catch_timer.h
192 ${HEADER_DIR}/internal/catch_timer.hpp
193 ${HEADER_DIR}/internal/catch_tostring.h
194 ${HEADER_DIR}/internal/catch_tostring.hpp
195 ${HEADER_DIR}/internal/catch_totals.hpp
196 ${HEADER_DIR}/internal/catch_version.h
197 ${HEADER_DIR}/internal/catch_version.hpp
198 ${HEADER_DIR}/internal/catch_wildcard_pattern.hpp
Martin Hořeňovský531d2672017-01-16 19:56:57 +0100199 ${HEADER_DIR}/internal/catch_windows_h_proxy.h
Phil Nashe1fbbe12017-01-06 16:59:18 +0000200 ${HEADER_DIR}/internal/catch_xmlwriter.hpp
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100201 )
202CheckFileList(INTERNAL_HEADERS ${HEADER_DIR}/internal)
203
204# Please keep these ordered alphabetically
205set(REPORTER_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000206 ${HEADER_DIR}/reporters/catch_reporter_bases.hpp
207 ${HEADER_DIR}/reporters/catch_reporter_compact.hpp
208 ${HEADER_DIR}/reporters/catch_reporter_console.hpp
209 ${HEADER_DIR}/reporters/catch_reporter_junit.hpp
210 ${HEADER_DIR}/reporters/catch_reporter_multi.hpp
211 ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
212 ${HEADER_DIR}/reporters/catch_reporter_xml.hpp
213 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100214CheckFileList(REPORTER_HEADERS ${HEADER_DIR}/reporters)
215
216# Specify the headers, too, so CLion recognises them as project files
217set(HEADERS
218 ${TOP_LEVEL_HEADERS}
219 ${EXTERNAL_HEADERS}
220 ${INTERNAL_HEADERS}
221 ${REPORTER_HEADERS}
222 )
223
Phil Nashe1fbbe12017-01-06 16:59:18 +0000224
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +0100225set(BENCH_SOURCES
226 ${BENCHMARK_DIR}/BenchMain.cpp
227 ${BENCHMARK_DIR}/StringificationBench.cpp
228 )
Martin Hořeňovskýdab1d9d2017-01-25 23:02:25 +0100229CheckFileList(BENCH_SOURCES ${BENCHMARK_DIR})
230
Phil Nashd5360e82017-01-12 11:54:53 +0000231# Provide some groupings for IDEs
Phil Nash8abe17a2017-01-09 16:27:06 +0000232SOURCE_GROUP("Tests" FILES ${TEST_SOURCES})
233SOURCE_GROUP("Surrogates" FILES ${IMPL_SOURCES})
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +0100234SOURCE_GROUP("Benchmarks" FILES ${BENCH_SOURCES})
Phil Nash8abe17a2017-01-09 16:27:06 +0000235
Kostace441a92013-08-05 12:40:33 +0200236# configure the executable
Phil Nashe1fbbe12017-01-06 16:59:18 +0000237include_directories(${HEADER_DIR})
Phil Nash8abe17a2017-01-09 16:27:06 +0000238add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${HEADERS})
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +0100239add_executable(Benchmark ${BENCH_SOURCES} ${HEADERS})
Kostace441a92013-08-05 12:40:33 +0200240
Martin Hořeňovský7ae96c72017-01-31 17:37:27 +0100241# Add desired warnings
242if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
243 target_compile_options( SelfTest PRIVATE -Wall -Wextra )
244 target_compile_options( Benchmark PRIVATE -Wall -Wextra )
245endif()
246if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
247 target_compile_options( SelfTest PRIVATE /W4 )
248 target_compile_options( Benchmark PRIVATE /W4 )
249endif()
250
251
Fraser Hutchison69a3f162013-10-24 02:57:46 +0100252# configure unit tests via CTest
Kostace441a92013-08-05 12:40:33 +0200253enable_testing()
Fraser Hutchison69a3f162013-10-24 02:57:46 +0100254add_test(NAME RunTests COMMAND SelfTest)
255
256add_test(NAME ListTests COMMAND SelfTest --list-tests)
257set_tests_properties(ListTests PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ test cases")
258
259add_test(NAME ListTags COMMAND SelfTest --list-tags)
260set_tests_properties(ListTags PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ tags")