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)
|
|
|
|
endif()
|
|
|
|
|
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()
|
|
|
|
|
2019-10-18 18:47:57 +02:00
|
|
|
|
2020-06-29 20:50:39 +02:00
|
|
|
project(Catch2 LANGUAGES CXX VERSION 2.12.3)
|
2019-10-18 18:47:57 +02:00
|
|
|
|
2018-06-11 10:48:10 +02:00
|
|
|
# Provide path for scripts
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
|
|
|
|
|
2018-01-18 00:01:27 +01:00
|
|
|
include(GNUInstallDirs)
|
2018-06-11 10:48:10 +02:00
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
include(CTest)
|
2018-01-18 00:01:27 +01:00
|
|
|
|
2018-01-18 19:20:08 +01:00
|
|
|
option(CATCH_USE_VALGRIND "Perform SelfTests with Valgrind" OFF)
|
2018-07-22 18:01:42 +02:00
|
|
|
option(CATCH_BUILD_TESTING "Build SelfTest project" ON)
|
2018-01-18 19:20:08 +01:00
|
|
|
option(CATCH_BUILD_EXAMPLES "Build documentation examples" OFF)
|
2018-08-28 09:44:47 +02:00
|
|
|
option(CATCH_BUILD_EXTRA_TESTS "Build extra tests" OFF)
|
2018-01-18 19:20:08 +01:00
|
|
|
option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF)
|
|
|
|
option(CATCH_ENABLE_WERROR "Enable all warnings as errors" ON)
|
2018-06-19 07:14:09 +02:00
|
|
|
option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
|
2018-06-23 19:04:22 +02:00
|
|
|
option(CATCH_INSTALL_HELPERS "Install contrib alongside library" ON)
|
|
|
|
|
2017-11-05 12:46:04 +01:00
|
|
|
|
2017-01-09 17:27:06 +01:00
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
|
|
|
2013-08-05 12:40:33 +02:00
|
|
|
# define some folders
|
2017-01-06 17:19:20 +01:00
|
|
|
set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
2013-08-05 12:40:33 +02:00
|
|
|
set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
|
2017-01-14 21:55:37 +01:00
|
|
|
set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
|
2017-01-06 17:59:18 +01:00
|
|
|
set(HEADER_DIR ${CATCH_DIR}/include)
|
|
|
|
|
2017-05-11 13:00:03 +02:00
|
|
|
if(USE_WMAIN)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
|
|
|
|
endif()
|
|
|
|
|
2018-07-22 18:01:42 +02:00
|
|
|
if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT)
|
2018-09-02 18:54:41 +02:00
|
|
|
find_package(PythonInterp)
|
2018-08-18 22:06:25 +02:00
|
|
|
if (NOT PYTHONINTERP_FOUND)
|
|
|
|
message(FATAL_ERROR "Python not found, but required for tests")
|
|
|
|
endif()
|
2018-06-11 10:48:10 +02:00
|
|
|
add_subdirectory(projects)
|
|
|
|
endif()
|
2017-01-31 20:22:45 +01:00
|
|
|
|
2018-01-18 19:20:08 +01:00
|
|
|
if(CATCH_BUILD_EXAMPLES)
|
2017-11-05 09:15:22 +01:00
|
|
|
add_subdirectory(examples)
|
|
|
|
endif()
|
|
|
|
|
2018-08-28 09:44:47 +02:00
|
|
|
if(CATCH_BUILD_EXTRA_TESTS)
|
|
|
|
add_subdirectory(projects/ExtraTests)
|
|
|
|
endif()
|
2018-01-29 23:56:43 +01:00
|
|
|
|
|
|
|
# add catch as a 'linkable' target
|
2018-06-11 10:48:10 +02:00
|
|
|
add_library(Catch2 INTERFACE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# depend on some obvious c++11 features so the dependency is transitively added dependents
|
|
|
|
target_compile_features(Catch2
|
|
|
|
INTERFACE
|
|
|
|
cxx_alignas
|
|
|
|
cxx_alignof
|
|
|
|
cxx_attributes
|
|
|
|
cxx_auto_type
|
|
|
|
cxx_constexpr
|
|
|
|
cxx_defaulted_functions
|
|
|
|
cxx_deleted_functions
|
|
|
|
cxx_final
|
|
|
|
cxx_lambdas
|
|
|
|
cxx_noexcept
|
|
|
|
cxx_override
|
|
|
|
cxx_range_for
|
|
|
|
cxx_rvalue_references
|
|
|
|
cxx_static_assert
|
|
|
|
cxx_strong_enums
|
|
|
|
cxx_trailing_return_types
|
|
|
|
cxx_unicode_literals
|
|
|
|
cxx_user_literals
|
|
|
|
cxx_variadic_macros
|
|
|
|
)
|
|
|
|
|
|
|
|
target_include_directories(Catch2
|
|
|
|
INTERFACE
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/single_include>
|
|
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
|
|
|
)
|
2018-01-29 23:56:43 +01:00
|
|
|
|
2019-08-10 20:51:15 +02:00
|
|
|
if (ANDROID)
|
|
|
|
target_link_libraries(Catch2 INTERFACE log)
|
|
|
|
endif()
|
|
|
|
|
2018-01-29 23:56:43 +01:00
|
|
|
# provide a namespaced alias for clients to 'link' against if catch is included as a sub-project
|
2018-06-11 10:48:10 +02:00
|
|
|
add_library(Catch2::Catch2 ALIAS Catch2)
|
2018-01-29 23:56:43 +01:00
|
|
|
|
2018-08-31 11:40:55 +02: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)
|
|
|
|
set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
|
|
|
|
|
|
|
|
configure_package_config_file(
|
|
|
|
${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
|
|
|
|
INSTALL_DESTINATION
|
|
|
|
${CATCH_CMAKE_CONFIG_DESTINATION}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# create and install an export set for catch target as Catch2::Catch
|
|
|
|
install(
|
|
|
|
TARGETS
|
|
|
|
Catch2
|
|
|
|
EXPORT
|
|
|
|
Catch2Targets
|
|
|
|
DESTINATION
|
|
|
|
${CMAKE_INSTALL_LIBDIR}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
install(
|
|
|
|
EXPORT
|
|
|
|
Catch2Targets
|
|
|
|
NAMESPACE
|
|
|
|
Catch2::
|
|
|
|
DESTINATION
|
|
|
|
${CATCH_CMAKE_CONFIG_DESTINATION}
|
|
|
|
)
|
|
|
|
|
2018-09-01 21:51:49 +02:00
|
|
|
# By default, FooConfigVersion is tied to architecture that it was
|
|
|
|
# generated on. Because Catch2 is header-only, it is arch-independent
|
|
|
|
# and thus Catch2ConfigVersion should not be tied to the architecture
|
|
|
|
# it was generated on.
|
|
|
|
#
|
|
|
|
# CMake does not provide a direct customization point for this in
|
|
|
|
# `write_basic_package_version_file`, but it can be accomplished
|
2019-06-17 19:08:16 +02:00
|
|
|
# indirectly by temporarily redefining `CMAKE_SIZEOF_VOID_P` to an
|
|
|
|
# empty string. Note that just undefining the variable could be
|
|
|
|
# insufficient in cases where the variable was already in CMake cache
|
2018-09-01 21:51:49 +02:00
|
|
|
set(CATCH2_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
|
2019-06-17 19:08:16 +02:00
|
|
|
set(CMAKE_SIZEOF_VOID_P "")
|
2018-08-31 11:40:55 +02:00
|
|
|
write_basic_package_version_file(
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
|
|
|
|
COMPATIBILITY
|
|
|
|
SameMajorVersion
|
|
|
|
)
|
2018-09-01 21:51:49 +02:00
|
|
|
set(CMAKE_SIZEOF_VOID_P ${CATCH2_CMAKE_SIZEOF_VOID_P})
|
2018-08-31 11:40:55 +02:00
|
|
|
|
|
|
|
install(
|
|
|
|
DIRECTORY
|
|
|
|
"single_include/"
|
|
|
|
DESTINATION
|
|
|
|
"${CMAKE_INSTALL_INCLUDEDIR}"
|
|
|
|
)
|
|
|
|
|
|
|
|
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}"
|
|
|
|
)
|
|
|
|
endif()
|
2018-06-23 19:04:22 +02:00
|
|
|
|
2018-08-31 11:40:55 +02:00
|
|
|
if(CATCH_INSTALL_HELPERS)
|
|
|
|
# Install CMake scripts
|
|
|
|
install(
|
|
|
|
FILES
|
|
|
|
"contrib/ParseAndAddCatchTests.cmake"
|
|
|
|
"contrib/Catch.cmake"
|
|
|
|
"contrib/CatchAddTests.cmake"
|
|
|
|
DESTINATION
|
|
|
|
${CATCH_CMAKE_CONFIG_DESTINATION}
|
|
|
|
)
|
|
|
|
|
|
|
|
# Install debugger helpers
|
|
|
|
install(
|
|
|
|
FILES
|
|
|
|
"contrib/gdbinit"
|
|
|
|
"contrib/lldbinit"
|
|
|
|
DESTINATION
|
|
|
|
${CMAKE_INSTALL_DATAROOTDIR}/Catch2
|
|
|
|
)
|
|
|
|
endif()
|
2018-01-29 23:56:43 +01:00
|
|
|
|
2018-08-31 11:40:55 +02:00
|
|
|
## 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
|
|
|
|
)
|
|
|
|
install(
|
|
|
|
FILES
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
|
|
|
|
DESTINATION
|
|
|
|
${PKGCONFIG_INSTALL_DIR}
|
|
|
|
)
|
|
|
|
|
2019-04-18 13:46:02 +02:00
|
|
|
# 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 )
|
|
|
|
|
2018-08-31 11:40:55 +02:00
|
|
|
endif(NOT_SUBPROJECT)
|