Joshua Goins | 3a01ec3 | 2024-01-08 09:16:29 +0000 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.5) |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 2 | |
Denilson das Mercês Amorim | b2d1677 | 2020-04-29 17:57:53 -0300 | [diff] [blame] | 3 | if(POLICY CMP0077) |
| 4 | cmake_policy(SET CMP0077 NEW) |
| 5 | endif() |
| 6 | |
onqtam | bff67f7 | 2017-04-16 20:04:32 +0300 | [diff] [blame] | 7 | ################################################################################ |
| 8 | ## DOCTEST |
| 9 | ################################################################################ |
| 10 | |
| 11 | file(READ ${CMAKE_CURRENT_SOURCE_DIR}/scripts/version.txt ver) |
zhihaoy | 7df0644 | 2019-08-05 06:44:23 -0500 | [diff] [blame] | 12 | project(doctest VERSION ${ver} LANGUAGES CXX) |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 13 | |
Martin Stump | 4d345d8 | 2020-12-15 11:36:37 +0100 | [diff] [blame] | 14 | # Determine if doctest is built as a subproject (using add_subdirectory) or if it is the main project. |
| 15 | set(MAIN_PROJECT OFF) |
| 16 | if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) |
| 17 | set(MAIN_PROJECT ON) |
| 18 | endif() |
| 19 | |
| 20 | option(DOCTEST_WITH_TESTS "Build tests/examples" ${MAIN_PROJECT}) |
onqtam | 36e3745 | 2019-03-02 20:10:05 +0200 | [diff] [blame] | 21 | option(DOCTEST_WITH_MAIN_IN_STATIC_LIB "Build a static lib (cmake target) with a default main entry point" ON) |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 22 | option(DOCTEST_NO_INSTALL "Skip the installation process" OFF) |
avostrik | 51e4a0d | 2020-09-04 17:49:49 +0300 | [diff] [blame] | 23 | option(DOCTEST_USE_STD_HEADERS "Use std headers" OFF) |
Giuseppe Roberti | f3425ae | 2017-03-28 02:03:50 +0200 | [diff] [blame] | 24 | |
onqtam | 61954c3 | 2017-04-16 17:22:44 +0300 | [diff] [blame] | 25 | add_library(${PROJECT_NAME} INTERFACE) |
Trond H Emaus | de04576 | 2019-06-24 00:57:25 +0200 | [diff] [blame] | 26 | add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) |
onqtam | 36e3745 | 2019-03-02 20:10:05 +0200 | [diff] [blame] | 27 | |
BerengerBerthoul | 8aeb798 | 2020-10-29 14:49:02 +0100 | [diff] [blame] | 28 | if(NOT CMAKE_VERSION VERSION_LESS 3.8) |
Viktor Kirilov | 10101a1 | 2019-08-11 18:16:08 +0300 | [diff] [blame] | 29 | target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11) |
| 30 | endif() |
| 31 | |
onqtam | f80b3f0 | 2019-03-24 10:19:09 +0200 | [diff] [blame] | 32 | set(doctest_parts_folder "${CMAKE_CURRENT_SOURCE_DIR}/doctest/parts") |
BerengerBerthoul | 8aeb798 | 2020-10-29 14:49:02 +0100 | [diff] [blame] | 33 | set(doctest_folder "${CMAKE_CURRENT_SOURCE_DIR}/") # in order to have the mpi extension files, not included into the doctest.h single header |
onqtam | f80b3f0 | 2019-03-24 10:19:09 +0200 | [diff] [blame] | 34 | |
Martin Stump | 4d345d8 | 2020-12-15 11:36:37 +0100 | [diff] [blame] | 35 | if(MAIN_PROJECT) |
onqtam | b22d878 | 2019-03-24 13:29:57 +0200 | [diff] [blame] | 36 | # use a special hidden version of the header which directly includes the 2 parts - proper reporting of file/line locations during dev |
onqtam | 36e3745 | 2019-03-02 20:10:05 +0200 | [diff] [blame] | 37 | target_include_directories(${PROJECT_NAME} INTERFACE |
| 38 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/scripts/development_only/> |
BerengerBerthoul | 8aeb798 | 2020-10-29 14:49:02 +0100 | [diff] [blame] | 39 | $<BUILD_INTERFACE:${doctest_parts_folder}> |
| 40 | $<BUILD_INTERFACE:${doctest_folder}>) |
onqtam | f80b3f0 | 2019-03-24 10:19:09 +0200 | [diff] [blame] | 41 | |
| 42 | # add a custom target that assembles the single header when any of the parts are touched |
| 43 | add_custom_command( |
| 44 | OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/doctest/doctest.h |
| 45 | DEPENDS |
| 46 | ${doctest_parts_folder}/doctest_fwd.h |
| 47 | ${doctest_parts_folder}/doctest.cpp |
| 48 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/assemble_single_header.cmake |
| 49 | COMMENT "assembling the single header") |
| 50 | |
| 51 | add_custom_target(assemble_single_header ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/doctest/doctest.h) |
onqtam | 36e3745 | 2019-03-02 20:10:05 +0200 | [diff] [blame] | 52 | else() |
| 53 | target_include_directories(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>) |
| 54 | endif() |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 55 | |
Navin P | 55c930c | 2023-03-15 11:42:11 +0530 | [diff] [blame] | 56 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 57 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 58 | if (NOT WIN32) |
| 59 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gdwarf-4 ") |
| 60 | endif() |
| 61 | endif() |
| 62 | endif() |
| 63 | |
Dimitrij Mijoski | 0dbbd4f | 2019-03-02 17:37:34 +0100 | [diff] [blame] | 64 | # hack to support building on XCode 6 and 7 - propagate the definition to everything |
| 65 | if(DEFINED DOCTEST_THREAD_LOCAL) |
| 66 | target_compile_definitions(${PROJECT_NAME} INTERFACE |
| 67 | DOCTEST_THREAD_LOCAL=${DOCTEST_THREAD_LOCAL}) |
| 68 | endif() |
| 69 | |
avostrik | 51e4a0d | 2020-09-04 17:49:49 +0300 | [diff] [blame] | 70 | if(DOCTEST_USE_STD_HEADERS) |
| 71 | target_compile_definitions(${PROJECT_NAME} INTERFACE DOCTEST_CONFIG_USE_STD_HEADERS) |
| 72 | endif() |
| 73 | |
onqtam | b759fb4 | 2017-08-01 18:38:26 +0300 | [diff] [blame] | 74 | ################################################################################ |
| 75 | ## TESTS/EXAMPLES/HELPERS |
| 76 | ################################################################################ |
Yordan Madzhunkov | 7d8af91 | 2017-06-26 12:20:57 +0300 | [diff] [blame] | 77 | |
Dimitrij Mijoski | 02d4c9b | 2019-03-14 15:09:37 +0100 | [diff] [blame] | 78 | if(${DOCTEST_WITH_MAIN_IN_STATIC_LIB}) |
onqtam | f80b3f0 | 2019-03-24 10:19:09 +0200 | [diff] [blame] | 79 | add_library(${PROJECT_NAME}_with_main STATIC EXCLUDE_FROM_ALL ${doctest_parts_folder}/doctest.cpp) |
Jesse Stricker | 302f158 | 2022-02-17 20:28:20 +0100 | [diff] [blame] | 80 | add_library(${PROJECT_NAME}::${PROJECT_NAME}_with_main ALIAS ${PROJECT_NAME}_with_main) |
Dimitrij Mijoski | 0dbbd4f | 2019-03-02 17:37:34 +0100 | [diff] [blame] | 81 | target_compile_definitions(${PROJECT_NAME}_with_main PRIVATE |
| 82 | DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN) |
Viktor Kirilov | 10101a1 | 2019-08-11 18:16:08 +0300 | [diff] [blame] | 83 | set_target_properties(${PROJECT_NAME}_with_main PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) |
Dimitrij Mijoski | 02d4c9b | 2019-03-14 15:09:37 +0100 | [diff] [blame] | 84 | target_link_libraries(${PROJECT_NAME}_with_main PUBLIC ${PROJECT_NAME}) |
onqtam | b759fb4 | 2017-08-01 18:38:26 +0300 | [diff] [blame] | 85 | endif() |
onqtam | cc9e865 | 2016-08-02 14:23:38 +0300 | [diff] [blame] | 86 | |
Martin Stump | 4d345d8 | 2020-12-15 11:36:37 +0100 | [diff] [blame] | 87 | if(MAIN_PROJECT AND DOCTEST_WITH_TESTS) |
onqtam | 61954c3 | 2017-04-16 17:22:44 +0300 | [diff] [blame] | 88 | include(scripts/cmake/common.cmake) |
onqtam | f6d1a51 | 2017-05-01 13:56:12 +0300 | [diff] [blame] | 89 | |
| 90 | add_subdirectory(examples/all_features) |
Stefan | bf037c1 | 2022-01-20 13:06:51 +0100 | [diff] [blame] | 91 | add_subdirectory(examples/exe_with_static_libs) |
| 92 | add_subdirectory(examples/executable_dll_and_plugin) |
| 93 | add_subdirectory(examples/combining_the_same_tests_built_differently_in_multiple_shared_objects) |
| 94 | add_subdirectory(scripts/playground) |
| 95 | add_subdirectory(examples/mpi) |
Giuseppe Roberti | f3425ae | 2017-03-28 02:03:50 +0200 | [diff] [blame] | 96 | endif() |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 97 | |
Chris Apple | 66ff54a | 2023-03-24 05:36:22 -0700 | [diff] [blame] | 98 | set(DOCTEST_CMAKE_HELPER "${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/doctest.cmake" CACHE PATH "Absolute path to to doctest helper file. `include(${DOCTEST_CMAKE_HELPER})`") |
| 99 | |
onqtam | 61954c3 | 2017-04-16 17:22:44 +0300 | [diff] [blame] | 100 | ################################################################################ |
| 101 | ## PACKAGE SUPPORT |
| 102 | ################################################################################ |
| 103 | |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 104 | set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") |
| 105 | |
Harald | c123a69 | 2019-04-01 18:00:31 +0200 | [diff] [blame] | 106 | if(CMAKE_SYSTEM_NAME STREQUAL Linux) |
| 107 | include(GNUInstallDirs) |
| 108 | set(include_install_dir ${CMAKE_INSTALL_INCLUDEDIR}) |
| 109 | set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") |
| 110 | else() |
| 111 | set(include_install_dir "include") |
| 112 | set(config_install_dir "lib/cmake/${PROJECT_NAME}") |
| 113 | endif() |
| 114 | |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 115 | |
| 116 | set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") |
| 117 | set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") |
| 118 | set(targets_export_name "${PROJECT_NAME}Targets") |
| 119 | set(namespace "${PROJECT_NAME}::") |
| 120 | |
| 121 | include(CMakePackageConfigHelpers) |
Morris Hafner | f9d5d6a | 2019-04-16 06:34:07 +0100 | [diff] [blame] | 122 | |
| 123 | # CMake automatically adds an architecture compatibility check to make sure |
| 124 | # 32 and 64 bit code is not accidentally mixed. For a header-only library this |
| 125 | # is not required. The check can be disabled by temporarily unsetting |
| 126 | # CMAKE_SIZEOF_VOID_P. In CMake 3.14 and later this can be achieved more cleanly |
| 127 | # with write_basic_package_version_file(ARCH_INDEPENDENT). |
| 128 | # TODO: Use this once a newer CMake can be required. |
| 129 | set(DOCTEST_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) |
| 130 | unset(CMAKE_SIZEOF_VOID_P) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 131 | write_basic_package_version_file( |
Giuseppe Roberti | c89cf82 | 2017-04-12 17:14:17 +0200 | [diff] [blame] | 132 | "${version_config}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 133 | ) |
Morris Hafner | f9d5d6a | 2019-04-16 06:34:07 +0100 | [diff] [blame] | 134 | set(CMAKE_SIZEOF_VOID_P ${DOCTEST_SIZEOF_VOID_P}) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 135 | |
onqtam | 08cf7dc | 2017-04-16 11:37:22 +0300 | [diff] [blame] | 136 | configure_file("scripts/cmake/Config.cmake.in" "${project_config}" @ONLY) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 137 | |
onqtam | 17c9738 | 2019-03-24 09:24:02 +0200 | [diff] [blame] | 138 | if(NOT ${DOCTEST_NO_INSTALL}) |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 139 | install( |
| 140 | TARGETS ${PROJECT_NAME} |
| 141 | EXPORT "${targets_export_name}" |
| 142 | INCLUDES DESTINATION "${include_install_dir}" |
| 143 | ) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 144 | |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 145 | install( |
onqtam | 36e3745 | 2019-03-02 20:10:05 +0200 | [diff] [blame] | 146 | FILES "doctest/doctest.h" |
ncihnegn | bc43fe4 | 2019-01-27 05:28:54 -0800 | [diff] [blame] | 147 | DESTINATION "${include_install_dir}/doctest" |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 148 | ) |
BerengerBerthoul | 3860c12 | 2023-03-07 16:36:40 +0100 | [diff] [blame] | 149 | install( |
| 150 | DIRECTORY "doctest/extensions" |
| 151 | DESTINATION "${include_install_dir}/doctest" |
| 152 | FILES_MATCHING PATTERN "*.h" |
| 153 | ) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 154 | |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 155 | install( |
| 156 | FILES "${project_config}" "${version_config}" |
| 157 | DESTINATION "${config_install_dir}" |
| 158 | ) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 159 | |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 160 | install( |
Cristian Morales Vega | 35b339f | 2019-05-19 20:12:41 +0100 | [diff] [blame] | 161 | FILES "scripts/cmake/doctest.cmake" "scripts/cmake/doctestAddTests.cmake" |
| 162 | DESTINATION "${config_install_dir}" |
| 163 | ) |
| 164 | |
| 165 | install( |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 166 | EXPORT "${targets_export_name}" |
| 167 | NAMESPACE "${namespace}" |
| 168 | DESTINATION "${config_install_dir}" |
| 169 | ) |
| 170 | endif() |