blob: 56d552982be7de6cc7cfc6eac3336537c9ccfe69 [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ý15cf3ca2018-07-23 10:12:15 +02009project(Catch2 LANGUAGES CXX VERSION 2.3.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)
21option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF)
22option(CATCH_ENABLE_WERROR "Enable all warnings as errors" ON)
Paul le Roux0eb99fb2018-06-19 07:14:09 +020023option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
Martin Hořeňovskýed582bd2018-06-23 19:04:22 +020024option(CATCH_INSTALL_HELPERS "Install contrib alongside library" ON)
25
Martin Hořeňovskýa20b2862017-11-05 12:46:04 +010026
Phil Nash8abe17a2017-01-09 16:27:06 +000027set_property(GLOBAL PROPERTY USE_FOLDERS ON)
28
Kostace441a92013-08-05 12:40:33 +020029# define some folders
Phil Nashc8fefc42017-01-06 16:19:20 +000030set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Kostace441a92013-08-05 12:40:33 +020031set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
Martin Hořeňovský3b7511e2017-01-14 21:55:37 +010032set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
Phil Nashe1fbbe12017-01-06 16:59:18 +000033set(HEADER_DIR ${CATCH_DIR}/include)
34
Antonio Di Monacob8443e62017-05-11 13:00:03 +020035if(USE_WMAIN)
36 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
37endif()
38
David Seifert7f182822018-08-18 22:06:25 +020039find_package(PythonInterp)
Martin Hořeňovský797d3b02018-07-22 18:01:42 +020040if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT)
David Seifert7f182822018-08-18 22:06:25 +020041 if (NOT PYTHONINTERP_FOUND)
42 message(FATAL_ERROR "Python not found, but required for tests")
43 endif()
Martin Hořeňovský44722f92018-06-11 10:48:10 +020044 add_subdirectory(projects)
45endif()
Saad K7dd4f292017-01-31 14:22:45 -050046
David Seifertb0f4f162018-01-18 19:20:08 +010047if(CATCH_BUILD_EXAMPLES)
Martin Moene85de0722017-11-05 09:15:22 +010048 add_subdirectory(examples)
49endif()
50
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +000051
52# add catch as a 'linkable' target
Martin Hořeňovský44722f92018-06-11 10:48:10 +020053add_library(Catch2 INTERFACE)
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +000054
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +000055
Martin Hořeňovský44722f92018-06-11 10:48:10 +020056
57# depend on some obvious c++11 features so the dependency is transitively added dependents
58target_compile_features(Catch2
59 INTERFACE
60 cxx_alignas
61 cxx_alignof
62 cxx_attributes
63 cxx_auto_type
64 cxx_constexpr
65 cxx_defaulted_functions
66 cxx_deleted_functions
67 cxx_final
68 cxx_lambdas
69 cxx_noexcept
70 cxx_override
71 cxx_range_for
72 cxx_rvalue_references
73 cxx_static_assert
74 cxx_strong_enums
75 cxx_trailing_return_types
76 cxx_unicode_literals
77 cxx_user_literals
78 cxx_variadic_macros
79)
80
81target_include_directories(Catch2
82 INTERFACE
83 $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/single_include>
84 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
85)
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +000086
87# 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 +020088add_library(Catch2::Catch2 ALIAS Catch2)
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +000089
90set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
91
Martin Hořeňovský1af60ef2018-06-24 10:11:14 +020092include(CMakePackageConfigHelpers)
93configure_package_config_file(
94 ${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
95 ${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
96 INSTALL_DESTINATION
97 ${CATCH_CMAKE_CONFIG_DESTINATION}
98)
99
100
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +0000101# create and install an export set for catch target as Catch2::Catch
Martin Hořeňovský44722f92018-06-11 10:48:10 +0200102install(
103 TARGETS
104 Catch2
105 EXPORT
Martin Hořeňovský1af60ef2018-06-24 10:11:14 +0200106 Catch2Targets
107 DESTINATION
108 ${CMAKE_INSTALL_LIBDIR}
Martin Hořeňovský44722f92018-06-11 10:48:10 +0200109)
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +0000110
Martin Hořeňovský1af60ef2018-06-24 10:11:14 +0200111
Martin Hořeňovský44722f92018-06-11 10:48:10 +0200112install(
113 EXPORT
Martin Hořeňovský1af60ef2018-06-24 10:11:14 +0200114 Catch2Targets
Martin Hořeňovský44722f92018-06-11 10:48:10 +0200115 NAMESPACE
116 Catch2::
117 DESTINATION
118 ${CATCH_CMAKE_CONFIG_DESTINATION}
119)
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +0000120
Bastian Dörigd38f7822018-02-09 10:50:14 +0100121write_basic_package_version_file(
Martin Hořeňovský44722f92018-06-11 10:48:10 +0200122 "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
123 COMPATIBILITY
124 SameMajorVersion
125)
Daniel J. Rollins39bfc6e2018-01-29 22:56:43 +0000126
Martin Hořeňovský44722f92018-06-11 10:48:10 +0200127install(
128 DIRECTORY
129 "single_include/"
130 DESTINATION
131 "${CMAKE_INSTALL_INCLUDEDIR}"
132)
133
134install(
135 FILES
Martin Hořeňovský1af60ef2018-06-24 10:11:14 +0200136 "${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
Martin Hořeňovský44722f92018-06-11 10:48:10 +0200137 "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
138 DESTINATION
139 ${CATCH_CMAKE_CONFIG_DESTINATION}
140)
141
142# Install documentation
Paul le Roux0eb99fb2018-06-19 07:14:09 +0200143if(CATCH_INSTALL_DOCS)
144 install(
145 DIRECTORY
146 docs/
147 DESTINATION
148 "${CMAKE_INSTALL_DOCDIR}"
149 )
150endif()
Martin Hořeňovský44722f92018-06-11 10:48:10 +0200151
Martin Hořeňovskýed582bd2018-06-23 19:04:22 +0200152if(CATCH_INSTALL_HELPERS)
153# Install CMake scripts
154install(
155 FILES
156 "contrib/ParseAndAddCatchTests.cmake"
157 "contrib/Catch.cmake"
158 "contrib/CatchAddTests.cmake"
159 DESTINATION
160 ${CATCH_CMAKE_CONFIG_DESTINATION}
161)
162
163# Install debugger helpers
164install(
165 FILES
166 "contrib/gdbinit"
167 "contrib/lldbinit"
168 DESTINATION
169 ${CMAKE_INSTALL_DATAROOTDIR}/Catch2
170)
171endif()
Martin Hořeňovský44722f92018-06-11 10:48:10 +0200172
173## Provide some pkg-config integration
174set(PKGCONFIG_INSTALL_DIR
175 "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
176 CACHE PATH "Path where catch2.pc is installed"
177)
178configure_file(
179 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in
180 ${CMAKE_CURRENT_BINARY_DIR}/catch2.pc
181 @ONLY
182)
183install(
184 FILES
185 "${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
186 DESTINATION
187 ${PKGCONFIG_INSTALL_DIR}
188)