Debian Codegraph @

3rdparty/catch2/CMakeLists.txt

raw
1 cmake_minimum_required(VERSION 3.10)
2
3 # detect if Catch is being bundled,
4 # disable testsuite in that case
5 if(NOT DEFINED PROJECT_NAME)
6 set(NOT_SUBPROJECT ON)
7 else()
8 set(NOT_SUBPROJECT OFF)
9 endif()
10
11 option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
12 option(CATCH_INSTALL_EXTRAS "Install extras (CMake scripts, debugger helpers) alongside library" ON)
13 option(CATCH_DEVELOPMENT_BUILD "Build tests, enable warnings, enable Werror, etc" OFF)
14
15 include(CMakeDependentOption)
16 cmake_dependent_option(CATCH_BUILD_TESTING "Build the SelfTest project" ON "CATCH_DEVELOPMENT_BUILD" OFF)
17 cmake_dependent_option(CATCH_BUILD_EXAMPLES "Build code examples" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
18 cmake_dependent_option(CATCH_BUILD_EXTRA_TESTS "Build extra tests" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
19 cmake_dependent_option(CATCH_BUILD_FUZZERS "Build fuzzers" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
20 cmake_dependent_option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
21 cmake_dependent_option(CATCH_ENABLE_WERROR "Enables Werror during build" ON "CATCH_DEVELOPMENT_BUILD" OFF)
22 cmake_dependent_option(CATCH_BUILD_SURROGATES "Enable generating and building surrogate TUs for the main headers" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
23 cmake_dependent_option(CATCH_ENABLE_CONFIGURE_TESTS "Enable CMake configuration tests. WARNING: VERY EXPENSIVE" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
24 cmake_dependent_option(CATCH_ENABLE_CMAKE_HELPER_TESTS "Enable CMake helper tests. WARNING: VERY EXPENSIVE" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
25
26
27 # Catch2's build breaks if done in-tree. You probably should not build
28 # things in tree anyway, but we can allow projects that include Catch2
29 # as a subproject to build in-tree as long as it is not in our tree.
30 if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
31 message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
32 endif()
33
34 project(Catch2
35 VERSION 3.4.0 # CML version placeholder, don't delete
36 LANGUAGES CXX
37 # HOMEPAGE_URL is not supported until CMake version 3.12, which
38 # we do not target yet.
39 # HOMEPAGE_URL "https://github.com/catchorg/Catch2"
40 DESCRIPTION "A modern, C++-native, unit test framework."
41 )
42
43
44 # Provide path for scripts. We first add path to the scripts we don't use,
45 # but projects including us might, and set the path up to parent scope.
46 # Then we also add path that we use to configure the project, but is of
47 # no use to top level projects.
48 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/extras")
49 if (NOT NOT_SUBPROJECT)
50 set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
51 endif()
52 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
53
54 include(GNUInstallDirs)
55 include(CMakePackageConfigHelpers)
56 include(CatchConfigOptions)
57 if(CATCH_DEVELOPMENT_BUILD)
58 include(CTest)
59 endif()
60
61 # This variable is used in some subdirectories, so we need it here, rather
62 # than later in the install block
63 set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
64
65 # We have some Windows builds that test `wmain` entry point,
66 # and we need this change to be present in all binaries that
67 # are built during these tests, so this is required here, before
68 # the subdirectories are added.
69 if(CATCH_TEST_USE_WMAIN)
70 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
71 endif()
72
73
74 # Basic paths
75 set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
76 set(SOURCES_DIR ${CATCH_DIR}/src/catch2)
77 set(SELF_TEST_DIR ${CATCH_DIR}/tests/SelfTest)
78 set(BENCHMARK_DIR ${CATCH_DIR}/tests/Benchmark)
79 set(EXAMPLES_DIR ${CATCH_DIR}/examples)
80
81 # We need to bring-in the variables defined there to this scope
82 add_subdirectory(src)
83
84 # Build tests only if requested
85 if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT)
86 find_package(PythonInterp 3 REQUIRED)
87 if (NOT PYTHONINTERP_FOUND)
88 message(FATAL_ERROR "Python not found, but required for tests")
89 endif()
90 add_subdirectory(tests)
91 endif()
92
93 if(CATCH_BUILD_EXAMPLES)
94 add_subdirectory(examples)
95 endif()
96
97 if(CATCH_BUILD_EXTRA_TESTS)
98 add_subdirectory(tests/ExtraTests)
99 endif()
100
101 if(CATCH_BUILD_FUZZERS)
102 add_subdirectory(fuzzing)
103 endif()
104
105 if (CATCH_DEVELOPMENT_BUILD)
106 add_warnings_to_targets("${CATCH_WARNING_TARGETS}")
107 endif()
108
109 # Only perform the installation steps when Catch is not being used as
110 # a subproject via `add_subdirectory`, or the destinations will break,
111 # see https://github.com/catchorg/Catch2/issues/1373
112 if (NOT_SUBPROJECT)
113 configure_package_config_file(
114 ${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
115 ${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
116 INSTALL_DESTINATION
117 ${CATCH_CMAKE_CONFIG_DESTINATION}
118 )
119
120 write_basic_package_version_file(
121 "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
122 COMPATIBILITY
123 SameMajorVersion
124 )
125
126 install(
127 FILES
128 "${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
129 "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
130 DESTINATION
131 ${CATCH_CMAKE_CONFIG_DESTINATION}
132 )
133
134 # Install documentation
135 if(CATCH_INSTALL_DOCS)
136 install(
137 DIRECTORY
138 docs/
139 DESTINATION
140 "${CMAKE_INSTALL_DOCDIR}"
141 PATTERN "doxygen" EXCLUDE
142 )
143 endif()
144
145 if(CATCH_INSTALL_EXTRAS)
146 # Install CMake scripts
147 install(
148 FILES
149 "extras/ParseAndAddCatchTests.cmake"
150 "extras/Catch.cmake"
151 "extras/CatchAddTests.cmake"
152 "extras/CatchShardTests.cmake"
153 "extras/CatchShardTestsImpl.cmake"
154 DESTINATION
155 ${CATCH_CMAKE_CONFIG_DESTINATION}
156 )
157
158 # Install debugger helpers
159 install(
160 FILES
161 "extras/gdbinit"
162 "extras/lldbinit"
163 DESTINATION
164 ${CMAKE_INSTALL_DATAROOTDIR}/Catch2
165 )
166 endif()
167
168 ## Provide some pkg-config integration
169 set(PKGCONFIG_INSTALL_DIR
170 "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
171 CACHE PATH "Path where catch2.pc is installed"
172 )
173 configure_file(
174 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in
175 ${CMAKE_CURRENT_BINARY_DIR}/catch2.pc
176 @ONLY
177 )
178 configure_file(
179 ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2-with-main.pc.in
180 ${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc
181 @ONLY
182 )
183 install(
184 FILES
185 "${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
186 "${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc"
187 DESTINATION
188 ${PKGCONFIG_INSTALL_DIR}
189 )
190
191 # CPack/CMake started taking the package version from project version 3.12
192 # So we need to set the version manually for older CMake versions
193 if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
194 set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
195 endif()
196
197 set(CPACK_PACKAGE_CONTACT "https://github.com/catchorg/Catch2/")
198
199
200 include( CPack )
201
202 endif(NOT_SUBPROJECT)