blob: 1e095f318cccfcb2abe211d914e2aebf523d4de8 [file] [log] [blame]
Kostace441a92013-08-05 12:40:33 +02001cmake_minimum_required(VERSION 2.8)
2
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)
Phil Nashe1fbbe12017-01-06 16:59:18 +000010set(HEADER_DIR ${CATCH_DIR}/include)
11
Andy Sawyer13cbdf72014-09-04 00:32:05 +010012if(USE_CPP11)
Phil Nash30cebd62016-11-09 22:55:32 +000013 ## We can't turn this on by default, since it breaks on travis
14 message(STATUS "Enabling C++11")
15 set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010016elseif(USE_CPP14)
17 message(STATUS "Enabling C++14")
18 set(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")
Andy Sawyer13cbdf72014-09-04 00:32:05 +010019endif()
Kostace441a92013-08-05 12:40:33 +020020
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010021#checks that the given hard-coded list contains all headers + sources in the given folder
22function(CheckFileList LIST_VAR FOLDER)
23 set(MESSAGE " should be added to the variable ${LIST_VAR}")
24 set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n")
25 file(GLOB GLOBBED_LIST "${FOLDER}/*.cpp"
26 "${FOLDER}/*.hpp"
27 "${FOLDER}/*.h")
28 list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}})
29 foreach(EXTRA_ITEM ${GLOBBED_LIST})
30 string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}")
31 message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}")
32 endforeach()
33endfunction()
34
35function(CheckFileListRec LIST_VAR FOLDER)
36 set(MESSAGE " should be added to the variable ${LIST_VAR}")
37 set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n")
38 file(GLOB_RECURSE GLOBBED_LIST "${FOLDER}/*.cpp"
39 "${FOLDER}/*.hpp"
40 "${FOLDER}/*.h")
41 list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}})
42 foreach(EXTRA_ITEM ${GLOBBED_LIST})
43 string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}")
44 message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}")
45 endforeach()
46endfunction()
47
Kostace441a92013-08-05 12:40:33 +020048# define the sources of the self test
Phil Nashd5360e82017-01-12 11:54:53 +000049# Please keep these ordered alphabetically
Phil Nash8abe17a2017-01-09 16:27:06 +000050set(TEST_SOURCES
Phil Nash30cebd62016-11-09 22:55:32 +000051 ${SELF_TEST_DIR}/ApproxTests.cpp
52 ${SELF_TEST_DIR}/BDDTests.cpp
53 ${SELF_TEST_DIR}/ClassTests.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000054 ${SELF_TEST_DIR}/CmdLineTests.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000055 ${SELF_TEST_DIR}/ConditionTests.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000056 ${SELF_TEST_DIR}/EnumToString.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000057 ${SELF_TEST_DIR}/ExceptionTests.cpp
58 ${SELF_TEST_DIR}/GeneratorTests.cpp
59 ${SELF_TEST_DIR}/MessageTests.cpp
60 ${SELF_TEST_DIR}/MiscTests.cpp
61 ${SELF_TEST_DIR}/PartTrackerTests.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000062 ${SELF_TEST_DIR}/TagAliasTests.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000063 ${SELF_TEST_DIR}/TestMain.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000064 ${SELF_TEST_DIR}/ToStringPair.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000065 ${SELF_TEST_DIR}/ToStringTuple.cpp
Phil Nash30cebd62016-11-09 22:55:32 +000066 ${SELF_TEST_DIR}/ToStringVector.cpp
67 ${SELF_TEST_DIR}/ToStringWhich.cpp
Phil Nashd5360e82017-01-12 11:54:53 +000068 ${SELF_TEST_DIR}/TrickyTests.cpp
69 ${SELF_TEST_DIR}/VariadicMacrosTests.cpp
Phil Nash8abe17a2017-01-09 16:27:06 +000070 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010071CheckFileList(TEST_SOURCES ${SELF_TEST_DIR})
Phil Nashd5360e82017-01-12 11:54:53 +000072
73# A set of impl files that just #include a single header
74# Please keep these ordered alphabetically
Phil Nash8abe17a2017-01-09 16:27:06 +000075set(IMPL_SOURCES
Phil Nash30cebd62016-11-09 22:55:32 +000076 ${SELF_TEST_DIR}/SurrogateCpps/catch_common.cpp
77 ${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp
78 ${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp
79 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_capture.cpp
80 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_config.cpp
81 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_exception.cpp
82 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_generators.cpp
83 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_registry_hub.cpp
84 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp
85 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_runner.cpp
86 ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_testcase.cpp
87 ${SELF_TEST_DIR}/SurrogateCpps/catch_message.cpp
88 ${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp
89 ${SELF_TEST_DIR}/SurrogateCpps/catch_ptr.cpp
90 ${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp
91 ${SELF_TEST_DIR}/SurrogateCpps/catch_streambuf.cpp
92 ${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp
93 ${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp
94 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010095CheckFileList(IMPL_SOURCES ${SELF_TEST_DIR}/SurrogateCpps)
Kostace441a92013-08-05 12:40:33 +020096
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010097
Phil Nashd5360e82017-01-12 11:54:53 +000098# Please keep these ordered alphabetically
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +010099set(TOP_LEVEL_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000100 ${HEADER_DIR}/catch.hpp
101 ${HEADER_DIR}/catch_session.hpp
102 ${HEADER_DIR}/catch_with_main.hpp
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100103 )
104CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR})
105
106# Please keep these ordered alphabetically
107set(EXTERNAL_HEADERS
Phil Nashd5360e82017-01-12 11:54:53 +0000108 ${HEADER_DIR}/external/clara.h
109 ${HEADER_DIR}/external/tbc_text_format.h
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100110 )
111CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external)
112
113
114# Please keep these ordered alphabetically
115set(INTERNAL_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000116 ${HEADER_DIR}/internal/catch_approx.hpp
117 ${HEADER_DIR}/internal/catch_assertionresult.h
118 ${HEADER_DIR}/internal/catch_assertionresult.hpp
119 ${HEADER_DIR}/internal/catch_capture.hpp
120 ${HEADER_DIR}/internal/catch_clara.h
121 ${HEADER_DIR}/internal/catch_commandline.hpp
122 ${HEADER_DIR}/internal/catch_common.h
123 ${HEADER_DIR}/internal/catch_common.hpp
124 ${HEADER_DIR}/internal/catch_compiler_capabilities.h
125 ${HEADER_DIR}/internal/catch_config.hpp
126 ${HEADER_DIR}/internal/catch_console_colour.hpp
127 ${HEADER_DIR}/internal/catch_console_colour_impl.hpp
128 ${HEADER_DIR}/internal/catch_context.h
129 ${HEADER_DIR}/internal/catch_context_impl.hpp
130 ${HEADER_DIR}/internal/catch_debugger.h
131 ${HEADER_DIR}/internal/catch_debugger.hpp
132 ${HEADER_DIR}/internal/catch_default_main.hpp
133 ${HEADER_DIR}/internal/catch_evaluate.hpp
134 ${HEADER_DIR}/internal/catch_exception_translator_registry.hpp
135 ${HEADER_DIR}/internal/catch_expression_lhs.hpp
136 ${HEADER_DIR}/internal/catch_fatal_condition.hpp
137 ${HEADER_DIR}/internal/catch_generators.hpp
138 ${HEADER_DIR}/internal/catch_generators_impl.hpp
139 ${HEADER_DIR}/internal/catch_impl.hpp
140 ${HEADER_DIR}/internal/catch_interfaces_capture.h
141 ${HEADER_DIR}/internal/catch_interfaces_config.h
142 ${HEADER_DIR}/internal/catch_interfaces_exception.h
143 ${HEADER_DIR}/internal/catch_interfaces_generators.h
144 ${HEADER_DIR}/internal/catch_interfaces_registry_hub.h
145 ${HEADER_DIR}/internal/catch_interfaces_reporter.h
146 ${HEADER_DIR}/internal/catch_interfaces_runner.h
147 ${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h
148 ${HEADER_DIR}/internal/catch_interfaces_testcase.h
149 ${HEADER_DIR}/internal/catch_legacy_reporter_adapter.h
150 ${HEADER_DIR}/internal/catch_legacy_reporter_adapter.hpp
151 ${HEADER_DIR}/internal/catch_list.hpp
152 ${HEADER_DIR}/internal/catch_matchers.hpp
153 ${HEADER_DIR}/internal/catch_message.h
154 ${HEADER_DIR}/internal/catch_message.hpp
155 ${HEADER_DIR}/internal/catch_notimplemented_exception.h
156 ${HEADER_DIR}/internal/catch_notimplemented_exception.hpp
157 ${HEADER_DIR}/internal/catch_objc.hpp
158 ${HEADER_DIR}/internal/catch_objc_arc.hpp
159 ${HEADER_DIR}/internal/catch_option.hpp
160 ${HEADER_DIR}/internal/catch_platform.h
161 ${HEADER_DIR}/internal/catch_ptr.hpp
162 ${HEADER_DIR}/internal/catch_reenable_warnings.h
163 ${HEADER_DIR}/internal/catch_registry_hub.hpp
164 ${HEADER_DIR}/internal/catch_reporter_registrars.hpp
165 ${HEADER_DIR}/internal/catch_reporter_registry.hpp
166 ${HEADER_DIR}/internal/catch_result_builder.h
167 ${HEADER_DIR}/internal/catch_result_builder.hpp
168 ${HEADER_DIR}/internal/catch_result_type.h
169 ${HEADER_DIR}/internal/catch_run_context.hpp
170 ${HEADER_DIR}/internal/catch_section.h
171 ${HEADER_DIR}/internal/catch_section.hpp
172 ${HEADER_DIR}/internal/catch_section_info.h
173 ${HEADER_DIR}/internal/catch_section_info.hpp
174 ${HEADER_DIR}/internal/catch_stream.h
175 ${HEADER_DIR}/internal/catch_stream.hpp
176 ${HEADER_DIR}/internal/catch_streambuf.h
177 ${HEADER_DIR}/internal/catch_suppress_warnings.h
178 ${HEADER_DIR}/internal/catch_tag_alias.h
179 ${HEADER_DIR}/internal/catch_tag_alias_registry.h
180 ${HEADER_DIR}/internal/catch_tag_alias_registry.hpp
181 ${HEADER_DIR}/internal/catch_test_case_info.h
182 ${HEADER_DIR}/internal/catch_test_case_info.hpp
183 ${HEADER_DIR}/internal/catch_test_case_registry_impl.hpp
184 ${HEADER_DIR}/internal/catch_test_case_tracker.hpp
185 ${HEADER_DIR}/internal/catch_test_registry.hpp
186 ${HEADER_DIR}/internal/catch_test_spec.hpp
187 ${HEADER_DIR}/internal/catch_test_spec_parser.hpp
188 ${HEADER_DIR}/internal/catch_text.h
189 ${HEADER_DIR}/internal/catch_timer.h
190 ${HEADER_DIR}/internal/catch_timer.hpp
191 ${HEADER_DIR}/internal/catch_tostring.h
192 ${HEADER_DIR}/internal/catch_tostring.hpp
193 ${HEADER_DIR}/internal/catch_totals.hpp
194 ${HEADER_DIR}/internal/catch_version.h
195 ${HEADER_DIR}/internal/catch_version.hpp
196 ${HEADER_DIR}/internal/catch_wildcard_pattern.hpp
Martin Hořeňovský531d2672017-01-16 19:56:57 +0100197 ${HEADER_DIR}/internal/catch_windows_h_proxy.h
Phil Nashe1fbbe12017-01-06 16:59:18 +0000198 ${HEADER_DIR}/internal/catch_xmlwriter.hpp
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100199 )
200CheckFileList(INTERNAL_HEADERS ${HEADER_DIR}/internal)
201
202# Please keep these ordered alphabetically
203set(REPORTER_HEADERS
Phil Nashe1fbbe12017-01-06 16:59:18 +0000204 ${HEADER_DIR}/reporters/catch_reporter_bases.hpp
205 ${HEADER_DIR}/reporters/catch_reporter_compact.hpp
206 ${HEADER_DIR}/reporters/catch_reporter_console.hpp
207 ${HEADER_DIR}/reporters/catch_reporter_junit.hpp
208 ${HEADER_DIR}/reporters/catch_reporter_multi.hpp
209 ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
210 ${HEADER_DIR}/reporters/catch_reporter_xml.hpp
211 )
Martin Hořeňovskýe6ef60a2017-01-15 22:07:36 +0100212CheckFileList(REPORTER_HEADERS ${HEADER_DIR}/reporters)
213
214# Specify the headers, too, so CLion recognises them as project files
215set(HEADERS
216 ${TOP_LEVEL_HEADERS}
217 ${EXTERNAL_HEADERS}
218 ${INTERNAL_HEADERS}
219 ${REPORTER_HEADERS}
220 )
221
Phil Nashe1fbbe12017-01-06 16:59:18 +0000222
Phil Nashd5360e82017-01-12 11:54:53 +0000223# Provide some groupings for IDEs
Phil Nash8abe17a2017-01-09 16:27:06 +0000224SOURCE_GROUP("Tests" FILES ${TEST_SOURCES})
225SOURCE_GROUP("Surrogates" FILES ${IMPL_SOURCES})
226
Kostace441a92013-08-05 12:40:33 +0200227# configure the executable
Phil Nashe1fbbe12017-01-06 16:59:18 +0000228include_directories(${HEADER_DIR})
Phil Nash8abe17a2017-01-09 16:27:06 +0000229add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${HEADERS})
Kostace441a92013-08-05 12:40:33 +0200230
Fraser Hutchison69a3f162013-10-24 02:57:46 +0100231# configure unit tests via CTest
Kostace441a92013-08-05 12:40:33 +0200232enable_testing()
Fraser Hutchison69a3f162013-10-24 02:57:46 +0100233add_test(NAME RunTests COMMAND SelfTest)
234
235add_test(NAME ListTests COMMAND SelfTest --list-tests)
236set_tests_properties(ListTests PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ test cases")
237
238add_test(NAME ListTags COMMAND SelfTest --list-tags)
239set_tests_properties(ListTags PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ tags")