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
chore(cmake): adopt submodule-first deps and standardize FetchContent usage
- Adopt a "submodule-first, FetchContent-fallback" strategy for third-party dependencies:
- Default `*_FETCHCONTENT` to OFF in top-level `CMakeLists.txt` and prefer pinned submodules under `3rdparty/`.
- Each `cmake/*.cmake` module auto-detects a local submodule and enables FetchContent only as a fallback when the submodule is absent.
- Auto-detection is non-authoritative (does not FORCE cache values) so `-D` overrides from users take precedence; a sanity check fails when the user explicitly requests both modes.
- Add and pin third-party submodules (commits/tags):
- `3rdparty/spdlog` (pinned)
- `3rdparty/fmt` (pinned to 8.1.1)
- `3rdparty/httplib` (pinned to v0.22.0)
- `3rdparty/skywalking-data-collect-protocol` (pinned to v10.3.0)
- `3rdparty/grpc` (pinned to v1.74.1)
- Standardize FetchContent declarations:
- Use `GIT_REPOSITORY` + `GIT_TAG` (via `*_GIT_URL` / `*_GIT_TAG` variables) for FetchContent where appropriate so pins can be tags or commit SHAs.
- For gRPC, support archive or git+tag; when using git clone, initialize nested submodules after `FetchContent_Populate`.
- Move and tidy dependency logic:
- Move auto-detection and conflict validation into each dependency module (`cmake/*.cmake`) to keep `CMakeLists.txt` lean.
- Disable `*_FETCHCONTENT` automatically only when the submodule is present and the user has not explicitly requested FetchContent.
- CI and docs:
- Update CI (`.github/workflows/main.yml`) to checkout submodules recursively and build gRPC from `3rdparty/grpc`.
- Update `README.md` documenting submodule-first workflow, FetchContent fallback, `GIT_REPOSITORY+GIT_TAG` usage, and the bump procedure.
- Additions and refactors:
- Add `cmake/skywalking.cmake` and expose `SKYWALKING_PROTOCOL_PATH` for `proto2cpp`.
- Harmonize FetchContent usage and expose `*_GIT_URL` / `*_GIT_TAG` variables for maintainability.
Why
- Improves reproducibility and developer ergonomics by making dependency pins explicit and consistent.
- Allows local `-D` overrides for advanced use-cases or debugging while keeping CI deterministic.
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This repository pins several third-party dependencies under `3rdparty/` (example: `spdlog`, `fmt`, `httplib`, `skywalking-data-collect-protocol`). The top-level CMake will auto-detect these submodules and use them via `add_subdirectory()`.
46
+
47
+
- FetchContent fallback (automatic clone at configure time):
48
+
49
+
If a submodule is not present, CMake can automatically download the dependency at configure time using FetchContent. This is controlled by CMake options of the form `-D<LIB>_FETCHCONTENT=ON`.
50
+
51
+
Important: this project now defaults `*_FETCHCONTENT` to `OFF` to favour a submodule-first workflow (reproducible builds). Each dependency module will auto-detect a local `3rdparty/<lib>` submodule and, unless you explicitly set the corresponding `-D` option, enable the submodule and only enable FetchContent as a fallback when the submodule is absent.
52
+
53
+
FetchContent is declared uniformly using `GIT_REPOSITORY` + `GIT_TAG` where possible so the build can be pinned to a tag or an exact commit SHA. We strongly encourage this pattern because it makes bumps and temporary testing against a branch/commit straightforward.
54
+
55
+
Recommended FetchContent pattern (preferred)
56
+
57
+
```cmake
58
+
# variables make bumps easy and visible in the cmake file
In this repository we prefer the archive approach for gRPC in CI for simplicity, but the git+tag approach is supported and useful for local testing or when you need to pin to a commit SHA.
90
+
91
+
If you need to force FetchContent for any dependency (for example, to debug or when you prefer not to initialize submodules), you can pass `-D<LIB>_FETCHCONTENT=ON` on the `cmake` command line. If you pass conflicting options (both `-D<LIB>_AS_SUBMODULE=ON` and `-D<LIB>_FETCHCONTENT=ON`) CMake will stop with a helpful error and you must choose one.
92
+
93
+
For SkyWalking you can enable FetchContent with:
94
+
95
+
```bash
96
+
cmake -DSKYWALKING_FETCHCONTENT=ON -S . -B build
97
+
cmake --build build
98
+
```
99
+
100
+
- Explicit path (developer workflow):
101
+
102
+
If you already have a local checkout of `skywalking-data-collect-protocol`, point CMake to it:
Most third-party dependencies follow the same pattern: prefer the pinned submodule under `3rdparty/` (submodule-first) and fall back to `FetchContent` at configure time when the submodule is not present. See the top-level `CMakeLists.txt` and the modules in `cmake/` for details.
112
+
113
+
There are two cases worth calling out because their consumption/build steps differ slightly:
114
+
115
+
- gRPC
116
+
117
+
gRPC is not header-only and typically needs configuration and a build step (or its targets must be available via `find_package`). This repository includes a pinned copy of gRPC at `3rdparty/grpc` (tag `v1.74.1`) so builds are reproducible. CI is configured to build gRPC from that submodule.
118
+
119
+
To build gRPC locally from the submodule and install it for the rest of the project:
If you prefer not to use the submodule you can still clone and build gRPC separately and make its CMake targets available to the project, but using the pinned submodule is recommended for reproducibility.
139
+
140
+
- skywalking-data-collect-protocol (protobufs)
141
+
142
+
The SkyWalking protocol repository contains the protobuf definitions used to generate code for the project. The `cmake/skywalking.cmake` module sets `SKYWALKING_PROTOCOL_PATH` when the `3rdparty/skywalking-data-collect-protocol` submodule is present so the proto generation step can locate the `.proto` files.
143
+
144
+
You can override that behavior by supplying an explicit path:
Alternatively, enable FetchContent for SkyWalking with `-DSKYWALKING_FETCHCONTENT=ON` to let CMake fetch the proto repo at configure time.
152
+
153
+
How to bump a submodule (example for skywalking-data-collect-protocol):
154
+
```bash
155
+
cd 3rdparty/skywalking-data-collect-protocol
156
+
git fetch --tags
157
+
git checkout tags/v10.4.0 # or a specific commit
158
+
cd ../..
159
+
git add 3rdparty/skywalking-data-collect-protocol
160
+
git commit -m "Pin skywalking-data-collect-protocol to v10.4.0"
161
+
git push
162
+
```
163
+
164
+
If you prefer CI to always fetch the latest submodules, ensure the workflow initializes submodules (this repo's CI uses `actions/checkout` with `submodules: 'recursive'`).
165
+
45
166
You can also use find_package to get target libary in your project. Like this:
0 commit comments