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 | b759fb4 | 2017-08-01 18:38:26 +0300 | [diff] [blame] | 10 | option(DOCTEST_WITH_TESTS "Build tests/examples" ON) |
| 11 | option(DOCTEST_WITH_MAIN_IN_STATIC_LIB "Build a static lib (cmake target) with a main entry point" ON) |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 12 | option(DOCTEST_NO_INSTALL "Skip the installation process" OFF) |
Giuseppe Roberti | f3425ae | 2017-03-28 02:03:50 +0200 | [diff] [blame] | 13 | |
onqtam | 61954c3 | 2017-04-16 17:22:44 +0300 | [diff] [blame] | 14 | add_library(${PROJECT_NAME} INTERFACE) |
| 15 | target_include_directories(${PROJECT_NAME} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/doctest/>) |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 16 | |
onqtam | b759fb4 | 2017-08-01 18:38:26 +0300 | [diff] [blame] | 17 | ################################################################################ |
| 18 | ## TESTS/EXAMPLES/HELPERS |
| 19 | ################################################################################ |
Yordan Madzhunkov | 7d8af91 | 2017-06-26 12:20:57 +0300 | [diff] [blame] | 20 | |
onqtam | b759fb4 | 2017-08-01 18:38:26 +0300 | [diff] [blame] | 21 | if(${DOCTEST_WITH_MAIN_IN_STATIC_LIB}) |
| 22 | include(scripts/cmake/common.cmake) |
| 23 | doctest_add_library(${PROJECT_NAME}_with_main STATIC EXCLUDE_FROM_ALL doctest/parts/doctest_main.cpp) |
| 24 | target_link_libraries(${PROJECT_NAME}_with_main PUBLIC ${PROJECT_NAME}) |
| 25 | endif() |
onqtam | cc9e865 | 2016-08-02 14:23:38 +0300 | [diff] [blame] | 26 | |
onqtam | 61954c3 | 2017-04-16 17:22:44 +0300 | [diff] [blame] | 27 | if(${DOCTEST_WITH_TESTS}) |
| 28 | include(scripts/cmake/common.cmake) |
onqtam | f6d1a51 | 2017-05-01 13:56:12 +0300 | [diff] [blame] | 29 | |
| 30 | add_subdirectory(examples/all_features) |
onqtam | aec53d2 | 2017-05-03 06:29:47 +0300 | [diff] [blame] | 31 | |
| 32 | if(NOT DEFINED ENV{CODE_COVERAGE}) |
| 33 | add_subdirectory(examples/exe_with_static_libs) |
| 34 | add_subdirectory(examples/executable_dll_and_plugin) |
| 35 | add_subdirectory(scripts/playground) |
| 36 | endif() |
Giuseppe Roberti | f3425ae | 2017-03-28 02:03:50 +0200 | [diff] [blame] | 37 | endif() |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 38 | |
onqtam | 61954c3 | 2017-04-16 17:22:44 +0300 | [diff] [blame] | 39 | ################################################################################ |
| 40 | ## PACKAGE SUPPORT |
| 41 | ################################################################################ |
| 42 | |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 43 | set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") |
| 44 | |
| 45 | set(include_install_dir "include/doctest/") |
| 46 | set(config_install_dir "lib/cmake/${PROJECT_NAME}") |
| 47 | |
| 48 | set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") |
| 49 | set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") |
| 50 | set(targets_export_name "${PROJECT_NAME}Targets") |
| 51 | set(namespace "${PROJECT_NAME}::") |
| 52 | |
| 53 | include(CMakePackageConfigHelpers) |
| 54 | write_basic_package_version_file( |
Giuseppe Roberti | c89cf82 | 2017-04-12 17:14:17 +0200 | [diff] [blame] | 55 | "${version_config}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 56 | ) |
| 57 | |
onqtam | 08cf7dc | 2017-04-16 11:37:22 +0300 | [diff] [blame] | 58 | configure_file("scripts/cmake/Config.cmake.in" "${project_config}" @ONLY) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 59 | |
Viktor Kirilov | 79a3798 | 2017-11-04 18:34:54 +0200 | [diff] [blame] | 60 | if (NOT ${DOCTEST_NO_INSTALL}) |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 61 | install( |
| 62 | TARGETS ${PROJECT_NAME} |
| 63 | EXPORT "${targets_export_name}" |
| 64 | INCLUDES DESTINATION "${include_install_dir}" |
| 65 | ) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 66 | |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 67 | install( |
| 68 | FILES "doctest/doctest.h" |
| 69 | DESTINATION "${include_install_dir}" |
| 70 | ) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 71 | |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 72 | install( |
| 73 | FILES "${project_config}" "${version_config}" |
| 74 | DESTINATION "${config_install_dir}" |
| 75 | ) |
Giuseppe Roberti | e01299b | 2017-03-26 14:18:59 +0200 | [diff] [blame] | 76 | |
NeverMine17 | b63bf85 | 2017-10-28 16:06:43 +0300 | [diff] [blame] | 77 | install( |
| 78 | EXPORT "${targets_export_name}" |
| 79 | NAMESPACE "${namespace}" |
| 80 | DESTINATION "${config_install_dir}" |
| 81 | ) |
| 82 | endif() |