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
Improve dependency mapping and version override support
Updated dependency mapping logic to distinguish between internal cpp-library and external dependencies, ensuring package names are collision-safe and consistent. Added support for overriding the version using the CPP_LIBRARY_VERSION variable, which is useful for package managers and CI systems without git history. Improved documentation in README.md to clarify dependency handling, target naming patterns, and version management. Refactored CMake scripts to align with these changes and updated comments for clarity.
Tags should follow [semantic versioning](https://semver.org/) (e.g., `v1.0.0`, `v2.1.3`).
224
229
230
+
Alternatively, you can override the version using `-DCPP_LIBRARY_VERSION=x.y.z` (useful for package managers). See [Version Management](#version-management) for details.
231
+
225
232
#### GitHub Pages Deployment
226
233
227
234
To enable automatic documentation deployment to GitHub Pages:
@@ -257,30 +264,52 @@ cpp_library_setup(
257
264
**Notes:**
258
265
259
266
- The project name is automatically taken from `PROJECT_NAME` (set by the `project()` command). You must call `project(your-library)` before `cpp_library_setup()`.
260
-
- Version is automatically detected from git tags(see [Version Tagging](#version-tagging)).
267
+
- Version is automatically detected from git tags, or can be overridden with `-DCPP_LIBRARY_VERSION=x.y.z`(see [Version Management](#version-management)).
261
268
- Examples using doctest should include `test` in the filename to be visible in the [C++ TestMate](https://marketplace.visualstudio.com/items?itemName=matepek.vscode-catch2-test-adapter) extension for VS Code test explorer.
262
269
263
270
### Target Naming
264
271
265
-
For `project(your-library)`, `cpp_library_setup` will create a target called `your-library`.
266
-
267
-
The utility will additionally create an alias target based on the `NAMESPACE` option: `your_namespace::your-library`.
272
+
**Recommended Pattern** (collision-safe):
268
273
269
-
If your project name starts with the namespace followed by a dash, the namespace in the project name is stripped from the alias target:
274
+
Use the component name as your project name, and specify the organizational namespace separately:
270
275
271
276
```cmake
272
-
cmake_minimum_required(VERSION 3.20)
273
-
project(namespace-library)
277
+
project(enum-ops) # Component name only
278
+
279
+
cpp_library_setup(
280
+
NAMESPACE stlab # Organizational namespace
281
+
# ...
282
+
)
283
+
```
284
+
285
+
This produces:
286
+
287
+
- Target name: `enum-ops`
288
+
- Package name: `stlab-enum-ops` (used in `find_package(stlab-enum-ops)`)
289
+
- Target alias: `stlab::enum-ops` (used in `target_link_libraries()`)
290
+
291
+
**Alternative Patterns:**
274
292
275
-
# ... CPM setup ...
293
+
You can also use `project(namespace-component)` - the namespace prefix will be detected and stripped from the target alias:
294
+
295
+
```cmake
296
+
project(stlab-enum-ops) # Includes namespace prefix
276
297
277
298
cpp_library_setup(
278
-
NAMESPACE namespace
299
+
NAMESPACE stlab
279
300
# ...
280
301
)
281
302
```
282
303
283
-
Results in `namespace-library` and `namespace::library` targets.
304
+
Produces the same result as above.
305
+
306
+
**Single-component namespace** (e.g., `project(stlab)` with `NAMESPACE stlab`):
307
+
308
+
- Target name: `stlab`
309
+
- Package name: `stlab` (used in `find_package(stlab)`)
310
+
- Target alias: `stlab::stlab` (used in `target_link_libraries()`)
311
+
312
+
All package names include the namespace prefix for collision prevention.
284
313
285
314
### `cpp_library_map_dependency`
286
315
@@ -380,6 +409,15 @@ Version is automatically detected from git tags:
380
409
- Falls back to `0.0.0` if no tag is found (with warning)
381
410
- Version used in CMake package config files
382
411
412
+
For package managers or CI systems building from source archives without git history, you can override the version using the `CPP_LIBRARY_VERSION` cache variable:
413
+
414
+
```bash
415
+
cmake -DCPP_LIBRARY_VERSION=1.2.3 -B build
416
+
cmake --build build
417
+
```
418
+
419
+
This is particularly useful for vcpkg, Conan, or other package managers that don't have access to git tags.
0 commit comments