onqtam | b8220c5 | 2017-05-16 00:21:15 +0300 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <title>build-systems</title> |
| 4 | <xmp theme="united" style="display:none;"> |
| 5 | |
| 6 | ## Build systems |
| 7 | |
| 8 | The latest released version of doctest can be obtained from here: https://raw.githubusercontent.com/onqtam/doctest/master/doctest/doctest.h |
| 9 | |
onqtam | f8d5719 | 2018-08-23 16:02:12 +0300 | [diff] [blame] | 10 | You can substitute ```master``` with ```dev``` or a tag like ```1.2.9``` for a specific version in the URL above. |
onqtam | b8220c5 | 2017-05-16 00:21:15 +0300 | [diff] [blame] | 11 | |
| 12 | ### CMake |
| 13 | |
| 14 | - **doctest** is easiest to use as a single file inside your own repository. Then the following minimal example will work: |
| 15 | |
| 16 | ```cmake |
| 17 | cmake_minimum_required(VERSION 3.0) |
onqtam | 5014634 | 2019-08-12 22:29:59 +0300 | [diff] [blame] | 18 | project(cmake_test VERSION 0.0.1 LANGUAGES CXX) |
onqtam | b8220c5 | 2017-05-16 00:21:15 +0300 | [diff] [blame] | 19 | |
| 20 | # Prepare doctest for other targets to use |
onqtam | 5014634 | 2019-08-12 22:29:59 +0300 | [diff] [blame] | 21 | find_package(doctest REQUIRED) |
onqtam | b8220c5 | 2017-05-16 00:21:15 +0300 | [diff] [blame] | 22 | |
| 23 | # Make test executable |
| 24 | add_executable(tests main.cpp) |
onqtam | 5014634 | 2019-08-12 22:29:59 +0300 | [diff] [blame] | 25 | target_compile_features(test PRIVATE cxx_std_17) |
| 26 | target_link_libraries(test PRIVATE doctest::doctest) |
onqtam | b8220c5 | 2017-05-16 00:21:15 +0300 | [diff] [blame] | 27 | ``` |
| 28 | |
| 29 | - You can also use the following CMake snippet to automatically fetch the entire **doctest** repository from github and configure it as an external project: |
| 30 | |
| 31 | ```cmake |
| 32 | include(ExternalProject) |
| 33 | find_package(Git REQUIRED) |
| 34 | |
| 35 | ExternalProject_Add( |
| 36 | doctest |
| 37 | PREFIX ${CMAKE_BINARY_DIR}/doctest |
| 38 | GIT_REPOSITORY https://github.com/onqtam/doctest.git |
| 39 | TIMEOUT 10 |
| 40 | UPDATE_COMMAND ${GIT_EXECUTABLE} pull |
| 41 | CONFIGURE_COMMAND "" |
| 42 | BUILD_COMMAND "" |
| 43 | INSTALL_COMMAND "" |
| 44 | LOG_DOWNLOAD ON |
| 45 | ) |
| 46 | |
| 47 | # Expose required variable (DOCTEST_INCLUDE_DIR) to parent scope |
| 48 | ExternalProject_Get_Property(doctest source_dir) |
| 49 | set(DOCTEST_INCLUDE_DIR ${source_dir}/doctest CACHE INTERNAL "Path to include folder for doctest") |
| 50 | ``` |
| 51 | |
| 52 | And later you'll be able to use the doctest include directory like this: |
| 53 | |
| 54 | ```cmake |
| 55 | # add it globally |
| 56 | include_directories(${DOCTEST_INCLUDE_DIR}) |
| 57 | |
| 58 | # or per target |
| 59 | target_include_directories(my_target PUBLIC ${DOCTEST_INCLUDE_DIR}) |
| 60 | ``` |
| 61 | |
| 62 | - If you have the entire doctest repository available (as a submodule or just as files) you could also include it in your CMake build by using ```add_subdirectory(path/to/doctest)``` and then you could use it like this: |
| 63 | |
| 64 | ```cmake |
| 65 | add_executable(my_tests src_1.cpp src_2.cpp ...) |
| 66 | target_link_libraries(my_tests doctest) |
| 67 | ``` |
| 68 | |
| 69 | - The ```CMakeLists.txt``` file of the doctest repository has ```install()``` commands so you could also use doctest as a package. |
| 70 | |
onqtam | a52e94b | 2019-06-02 17:42:14 +0300 | [diff] [blame] | 71 | - To discover tests from an executable and register them in ctest you could use [```doctest_discover_tests(<target>)``` from scripts/cmake/doctest.cmake](../../scripts/cmake/doctest.cmake) - read the comments in the file on how to use it. It works just like [the same functionality in Catch](https://github.com/catchorg/Catch2/blob/master/docs/cmake-integration.html#automatic-test-registration). |
| 72 | |
onqtam | b8220c5 | 2017-05-16 00:21:15 +0300 | [diff] [blame] | 73 | ### Package managers |
| 74 | |
| 75 | **doctest** is available through the following package managers: |
| 76 | |
| 77 | - vcpkg |
| 78 | - hunter |
| 79 | - conan |
onqtam | 8cec917 | 2018-02-06 23:34:14 +0200 | [diff] [blame] | 80 | - https://bintray.com/bincrafters/public-conan/doctest:bincrafters |
| 81 | - https://bintray.com/mmha/conan/doctest%3Ammha |
onqtam | 7053110 | 2020-06-27 09:58:35 +0300 | [diff] [blame^] | 82 | - Homebrew (`brew install doctest`) |
onqtam | b8220c5 | 2017-05-16 00:21:15 +0300 | [diff] [blame] | 83 | |
| 84 | --- |
| 85 | |
| 86 | [Home](readme.html#reference) |
| 87 | |
onqtam | f8d5719 | 2018-08-23 16:02:12 +0300 | [diff] [blame] | 88 | <p align="center"><img src="../../scripts/data/logo/icon_2.svg"></p> |
| 89 | |
onqtam | b8220c5 | 2017-05-16 00:21:15 +0300 | [diff] [blame] | 90 | |
| 91 | </xmp> |
| 92 | <script src="strapdown.js/strapdown.js"></script> |
| 93 | </html> |