Skip to content

Commit 579b1ed

Browse files
committed
Update README for CPM repository naming compatibility
Clarifies that GitHub repository names must match package names, including namespace prefixes, for CPM compatibility. Updates usage examples, instructions, and project links to reflect this requirement and prevent issues with CPM's local package finding and source fetching. Repository naming requirements may be backed out if [this CPM PR](cpm-cmake/CPM.cmake#682) lands.
1 parent 4f09b3b commit 579b1ed

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ cmake_minimum_required(VERSION 3.20)
3030
# Project declaration - cpp_library_setup will use this name and detect version from git tags
3131
project(your-library)
3232
33-
# Only set CPM cache when building as top-level project
34-
if(PROJECT_IS_TOP_LEVEL)
35-
set(CPM_SOURCE_CACHE ${CMAKE_SOURCE_DIR}/.cache/cpm CACHE PATH "CPM cache")
33+
# Setup CPM
34+
if(PROJECT_IS_TOP_LEVEL AND NOT CPM_SOURCE_CACHE AND NOT DEFINED ENV{CPM_SOURCE_CACHE})
35+
set(CPM_SOURCE_CACHE "${CMAKE_SOURCE_DIR}/.cache/cpm" CACHE PATH "CPM source cache")
36+
message(STATUS "Setting cpm cache dir to: ${CPM_SOURCE_CACHE}")
3637
endif()
3738
include(cmake/CPM.cmake)
3839
@@ -99,14 +100,17 @@ project(my-app)
99100
include(cmake/CPM.cmake)
100101
101102
# Fetch the library directly from GitHub
102-
CPMAddPackage("gh:your-org/your-library@1.0.0")
103+
# Note: Repository name must match the package name (including namespace prefix)
104+
CPMAddPackage("gh:stlab/stlab-enum-ops@1.0.0")
103105
104106
add_executable(my-app main.cpp)
105-
target_link_libraries(my-app PRIVATE your_namespace::your-library)
107+
target_link_libraries(my-app PRIVATE stlab::enum-ops)
106108
```
107109

108110
The library will be automatically fetched and built as part of your project.
109111

112+
**Important:** For CPM compatibility, especially with `CPM_USE_LOCAL_PACKAGES`, your GitHub repository name should match the package name. For a library with package name `stlab-enum-ops`, name your repository `stlab/stlab-enum-ops`, not `stlab/enum-ops`. This ensures CPM's abbreviated syntax works correctly with both source fetching and local package finding.
113+
110114
#### Installation (optional)
111115

112116
Installation is optional and typically not required when using CPM. If you need to install your library (e.g., for system-wide deployment or use with a package manager) use:
@@ -216,6 +220,17 @@ This ensures your project uses the latest presets and CI configurations from the
216220

217221
### Setting Up GitHub Repository
218222

223+
#### Repository Naming
224+
225+
**Critical:** Your GitHub repository name must match your package name for CPM compatibility.
226+
227+
For the recommended pattern (`project(enum-ops)` with `NAMESPACE stlab`):
228+
229+
- Package name will be: `stlab-enum-ops`
230+
- Repository should be: `github.com/stlab/stlab-enum-ops`
231+
232+
This ensures `CPMAddPackage("gh:stlab/stlab-enum-ops@1.0.0")` works correctly with both source builds and `CPM_USE_LOCAL_PACKAGES`.
233+
219234
#### Version Tagging
220235

221236
cpp-library automatically detects your library version from git tags. To version your library:
@@ -287,6 +302,7 @@ This produces:
287302
- Target name: `enum-ops`
288303
- Package name: `stlab-enum-ops` (used in `find_package(stlab-enum-ops)`)
289304
- Target alias: `stlab::enum-ops` (used in `target_link_libraries()`)
305+
- GitHub repository should be named: `stlab/stlab-enum-ops` (for CPM compatibility)
290306

291307
**Alternative Patterns:**
292308

@@ -441,8 +457,10 @@ These files are generated automatically. To regenerate with the latest templates
441457

442458
See these projects using cpp-library:
443459

444-
- [stlab/enum-ops](https://github.com/stlab/enum-ops) - Type-safe operators for enums
445-
- [stlab/copy-on-write](https://github.com/stlab/copy-on-write) - Copy-on-write wrapper
460+
- [stlab/stlab-enum-ops](https://github.com/stlab/stlab-enum-ops) - Type-safe operators for enums
461+
- [stlab/stlab-copy-on-write](https://github.com/stlab/stlab-copy-on-write) - Copy-on-write wrapper
462+
463+
Note: Repository names include the namespace prefix for CPM compatibility and collision prevention.
446464

447465
## License
448466

0 commit comments

Comments
 (0)