1
0
Fork 0
mirror of https://github.com/TheLartians/ModernCppStarter.git synced 2025-08-31 22:21:13 +02:00
ModernCppStarter/test/CMakeLists.txt
ClausKlein e5c060387e FIXME: the packageProject() makes the problem
so the standalone project does not build!
and the cmake project config files can't be installed this way?
2021-02-06 11:13:07 +01:00

71 lines
1.9 KiB
CMake

cmake_minimum_required(VERSION 3.14...3.19)
project(GreeterTests LANGUAGES CXX)
# ---- Options ----
option(ENABLE_TEST_COVERAGE "Enable test coverage" OFF)
option(TEST_INSTALLED_VERSION "Test the version found by find_package" OFF)
# --- Import tools ----
include(../cmake/tools.cmake)
# ---- Dependencies ----
include(../cmake/CPM.cmake)
CPMAddPackage(
NAME doctest
GITHUB_REPOSITORY onqtam/doctest
GIT_TAG 2.3.7
)
if(TEST_INSTALLED_VERSION)
find_package(Greeter REQUIRED)
else()
CPMAddPackage(NAME Greeter SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
endif()
CPMAddPackage(
NAME Format.cmake
GITHUB_REPOSITORY TheLartians/Format.cmake
VERSION 1.6
OPTIONS # enable cmake formatting
"FORMAT_CHECK_CMAKE ON"
)
# ---- Create binary ----
file(GLOB sources CONFIGURE_DEPENDS source/*.cpp)
add_executable(GreeterTests ${sources})
target_link_libraries(GreeterTests PRIVATE doctest::doctest Greeter::Greeter)
target_compile_features(GreeterTests PUBLIC cxx_std_17)
# enable compiler warnings
if(NOT TEST_INSTALLED_VERSION)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(Greeter PRIVATE -Wall -pedantic -Wextra -Werror)
elseif(MSVC)
target_compile_options(Greeter PRIVATE /W4 /WX)
target_compile_definitions(GreeterTests PRIVATE DOCTEST_CONFIG_USE_STD_HEADERS)
endif()
endif()
# ---- Add GreeterTests ----
enable_testing()
# Note: doctest and similar testing frameworks can automatically configure CMake tests.
# include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake)
# doctest_discover_tests(GreeterTests)
# For other testing frameworks add the tests target instead:
add_test(NAME GreeterTests COMMAND GreeterTests --success=false)
# ---- code coverage ----
if(ENABLE_TEST_COVERAGE AND NOT TEST_INSTALLED_VERSION)
target_compile_options(Greeter PRIVATE -O0 -g -fprofile-arcs -ftest-coverage)
target_link_options(Greeter PRIVATE -fprofile-arcs -ftest-coverage)
endif()