The latest released version of doctest can be obtained from here: https://raw.githubusercontent.com/doctest/doctest/master/doctest/doctest.h
You can substitute master
with dev
or a tag like v1.4.8
for a specific version in the URL above.
cmake_minimum_required(VERSION 3.0)
project(cmake_test VERSION 0.0.1 LANGUAGES CXX)
# Prepare doctest for other targets to use
find_package(doctest REQUIRED)
# Make test executable
add_executable(tests main.cpp)
target_compile_features(tests PRIVATE cxx_std_17)
target_link_libraries(tests PRIVATE doctest::doctest)
include(ExternalProject)
find_package(Git REQUIRED)
ExternalProject_Add(
doctest
PREFIX ${CMAKE_BINARY_DIR}/doctest
GIT_REPOSITORY https://github.com/doctest/doctest.git
TIMEOUT 10
UPDATE_COMMAND ${GIT_EXECUTABLE} pull
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
)
# Expose required variable (DOCTEST_INCLUDE_DIR) to parent scope
ExternalProject_Get_Property(doctest source_dir)
set(DOCTEST_INCLUDE_DIR ${source_dir}/doctest CACHE INTERNAL "Path to include folder for doctest")
And later you'll be able to use the doctest include directory like this:
# add it globally
include_directories(${DOCTEST_INCLUDE_DIR})
# or per target
target_include_directories(my_target PUBLIC ${DOCTEST_INCLUDE_DIR})
add_subdirectory(path/to/doctest)
and then you could use it like this:add_executable(my_tests src_1.cpp src_2.cpp ...)
target_link_libraries(my_tests doctest)
The CMakeLists.txt
file of the doctest repository has install()
commands so you could also use doctest as a package.
To discover tests from an executable and register them in ctest you could use doctest_discover_tests(<target>)
from scripts/cmake/doctest.cmake - read the comments in the file on how to use it. It works just like the same functionality in Catch.
doctest is available through the following package managers:
vcpkg
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh #.\bootstrap-vcpkg.bat(for windows)
./vcpkg integrate install
./vcpkg install doctest
hunter
conan
Homebrew (brew install doctest
)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。