blob: 1719cacc67e509242c563d866b69021db87a597b [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
onqtamb22d8782019-03-24 13:29:57 +020010option(DOCTEST_WITH_TESTS "Build tests/examples" ON)
onqtam36e37452019-03-02 20:10:05 +020011option(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 +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)
onqtam36e37452019-03-02 20:10:05 +020015
onqtamf80b3f02019-03-24 10:19:09 +020016set(doctest_parts_folder "${CMAKE_CURRENT_SOURCE_DIR}/doctest/parts")
17
onqtam36e37452019-03-02 20:10:05 +020018if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
onqtamb22d8782019-03-24 13:29:57 +020019 # use a special hidden version of the header which directly includes the 2 parts - proper reporting of file/line locations during dev
onqtam36e37452019-03-02 20:10:05 +020020 target_include_directories(${PROJECT_NAME} INTERFACE
21 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/scripts/development_only/>
onqtamf80b3f02019-03-24 10:19:09 +020022 $<BUILD_INTERFACE:${doctest_parts_folder}>)
23
24 # add a custom target that assembles the single header when any of the parts are touched
25 add_custom_command(
26 OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/doctest/doctest.h
27 DEPENDS
28 ${doctest_parts_folder}/doctest_fwd.h
29 ${doctest_parts_folder}/doctest.cpp
30 COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/assemble_single_header.cmake
31 COMMENT "assembling the single header")
32
33 add_custom_target(assemble_single_header ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/doctest/doctest.h)
onqtam36e37452019-03-02 20:10:05 +020034else()
35 target_include_directories(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>)
36endif()
onqtam4a655632016-05-26 14:20:52 +030037
Dimitrij Mijoski0dbbd4f2019-03-02 17:37:34 +010038# hack to support building on XCode 6 and 7 - propagate the definition to everything
39if(DEFINED DOCTEST_THREAD_LOCAL)
40 target_compile_definitions(${PROJECT_NAME} INTERFACE
41 DOCTEST_THREAD_LOCAL=${DOCTEST_THREAD_LOCAL})
42endif()
43
onqtamb759fb42017-08-01 18:38:26 +030044################################################################################
45## TESTS/EXAMPLES/HELPERS
46################################################################################
Yordan Madzhunkov7d8af912017-06-26 12:20:57 +030047
Dimitrij Mijoski02d4c9b2019-03-14 15:09:37 +010048if(${DOCTEST_WITH_MAIN_IN_STATIC_LIB})
onqtamf80b3f02019-03-24 10:19:09 +020049 add_library(${PROJECT_NAME}_with_main STATIC EXCLUDE_FROM_ALL ${doctest_parts_folder}/doctest.cpp)
Dimitrij Mijoski0dbbd4f2019-03-02 17:37:34 +010050 target_compile_definitions(${PROJECT_NAME}_with_main PRIVATE
51 DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN)
Dimitrij Mijoski02d4c9b2019-03-14 15:09:37 +010052 target_link_libraries(${PROJECT_NAME}_with_main PUBLIC ${PROJECT_NAME})
onqtamb759fb42017-08-01 18:38:26 +030053endif()
onqtamcc9e8652016-08-02 14:23:38 +030054
onqtamb22d8782019-03-24 13:29:57 +020055if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR AND DOCTEST_WITH_TESTS)
onqtam61954c32017-04-16 17:22:44 +030056 include(scripts/cmake/common.cmake)
onqtamf6d1a512017-05-01 13:56:12 +030057
58 add_subdirectory(examples/all_features)
onqtamaec53d22017-05-03 06:29:47 +030059
onqtamc6cc9ff2019-03-15 17:22:50 +020060 # for code coverage we want exactly one binary to be produced and exercised
onqtamaec53d22017-05-03 06:29:47 +030061 if(NOT DEFINED ENV{CODE_COVERAGE})
62 add_subdirectory(examples/exe_with_static_libs)
63 add_subdirectory(examples/executable_dll_and_plugin)
64 add_subdirectory(scripts/playground)
65 endif()
Giuseppe Robertif3425ae2017-03-28 02:03:50 +020066endif()
Giuseppe Robertie01299b2017-03-26 14:18:59 +020067
onqtam61954c32017-04-16 17:22:44 +030068################################################################################
69## PACKAGE SUPPORT
70################################################################################
71
Giuseppe Robertie01299b2017-03-26 14:18:59 +020072set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
73
Haraldc123a692019-04-01 18:00:31 +020074if(CMAKE_SYSTEM_NAME STREQUAL Linux)
75 include(GNUInstallDirs)
76 set(include_install_dir ${CMAKE_INSTALL_INCLUDEDIR})
77 set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
78else()
79 set(include_install_dir "include")
80 set(config_install_dir "lib/cmake/${PROJECT_NAME}")
81endif()
82
Giuseppe Robertie01299b2017-03-26 14:18:59 +020083
84set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
85set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
86set(targets_export_name "${PROJECT_NAME}Targets")
87set(namespace "${PROJECT_NAME}::")
88
89include(CMakePackageConfigHelpers)
90write_basic_package_version_file(
Giuseppe Robertic89cf822017-04-12 17:14:17 +020091 "${version_config}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion
Giuseppe Robertie01299b2017-03-26 14:18:59 +020092)
93
onqtam08cf7dc2017-04-16 11:37:22 +030094configure_file("scripts/cmake/Config.cmake.in" "${project_config}" @ONLY)
Giuseppe Robertie01299b2017-03-26 14:18:59 +020095
onqtam17c97382019-03-24 09:24:02 +020096if(NOT ${DOCTEST_NO_INSTALL})
NeverMine17b63bf852017-10-28 16:06:43 +030097 install(
98 TARGETS ${PROJECT_NAME}
99 EXPORT "${targets_export_name}"
100 INCLUDES DESTINATION "${include_install_dir}"
101 )
Giuseppe Robertie01299b2017-03-26 14:18:59 +0200102
NeverMine17b63bf852017-10-28 16:06:43 +0300103 install(
onqtam36e37452019-03-02 20:10:05 +0200104 FILES "doctest/doctest.h"
ncihnegnbc43fe42019-01-27 05:28:54 -0800105 DESTINATION "${include_install_dir}/doctest"
NeverMine17b63bf852017-10-28 16:06:43 +0300106 )
Giuseppe Robertie01299b2017-03-26 14:18:59 +0200107
NeverMine17b63bf852017-10-28 16:06:43 +0300108 install(
109 FILES "${project_config}" "${version_config}"
110 DESTINATION "${config_install_dir}"
111 )
Giuseppe Robertie01299b2017-03-26 14:18:59 +0200112
NeverMine17b63bf852017-10-28 16:06:43 +0300113 install(
114 EXPORT "${targets_export_name}"
115 NAMESPACE "${namespace}"
116 DESTINATION "${config_install_dir}"
117 )
118endif()