blob: baa13a9d2510a3707f3b03c5ee77f1db17ae4979 [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
Dimitrij Mijoski02d4c9b2019-03-14 15:09:37 +010049if(${DOCTEST_WITH_MAIN_IN_STATIC_LIB})
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)
Dimitrij Mijoski02d4c9b2019-03-14 15:09:37 +010054 target_link_libraries(${PROJECT_NAME}_with_main PUBLIC ${PROJECT_NAME})
onqtamb759fb42017-08-01 18:38:26 +030055endif()
onqtamcc9e8652016-08-02 14:23:38 +030056
onqtam36e37452019-03-02 20:10:05 +020057if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
onqtam61954c32017-04-16 17:22:44 +030058 include(scripts/cmake/common.cmake)
onqtamf6d1a512017-05-01 13:56:12 +030059
60 add_subdirectory(examples/all_features)
onqtamaec53d22017-05-03 06:29:47 +030061
62 if(NOT DEFINED ENV{CODE_COVERAGE})
63 add_subdirectory(examples/exe_with_static_libs)
64 add_subdirectory(examples/executable_dll_and_plugin)
65 add_subdirectory(scripts/playground)
66 endif()
Giuseppe Robertif3425ae2017-03-28 02:03:50 +020067endif()
Giuseppe Robertie01299b2017-03-26 14:18:59 +020068
onqtam61954c32017-04-16 17:22:44 +030069################################################################################
70## PACKAGE SUPPORT
71################################################################################
72
Giuseppe Robertie01299b2017-03-26 14:18:59 +020073set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
74
ncihnegnbc43fe42019-01-27 05:28:54 -080075set(include_install_dir "include")
Giuseppe Robertie01299b2017-03-26 14:18:59 +020076set(config_install_dir "lib/cmake/${PROJECT_NAME}")
77
78set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
79set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
80set(targets_export_name "${PROJECT_NAME}Targets")
81set(namespace "${PROJECT_NAME}::")
82
83include(CMakePackageConfigHelpers)
84write_basic_package_version_file(
Giuseppe Robertic89cf822017-04-12 17:14:17 +020085 "${version_config}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion
Giuseppe Robertie01299b2017-03-26 14:18:59 +020086)
87
onqtam08cf7dc2017-04-16 11:37:22 +030088configure_file("scripts/cmake/Config.cmake.in" "${project_config}" @ONLY)
Giuseppe Robertie01299b2017-03-26 14:18:59 +020089
Viktor Kirilov79a37982017-11-04 18:34:54 +020090if (NOT ${DOCTEST_NO_INSTALL})
NeverMine17b63bf852017-10-28 16:06:43 +030091 install(
92 TARGETS ${PROJECT_NAME}
93 EXPORT "${targets_export_name}"
94 INCLUDES DESTINATION "${include_install_dir}"
95 )
Giuseppe Robertie01299b2017-03-26 14:18:59 +020096
NeverMine17b63bf852017-10-28 16:06:43 +030097 install(
onqtam36e37452019-03-02 20:10:05 +020098 FILES "doctest/doctest.h"
ncihnegnbc43fe42019-01-27 05:28:54 -080099 DESTINATION "${include_install_dir}/doctest"
NeverMine17b63bf852017-10-28 16:06:43 +0300100 )
Giuseppe Robertie01299b2017-03-26 14:18:59 +0200101
NeverMine17b63bf852017-10-28 16:06:43 +0300102 install(
103 FILES "${project_config}" "${version_config}"
104 DESTINATION "${config_install_dir}"
105 )
Giuseppe Robertie01299b2017-03-26 14:18:59 +0200106
NeverMine17b63bf852017-10-28 16:06:43 +0300107 install(
108 EXPORT "${targets_export_name}"
109 NAMESPACE "${namespace}"
110 DESTINATION "${config_install_dir}"
111 )
112endif()