onqtam | c7aaa96 | 2016-09-10 02:16:57 +0300 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.0) |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 2 | |
onqtam | bff67f7 | 2017-04-16 20:04:32 +0300 | [diff] [blame] | 3 | ################################################################################ |
| 4 | ## DOCTEST |
| 5 | ################################################################################ |
| 6 | |
| 7 | file(READ ${CMAKE_CURRENT_SOURCE_DIR}/scripts/version.txt ver) |
| 8 | project(doctest VERSION ${ver}) |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 9 | |
onqtam | 36e3745 | 2019-03-02 20:10:05 +0200 | [diff] [blame^] | 10 | 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] | 11 | option(DOCTEST_NO_INSTALL "Skip the installation process" OFF) |
Giuseppe Roberti | f3425ae | 2017-03-28 02:03:50 +0200 | [diff] [blame] | 12 | |
onqtam | 61954c3 | 2017-04-16 17:22:44 +0300 | [diff] [blame] | 13 | add_library(${PROJECT_NAME} INTERFACE) |
onqtam | 36e3745 | 2019-03-02 20:10:05 +0200 | [diff] [blame^] | 14 | |
| 15 | # use a special hidden version of the doctest header which directly includes the 2 parts - much easier during development |
| 16 | if(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/>) |
| 21 | else() |
| 22 | target_include_directories(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>) |
| 23 | endif() |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 24 | |
Dimitrij Mijoski | 0dbbd4f | 2019-03-02 17:37:34 +0100 | [diff] [blame] | 25 | # hack to support building on XCode 6 and 7 - propagate the definition to everything |
| 26 | if(DEFINED DOCTEST_THREAD_LOCAL) |
| 27 | target_compile_definitions(${PROJECT_NAME} INTERFACE |
| 28 | DOCTEST_THREAD_LOCAL=${DOCTEST_THREAD_LOCAL}) |
| 29 | endif() |
| 30 | |
| 31 | # add a custom target that assembles the single header when any of the parts are touched |
| 32 | |
| 33 | set(doctest_parts_folder "${CMAKE_CURRENT_SOURCE_DIR}/doctest/parts") |
| 34 | |
| 35 | add_custom_command( |
onqtam | 36e3745 | 2019-03-02 20:10:05 +0200 | [diff] [blame^] | 36 | OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/doctest/doctest.h |
Dimitrij Mijoski | 0dbbd4f | 2019-03-02 17:37:34 +0100 | [diff] [blame] | 37 | DEPENDS |
| 38 | ${doctest_parts_folder}/doctest_fwd.h |
| 39 | ${doctest_parts_folder}/doctest.cpp |
onqtam | 2870d77 | 2019-03-02 19:50:40 +0200 | [diff] [blame] | 40 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/assemble_single_header.cmake |
Dimitrij Mijoski | 0dbbd4f | 2019-03-02 17:37:34 +0100 | [diff] [blame] | 41 | COMMENT "assembling the single header") |
| 42 | |
onqtam | 36e3745 | 2019-03-02 20:10:05 +0200 | [diff] [blame^] | 43 | add_custom_target(assemble_single_header ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/doctest/doctest.h) |
Dimitrij Mijoski | 0dbbd4f | 2019-03-02 17:37:34 +0100 | [diff] [blame] | 44 | |
onqtam | b759fb4 | 2017-08-01 18:38:26 +0300 | [diff] [blame] | 45 | ################################################################################ |
| 46 | ## TESTS/EXAMPLES/HELPERS |
| 47 | ################################################################################ |
Yordan Madzhunkov | 7d8af91 | 2017-06-26 12:20:57 +0300 | [diff] [blame] | 48 | |
onqtam | 36e3745 | 2019-03-02 20:10:05 +0200 | [diff] [blame^] | 49 | if(${DOCTEST_WITH_MAIN_IN_STATIC_LIB} AND NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) |
onqtam | b759fb4 | 2017-08-01 18:38:26 +0300 | [diff] [blame] | 50 | include(scripts/cmake/common.cmake) |
Dimitrij Mijoski | 0dbbd4f | 2019-03-02 17:37:34 +0100 | [diff] [blame] | 51 | 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() |
onqtam | b759fb4 | 2017-08-01 18:38:26 +0300 | [diff] [blame] | 59 | endif() |
onqtam | cc9e865 | 2016-08-02 14:23:38 +0300 | [diff] [blame] | 60 | |
onqtam | 36e3745 | 2019-03-02 20:10:05 +0200 | [diff] [blame^] | 61 | if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) |
onqtam | 61954c3 | 2017-04-16 17:22:44 +0300 | [diff] [blame] | 62 | include(scripts/cmake/common.cmake) |
onqtam | f6d1a51 | 2017-05-01 13:56:12 +0300 | [diff] [blame] | 63 | |
| 64 | add_subdirectory(examples/all_features) |
onqtam | aec53d2 | 2017-05-03 06:29:47 +0300 | [diff] [blame] | 65 | |
| 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 Roberti | f3425ae | 2017-03-28 02:03:50 +0200 | [diff] [blame] | 71 | endif() |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 72 | |
onqtam | 61954c3 | 2017-04-16 17:22:44 +0300 | [diff] [blame] | 73 | ################################################################################ |
| 74 | ## PACKAGE SUPPORT |
| 75 | ################################################################################ |
| 76 | |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 77 | set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") |
| 78 | |
ncihnegn | bc43fe4 | 2019-01-27 05:28:54 -0800 | [diff] [blame] | 79 | set(include_install_dir "include") |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 80 | set(config_install_dir "lib/cmake/${PROJECT_NAME}") |
| 81 | |
| 82 | set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") |
| 83 | set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") |
| 84 | set(targets_export_name "${PROJECT_NAME}Targets") |
| 85 | set(namespace "${PROJECT_NAME}::") |
| 86 | |
| 87 | include(CMakePackageConfigHelpers) |
| 88 | write_basic_package_version_file( |
Giuseppe Roberti | c89cf82 | 2017-04-12 17:14:17 +0200 | [diff] [blame] | 89 | "${version_config}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 90 | ) |
| 91 | |
onqtam | 08cf7dc | 2017-04-16 11:37:22 +0300 | [diff] [blame] | 92 | configure_file("scripts/cmake/Config.cmake.in" "${project_config}" @ONLY) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 93 | |
Viktor Kirilov | 79a3798 | 2017-11-04 18:34:54 +0200 | [diff] [blame] | 94 | if (NOT ${DOCTEST_NO_INSTALL}) |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 95 | install( |
| 96 | TARGETS ${PROJECT_NAME} |
| 97 | EXPORT "${targets_export_name}" |
| 98 | INCLUDES DESTINATION "${include_install_dir}" |
| 99 | ) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 100 | |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 101 | install( |
onqtam | 36e3745 | 2019-03-02 20:10:05 +0200 | [diff] [blame^] | 102 | FILES "doctest/doctest.h" |
ncihnegn | bc43fe4 | 2019-01-27 05:28:54 -0800 | [diff] [blame] | 103 | DESTINATION "${include_install_dir}/doctest" |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 104 | ) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 105 | |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 106 | install( |
| 107 | FILES "${project_config}" "${version_config}" |
| 108 | DESTINATION "${config_install_dir}" |
| 109 | ) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 110 | |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 111 | install( |
| 112 | EXPORT "${targets_export_name}" |
| 113 | NAMESPACE "${namespace}" |
| 114 | DESTINATION "${config_install_dir}" |
| 115 | ) |
| 116 | endif() |