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