Skip to content

Commit 05b463e

Browse files
committed
Update docs and install logic; add troubleshooting
Expanded the README with a troubleshooting section and clarified documentation deployment instructions. Updated comments and logic in cpp-library-install.cmake to centralize system package handling for dependency mapping. Generalized cpp-library.cmake to support both header-only and compiled C++ libraries.
1 parent 3c81f5e commit 05b463e

3 files changed

Lines changed: 55 additions & 25 deletions

File tree

README.md

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ if(PROJECT_IS_TOP_LEVEL AND NOT CPM_SOURCE_CACHE AND NOT DEFINED ENV{CPM_SOURCE_
111111
endif()
112112
include(cmake/CPM.cmake)
113113
114-
# Fetch cpp-library via CPM
115-
CPMAddPackage("gh:stlab/cpp-library@4.0.3")
114+
# Fetch cpp-library via CPM (update to latest version)
115+
CPMAddPackage("gh:stlab/cpp-library@4.0.3") # Check for latest version
116116
include(${cpp-library_SOURCE_DIR}/cpp-library.cmake)
117117
118118
cpp_library_setup(
@@ -358,9 +358,9 @@ To enable automatic documentation deployment to GitHub Pages:
358358

359359
1. Go to your repository **Settings****Pages**
360360
2. Under **Source**, select **GitHub Actions**
361-
3. Push a commit to trigger the CI workflow
361+
3. Publish a release to trigger documentation build
362362

363-
Your documentation will be automatically built and deployed to `https://your-org.github.io/your-library/` on every push to the main branch.
363+
Your documentation will be automatically built and deployed to `https://your-org.github.io/your-library/` when you publish a GitHub release.
364364

365365
## API Reference
366366

@@ -410,21 +410,6 @@ This produces:
410410
- **Target alias**: `stlab::enum-ops` (used in `target_link_libraries()`)
411411
- **Repository name**: `stlab/stlab-enum-ops` (must match package name)
412412

413-
**Alternative Patterns:**
414-
415-
You can also use `project(namespace-component)` - the namespace prefix will be detected and stripped from the target alias:
416-
417-
```cmake
418-
project(stlab-enum-ops) # Includes namespace prefix
419-
420-
cpp_library_setup(
421-
NAMESPACE stlab
422-
# ...
423-
)
424-
```
425-
426-
Produces the same result as above.
427-
428413
**Special case** — single-component namespace (e.g., `project(stlab)` with `NAMESPACE stlab`):
429414

430415
- Target name: `stlab`
@@ -617,6 +602,49 @@ See these projects using cpp-library:
617602

618603
Note: Repository names include the namespace prefix for CPM compatibility and collision prevention.
619604

605+
## Troubleshooting
606+
607+
### Version Detection Fails
608+
609+
**Problem**: Error message: "Cannot determine version for dependency..."
610+
611+
**Solution**: Add explicit version mapping before `cpp_library_setup()`:
612+
```cmake
613+
cpp_library_map_dependency("stlab::enum-ops" "stlab-enum-ops 1.0.0")
614+
```
615+
616+
The error message shows the exact line to add.
617+
618+
### Non-Namespaced Target Error
619+
620+
**Problem**: "Cannot automatically handle non-namespaced dependency: opencv_core"
621+
622+
**Solution**: Non-namespaced targets must be explicitly mapped:
623+
```cmake
624+
cpp_library_map_dependency("opencv_core" "OpenCV 4.5.0")
625+
```
626+
627+
### Component Merging Not Working
628+
629+
**Problem**: Multiple Qt/Boost components generate separate `find_dependency()` calls
630+
631+
**Solution**: Ensure all components have **identical** package name, version, and additional arguments:
632+
```cmake
633+
# ✓ Correct - will merge
634+
cpp_library_map_dependency("Qt6::Core" "Qt6 6.5.0 COMPONENTS Core")
635+
cpp_library_map_dependency("Qt6::Widgets" "Qt6 6.5.0 COMPONENTS Widgets")
636+
637+
# ✗ Wrong - won't merge (different versions)
638+
cpp_library_map_dependency("Qt6::Core" "Qt6 6.5.0 COMPONENTS Core")
639+
cpp_library_map_dependency("Qt6::Widgets" "Qt6 6.4.0 COMPONENTS Widgets")
640+
```
641+
642+
### CPM Cannot Find Package
643+
644+
**Problem**: `CPMAddPackage("gh:stlab/enum-ops@1.0.0")` fails with `CPM_USE_LOCAL_PACKAGES`
645+
646+
**Solution**: Repository name must match package name. If package name is `stlab-enum-ops`, repository must be `stlab/stlab-enum-ops`, not `stlab/enum-ops`.
647+
620648
## Development
621649

622650
### Running Tests

cmake/cpp-library-install.cmake

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
include(GNUInstallDirs)
1313
include(CMakePackageConfigHelpers)
1414

15+
# System packages that don't require version constraints in find_dependency()
16+
# These are commonly available system libraries where version requirements are typically not specified.
17+
# To extend this list in your project, use cpp_library_map_dependency() to explicitly map additional packages.
18+
set(_CPP_LIBRARY_SYSTEM_PACKAGES "Threads" "OpenMP" "ZLIB" "CURL" "OpenSSL")
19+
1520
# Registers a custom dependency mapping for find_dependency() generation
1621
# - Precondition: TARGET is a namespaced target (e.g., "Qt6::Core", "stlab::enum-ops") or non-namespaced (e.g., "opencv_core")
1722
# - Postcondition: FIND_DEPENDENCY_CALL stored for TARGET, used in package config generation
@@ -86,10 +91,7 @@ function(_cpp_library_generate_dependencies OUTPUT_VAR TARGET_NAME NAMESPACE)
8691
endif()
8792
8893
# Check if this is a system package that doesn't require versions
89-
# These packages are commonly available and don't need version constraints
90-
set(SYSTEM_PACKAGES "Threads" "OpenMP" "ZLIB" "CURL" "OpenSSL")
91-
92-
if(FIND_PACKAGE_NAME IN_LIST SYSTEM_PACKAGES)
94+
if(FIND_PACKAGE_NAME IN_LIST _CPP_LIBRARY_SYSTEM_PACKAGES)
9395
# System package - no version required
9496
set(FIND_DEP_CALL "${FIND_PACKAGE_NAME}")
9597
else()

cpp-library.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# SPDX-License-Identifier: BSL-1.0
22
#
3-
# cpp-library.cmake - Modern C++ Header-Only Library Template
3+
# cpp-library.cmake - Modern C++ Library Template
44
#
5-
# This file provides common CMake infrastructure for stlab header-only libraries.
5+
# This file provides common CMake infrastructure for C++ libraries (header-only and compiled).
66
# Usage: include(cmake/cpp-library.cmake) then call cpp_library_setup(...)
77

88
# Determine the directory where this file is located

0 commit comments

Comments
 (0)