doctest

FORK: The fastest feature-rich C++11/14/17/20 single-header testing framework
git clone https://git.neptards.moe/neptards/doctest.git
Log | Files | Refs | README

build-systems.html (3084B)


      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/doctest/doctest/master/doctest/doctest.h
      9 
     10 You can substitute ```master``` with ```dev``` or a tag like ```v1.4.8``` for a specific version in the URL above.
     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)
     18 project(cmake_test VERSION 0.0.1 LANGUAGES CXX)
     19 
     20 # Prepare doctest for other targets to use
     21 find_package(doctest REQUIRED)
     22 
     23 # Make test executable
     24 add_executable(tests main.cpp)
     25 target_compile_features(test PRIVATE cxx_std_17)
     26 target_link_libraries(test PRIVATE doctest::doctest)
     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/doctest/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 
     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 
     73 ### Package managers
     74 
     75 **doctest** is available through the following package managers:
     76 
     77 - vcpkg
     78 - hunter
     79 - conan
     80     - https://conan.io/center/doctest
     81     - https://github.com/conan-io/conan-center-index/tree/master/recipes/doctest
     82 - Homebrew (`brew install doctest`)
     83 
     84 ---
     85 
     86 [Home](readme.html#reference)
     87 
     88 <p align="center"><img src="../../scripts/data/logo/icon_2.svg"></p>
     89 
     90 
     91 </xmp>
     92 <script src="strapdown.js/strapdown.js"></script>
     93 </html>