2018-06-11 10:48:10 +02:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
2013-08-05 12:40:33 +02:00
|
|
|
|
2018-01-18 00:01:27 +01:00
|
|
|
# detect if Catch is being bundled,
|
|
|
|
# disable testsuite in that case
|
|
|
|
if(NOT DEFINED PROJECT_NAME)
|
|
|
|
set(NOT_SUBPROJECT ON)
|
2021-04-16 21:19:58 +02:00
|
|
|
else()
|
|
|
|
set(NOT_SUBPROJECT OFF)
|
2018-01-18 00:01:27 +01:00
|
|
|
endif()
|
|
|
|
|
2019-12-16 22:33:56 +01:00
|
|
|
option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
|
2022-01-06 10:53:26 +01:00
|
|
|
option(CATCH_INSTALL_EXTRAS "Install extras (CMake scripts, debugger helpers) alongside library" ON)
|
2020-04-25 18:18:45 +02:00
|
|
|
option(CATCH_DEVELOPMENT_BUILD "Build tests, enable warnings, enable Werror, etc" OFF)
|
2019-12-16 22:33:56 +01:00
|
|
|
|
2020-02-21 21:15:45 +01:00
|
|
|
include(CMakeDependentOption)
|
|
|
|
cmake_dependent_option(CATCH_BUILD_TESTING "Build the SelfTest project" ON "CATCH_DEVELOPMENT_BUILD" OFF)
|
|
|
|
cmake_dependent_option(CATCH_BUILD_EXAMPLES "Build code examples" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
|
|
|
cmake_dependent_option(CATCH_BUILD_EXTRA_TESTS "Build extra tests" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
2020-09-23 21:54:09 +02:00
|
|
|
cmake_dependent_option(CATCH_BUILD_FUZZERS "Build fuzzers" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
2020-02-21 21:15:45 +01:00
|
|
|
cmake_dependent_option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
|
|
|
cmake_dependent_option(CATCH_ENABLE_WERROR "Enables Werror during build" ON "CATCH_DEVELOPMENT_BUILD" OFF)
|
2021-02-15 23:56:56 +01:00
|
|
|
cmake_dependent_option(CATCH_BUILD_SURROGATES "Enable generating and building surrogate TUs for the main headers" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
2022-02-19 21:27:53 +01:00
|
|
|
cmake_dependent_option(CATCH_ENABLE_CONFIGURE_TESTS "Enable CMake configuration tests. WARNING: VERY EXPENSIVE" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
2021-02-15 23:56:56 +01:00
|
|
|
|
2019-12-16 22:33:56 +01:00
|
|
|
|
2019-10-18 18:47:57 +02:00
|
|
|
# Catch2's build breaks if done in-tree. You probably should not build
|
|
|
|
# things in tree anyway, but we can allow projects that include Catch2
|
|
|
|
# as a subproject to build in-tree as long as it is not in our tree.
|
|
|
|
if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
2019-05-21 06:38:06 +02:00
|
|
|
message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
|
|
|
|
endif()
|
|
|
|
|
2022-07-26 14:39:27 +02:00
|
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.9)
|
2020-11-01 10:36:42 +01:00
|
|
|
# Enable IPO for CMake versions that support it
|
|
|
|
cmake_policy(SET CMP0069 NEW)
|
2022-07-26 14:39:27 +02:00
|
|
|
project(Catch2
|
|
|
|
VERSION 3.1.0 # CML version placeholder, don't delete
|
|
|
|
LANGUAGES CXX
|
|
|
|
# HOMEPAGE_URL is not supported until CMake version 3.12, which
|
|
|
|
# we do not target yet.
|
|
|
|
# HOMEPAGE_URL "https://github.com/catchorg/Catch2"
|
|
|
|
DESCRIPTION "A modern, C++-native, unit test framework."
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
project(Catch2
|
|
|
|
VERSION 3.1.0 # CML version placeholder, don't delete
|
|
|
|
LANGUAGES CXX
|
|
|
|
)
|
2020-11-01 10:36:42 +01:00
|
|
|
endif()
|
|
|
|
|
2022-04-27 23:28:31 +02:00
|
|
|
# Provide path for scripts. We first add path to the scripts we don't use,
|
|
|
|
# but projects including us might, and set the path up to parent scope.
|
|
|
|
# Then we also add path that we use to configure the project, but is of
|
|
|
|
# no use to top level projects.
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/extras")
|
|
|
|
if (NOT NOT_SUBPROJECT)
|
|
|
|
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
|
|
|
|
endif()
|
2018-06-11 10:48:10 +02:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
|
2022-04-27 23:28:31 +02:00
|
|
|
|
2018-01-18 00:01:27 +01:00
|
|
|
include(GNUInstallDirs)
|
2018-06-11 10:48:10 +02:00
|
|
|
include(CMakePackageConfigHelpers)
|
2022-02-02 15:36:58 +01:00
|
|
|
include(CatchConfigOptions)
|
2021-05-23 21:10:01 +02:00
|
|
|
if(CATCH_DEVELOPMENT_BUILD)
|
|
|
|
include(CTest)
|
|
|
|
endif()
|
2018-01-18 00:01:27 +01:00
|
|
|
|
2020-03-18 10:51:35 +01:00
|
|
|
# This variable is used in some subdirectories, so we need it here, rather
|
|
|
|
# than later in the install block
|
|
|
|
set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
|
|
|
|
|
2020-05-07 16:24:05 +02:00
|
|
|
# We have some Windows builds that test `wmain` entry point,
|
|
|
|
# and we need this change to be present in all binaries that
|
|
|
|
# are built during these tests, so this is required here, before
|
|
|
|
# the subdirectories are added.
|
|
|
|
if(CATCH_TEST_USE_WMAIN)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
|
|
|
|
endif()
|
|
|
|
|
2020-03-18 10:51:35 +01:00
|
|
|
|
2019-11-30 17:41:41 +01:00
|
|
|
# Basic paths
|
2017-01-06 17:19:20 +01:00
|
|
|
set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
2019-11-30 17:41:41 +01:00
|
|
|
set(SOURCES_DIR ${CATCH_DIR}/src/catch2)
|
2019-12-05 16:00:20 +01:00
|
|
|
set(SELF_TEST_DIR ${CATCH_DIR}/tests/SelfTest)
|
|
|
|
set(BENCHMARK_DIR ${CATCH_DIR}/tests/Benchmark)
|
2019-12-08 15:55:04 +01:00
|
|
|
set(EXAMPLES_DIR ${CATCH_DIR}/examples)
|
2019-04-18 13:46:02 +02:00
|
|
|
|
2019-12-08 20:57:55 +01:00
|
|
|
# We need to bring-in the variables defined there to this scope
|
2019-12-15 20:33:39 +01:00
|
|
|
add_subdirectory(src)
|
2019-12-08 15:55:04 +01:00
|
|
|
|
|
|
|
# Build tests only if requested
|
|
|
|
if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT)
|
2020-05-06 12:39:26 +02:00
|
|
|
find_package(PythonInterp 3 REQUIRED)
|
2019-12-08 15:55:04 +01:00
|
|
|
if (NOT PYTHONINTERP_FOUND)
|
|
|
|
message(FATAL_ERROR "Python not found, but required for tests")
|
|
|
|
endif()
|
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CATCH_BUILD_EXAMPLES)
|
|
|
|
add_subdirectory(examples)
|
|
|
|
endif()
|
|
|
|
|
2019-12-09 10:04:26 +01:00
|
|
|
if(CATCH_BUILD_EXTRA_TESTS)
|
|
|
|
add_subdirectory(tests/ExtraTests)
|
|
|
|
endif()
|
2019-11-30 17:41:41 +01:00
|
|
|
|
2020-09-23 21:54:09 +02:00
|
|
|
if(CATCH_BUILD_FUZZERS)
|
|
|
|
add_subdirectory(fuzzing)
|
|
|
|
endif()
|
2020-02-21 21:15:45 +01:00
|
|
|
|
|
|
|
if (CATCH_DEVELOPMENT_BUILD)
|
|
|
|
add_warnings_to_targets("${CATCH_WARNING_TARGETS}")
|
|
|
|
endif()
|
|
|
|
|
2019-12-16 22:33:56 +01:00
|
|
|
# Only perform the installation steps when Catch is not being used as
|
|
|
|
# a subproject via `add_subdirectory`, or the destinations will break,
|
|
|
|
# see https://github.com/catchorg/Catch2/issues/1373
|
|
|
|
if (NOT_SUBPROJECT)
|
|
|
|
configure_package_config_file(
|
|
|
|
${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
|
|
|
|
INSTALL_DESTINATION
|
|
|
|
${CATCH_CMAKE_CONFIG_DESTINATION}
|
|
|
|
)
|
|
|
|
|
|
|
|
write_basic_package_version_file(
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
|
|
|
|
COMPATIBILITY
|
|
|
|
SameMajorVersion
|
|
|
|
)
|
|
|
|
|
|
|
|
install(
|
|
|
|
FILES
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
|
|
|
|
DESTINATION
|
|
|
|
${CATCH_CMAKE_CONFIG_DESTINATION}
|
|
|
|
)
|
|
|
|
|
|
|
|
# Install documentation
|
|
|
|
if(CATCH_INSTALL_DOCS)
|
|
|
|
install(
|
|
|
|
DIRECTORY
|
|
|
|
docs/
|
|
|
|
DESTINATION
|
|
|
|
"${CMAKE_INSTALL_DOCDIR}"
|
2022-04-27 14:57:55 +02:00
|
|
|
PATTERN "doxygen" EXCLUDE
|
2019-12-16 22:33:56 +01:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2020-05-06 21:21:08 +02:00
|
|
|
if(CATCH_INSTALL_EXTRAS)
|
|
|
|
# Install CMake scripts
|
|
|
|
install(
|
|
|
|
FILES
|
|
|
|
"extras/ParseAndAddCatchTests.cmake"
|
|
|
|
"extras/Catch.cmake"
|
|
|
|
"extras/CatchAddTests.cmake"
|
|
|
|
DESTINATION
|
|
|
|
${CATCH_CMAKE_CONFIG_DESTINATION}
|
|
|
|
)
|
|
|
|
|
|
|
|
# Install debugger helpers
|
|
|
|
install(
|
|
|
|
FILES
|
|
|
|
"extras/gdbinit"
|
|
|
|
"extras/lldbinit"
|
|
|
|
DESTINATION
|
|
|
|
${CMAKE_INSTALL_DATAROOTDIR}/Catch2
|
|
|
|
)
|
2019-12-16 22:33:56 +01:00
|
|
|
endif()
|
|
|
|
|
|
|
|
## Provide some pkg-config integration
|
|
|
|
set(PKGCONFIG_INSTALL_DIR
|
|
|
|
"${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
|
|
|
|
CACHE PATH "Path where catch2.pc is installed"
|
|
|
|
)
|
|
|
|
configure_file(
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/catch2.pc
|
|
|
|
@ONLY
|
|
|
|
)
|
2020-03-18 10:51:35 +01:00
|
|
|
configure_file(
|
2020-05-03 18:54:38 +02:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2-with-main.pc.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc
|
2020-03-18 10:51:35 +01:00
|
|
|
@ONLY
|
|
|
|
)
|
2019-12-16 22:33:56 +01:00
|
|
|
install(
|
|
|
|
FILES
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
|
2020-05-03 18:54:38 +02:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc"
|
2019-12-16 22:33:56 +01:00
|
|
|
DESTINATION
|
|
|
|
${PKGCONFIG_INSTALL_DIR}
|
|
|
|
)
|
|
|
|
|
|
|
|
# CPack/CMake started taking the package version from project version 3.12
|
|
|
|
# So we need to set the version manually for older CMake versions
|
|
|
|
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
|
|
|
|
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CPACK_PACKAGE_CONTACT "https://github.com/catchorg/Catch2/")
|
|
|
|
|
|
|
|
|
|
|
|
include( CPack )
|
|
|
|
|
|
|
|
endif(NOT_SUBPROJECT)
|