Skip to content

Commit e1f2a81

Browse files
committed
Refine CMake regex handling for clean name calculation and version extraction
- Simplified the clean name calculation in cpp_library_setup by removing unnecessary regex escaping. - Updated the version extraction logic in _cpp_library_add_dependency to ensure proper semantic versioning format. These changes enhance the clarity and efficiency of the CMake configuration for the cpp-library.
1 parent 219221c commit e1f2a81

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

cmake/cpp-library-install.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function(_cpp_library_add_dependency FIND_DEP_ARGS)
194194

195195
# Extract version (first token that looks like a semantic version number: major.minor[.patch]...)
196196
set(VERSION "")
197-
if(REMAINING_ARGS MATCHES "^([0-9]+\\.[0-9]+(?:\\.[0-9]+)*)")
197+
if(REMAINING_ARGS MATCHES "^([0-9]+\\.[0-9]+(\\.[0-9]+)*)")
198198
set(VERSION "${CMAKE_MATCH_1}")
199199
# Remove version from args - use substring to avoid regex issues with dots
200200
string(LENGTH "${VERSION}" VERSION_LEN)

cpp-library.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ function(cpp_library_setup)
170170

171171
# Calculate clean name (without namespace prefix) for target alias
172172
# If PROJECT_NAME starts with NAMESPACE-, strip it; otherwise use PROJECT_NAME as-is
173-
string(REGEX ESCAPE "${ARG_NAMESPACE}" ESCAPED_NAMESPACE)
174-
string(REGEX REPLACE "^${ESCAPED_NAMESPACE}-" "" CLEAN_NAME "${ARG_NAME}")
173+
string(REPLACE "${ARG_NAMESPACE}-" "" CLEAN_NAME "${ARG_NAME}")
174+
# If no replacement happened, CLEAN_NAME equals ARG_NAME (which is what we want)
175175

176176
# Always prefix package name with namespace for collision prevention
177177
# Special case: if namespace equals clean name, don't duplicate (e.g., stlab::stlab → stlab)

0 commit comments

Comments
 (0)