doctest / doctest

The fastest feature-rich C++11/14/17/20/23 single-header testing framework

Home Page:https://bit.ly/doctest-docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion: document a simpler CMake integration via FetchContent

gershnik opened this issue · comments

Currently in build-systems.md the suggested CMake integrations are either via manual file download or ExternalProject.
The first is, well, manual and the second is heavyweight, cumbersome and downloads at build time (yikes!).

There is a much simpler way to integrate doctest using FetchContent.

Something like this:

include(FetchContent)

FetchContent_Declare(doctest
    URL  https://raw.githubusercontent.com/doctest/doctest/v2.4.11/doctest/doctest.h
    DOWNLOAD_NO_EXTRACT TRUE
    DOWNLOAD_EXTRACT_TIMESTAMP TRUE #for CMake 3.24 and higher
)
FetchContent_MakeAvailable(doctest)

set(DOCTEST_INCLUDE_DIR ${doctest_SOURCE_DIR})

This downloads just the header and does it during configure, not build, time.

If you think this is reasonable to document in addition or instead of ExternalProject method happy to submit a PR.

Relevant:
#698
#821

I guess there's a few ways of doing it

Ah, my issue search skills are obviously pretty bad, thank you!
However, the approach suggested in #698 and implemented in #821 is still suboptimal for doctest unless one needs doctest_discover_tests(<target>) functionality.
It works but it clones the GitHub repo and perform CMake configure on it. The library is a single header and none of it is really necessary.
The approach above is bare-bones and faster - only a single header is downloaded and no configuration is performed at all.

Thank you!