blob: 4e986fadded960f771641a15796fb1ab3456bf63 [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
onqtam36e37452019-03-02 20:10:05 +020010option(DOCTEST_WITH_MAIN_IN_STATIC_LIB "Build a static lib (cmake target) with a default main entry point" ON)
NeverMine17b63bf852017-10-28 16:06:43 +030011option(DOCTEST_NO_INSTALL "Skip the installation process" OFF)
Giuseppe Robertif3425ae2017-03-28 02:03:50 +020012
onqtam61954c32017-04-16 17:22:44 +030013add_library(${PROJECT_NAME} INTERFACE)
onqtam36e37452019-03-02 20:10:05 +020014
15# use a special hidden version of the doctest header which directly includes the 2 parts - much easier during development
16if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
17 message("using the DEV version!")
18 target_include_directories(${PROJECT_NAME} INTERFACE
19 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/scripts/development_only/>
20 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/doctest/parts/>)
21else()
22 target_include_directories(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>)
23endif()
onqtam4a655632016-05-26 14:20:52 +030024
Dimitrij Mijoski0dbbd4f2019-03-02 17:37:34 +010025# hack to support building on XCode 6 and 7 - propagate the definition to everything
26if(DEFINED DOCTEST_THREAD_LOCAL)
27 target_compile_definitions(${PROJECT_NAME} INTERFACE
28 DOCTEST_THREAD_LOCAL=${DOCTEST_THREAD_LOCAL})
29endif()
30
31# add a custom target that assembles the single header when any of the parts are touched
32
33set(doctest_parts_folder "${CMAKE_CURRENT_SOURCE_DIR}/doctest/parts")
34
35add_custom_command(
onqtam36e37452019-03-02 20:10:05 +020036 OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/doctest/doctest.h
Dimitrij Mijoski0dbbd4f2019-03-02 17:37:34 +010037 DEPENDS
38 ${doctest_parts_folder}/doctest_fwd.h
39 ${doctest_parts_folder}/doctest.cpp
onqtam2870d772019-03-02 19:50:40 +020040 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/assemble_single_header.cmake
Dimitrij Mijoski0dbbd4f2019-03-02 17:37:34 +010041 COMMENT "assembling the single header")
42
onqtam36e37452019-03-02 20:10:05 +020043add_custom_target(assemble_single_header ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/doctest/doctest.h)
Dimitrij Mijoski0dbbd4f2019-03-02 17:37:34 +010044
onqtamb759fb42017-08-01 18:38:26 +030045################################################################################
46## TESTS/EXAMPLES/HELPERS
47################################################################################
Yordan Madzhunkov7d8af912017-06-26 12:20:57 +030048
onqtam36e37452019-03-02 20:10:05 +020049if(${DOCTEST_WITH_MAIN_IN_STATIC_LIB} AND NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
onqtamb759fb42017-08-01 18:38:26 +030050 include(scripts/cmake/common.cmake)
Dimitrij Mijoski0dbbd4f2019-03-02 17:37:34 +010051 add_library(${PROJECT_NAME}_with_main STATIC EXCLUDE_FROM_ALL doctest/parts/doctest.cpp)
52 target_compile_definitions(${PROJECT_NAME}_with_main PRIVATE
53 DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN)
54 # hack to support building on XCode 6 and 7 - propagate the definition to everything
55 if(DEFINED DOCTEST_THREAD_LOCAL)
56 target_compile_definitions(${PROJECT_NAME}_with_main PRIVATE
57 DOCTEST_THREAD_LOCAL=${DOCTEST_THREAD_LOCAL})
58 endif()
onqtamb759fb42017-08-01 18:38:26 +030059endif()
onqtamcc9e8652016-08-02 14:23:38 +030060
onqtam36e37452019-03-02 20:10:05 +020061if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
onqtam61954c32017-04-16 17:22:44 +030062 include(scripts/cmake/common.cmake)
onqtamf6d1a512017-05-01 13:56:12 +030063
64 add_subdirectory(examples/all_features)
onqtamaec53d22017-05-03 06:29:47 +030065
66 if(NOT DEFINED ENV{CODE_COVERAGE})
67 add_subdirectory(examples/exe_with_static_libs)
68 add_subdirectory(examples/executable_dll_and_plugin)
69 add_subdirectory(scripts/playground)
70 endif()
Giuseppe Robertif3425ae2017-03-28 02:03:50 +020071endif()
Giuseppe Robertie01299b2017-03-26 14:18:59 +020072
onqtam61954c32017-04-16 17:22:44 +030073################################################################################
74## PACKAGE SUPPORT
75################################################################################
76
Giuseppe Robertie01299b2017-03-26 14:18:59 +020077set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
78
ncihnegnbc43fe42019-01-27 05:28:54 -080079set(include_install_dir "include")
Giuseppe Robertie01299b2017-03-26 14:18:59 +020080set(config_install_dir "lib/cmake/${PROJECT_NAME}")
81
82set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
83set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
84set(targets_export_name "${PROJECT_NAME}Targets")
85set(namespace "${PROJECT_NAME}::")
86
87include(CMakePackageConfigHelpers)
88write_basic_package_version_file(
Giuseppe Robertic89cf822017-04-12 17:14:17 +020089 "${version_config}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion
Giuseppe Robertie01299b2017-03-26 14:18:59 +020090)
91
onqtam08cf7dc2017-04-16 11:37:22 +030092configure_file("scripts/cmake/Config.cmake.in" "${project_config}" @ONLY)
Giuseppe Robertie01299b2017-03-26 14:18:59 +020093
Viktor Kirilov79a37982017-11-04 18:34:54 +020094if (NOT ${DOCTEST_NO_INSTALL})
NeverMine17b63bf852017-10-28 16:06:43 +030095 install(
96 TARGETS ${PROJECT_NAME}
97 EXPORT "${targets_export_name}"
98 INCLUDES DESTINATION "${include_install_dir}"
99 )
Giuseppe Robertie01299b2017-03-26 14:18:59 +0200100
NeverMine17b63bf852017-10-28 16:06:43 +0300101 install(
onqtam36e37452019-03-02 20:10:05 +0200102 FILES "doctest/doctest.h"
ncihnegnbc43fe42019-01-27 05:28:54 -0800103 DESTINATION "${include_install_dir}/doctest"
NeverMine17b63bf852017-10-28 16:06:43 +0300104 )
Giuseppe Robertie01299b2017-03-26 14:18:59 +0200105
NeverMine17b63bf852017-10-28 16:06:43 +0300106 install(
107 FILES "${project_config}" "${version_config}"
108 DESTINATION "${config_install_dir}"
109 )
Giuseppe Robertie01299b2017-03-26 14:18:59 +0200110
NeverMine17b63bf852017-10-28 16:06:43 +0300111 install(
112 EXPORT "${targets_export_name}"
113 NAMESPACE "${namespace}"
114 DESTINATION "${config_install_dir}"
115 )
116endif()