blob: 95bdf68e69db93a2d236bb823aca47955293403d [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
Martin Hořeňovský7db4d8d2017-02-07 13:32:48 +010056 ${SELF_TEST_DIR}/CompilationTests.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000057 ${SELF_TEST_DIR}/ConditionTests.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000058 ${SELF_TEST_DIR}/EnumToString.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000059 ${SELF_TEST_DIR}/ExceptionTests.cpp
60 ${SELF_TEST_DIR}/GeneratorTests.cpp
61 ${SELF_TEST_DIR}/MessageTests.cpp
62 ${SELF_TEST_DIR}/MiscTests.cpp
63 ${SELF_TEST_DIR}/PartTrackerTests.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000064 ${SELF_TEST_DIR}/TagAliasTests.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000065 ${SELF_TEST_DIR}/TestMain.cpp
Martin Hořeňovský7db4d8d2017-02-07 13:32:48 +010066 ${SELF_TEST_DIR}/ToStringGeneralTests.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000067 ${SELF_TEST_DIR}/ToStringPair.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000068 ${SELF_TEST_DIR}/ToStringTuple.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000069 ${SELF_TEST_DIR}/ToStringVector.cpp
70 ${SELF_TEST_DIR}/ToStringWhich.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000071 ${SELF_TEST_DIR}/TrickyTests.cpp
72 ${SELF_TEST_DIR}/VariadicMacrosTests.cpp
Phil Nash4e6938d2017-02-21 14:19:09 +000073 ${SELF_TEST_DIR}/MatchersTests.cpp
Phil Nash8abe17a2017-01-09 16:27:06 +000074 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010075CheckFileList(TEST_SOURCES ${SELF_TEST_DIR})
Phil Nashd5360e82017-01-12 11:54:53 +000076
77# A set of impl files that just #include a single header
78# Please keep these ordered alphabetically
Phil Nash8abe17a2017-01-09 16:27:06 +000079set(IMPL_SOURCES
Phil Nash30cebd62016-11-09 22:55:32 +000080 ${SELF_TEST_DIR}/SurrogateCpps/catch_common.cpp
81 ${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp
82 ${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp
83 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_capture.cpp
84 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_config.cpp
85 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_exception.cpp
86 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_generators.cpp
87 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_registry_hub.cpp
88 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp
89 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_runner.cpp
90 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_testcase.cpp
91 ${SELF_TEST_DIR}/SurrogateCpps/catch_message.cpp
92 ${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp
93 ${SELF_TEST_DIR}/SurrogateCpps/catch_ptr.cpp
94 ${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp
95 ${SELF_TEST_DIR}/SurrogateCpps/catch_streambuf.cpp
96 ${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp
97 ${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp
Phil Nash876af872017-01-23 15:18:23 +000098 ${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000099 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100100CheckFileList(IMPL_SOURCES ${SELF_TEST_DIR}/SurrogateCpps)
Kostace441a92013-08-05 12:40:33 +0200101
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100102
Phil Nashd5360e82017-01-12 11:54:53 +0000103# Please keep these ordered alphabetically
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100104set(TOP_LEVEL_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000105 ${HEADER_DIR}/catch.hpp
106 ${HEADER_DIR}/catch_session.hpp
107 ${HEADER_DIR}/catch_with_main.hpp
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100108 )
109CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR})
Martin Hořeňovskýdab1d9d2017-01-25 23:02:25 +0100110
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100111# Please keep these ordered alphabetically
112set(EXTERNAL_HEADERS
Phil Nashd5360e82017-01-12 11:54:53 +0000113 ${HEADER_DIR}/external/clara.h
114 ${HEADER_DIR}/external/tbc_text_format.h
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100115 )
116CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external)
117
Martin Hořeňovskýdab1d9d2017-01-25 23:02:25 +0100118
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100119# Please keep these ordered alphabetically
120set(INTERNAL_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000121 ${HEADER_DIR}/internal/catch_approx.hpp
122 ${HEADER_DIR}/internal/catch_assertionresult.h
123 ${HEADER_DIR}/internal/catch_assertionresult.hpp
124 ${HEADER_DIR}/internal/catch_capture.hpp
125 ${HEADER_DIR}/internal/catch_clara.h
126 ${HEADER_DIR}/internal/catch_commandline.hpp
127 ${HEADER_DIR}/internal/catch_common.h
128 ${HEADER_DIR}/internal/catch_common.hpp
129 ${HEADER_DIR}/internal/catch_compiler_capabilities.h
130 ${HEADER_DIR}/internal/catch_config.hpp
131 ${HEADER_DIR}/internal/catch_console_colour.hpp
132 ${HEADER_DIR}/internal/catch_console_colour_impl.hpp
133 ${HEADER_DIR}/internal/catch_context.h
134 ${HEADER_DIR}/internal/catch_context_impl.hpp
135 ${HEADER_DIR}/internal/catch_debugger.h
136 ${HEADER_DIR}/internal/catch_debugger.hpp
137 ${HEADER_DIR}/internal/catch_default_main.hpp
Martin Hořeňovský613e1462017-03-06 21:51:22 +0100138 ${HEADER_DIR}/internal/catch_errno_guard.hpp
Phil Nashe1fbbe12017-01-06 16:59:18 +0000139 ${HEADER_DIR}/internal/catch_evaluate.hpp
140 ${HEADER_DIR}/internal/catch_exception_translator_registry.hpp
141 ${HEADER_DIR}/internal/catch_expression_lhs.hpp
142 ${HEADER_DIR}/internal/catch_fatal_condition.hpp
143 ${HEADER_DIR}/internal/catch_generators.hpp
144 ${HEADER_DIR}/internal/catch_generators_impl.hpp
145 ${HEADER_DIR}/internal/catch_impl.hpp
146 ${HEADER_DIR}/internal/catch_interfaces_capture.h
147 ${HEADER_DIR}/internal/catch_interfaces_config.h
148 ${HEADER_DIR}/internal/catch_interfaces_exception.h
149 ${HEADER_DIR}/internal/catch_interfaces_generators.h
150 ${HEADER_DIR}/internal/catch_interfaces_registry_hub.h
151 ${HEADER_DIR}/internal/catch_interfaces_reporter.h
152 ${HEADER_DIR}/internal/catch_interfaces_runner.h
153 ${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h
154 ${HEADER_DIR}/internal/catch_interfaces_testcase.h
155 ${HEADER_DIR}/internal/catch_legacy_reporter_adapter.h
156 ${HEADER_DIR}/internal/catch_legacy_reporter_adapter.hpp
157 ${HEADER_DIR}/internal/catch_list.hpp
158 ${HEADER_DIR}/internal/catch_matchers.hpp
Phil Nash14001272017-02-08 15:14:51 +0000159 ${HEADER_DIR}/internal/catch_matchers_string.h
Phil Nash7fed25a2017-02-08 14:17:17 +0000160 ${HEADER_DIR}/internal/catch_matchers_string.hpp
Phil Nash10dfca32017-02-21 16:05:04 +0000161 ${HEADER_DIR}/internal/catch_matchers_vector.h
Phil Nashe1fbbe12017-01-06 16:59:18 +0000162 ${HEADER_DIR}/internal/catch_message.h
163 ${HEADER_DIR}/internal/catch_message.hpp
164 ${HEADER_DIR}/internal/catch_notimplemented_exception.h
165 ${HEADER_DIR}/internal/catch_notimplemented_exception.hpp
166 ${HEADER_DIR}/internal/catch_objc.hpp
167 ${HEADER_DIR}/internal/catch_objc_arc.hpp
168 ${HEADER_DIR}/internal/catch_option.hpp
169 ${HEADER_DIR}/internal/catch_platform.h
170 ${HEADER_DIR}/internal/catch_ptr.hpp
171 ${HEADER_DIR}/internal/catch_reenable_warnings.h
172 ${HEADER_DIR}/internal/catch_registry_hub.hpp
173 ${HEADER_DIR}/internal/catch_reporter_registrars.hpp
174 ${HEADER_DIR}/internal/catch_reporter_registry.hpp
175 ${HEADER_DIR}/internal/catch_result_builder.h
176 ${HEADER_DIR}/internal/catch_result_builder.hpp
177 ${HEADER_DIR}/internal/catch_result_type.h
178 ${HEADER_DIR}/internal/catch_run_context.hpp
179 ${HEADER_DIR}/internal/catch_section.h
180 ${HEADER_DIR}/internal/catch_section.hpp
181 ${HEADER_DIR}/internal/catch_section_info.h
182 ${HEADER_DIR}/internal/catch_section_info.hpp
183 ${HEADER_DIR}/internal/catch_stream.h
184 ${HEADER_DIR}/internal/catch_stream.hpp
185 ${HEADER_DIR}/internal/catch_streambuf.h
186 ${HEADER_DIR}/internal/catch_suppress_warnings.h
187 ${HEADER_DIR}/internal/catch_tag_alias.h
188 ${HEADER_DIR}/internal/catch_tag_alias_registry.h
189 ${HEADER_DIR}/internal/catch_tag_alias_registry.hpp
190 ${HEADER_DIR}/internal/catch_test_case_info.h
191 ${HEADER_DIR}/internal/catch_test_case_info.hpp
192 ${HEADER_DIR}/internal/catch_test_case_registry_impl.hpp
193 ${HEADER_DIR}/internal/catch_test_case_tracker.hpp
194 ${HEADER_DIR}/internal/catch_test_registry.hpp
195 ${HEADER_DIR}/internal/catch_test_spec.hpp
196 ${HEADER_DIR}/internal/catch_test_spec_parser.hpp
197 ${HEADER_DIR}/internal/catch_text.h
198 ${HEADER_DIR}/internal/catch_timer.h
199 ${HEADER_DIR}/internal/catch_timer.hpp
200 ${HEADER_DIR}/internal/catch_tostring.h
201 ${HEADER_DIR}/internal/catch_tostring.hpp
202 ${HEADER_DIR}/internal/catch_totals.hpp
Martin Hořeňovský73159ac2017-02-09 12:57:01 +0100203 ${HEADER_DIR}/internal/catch_type_traits.hpp
Phil Nashe1fbbe12017-01-06 16:59:18 +0000204 ${HEADER_DIR}/internal/catch_version.h
205 ${HEADER_DIR}/internal/catch_version.hpp
206 ${HEADER_DIR}/internal/catch_wildcard_pattern.hpp
Martin Hořeňovský531d2672017-01-16 19:56:57 +0100207 ${HEADER_DIR}/internal/catch_windows_h_proxy.h
Phil Nashe1fbbe12017-01-06 16:59:18 +0000208 ${HEADER_DIR}/internal/catch_xmlwriter.hpp
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100209 )
210CheckFileList(INTERNAL_HEADERS ${HEADER_DIR}/internal)
211
212# Please keep these ordered alphabetically
213set(REPORTER_HEADERS
Justin Wilsonb753f052017-02-22 04:17:25 -0600214 ${HEADER_DIR}/reporters/catch_reporter_automake.hpp
Phil Nashe1fbbe12017-01-06 16:59:18 +0000215 ${HEADER_DIR}/reporters/catch_reporter_bases.hpp
216 ${HEADER_DIR}/reporters/catch_reporter_compact.hpp
217 ${HEADER_DIR}/reporters/catch_reporter_console.hpp
218 ${HEADER_DIR}/reporters/catch_reporter_junit.hpp
219 ${HEADER_DIR}/reporters/catch_reporter_multi.hpp
Martin Hořeňovskýb0260c62017-02-22 13:28:13 +0100220 ${HEADER_DIR}/reporters/catch_reporter_tap.hpp
Phil Nashe1fbbe12017-01-06 16:59:18 +0000221 ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
222 ${HEADER_DIR}/reporters/catch_reporter_xml.hpp
223 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100224CheckFileList(REPORTER_HEADERS ${HEADER_DIR}/reporters)
225
226# Specify the headers, too, so CLion recognises them as project files
227set(HEADERS
228 ${TOP_LEVEL_HEADERS}
229 ${EXTERNAL_HEADERS}
230 ${INTERNAL_HEADERS}
231 ${REPORTER_HEADERS}
232 )
233
Phil Nashe1fbbe12017-01-06 16:59:18 +0000234
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +0100235set(BENCH_SOURCES
236 ${BENCHMARK_DIR}/BenchMain.cpp
237 ${BENCHMARK_DIR}/StringificationBench.cpp
238 )
Martin Hořeňovskýdab1d9d2017-01-25 23:02:25 +0100239CheckFileList(BENCH_SOURCES ${BENCHMARK_DIR})
240
Phil Nashd5360e82017-01-12 11:54:53 +0000241# Provide some groupings for IDEs
Phil Nash8abe17a2017-01-09 16:27:06 +0000242SOURCE_GROUP("Tests" FILES ${TEST_SOURCES})
243SOURCE_GROUP("Surrogates" FILES ${IMPL_SOURCES})
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +0100244SOURCE_GROUP("Benchmarks" FILES ${BENCH_SOURCES})
Phil Nash8abe17a2017-01-09 16:27:06 +0000245
Kostace441a92013-08-05 12:40:33 +0200246# configure the executable
Phil Nashe1fbbe12017-01-06 16:59:18 +0000247include_directories(${HEADER_DIR})
Phil Nash8abe17a2017-01-09 16:27:06 +0000248add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${HEADERS})
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +0100249add_executable(Benchmark ${BENCH_SOURCES} ${HEADERS})
Kostace441a92013-08-05 12:40:33 +0200250
Martin Hořeňovský7ae96c72017-01-31 17:37:27 +0100251# Add desired warnings
252if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
253 target_compile_options( SelfTest PRIVATE -Wall -Wextra )
254 target_compile_options( Benchmark PRIVATE -Wall -Wextra )
255endif()
256if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
Martin Hořeňovský932a4052017-03-06 11:29:57 +0100257 target_compile_options( SelfTest PRIVATE /W4 /w44265 /WX )
Martin Hořeňovský7ae96c72017-01-31 17:37:27 +0100258 target_compile_options( Benchmark PRIVATE /W4 )
259endif()
260
261
Fraser Hutchison69a3f162013-10-24 02:57:46 +0100262# configure unit tests via CTest
Kostace441a92013-08-05 12:40:33 +0200263enable_testing()
Fraser Hutchison69a3f162013-10-24 02:57:46 +0100264add_test(NAME RunTests COMMAND SelfTest)
265
266add_test(NAME ListTests COMMAND SelfTest --list-tests)
267set_tests_properties(ListTests PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ test cases")
268
269add_test(NAME ListTags COMMAND SelfTest --list-tags)
270set_tests_properties(ListTags PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ tags")
Saad K7dd4f292017-01-31 14:22:45 -0500271
Rian Quinn79ce6932017-03-22 14:19:51 -0600272install(DIRECTORY "single_include/" DESTINATION "include/catch")