blob: 4d0d3175000698bb5f997f0eb69e47273c75b70a [file] [log] [blame]
onqtamb8220c52017-05-16 00:21:15 +03001<!DOCTYPE html>
2<html>
3<title>build-systems</title>
4<xmp theme="united" style="display:none;">
5
6## Build systems
7
8The latest released version of doctest can be obtained from here: https://raw.githubusercontent.com/onqtam/doctest/master/doctest/doctest.h
9
onqtamf8d57192018-08-23 16:02:12 +030010You can substitute ```master``` with ```dev``` or a tag like ```1.2.9``` for a specific version in the URL above.
onqtamb8220c52017-05-16 00:21:15 +030011
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
17cmake_minimum_required(VERSION 3.0)
onqtam50146342019-08-12 22:29:59 +030018project(cmake_test VERSION 0.0.1 LANGUAGES CXX)
onqtamb8220c52017-05-16 00:21:15 +030019
20# Prepare doctest for other targets to use
onqtam50146342019-08-12 22:29:59 +030021find_package(doctest REQUIRED)
onqtamb8220c52017-05-16 00:21:15 +030022
23# Make test executable
24add_executable(tests main.cpp)
onqtam50146342019-08-12 22:29:59 +030025target_compile_features(test PRIVATE cxx_std_17)
26target_link_libraries(test PRIVATE doctest::doctest)
onqtamb8220c52017-05-16 00:21:15 +030027```
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
32include(ExternalProject)
33find_package(Git REQUIRED)
34
35ExternalProject_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
48ExternalProject_Get_Property(doctest source_dir)
49set(DOCTEST_INCLUDE_DIR ${source_dir}/doctest CACHE INTERNAL "Path to include folder for doctest")
50```
51
52And later you'll be able to use the doctest include directory like this:
53
54```cmake
55# add it globally
56include_directories(${DOCTEST_INCLUDE_DIR})
57
58# or per target
59target_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
65add_executable(my_tests src_1.cpp src_2.cpp ...)
66target_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
onqtama52e94b2019-06-02 17:42:14 +030071- 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
onqtamb8220c52017-05-16 00:21:15 +030073### Package managers
74
75**doctest** is available through the following package managers:
76
77- vcpkg
78- hunter
79- conan
onqtam8cec9172018-02-06 23:34:14 +020080 - https://bintray.com/bincrafters/public-conan/doctest:bincrafters
81 - https://bintray.com/mmha/conan/doctest%3Ammha
onqtam70531102020-06-27 09:58:35 +030082- Homebrew (`brew install doctest`)
onqtamb8220c52017-05-16 00:21:15 +030083
84---
85
86[Home](readme.html#reference)
87
onqtamf8d57192018-08-23 16:02:12 +030088<p align="center"><img src="../../scripts/data/logo/icon_2.svg"></p>
89
onqtamb8220c52017-05-16 00:21:15 +030090
91</xmp>
92<script src="strapdown.js/strapdown.js"></script>
93</html>