Skip to content

Commit 31df212

Browse files
committed
Simplify README - remove design rationale and redundant examples
Removed verbose explanations about implementation choices and consolidated documentation to be more practical and concise. Changes: - Removed 'Key benefits' section explaining design rationale - Simplified 'Dependency Handling' section from detailed examples to essential usage - Reduced cpp_library_map_dependency() documentation from 3 examples to 1 - Removed redundant Examples 2 & 3 (now automatic with dependency provider) - Simplified Troubleshooting section - removed obsolete issues - Removed 'Component Merging Not Working' (automatic with provider) - Removed 'Version Detection Fails' (automatic with provider) - Added 'Dependency Not Tracked' troubleshooting entry Net result: 144 lines removed (161 deleted, 17 added) Focus: Show users HOW to use it, not WHY we designed it that way.
1 parent 5423d14 commit 31df212

1 file changed

Lines changed: 17 additions & 161 deletions

File tree

README.md

Lines changed: 17 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -203,92 +203,40 @@ For information about using installed packages with `find_package()`, see the [C
203203

204204
#### Dependency Handling in Installed Packages
205205

206-
cpp-library automatically generates correct `find_dependency()` calls in the installed CMake package configuration files by tracking your `find_package()` and `CPMAddPackage()` calls. This ensures downstream users can find and link all required dependencies when using your installed library.
207-
208-
**Setup: Enable Dependency Tracking (CMake 3.24+ Required)**
209-
210-
Enable dependency tracking to capture the exact syntax of your dependency requests:
206+
cpp-library automatically generates `find_dependency()` calls in the installed CMake package configuration. Call `cpp_library_enable_dependency_tracking()` before `project()`:
211207

212208
```cmake
213209
cmake_minimum_required(VERSION 3.24)
214-
215-
# Setup CPM (before project())
216210
include(cmake/CPM.cmake)
217211
218-
# Fetch cpp-library (before project())
219212
CPMAddPackage("gh:stlab/cpp-library@5.0.0")
220213
include(${cpp-library_SOURCE_DIR}/cpp-library.cmake)
221214
222-
# Enable dependency tracking (before project())
223-
cpp_library_enable_dependency_tracking()
224-
225-
# Now call project() - this activates tracking
215+
cpp_library_enable_dependency_tracking() # Before project()
226216
project(my-library)
227217
228-
# All dependencies from here are tracked with exact versions and syntax
229-
CPMAddPackage("gh:stlab/stlab-copy-on-write@2.1.0")
218+
# Add dependencies
230219
CPMAddPackage("gh:stlab/stlab-enum-ops@1.0.0")
231220
find_package(Boost 1.79 COMPONENTS filesystem)
232221
233-
# Setup your library
234222
cpp_library_setup(
235223
DESCRIPTION "My library"
236224
NAMESPACE mylib
237225
HEADERS mylib.hpp
238226
)
239227
240-
# Link dependencies - cpp-library knows exactly how they were added
241228
target_link_libraries(my-library INTERFACE
242-
stlab::copy-on-write # Tracked: CPMAddPackage("gh:stlab/stlab-copy-on-write@2.1.0")
243-
stlab::enum-ops # Tracked: CPMAddPackage("gh:stlab/stlab-enum-ops@1.0.0")
244-
Boost::filesystem # Tracked: find_package(Boost 1.79 COMPONENTS filesystem)
229+
stlab::enum-ops
230+
Boost::filesystem
245231
)
246232
```
247233

248-
When installed, the generated `my-libraryConfig.cmake` will include:
234+
**Non-namespaced targets:** For targets like `opencv_core`, add an explicit mapping:
249235

250236
```cmake
251-
include(CMakeFindDependencyMacro)
252-
253-
# Find dependencies with exact syntax from your build
254-
find_dependency(stlab-copy-on-write 2.1.0)
255-
find_dependency(stlab-enum-ops 1.0.0)
256-
find_dependency(Boost 1.79 COMPONENTS filesystem)
257-
258-
include("${CMAKE_CURRENT_LIST_DIR}/my-libraryTargets.cmake")
259-
```
260-
261-
**Key benefits:**
262-
- ✅ Perfect accuracy - captures exact `find_package()` syntax including COMPONENTS
263-
- ✅ Handles conditional dependencies automatically
264-
- ✅ Works seamlessly with CPM and find_package
265-
- ✅ No manual mapping needed for namespaced dependencies
266-
267-
**Special Case: Non-namespaced Targets**
268-
269-
For non-namespaced targets (like `opencv_core`), the provider cannot determine which package they came from. Use `cpp_library_map_dependency()` to map them:
270-
271-
```cmake
272-
# Non-namespaced targets require explicit mapping
273237
cpp_library_map_dependency("opencv_core" "OpenCV 4.5.0")
274-
cpp_library_map_dependency("opencv_imgproc" "OpenCV 4.5.0")
275-
276-
cpp_library_setup(...)
277-
278-
target_link_libraries(my-library INTERFACE
279-
opencv_core
280-
opencv_imgproc
281-
)
282238
```
283239

284-
Generated config:
285-
286-
```cmake
287-
find_dependency(OpenCV 4.5.0) # Mapped from opencv_core and opencv_imgproc
288-
```
289-
290-
**Note:** Namespaced targets like `Qt6::Core` and `Boost::filesystem` work automatically - the provider tracks the original `find_package()` calls and handles component merging automatically.
291-
292240
### Updating cpp-library
293241

294242
To update to the latest version of cpp-library in your project:
@@ -411,87 +359,15 @@ This produces:
411359
cpp_library_map_dependency(target find_dependency_call)
412360
```
413361

414-
Registers a custom dependency mapping for `find_dependency()` generation in installed CMake package config files.
415-
416-
**Parameters:**
417-
418-
- `target`: The target name, either namespaced (e.g., `"Qt5::Core"`, `"stlab::enum-ops"`) or non-namespaced (e.g., `"opencv_core"`)
419-
- `find_dependency_call`: The complete arguments to pass to `find_dependency()`, including version and any special syntax (e.g., `"Qt5 5.15.0 COMPONENTS Core"`, `"OpenCV 4.5.0"`)
420-
421-
**When to use:**
422-
423-
- **Required** for non-namespaced targets (e.g., `opencv_core`) - these cannot be automatically detected
424-
- When automatic version detection fails (cpp-library will generate an error with a helpful example)
425-
- Dependencies requiring `COMPONENTS` or other special `find_package()` syntax
426-
- When you need to override automatically detected versions
427-
428-
**Automatic behavior:**
429-
430-
For namespaced targets (e.g., `Namespace::Target`), cpp-library automatically detects dependency versions from CMake's `<PackageName>_VERSION` variable (set by `find_package()` or CPM after fetching). Most namespaced dependencies work automatically without any mapping needed. If automatic detection fails, you'll get a clear error message showing exactly how to fix it.
431-
432-
**Example 1 - Non-namespaced targets (required):**
362+
Maps non-namespaced targets to their package. Required only for targets like `opencv_core` where the package name cannot be inferred:
433363

434364
```cmake
435-
# Non-namespaced targets must be explicitly mapped
436365
cpp_library_map_dependency("opencv_core" "OpenCV 4.5.0")
437-
cpp_library_map_dependency("opencv_imgproc" "OpenCV 4.5.0")
438366
439-
target_link_libraries(my-target INTERFACE
440-
opencv_core
441-
opencv_imgproc
442-
)
443-
```
444-
445-
**Example 2 - Custom syntax (Qt with COMPONENTS):**
446-
447-
```cmake
448-
# Register mappings for dependencies needing COMPONENTS syntax
449-
# Note: Multiple components of the same package are automatically merged
450-
cpp_library_map_dependency("Qt6::Core" "Qt6 6.5.0 COMPONENTS Core")
451-
cpp_library_map_dependency("Qt6::Widgets" "Qt6 6.5.0 COMPONENTS Widgets")
452-
cpp_library_map_dependency("Qt6::Network" "Qt6 6.5.0 COMPONENTS Network")
453-
454-
# Then link normally
455-
target_link_libraries(my-target INTERFACE
456-
Qt6::Core
457-
Qt6::Widgets
458-
Qt6::Network
459-
)
460-
461-
# Generated config will contain a single merged find_dependency() call:
462-
# find_dependency(Qt6 6.5.0 COMPONENTS Core Widgets Network)
367+
target_link_libraries(my-target INTERFACE opencv_core)
463368
```
464369

465-
**Example 3 - Version override:**
466-
467-
```cmake
468-
# Fetch dependencies
469-
CPMAddPackage("gh:stlab/stlab-enum-ops@1.0.0")
470-
CPMAddPackage("gh:stlab/stlab-copy-on-write@2.1.0")
471-
472-
# If automatic version detection fails, you'll get an error like:
473-
# "Cannot determine version for dependency stlab::enum-ops..."
474-
# The error message will show you the exact fix:
475-
cpp_library_map_dependency("stlab::enum-ops" "stlab-enum-ops 1.0.0")
476-
cpp_library_map_dependency("stlab::copy-on-write" "stlab-copy-on-write 2.1.0")
477-
478-
# Link as usual
479-
target_link_libraries(my-target INTERFACE
480-
stlab::enum-ops
481-
stlab::copy-on-write
482-
)
483-
```
484-
485-
The generated config file will include your mappings (note merged Qt components):
486-
487-
```cmake
488-
find_dependency(OpenCV 4.5.0) # From Example 1
489-
find_dependency(Qt6 6.5.0 COMPONENTS Core Widgets Network) # From Example 2 (merged)
490-
find_dependency(stlab-enum-ops 1.0.0) # From Example 3
491-
find_dependency(stlab-copy-on-write 2.1.0) # From Example 3
492-
```
493-
494-
**Note:** Version constraints in `find_dependency()` specify *minimum* versions. Consuming projects can override these with their own version requirements in `find_package()` or `CPMAddPackage()`.
370+
Namespaced targets like `Qt6::Core` and `Boost::filesystem` are tracked automatically.
495371

496372
### Path Conventions
497373

@@ -592,46 +468,26 @@ Note: Repository names include the namespace prefix for CPM compatibility and co
592468

593469
## Troubleshooting
594470

595-
### Version Detection Fails
596-
597-
**Problem**: Error message: "Cannot determine version for dependency..."
598-
599-
**Solution**: Add explicit version mapping before `cpp_library_setup()`:
600-
```cmake
601-
cpp_library_map_dependency("stlab::enum-ops" "stlab-enum-ops 1.0.0")
602-
```
603-
604-
The error message shows the exact line to add.
605-
606471
### Non-Namespaced Target Error
607472

608-
**Problem**: "Cannot automatically handle non-namespaced dependency: opencv_core"
473+
**Problem**: Error about non-namespaced dependency like `opencv_core`
609474

610-
**Solution**: Non-namespaced targets must be explicitly mapped:
475+
**Solution**: Map the target to its package:
611476
```cmake
612477
cpp_library_map_dependency("opencv_core" "OpenCV 4.5.0")
613478
```
614479

615-
### Component Merging Not Working
480+
### Dependency Not Tracked
616481

617-
**Problem**: Multiple Qt/Boost components generate separate `find_dependency()` calls
482+
**Problem**: Error that a dependency was not tracked
618483

619-
**Solution**: Ensure all components have **identical** package name, version, and additional arguments:
620-
```cmake
621-
# ✓ Correct - will merge
622-
cpp_library_map_dependency("Qt6::Core" "Qt6 6.5.0 COMPONENTS Core")
623-
cpp_library_map_dependency("Qt6::Widgets" "Qt6 6.5.0 COMPONENTS Widgets")
624-
625-
# ✗ Wrong - won't merge (different versions)
626-
cpp_library_map_dependency("Qt6::Core" "Qt6 6.5.0 COMPONENTS Core")
627-
cpp_library_map_dependency("Qt6::Widgets" "Qt6 6.4.0 COMPONENTS Widgets")
628-
```
484+
**Solution**: Ensure `cpp_library_enable_dependency_tracking()` is called before `project()`, and all dependencies are added after `project()` but before `cpp_library_setup()`.
629485

630-
### CPM Cannot Find Package
486+
### CPM Repository Name Mismatch
631487

632-
**Problem**: `CPMAddPackage("gh:stlab/enum-ops@1.0.0")` fails with `CPM_USE_LOCAL_PACKAGES`
488+
**Problem**: `CPMAddPackage()` fails with `CPM_USE_LOCAL_PACKAGES`
633489

634-
**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`.
490+
**Solution**: Repository name must match package name. For package `stlab-enum-ops`, use repository `stlab/stlab-enum-ops`, not `stlab/enum-ops`.
635491

636492
## Development
637493

0 commit comments

Comments
 (0)