blob: e9a00c2d86e8094c4822cde623604d4b7fe4ea0d [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 Nash8abe17a2017-01-09 16:27:06 +000073 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010074CheckFileList(TEST_SOURCES ${SELF_TEST_DIR})
Phil Nashd5360e82017-01-12 11:54:53 +000075
76# A set of impl files that just #include a single header
77# Please keep these ordered alphabetically
Phil Nash8abe17a2017-01-09 16:27:06 +000078set(IMPL_SOURCES
Phil Nash30cebd62016-11-09 22:55:32 +000079 ${SELF_TEST_DIR}/SurrogateCpps/catch_common.cpp
80 ${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp
81 ${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp
82 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_capture.cpp
83 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_config.cpp
84 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_exception.cpp
85 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_generators.cpp
86 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_registry_hub.cpp
87 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp
88 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_runner.cpp
89 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_testcase.cpp
90 ${SELF_TEST_DIR}/SurrogateCpps/catch_message.cpp
91 ${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp
92 ${SELF_TEST_DIR}/SurrogateCpps/catch_ptr.cpp
93 ${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp
94 ${SELF_TEST_DIR}/SurrogateCpps/catch_streambuf.cpp
95 ${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp
96 ${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp
Phil Nash876af872017-01-23 15:18:23 +000097 ${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000098 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010099CheckFileList(IMPL_SOURCES ${SELF_TEST_DIR}/SurrogateCpps)
Kostace441a92013-08-05 12:40:33 +0200100
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100101
Phil Nashd5360e82017-01-12 11:54:53 +0000102# Please keep these ordered alphabetically
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100103set(TOP_LEVEL_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000104 ${HEADER_DIR}/catch.hpp
105 ${HEADER_DIR}/catch_session.hpp
106 ${HEADER_DIR}/catch_with_main.hpp
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100107 )
108CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR})
Martin Hořeňovskýdab1d9d2017-01-25 23:02:25 +0100109
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100110# Please keep these ordered alphabetically
111set(EXTERNAL_HEADERS
Phil Nashd5360e82017-01-12 11:54:53 +0000112 ${HEADER_DIR}/external/clara.h
113 ${HEADER_DIR}/external/tbc_text_format.h
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100114 )
115CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external)
116
Martin Hořeňovskýdab1d9d2017-01-25 23:02:25 +0100117
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100118# Please keep these ordered alphabetically
119set(INTERNAL_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000120 ${HEADER_DIR}/internal/catch_approx.hpp
121 ${HEADER_DIR}/internal/catch_assertionresult.h
122 ${HEADER_DIR}/internal/catch_assertionresult.hpp
123 ${HEADER_DIR}/internal/catch_capture.hpp
124 ${HEADER_DIR}/internal/catch_clara.h
125 ${HEADER_DIR}/internal/catch_commandline.hpp
126 ${HEADER_DIR}/internal/catch_common.h
127 ${HEADER_DIR}/internal/catch_common.hpp
128 ${HEADER_DIR}/internal/catch_compiler_capabilities.h
129 ${HEADER_DIR}/internal/catch_config.hpp
130 ${HEADER_DIR}/internal/catch_console_colour.hpp
131 ${HEADER_DIR}/internal/catch_console_colour_impl.hpp
132 ${HEADER_DIR}/internal/catch_context.h
133 ${HEADER_DIR}/internal/catch_context_impl.hpp
134 ${HEADER_DIR}/internal/catch_debugger.h
135 ${HEADER_DIR}/internal/catch_debugger.hpp
136 ${HEADER_DIR}/internal/catch_default_main.hpp
137 ${HEADER_DIR}/internal/catch_evaluate.hpp
138 ${HEADER_DIR}/internal/catch_exception_translator_registry.hpp
139 ${HEADER_DIR}/internal/catch_expression_lhs.hpp
140 ${HEADER_DIR}/internal/catch_fatal_condition.hpp
141 ${HEADER_DIR}/internal/catch_generators.hpp
142 ${HEADER_DIR}/internal/catch_generators_impl.hpp
143 ${HEADER_DIR}/internal/catch_impl.hpp
144 ${HEADER_DIR}/internal/catch_interfaces_capture.h
145 ${HEADER_DIR}/internal/catch_interfaces_config.h
146 ${HEADER_DIR}/internal/catch_interfaces_exception.h
147 ${HEADER_DIR}/internal/catch_interfaces_generators.h
148 ${HEADER_DIR}/internal/catch_interfaces_registry_hub.h
149 ${HEADER_DIR}/internal/catch_interfaces_reporter.h
150 ${HEADER_DIR}/internal/catch_interfaces_runner.h
151 ${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h
152 ${HEADER_DIR}/internal/catch_interfaces_testcase.h
153 ${HEADER_DIR}/internal/catch_legacy_reporter_adapter.h
154 ${HEADER_DIR}/internal/catch_legacy_reporter_adapter.hpp
155 ${HEADER_DIR}/internal/catch_list.hpp
156 ${HEADER_DIR}/internal/catch_matchers.hpp
157 ${HEADER_DIR}/internal/catch_message.h
158 ${HEADER_DIR}/internal/catch_message.hpp
159 ${HEADER_DIR}/internal/catch_notimplemented_exception.h
160 ${HEADER_DIR}/internal/catch_notimplemented_exception.hpp
161 ${HEADER_DIR}/internal/catch_objc.hpp
162 ${HEADER_DIR}/internal/catch_objc_arc.hpp
163 ${HEADER_DIR}/internal/catch_option.hpp
164 ${HEADER_DIR}/internal/catch_platform.h
165 ${HEADER_DIR}/internal/catch_ptr.hpp
166 ${HEADER_DIR}/internal/catch_reenable_warnings.h
167 ${HEADER_DIR}/internal/catch_registry_hub.hpp
168 ${HEADER_DIR}/internal/catch_reporter_registrars.hpp
169 ${HEADER_DIR}/internal/catch_reporter_registry.hpp
170 ${HEADER_DIR}/internal/catch_result_builder.h
171 ${HEADER_DIR}/internal/catch_result_builder.hpp
172 ${HEADER_DIR}/internal/catch_result_type.h
173 ${HEADER_DIR}/internal/catch_run_context.hpp
174 ${HEADER_DIR}/internal/catch_section.h
175 ${HEADER_DIR}/internal/catch_section.hpp
176 ${HEADER_DIR}/internal/catch_section_info.h
177 ${HEADER_DIR}/internal/catch_section_info.hpp
178 ${HEADER_DIR}/internal/catch_stream.h
179 ${HEADER_DIR}/internal/catch_stream.hpp
180 ${HEADER_DIR}/internal/catch_streambuf.h
181 ${HEADER_DIR}/internal/catch_suppress_warnings.h
182 ${HEADER_DIR}/internal/catch_tag_alias.h
183 ${HEADER_DIR}/internal/catch_tag_alias_registry.h
184 ${HEADER_DIR}/internal/catch_tag_alias_registry.hpp
185 ${HEADER_DIR}/internal/catch_test_case_info.h
186 ${HEADER_DIR}/internal/catch_test_case_info.hpp
187 ${HEADER_DIR}/internal/catch_test_case_registry_impl.hpp
188 ${HEADER_DIR}/internal/catch_test_case_tracker.hpp
189 ${HEADER_DIR}/internal/catch_test_registry.hpp
190 ${HEADER_DIR}/internal/catch_test_spec.hpp
191 ${HEADER_DIR}/internal/catch_test_spec_parser.hpp
192 ${HEADER_DIR}/internal/catch_text.h
193 ${HEADER_DIR}/internal/catch_timer.h
194 ${HEADER_DIR}/internal/catch_timer.hpp
195 ${HEADER_DIR}/internal/catch_tostring.h
196 ${HEADER_DIR}/internal/catch_tostring.hpp
197 ${HEADER_DIR}/internal/catch_totals.hpp
Martin Hořeňovský73159ac2017-02-09 12:57:01 +0100198 ${HEADER_DIR}/internal/catch_type_traits.hpp
Phil Nashe1fbbe12017-01-06 16:59:18 +0000199 ${HEADER_DIR}/internal/catch_version.h
200 ${HEADER_DIR}/internal/catch_version.hpp
201 ${HEADER_DIR}/internal/catch_wildcard_pattern.hpp
Martin Hořeňovský531d2672017-01-16 19:56:57 +0100202 ${HEADER_DIR}/internal/catch_windows_h_proxy.h
Phil Nashe1fbbe12017-01-06 16:59:18 +0000203 ${HEADER_DIR}/internal/catch_xmlwriter.hpp
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100204 )
205CheckFileList(INTERNAL_HEADERS ${HEADER_DIR}/internal)
206
207# Please keep these ordered alphabetically
208set(REPORTER_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000209 ${HEADER_DIR}/reporters/catch_reporter_bases.hpp
210 ${HEADER_DIR}/reporters/catch_reporter_compact.hpp
211 ${HEADER_DIR}/reporters/catch_reporter_console.hpp
212 ${HEADER_DIR}/reporters/catch_reporter_junit.hpp
213 ${HEADER_DIR}/reporters/catch_reporter_multi.hpp
214 ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
215 ${HEADER_DIR}/reporters/catch_reporter_xml.hpp
216 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100217CheckFileList(REPORTER_HEADERS ${HEADER_DIR}/reporters)
218
219# Specify the headers, too, so CLion recognises them as project files
220set(HEADERS
221 ${TOP_LEVEL_HEADERS}
222 ${EXTERNAL_HEADERS}
223 ${INTERNAL_HEADERS}
224 ${REPORTER_HEADERS}
225 )
226
Phil Nashe1fbbe12017-01-06 16:59:18 +0000227
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +0100228set(BENCH_SOURCES
229 ${BENCHMARK_DIR}/BenchMain.cpp
230 ${BENCHMARK_DIR}/StringificationBench.cpp
231 )
Martin Hořeňovskýdab1d9d2017-01-25 23:02:25 +0100232CheckFileList(BENCH_SOURCES ${BENCHMARK_DIR})
233
Phil Nashd5360e82017-01-12 11:54:53 +0000234# Provide some groupings for IDEs
Phil Nash8abe17a2017-01-09 16:27:06 +0000235SOURCE_GROUP("Tests" FILES ${TEST_SOURCES})
236SOURCE_GROUP("Surrogates" FILES ${IMPL_SOURCES})
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +0100237SOURCE_GROUP("Benchmarks" FILES ${BENCH_SOURCES})
Phil Nash8abe17a2017-01-09 16:27:06 +0000238
Kostace441a92013-08-05 12:40:33 +0200239# configure the executable
Phil Nashe1fbbe12017-01-06 16:59:18 +0000240include_directories(${HEADER_DIR})
Phil Nash8abe17a2017-01-09 16:27:06 +0000241add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${HEADERS})
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +0100242add_executable(Benchmark ${BENCH_SOURCES} ${HEADERS})
Kostace441a92013-08-05 12:40:33 +0200243
Martin Hořeňovský7ae96c72017-01-31 17:37:27 +0100244# Add desired warnings
245if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
246 target_compile_options( SelfTest PRIVATE -Wall -Wextra )
247 target_compile_options( Benchmark PRIVATE -Wall -Wextra )
248endif()
249if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
250 target_compile_options( SelfTest PRIVATE /W4 )
251 target_compile_options( Benchmark PRIVATE /W4 )
252endif()
253
254
Fraser Hutchison69a3f162013-10-24 02:57:46 +0100255# configure unit tests via CTest
Kostace441a92013-08-05 12:40:33 +0200256enable_testing()
Fraser Hutchison69a3f162013-10-24 02:57:46 +0100257add_test(NAME RunTests COMMAND SelfTest)
258
259add_test(NAME ListTests COMMAND SelfTest --list-tests)
260set_tests_properties(ListTests PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ test cases")
261
262add_test(NAME ListTags COMMAND SelfTest --list-tags)
263set_tests_properties(ListTags PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ tags")
Saad K7dd4f292017-01-31 14:22:45 -0500264
265install(DIRECTORY "single_include/" DESTINATION "include/catch/")