blob: ea35d24e98ddebbe7b4d9e926ba0ce7e082f57d1 [file] [log] [blame]
Martin Hořeňovský44722f92018-06-11 10:48:10 +02001cmake_minimum_required(VERSION 3.5)
Kostace441a92013-08-05 12:40:33 +02002
David Seiferta0359982018-01-18 00:01:27 +01003# detect if Catch is being bundled,
4# disable testsuite in that case
5if(NOT DEFINED PROJECT_NAME)
6 set(NOT_SUBPROJECT ON)
7endif()
8
Martin Hořeňovskýd6330722019-03-07 21:44:57 +01009project(Catch2 LANGUAGES CXX VERSION 2.7.0)
Kostace441a92013-08-05 12:40:33 +020010
Martin Hořeňovský44722f92018-06-11 10:48:10 +020011# Provide path for scripts
12list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
13
David Seifert8d4074a2018-01-18 00:01:27 +010014include(GNUInstallDirs)
Martin Hořeňovský44722f92018-06-11 10:48:10 +020015include(CMakePackageConfigHelpers)
16include(CTest)
David Seifert8d4074a2018-01-18 00:01:27 +010017
David Seifertb0f4f162018-01-18 19:20:08 +010018option(CATCH_USE_VALGRIND "Perform SelfTests with Valgrind" OFF)
Martin Hořeňovský797d3b02018-07-22 18:01:42 +020019option(CATCH_BUILD_TESTING "Build SelfTest project" ON)
David Seifertb0f4f162018-01-18 19:20:08 +010020option(CATCH_BUILD_EXAMPLES "Build documentation examples" OFF)
Martin Hořeňovskýf061dab2018-08-28 09:44:47 +020021option(CATCH_BUILD_EXTRA_TESTS "Build extra tests" OFF)
David Seifertb0f4f162018-01-18 19:20:08 +010022option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF)
23option(CATCH_ENABLE_WERROR "Enable all warnings as errors" ON)
Paul le Roux0eb99fb2018-06-19 07:14:09 +020024option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
Martin Hořeňovskýed582bd2018-06-23 19:04:22 +020025option(CATCH_INSTALL_HELPERS "Install contrib alongside library" ON)
26
Martin Hořeňovskýa20b2862017-11-05 12:46:04 +010027
Phil Nash8abe17a2017-01-09 16:27:06 +000028set_property(GLOBAL PROPERTY USE_FOLDERS ON)
29
Kostace441a92013-08-05 12:40:33 +020030# define some folders
Phil Nashc8fefc42017-01-06 16:19:20 +000031set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Kostace441a92013-08-05 12:40:33 +020032set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +010033set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
Phil Nashe1fbbe12017-01-06 16:59:18 +000034set(HEADER_DIR ${CATCH_DIR}/include)
35
Antonio Di Monacob8443e62017-05-11 13:00:03 +020036if(USE_WMAIN)
37 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
38endif()
39
Martin Hořeňovský797d3b02018-07-22 18:01:42 +020040if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT)
Martin Hořeňovskýfcd91c72018-09-02 18:54:41 +020041 find_package(PythonInterp)
David Seifert7f182822018-08-18 22:06:25 +020042 if (NOT PYTHONINTERP_FOUND)
43 message(FATAL_ERROR "Python not found, but required for tests")
44 endif()
Martin Hořeňovský44722f92018-06-11 10:48:10 +020045 add_subdirectory(projects)
46endif()
Saad K7dd4f292017-01-31 14:22:45 -050047
David Seifertb0f4f162018-01-18 19:20:08 +010048if(CATCH_BUILD_EXAMPLES)
Martin Moene85de0722017-11-05 09:15:22 +010049 add_subdirectory(examples)
50endif()
51
Martin Hořeňovskýf061dab2018-08-28 09:44:47 +020052if(CATCH_BUILD_EXTRA_TESTS)
53 add_subdirectory(projects/ExtraTests)
54endif()
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +000055
56# add catch as a 'linkable' target
Martin Hořeňovský44722f92018-06-11 10:48:10 +020057add_library(Catch2 INTERFACE)
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +000058
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +000059
Martin Hořeňovský44722f92018-06-11 10:48:10 +020060
61# depend on some obvious c++11 features so the dependency is transitively added dependents
62target_compile_features(Catch2
63 INTERFACE
64 cxx_alignas
65 cxx_alignof
66 cxx_attributes
67 cxx_auto_type
68 cxx_constexpr
69 cxx_defaulted_functions
70 cxx_deleted_functions
71 cxx_final
72 cxx_lambdas
73 cxx_noexcept
74 cxx_override
75 cxx_range_for
76 cxx_rvalue_references
77 cxx_static_assert
78 cxx_strong_enums
79 cxx_trailing_return_types
80 cxx_unicode_literals
81 cxx_user_literals
82 cxx_variadic_macros
83)
84
85target_include_directories(Catch2
86 INTERFACE
87 $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/single_include>
88 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
89)
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +000090
91# provide a namespaced alias for clients to 'link' against if catch is included as a sub-project
Martin Hořeňovský44722f92018-06-11 10:48:10 +020092add_library(Catch2::Catch2 ALIAS Catch2)
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +000093
Martin Hořeňovský0646e022018-08-31 11:40:55 +020094# Only perform the installation steps when Catch is not being used as
95# a subproject via `add_subdirectory`, or the destinations will break,
96# see https://github.com/catchorg/Catch2/issues/1373
97if (NOT_SUBPROJECT)
98 set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +000099
Martin Hořeňovský0646e022018-08-31 11:40:55 +0200100 configure_package_config_file(
101 ${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
102 ${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
103 INSTALL_DESTINATION
104 ${CATCH_CMAKE_CONFIG_DESTINATION}
105 )
Martin Hořeňovský1af60ef2018-06-24 10:11:14 +0200106
107
Martin Hořeňovský0646e022018-08-31 11:40:55 +0200108 # create and install an export set for catch target as Catch2::Catch
109 install(
110 TARGETS
111 Catch2
112 EXPORT
113 Catch2Targets
114 DESTINATION
115 ${CMAKE_INSTALL_LIBDIR}
116 )
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +0000117
Martin Hořeňovský1af60ef2018-06-24 10:11:14 +0200118
Martin Hořeňovský0646e022018-08-31 11:40:55 +0200119 install(
120 EXPORT
121 Catch2Targets
122 NAMESPACE
123 Catch2::
124 DESTINATION
125 ${CATCH_CMAKE_CONFIG_DESTINATION}
126 )
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +0000127
Martin Hořeňovský646e1f62018-09-01 21:51:49 +0200128 # By default, FooConfigVersion is tied to architecture that it was
129 # generated on. Because Catch2 is header-only, it is arch-independent
130 # and thus Catch2ConfigVersion should not be tied to the architecture
131 # it was generated on.
132 #
133 # CMake does not provide a direct customization point for this in
134 # `write_basic_package_version_file`, but it can be accomplished
135 # indirectly by temporarily undefining `CMAKE_SIZEOF_VOID_P`.
136 set(CATCH2_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
137 unset(CMAKE_SIZEOF_VOID_P)
Martin Hořeňovský0646e022018-08-31 11:40:55 +0200138 write_basic_package_version_file(
139 "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
140 COMPATIBILITY
141 SameMajorVersion
142 )
Martin Hořeňovský646e1f62018-09-01 21:51:49 +0200143 set(CMAKE_SIZEOF_VOID_P ${CATCH2_CMAKE_SIZEOF_VOID_P})
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +0000144
Martin Hořeňovský0646e022018-08-31 11:40:55 +0200145 install(
146 DIRECTORY
147 "single_include/"
148 DESTINATION
149 "${CMAKE_INSTALL_INCLUDEDIR}"
150 )
Martin Hořeňovský44722f92018-06-11 10:48:10 +0200151
Martin Hořeňovský0646e022018-08-31 11:40:55 +0200152 install(
153 FILES
154 "${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
155 "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
156 DESTINATION
157 ${CATCH_CMAKE_CONFIG_DESTINATION}
158 )
Martin Hořeňovský44722f92018-06-11 10:48:10 +0200159
Martin Hořeňovský0646e022018-08-31 11:40:55 +0200160 # Install documentation
161 if(CATCH_INSTALL_DOCS)
162 install(
163 DIRECTORY
164 docs/
165 DESTINATION
166 "${CMAKE_INSTALL_DOCDIR}"
167 )
168 endif()
Martin Hořeňovskýed582bd2018-06-23 19:04:22 +0200169
Martin Hořeňovský0646e022018-08-31 11:40:55 +0200170 if(CATCH_INSTALL_HELPERS)
171 # Install CMake scripts
172 install(
173 FILES
174 "contrib/ParseAndAddCatchTests.cmake"
175 "contrib/Catch.cmake"
176 "contrib/CatchAddTests.cmake"
177 DESTINATION
178 ${CATCH_CMAKE_CONFIG_DESTINATION}
179 )
Martin Hořeňovský44722f92018-06-11 10:48:10 +0200180
Martin Hořeňovský0646e022018-08-31 11:40:55 +0200181 # Install debugger helpers
182 install(
183 FILES
184 "contrib/gdbinit"
185 "contrib/lldbinit"
186 DESTINATION
187 ${CMAKE_INSTALL_DATAROOTDIR}/Catch2
188 )
189 endif()
190
191 ## Provide some pkg-config integration
192 set(PKGCONFIG_INSTALL_DIR
193 "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
194 CACHE PATH "Path where catch2.pc is installed"
195 )
196 configure_file(
197 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in
198 ${CMAKE_CURRENT_BINARY_DIR}/catch2.pc
199 @ONLY
200 )
201 install(
202 FILES
203 "${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
204 DESTINATION
205 ${PKGCONFIG_INSTALL_DIR}
206 )
207
208endif(NOT_SUBPROJECT)