Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: document a simpler CMake integration via FetchContent #823

Open
gershnik opened this issue Nov 6, 2023 · 2 comments
Open

Suggestion: document a simpler CMake integration via FetchContent #823

gershnik opened this issue Nov 6, 2023 · 2 comments

Comments

@gershnik
Copy link

gershnik commented Nov 6, 2023

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.

@onqtam
Copy link
Member

onqtam commented Nov 7, 2023

Relevant:
#698
#821

I guess there's a few ways of doing it

@gershnik
Copy link
Author

gershnik commented Nov 7, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants