Skip to content

Commit e940916

Browse files
committed
Refactor template and CI setup to use PACKAGE_NAME
Updated internal CMake functions to require PACKAGE_NAME as a parameter instead of relying on PROJECT_NAME. This clarifies the preconditions for template and CI workflow generation, ensuring correct substitution and improving maintainability.
1 parent 39419e2 commit e940916

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

cmake/cpp-library-ci.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
#
55
# This module handles GitHub Actions workflow generation with PROJECT_NAME substitution
66

7-
# Generates GitHub Actions CI workflow from template with PROJECT_NAME substitution.
7+
# Generates GitHub Actions CI workflow from template with PACKAGE_NAME substitution.
8+
# - Precondition: PACKAGE_NAME must be set in parent scope
89
# - Postcondition: .github/workflows/ci.yml created from template if not present
910
# - With force_init: overwrites existing workflow file
10-
function(_cpp_library_setup_ci force_init)
11+
function(_cpp_library_setup_ci PACKAGE_NAME force_init)
1112
set(ci_template "${CPP_LIBRARY_ROOT}/templates/.github/workflows/ci.yml.in")
1213
set(ci_dest "${CMAKE_CURRENT_SOURCE_DIR}/.github/workflows/ci.yml")
1314

cmake/cpp-library-install.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ endfunction()
2424
# - Precondition: TARGET_NAME specifies existing target with INTERFACE_LINK_LIBRARIES
2525
# - Postcondition: OUTPUT_VAR contains newline-separated find_dependency() calls for public dependencies
2626
# - Uses cpp_library_map_dependency() mappings if registered, otherwise uses defaults
27-
# - Automatically handles cpp-library dependencies (matching NAMESPACE)
27+
# - Automatically handles cpp-library dependencies (namespace::package → find_dependency(package))
2828
function(_cpp_library_generate_dependencies OUTPUT_VAR TARGET_NAME NAMESPACE)
2929
get_target_property(LINK_LIBS ${TARGET_NAME} INTERFACE_LINK_LIBRARIES)
3030

cmake/cpp-library-setup.cmake

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ function(_cpp_library_setup_core)
111111
endfunction()
112112

113113
# Copies template files (.clang-format, .gitignore, etc.) to project root if not present.
114-
# - Postcondition: missing template files copied to project, CI workflow configured with PROJECT_NAME substitution
114+
# - Precondition: PACKAGE_NAME must be passed as first parameter
115+
# - Postcondition: missing template files copied to project, CI workflow configured with PACKAGE_NAME substitution
115116
# - With FORCE_INIT: overwrites existing files
116-
function(_cpp_library_copy_templates)
117+
function(_cpp_library_copy_templates PACKAGE_NAME)
117118
set(options FORCE_INIT)
118119
cmake_parse_arguments(ARG "${options}" "" "" ${ARGN})
119120

@@ -141,6 +142,6 @@ function(_cpp_library_copy_templates)
141142
endif()
142143
endforeach()
143144

144-
# Setup CI workflow with PROJECT_NAME substitution
145-
_cpp_library_setup_ci(${ARG_FORCE_INIT})
145+
# Setup CI workflow with PACKAGE_NAME substitution
146+
_cpp_library_setup_ci("${PACKAGE_NAME}" ${ARG_FORCE_INIT})
146147
endfunction()

cpp-library.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ function(cpp_library_setup)
211211

212212
# Copy static template files (like .clang-format, .gitignore, CMakePresets.json, etc.)
213213
if(DEFINED CPP_LIBRARY_FORCE_INIT AND CPP_LIBRARY_FORCE_INIT)
214-
_cpp_library_copy_templates(FORCE_INIT)
214+
_cpp_library_copy_templates("${PACKAGE_NAME}" FORCE_INIT)
215215
else()
216-
_cpp_library_copy_templates()
216+
_cpp_library_copy_templates("${PACKAGE_NAME}")
217217
endif()
218218

219219
# Setup testing (if tests are specified)

0 commit comments

Comments
 (0)