Skip to content

Commit 14e9674

Browse files
committed
Standardize version usage and improve setup automation
Replaced hardcoded version numbers with a placeholder (X.Y.Z) in documentation, templates, and CMake scripts to encourage users to check for the latest release. Added logic in setup.cmake to auto-detect the current version from git tags, falling back to a placeholder if unavailable. Centralized example usage generation for consistent error messages and updated CI workflows to use actions/checkout@v6.
1 parent 4a3cb8c commit 14e9674

9 files changed

Lines changed: 56 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515

1616
steps:
17-
- uses: actions/checkout@v5
17+
- uses: actions/checkout@v6
1818

1919
- name: Run dependency mapping tests
2020
run: cmake -P tests/install/CMakeLists.txt
@@ -27,7 +27,7 @@ jobs:
2727
runs-on: ubuntu-latest
2828

2929
steps:
30-
- uses: actions/checkout@v5
30+
- uses: actions/checkout@v6
3131

3232
- name: Download CPM.cmake
3333
run: |
@@ -135,7 +135,7 @@ jobs:
135135
runs-on: ubuntu-latest
136136

137137
steps:
138-
- uses: actions/checkout@v5
138+
- uses: actions/checkout@v6
139139

140140
- name: Check README examples
141141
run: |

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The easiest way to create a new library project using cpp-library is with the `s
2828

2929
**Interactive mode:**
3030

31-
```bash
31+
```bash
3232
cmake -P <(curl -sSL https://raw.githubusercontent.com/stlab/cpp-library/main/setup.cmake)
3333
```
3434

@@ -210,7 +210,7 @@ cmake_minimum_required(VERSION 3.24)
210210
include(cmake/CPM.cmake)
211211
212212
# Check https://github.com/stlab/cpp-library/releases for the latest version
213-
CPMAddPackage("gh:stlab/cpp-library@5.0.0")
213+
CPMAddPackage("gh:stlab/cpp-library@X.Y.Z")
214214
include(${cpp-library_SOURCE_DIR}/cpp-library.cmake)
215215
216216
cpp_library_enable_dependency_tracking() # Before project()
@@ -247,7 +247,7 @@ To update to the latest version of cpp-library in your project:
247247
Change the version tag in your `CPMAddPackage` call:
248248

249249
```cmake
250-
CPMAddPackage("gh:stlab/cpp-library@4.1.0") # Update version here
250+
CPMAddPackage("gh:stlab/cpp-library@X.Y.Z") # Update version here
251251
```
252252

253253
#### Step 2: Regenerate template files

cmake/cpp-library-dependency-provider.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Usage:
1111
# cmake_minimum_required(VERSION 3.24)
1212
# include(cmake/CPM.cmake)
13-
# CPMAddPackage("gh:stlab/cpp-library@5.0.0")
13+
# CPMAddPackage("gh:stlab/cpp-library@X.Y.Z")
1414
#
1515
# # Enable dependency tracking
1616
# list(APPEND CMAKE_PROJECT_TOP_LEVEL_INCLUDES

cmake/cpp-library-install.cmake

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,13 @@ function(_cpp_library_resolve_dependency LIB NAMESPACE OUTPUT_VAR)
125125
# Not tracked and not a system package - check if provider is installed
126126
get_property(PROVIDER_INSTALLED GLOBAL PROPERTY _CPP_LIBRARY_PROVIDER_INSTALLED)
127127
if(NOT PROVIDER_INSTALLED)
128+
_cpp_library_example_usage(EXAMPLE)
128129
message(FATAL_ERROR
129130
"cpp-library: Dependency provider not installed.\n"
130131
"You must call cpp_library_enable_dependency_tracking() before project().\n"
131132
"\n"
132133
"Example:\n"
133-
" cmake_minimum_required(VERSION 3.24)\n"
134-
" include(cmake/CPM.cmake)\n"
135-
" CPMAddPackage(\"gh:stlab/cpp-library@5.0.0\")\n"
136-
" include(\${cpp-library_SOURCE_DIR}/cpp-library.cmake)\n"
137-
" cpp_library_enable_dependency_tracking()\n"
138-
" project(my-library)\n"
134+
"${EXAMPLE}\n"
139135
)
140136
else()
141137
# Provider is installed but dependency wasn't tracked

cmake/cpp-library-setup.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ function(_cpp_library_get_git_version OUTPUT_VAR)
3232
endif()
3333
endfunction()
3434

35+
# Returns standardized example usage string with current cpp-library version
36+
# This ensures consistent error messages across the library
37+
function(_cpp_library_example_usage OUTPUT_VAR)
38+
# Get the current cpp-library version
39+
_cpp_library_get_git_version(LIB_VERSION)
40+
41+
# If version detection failed, use X.Y.Z placeholder
42+
if(LIB_VERSION STREQUAL "0.0.0")
43+
set(LIB_VERSION "X.Y.Z")
44+
endif()
45+
46+
set(${OUTPUT_VAR}
47+
"cmake_minimum_required(VERSION 3.24)
48+
include(cmake/CPM.cmake)
49+
CPMAddPackage(\"gh:stlab/cpp-library@${LIB_VERSION}\")
50+
include(\${cpp-library_SOURCE_DIR}/cpp-library.cmake)
51+
cpp_library_enable_dependency_tracking()
52+
project(my-library)"
53+
PARENT_SCOPE)
54+
endfunction()
55+
3556
# Creates library target (INTERFACE or compiled) with headers and proper configuration.
3657
# - Precondition: NAME, NAMESPACE, PACKAGE_NAME, CLEAN_NAME, and REQUIRES_CPP_VERSION specified
3758
# - Postcondition: library target created with alias NAMESPACE::CLEAN_NAME, install configured if TOP_LEVEL

cpp-library.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ get_filename_component(CPP_LIBRARY_ROOT "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
1515
# Usage:
1616
# cmake_minimum_required(VERSION 3.24)
1717
# include(cmake/CPM.cmake)
18-
# CPMAddPackage("gh:stlab/cpp-library@5.0.0")
18+
# CPMAddPackage("gh:stlab/cpp-library@X.Y.Z")
1919
# include(${cpp-library_SOURCE_DIR}/cpp-library.cmake)
2020
#
2121
# cpp_library_enable_dependency_tracking() # Must be before project()

setup.cmake

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@
99

1010
cmake_minimum_required(VERSION 3.20)
1111

12+
# Detect cpp-library version from git tags
13+
execute_process(
14+
COMMAND git describe --tags --abbrev=0
15+
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
16+
OUTPUT_VARIABLE CPP_LIBRARY_GIT_VERSION
17+
OUTPUT_STRIP_TRAILING_WHITESPACE
18+
ERROR_QUIET
19+
)
20+
21+
# Clean version (remove 'v' prefix if present)
22+
if(CPP_LIBRARY_GIT_VERSION)
23+
string(REGEX REPLACE "^v" "" CPP_LIBRARY_VERSION "${CPP_LIBRARY_GIT_VERSION}")
24+
else()
25+
# Fallback to X.Y.Z placeholder if no git tag found
26+
set(CPP_LIBRARY_VERSION "X.Y.Z")
27+
message(WARNING "No git tag found for cpp-library version. Using placeholder 'X.Y.Z'. Check https://github.com/stlab/cpp-library/releases for the latest version.")
28+
endif()
29+
30+
message(STATUS "cpp-library version: ${CPP_LIBRARY_VERSION}")
31+
1232
# Parse command line arguments
1333
set(CMD_LINE_ARGS "")
1434
if(CMAKE_ARGV3)
@@ -317,7 +337,8 @@ file(WRITE "${PROJECT_DIR}/CMakeLists.txt"
317337
include(cmake/CPM.cmake)
318338
319339
# Fetch cpp-library before project()
320-
CPMAddPackage(\"gh:stlab/cpp-library@5.0.0\")
340+
# Check https://github.com/stlab/cpp-library/releases for the latest version
341+
CPMAddPackage(\"gh:stlab/cpp-library@${CPP_LIBRARY_VERSION}\")
321342
include(\${cpp-library_SOURCE_DIR}/cpp-library.cmake)
322343
323344
# Enable dependency tracking before project()

templates/.github/workflows/ci.yml.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
runs-on: ubuntu-latest
9898

9999
steps:
100-
- uses: actions/checkout@v5
100+
- uses: actions/checkout@v6
101101

102102
- name: Configure CMake with clang-tidy
103103
run: cmake --preset=clang-tidy
@@ -117,7 +117,7 @@ jobs:
117117
contents: read
118118

119119
steps:
120-
- uses: actions/checkout@v5
120+
- uses: actions/checkout@v6
121121

122122
# ssciwr/doxygen-install@1.6.4
123123
- name: Install Doxygen

tests/install/test_integration_example.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cmake_minimum_required(VERSION 3.24)
1010
include(cmake/CPM.cmake)
1111

1212
# Step 2: Fetch cpp-library before project()
13-
CPMAddPackage("gh:stlab/cpp-library@5.0.0")
13+
CPMAddPackage("gh:stlab/cpp-library@X.Y.Z")
1414
include(${cpp-library_SOURCE_DIR}/cpp-library.cmake)
1515

1616
# Step 3: Enable dependency tracking BEFORE project()

0 commit comments

Comments
 (0)