You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proper use of `FetchContent` requires sequencing all calls to
`FetchContent_Declare` before any calls to `FetchContent_MakeAvailable`.
This allows dependencies with similar `FetchContent` calls to coalesce
their declarations, so that projects don't end up repeatedly downloading
and building identical packages.
We introduce a directory dedicated to third-party packages for two
reasons:
1. Moving all of the third-party packages into a single directory
improves readability, as it becomes more apparent that calls to
`FetchContent_Declare` and `FetchContent_MakeAvailable` are correctly
sequenced.
2. Providing each third-party package with its own directory allows us
to colocate the `FindPackage_Declare` with any relevant project-local
patches. There aren't any at present, so we document how this ought
to be done below.
libdwarf and libunwind are still handled in `/CMakeLists.txt`. Their
requirements seem to be substantially more complicated than all other
third-party packages, so we'll migrate them into `/third_party` at a
later time.
**How to patch a third-party package**
Suppose googletest needed to be updated, and requires a local patch so
cpptrace can continue to support C++11. To integrate this with
FetchContent, we:
1. Make the necessary changes in our local fork of `google/googletest`.
2. Run `git format-patch @{u} -o /path/to/cpptrace/third_party/googletest`
to generate the patch files directly into `/third_party/googletest`.
3. Edit `/third_party/googletest/CMakeLists.txt` like so:
```
FetchContent_Declare(
"${package_name}"
GIT_REPOSITORY "https://github.com/google/googletest.git"
- GIT_TAG release-v1.12.1 # last to support C++11
+ GIT_TAG v1.17.0
+ PATCH_COMMAND git am 0001-makes-foo-c++11-compatible.patch
+ 0002-makes-bar-c++11-compatible.patch
+ 0003-makes-baz-c++11-compatible.patch
OVERRIDE_FIND_PACKAGE
SYSTEM
)
```
This will apply the patches during the `FetchContent` process, and
because all the `FetchContent_Declare`s come first, it will ensure that
the patches aren't clobbered by any dependencies.
0 commit comments