blob: c0a7ed5bcc796eaec477d68763b8f31f9c75eaa4 [file] [log] [blame]
onqtamc7aaa962016-09-10 02:16:57 +03001cmake_minimum_required(VERSION 3.0)
onqtam4a655632016-05-26 14:20:52 +03002
onqtambff67f72017-04-16 20:04:32 +03003################################################################################
4## DOCTEST
5################################################################################
6
7file(READ ${CMAKE_CURRENT_SOURCE_DIR}/scripts/version.txt ver)
8project(doctest VERSION ${ver})
onqtam4a655632016-05-26 14:20:52 +03009
onqtamb759fb42017-08-01 18:38:26 +030010option(DOCTEST_WITH_TESTS "Build tests/examples" ON)
11option(DOCTEST_WITH_MAIN_IN_STATIC_LIB "Build a static lib (cmake target) with a main entry point" ON)
NeverMine17b63bf852017-10-28 16:06:43 +030012option(DOCTEST_NO_INSTALL "Skip the installation process" OFF)
Giuseppe Robertif3425ae2017-03-28 02:03:50 +020013
onqtam61954c32017-04-16 17:22:44 +030014add_library(${PROJECT_NAME} INTERFACE)
15target_include_directories(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/doctest/>)
onqtam4a655632016-05-26 14:20:52 +030016
onqtamb759fb42017-08-01 18:38:26 +030017################################################################################
18## TESTS/EXAMPLES/HELPERS
19################################################################################
Yordan Madzhunkov7d8af912017-06-26 12:20:57 +030020
onqtamb759fb42017-08-01 18:38:26 +030021if(${DOCTEST_WITH_MAIN_IN_STATIC_LIB})
22 include(scripts/cmake/common.cmake)
23 doctest_add_library(${PROJECT_NAME}_with_main STATIC EXCLUDE_FROM_ALL doctest/parts/doctest_main.cpp)
24 target_link_libraries(${PROJECT_NAME}_with_main PUBLIC ${PROJECT_NAME})
25endif()
onqtamcc9e8652016-08-02 14:23:38 +030026
onqtam61954c32017-04-16 17:22:44 +030027if(${DOCTEST_WITH_TESTS})
28 include(scripts/cmake/common.cmake)
onqtamf6d1a512017-05-01 13:56:12 +030029
30 add_subdirectory(examples/all_features)
onqtamaec53d22017-05-03 06:29:47 +030031
32 if(NOT DEFINED ENV{CODE_COVERAGE})
33 add_subdirectory(examples/exe_with_static_libs)
34 add_subdirectory(examples/executable_dll_and_plugin)
35 add_subdirectory(scripts/playground)
36 endif()
Giuseppe Robertif3425ae2017-03-28 02:03:50 +020037endif()
Giuseppe Robertie01299b2017-03-26 14:18:59 +020038
onqtam61954c32017-04-16 17:22:44 +030039################################################################################
40## PACKAGE SUPPORT
41################################################################################
42
Giuseppe Robertie01299b2017-03-26 14:18:59 +020043set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
44
45set(include_install_dir "include/doctest/")
46set(config_install_dir "lib/cmake/${PROJECT_NAME}")
47
48set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
49set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
50set(targets_export_name "${PROJECT_NAME}Targets")
51set(namespace "${PROJECT_NAME}::")
52
53include(CMakePackageConfigHelpers)
54write_basic_package_version_file(
Giuseppe Robertic89cf822017-04-12 17:14:17 +020055 "${version_config}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion
Giuseppe Robertie01299b2017-03-26 14:18:59 +020056)
57
onqtam08cf7dc2017-04-16 11:37:22 +030058configure_file("scripts/cmake/Config.cmake.in" "${project_config}" @ONLY)
Giuseppe Robertie01299b2017-03-26 14:18:59 +020059
NeverMine17b63bf852017-10-28 16:06:43 +030060if (${DOCTEST_NO_INSTALL})
61 install(
62 TARGETS ${PROJECT_NAME}
63 EXPORT "${targets_export_name}"
64 INCLUDES DESTINATION "${include_install_dir}"
65 )
Giuseppe Robertie01299b2017-03-26 14:18:59 +020066
NeverMine17b63bf852017-10-28 16:06:43 +030067 install(
68 FILES "doctest/doctest.h"
69 DESTINATION "${include_install_dir}"
70 )
Giuseppe Robertie01299b2017-03-26 14:18:59 +020071
NeverMine17b63bf852017-10-28 16:06:43 +030072 install(
73 FILES "${project_config}" "${version_config}"
74 DESTINATION "${config_install_dir}"
75 )
Giuseppe Robertie01299b2017-03-26 14:18:59 +020076
NeverMine17b63bf852017-10-28 16:06:43 +030077 install(
78 EXPORT "${targets_export_name}"
79 NAMESPACE "${namespace}"
80 DESTINATION "${config_install_dir}"
81 )
82endif()