blob: 54416bf348ff32a7c7d30c275fc42bd6a580ef76 [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)
Giuseppe Robertif3425ae2017-03-28 02:03:50 +020012
onqtam61954c32017-04-16 17:22:44 +030013add_library(${PROJECT_NAME} INTERFACE)
14target_include_directories(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/doctest/>)
onqtam4a655632016-05-26 14:20:52 +030015
onqtamb759fb42017-08-01 18:38:26 +030016################################################################################
17## TESTS/EXAMPLES/HELPERS
18################################################################################
Yordan Madzhunkov7d8af912017-06-26 12:20:57 +030019
onqtamb759fb42017-08-01 18:38:26 +030020if(${DOCTEST_WITH_MAIN_IN_STATIC_LIB})
21 include(scripts/cmake/common.cmake)
22 doctest_add_library(${PROJECT_NAME}_with_main STATIC EXCLUDE_FROM_ALL doctest/parts/doctest_main.cpp)
23 target_link_libraries(${PROJECT_NAME}_with_main PUBLIC ${PROJECT_NAME})
24endif()
onqtamcc9e8652016-08-02 14:23:38 +030025
onqtam61954c32017-04-16 17:22:44 +030026if(${DOCTEST_WITH_TESTS})
27 include(scripts/cmake/common.cmake)
onqtamf6d1a512017-05-01 13:56:12 +030028
29 add_subdirectory(examples/all_features)
onqtamaec53d22017-05-03 06:29:47 +030030
31 if(NOT DEFINED ENV{CODE_COVERAGE})
32 add_subdirectory(examples/exe_with_static_libs)
33 add_subdirectory(examples/executable_dll_and_plugin)
34 add_subdirectory(scripts/playground)
35 endif()
Giuseppe Robertif3425ae2017-03-28 02:03:50 +020036endif()
Giuseppe Robertie01299b2017-03-26 14:18:59 +020037
onqtam61954c32017-04-16 17:22:44 +030038################################################################################
39## PACKAGE SUPPORT
40################################################################################
41
Giuseppe Robertie01299b2017-03-26 14:18:59 +020042set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
43
44set(include_install_dir "include/doctest/")
45set(config_install_dir "lib/cmake/${PROJECT_NAME}")
46
47set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
48set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
49set(targets_export_name "${PROJECT_NAME}Targets")
50set(namespace "${PROJECT_NAME}::")
51
52include(CMakePackageConfigHelpers)
53write_basic_package_version_file(
Giuseppe Robertic89cf822017-04-12 17:14:17 +020054 "${version_config}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion
Giuseppe Robertie01299b2017-03-26 14:18:59 +020055)
56
onqtam08cf7dc2017-04-16 11:37:22 +030057configure_file("scripts/cmake/Config.cmake.in" "${project_config}" @ONLY)
Giuseppe Robertie01299b2017-03-26 14:18:59 +020058
59install(
60 TARGETS ${PROJECT_NAME}
61 EXPORT "${targets_export_name}"
62 INCLUDES DESTINATION "${include_install_dir}"
63)
64
65install(
66 FILES "doctest/doctest.h"
67 DESTINATION "${include_install_dir}"
68)
69
70install(
71 FILES "${project_config}" "${version_config}"
72 DESTINATION "${config_install_dir}"
73)
74
75install(
76 EXPORT "${targets_export_name}"
77 NAMESPACE "${namespace}"
78 DESTINATION "${config_install_dir}"
79)