Skip to content

Commit 2244614

Browse files
committed
Simplifying templates
1 parent 18f09f5 commit 2244614

File tree

14 files changed

+63
-138
lines changed

14 files changed

+63
-138
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ cpp_library_setup(
7373
[TESTS test_list] # Test source files to build (e.g., "tests.cpp")
7474
[DOCS_EXCLUDE_SYMBOLS symbols] # Symbols to exclude from docs
7575
[REQUIRES_CPP_VERSION 17|20|23] # C++ version (default: 17)
76-
[FORCE_INIT] # Force regeneration of template files
7776
)
7877
```
7978

@@ -84,6 +83,23 @@ automatically detected from git tags.
8483
**NOTE**: Examples using doctest should have `test` in the name if you want them to be visible in
8584
the TestMate test explorer.
8685

86+
### Template Regeneration
87+
88+
To force regeneration of template files (CMakePresets.json, CI workflows, etc.), you can use the `init` preset:
89+
90+
```bash
91+
cmake --preset=init
92+
cmake --build --preset=init
93+
```
94+
95+
Alternatively, you can set the CMake variable `CPP_LIBRARY_FORCE_INIT` to `ON`:
96+
97+
```bash
98+
cmake -DCPP_LIBRARY_FORCE_INIT=ON .
99+
```
100+
101+
This will regenerate all template files, overwriting any existing ones.
102+
87103
### Path Conventions
88104

89105
The template uses consistent path conventions for all file specifications:
@@ -170,7 +186,7 @@ cpp_library_setup(
170186
- `test`: Debug build with testing
171187
- `docs`: Documentation generation
172188
- `clang-tidy`: Static analysis
173-
- `init`: Template regeneration
189+
- `init`: Template regeneration (forces regeneration of CMakePresets.json, CI workflows, etc.)
174190

175191
### CI/CD Features
176192

@@ -254,6 +270,12 @@ cpp_library_setup(
254270
ctest --preset=test
255271
```
256272

273+
7. **Regenerate templates** (if needed):
274+
```bash
275+
cmake --preset=init
276+
cmake --build --preset=init
277+
```
278+
257279
## Template Files Generated
258280

259281
The template automatically generates:

cmake/cpp-library-ci.cmake

Lines changed: 0 additions & 52 deletions
This file was deleted.

cmake/cpp-library-presets.cmake

Lines changed: 0 additions & 29 deletions
This file was deleted.

cmake/cpp-library-setup.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ function(_cpp_library_copy_templates)
141141
".gitattributes"
142142
".vscode/extensions.json"
143143
"docs/index.html"
144+
"CMakePresets.json"
145+
".github/workflows/ci.yml"
144146
)
145147

146148
foreach(template_file IN LISTS TEMPLATE_FILES)

cpp-library.cmake

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ include(CTest)
1515
include("${CPP_LIBRARY_ROOT}/cmake/cpp-library-setup.cmake")
1616
include("${CPP_LIBRARY_ROOT}/cmake/cpp-library-testing.cmake")
1717
include("${CPP_LIBRARY_ROOT}/cmake/cpp-library-docs.cmake")
18-
include("${CPP_LIBRARY_ROOT}/cmake/cpp-library-presets.cmake")
19-
include("${CPP_LIBRARY_ROOT}/cmake/cpp-library-ci.cmake")
2018

2119
# Shared function to handle examples and tests consistently
2220
function(_cpp_library_setup_executables)
@@ -101,9 +99,6 @@ endfunction()
10199
# Main entry point function - users call this to set up their library
102100
function(cpp_library_setup)
103101
# Parse arguments
104-
set(options
105-
FORCE_INIT # Force regeneration of template files
106-
)
107102
set(oneValueArgs
108103
DESCRIPTION # Description string
109104
NAMESPACE # Namespace (e.g., "stlab")
@@ -117,10 +112,8 @@ function(cpp_library_setup)
117112
DOCS_EXCLUDE_SYMBOLS # Symbols to exclude from docs
118113
)
119114

120-
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
121-
115+
cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
122116

123-
124117
# Validate required arguments
125118
if(NOT ARG_DESCRIPTION)
126119
message(FATAL_ERROR "cpp_library_setup: DESCRIPTION is required")
@@ -143,15 +136,6 @@ function(cpp_library_setup)
143136
set(ARG_REQUIRES_CPP_VERSION 17)
144137
endif()
145138

146-
# Set default for FORCE_INIT (can be overridden via -DCPP_LIBRARY_FORCE_INIT=ON)
147-
if(NOT DEFINED ARG_FORCE_INIT)
148-
set(ARG_FORCE_INIT FALSE)
149-
endif()
150-
151-
if(DEFINED CPP_LIBRARY_FORCE_INIT AND CPP_LIBRARY_FORCE_INIT)
152-
set(ARG_FORCE_INIT TRUE)
153-
endif()
154-
155139
# Get version from git tags
156140
_cpp_library_get_git_version(GIT_VERSION)
157141
set(ARG_VERSION "${GIT_VERSION}")
@@ -212,15 +196,8 @@ function(cpp_library_setup)
212196
)
213197
endif()
214198

215-
# Generate CMakePresets.json
216-
if(ARG_FORCE_INIT)
217-
_cpp_library_generate_presets(FORCE_INIT)
218-
else()
219-
_cpp_library_generate_presets()
220-
endif()
221-
222-
# Copy static template files (like .clang-format, .gitignore, etc.)
223-
if(ARG_FORCE_INIT)
199+
# Copy static template files (like .clang-format, .gitignore, CMakePresets.json, etc.)
200+
if(DEFINED CPP_LIBRARY_FORCE_INIT AND CPP_LIBRARY_FORCE_INIT)
224201
_cpp_library_copy_templates(FORCE_INIT)
225202
else()
226203
_cpp_library_copy_templates()
@@ -246,21 +223,7 @@ function(cpp_library_setup)
246223
)
247224
endif()
248225

249-
# Setup CI
250-
if(ARG_FORCE_INIT)
251-
_cpp_library_setup_ci(
252-
NAME "${ARG_NAME}"
253-
VERSION "${ARG_VERSION}"
254-
DESCRIPTION "${ARG_DESCRIPTION}"
255-
FORCE_INIT
256-
)
257-
else()
258-
_cpp_library_setup_ci(
259-
NAME "${ARG_NAME}"
260-
VERSION "${ARG_VERSION}"
261-
DESCRIPTION "${ARG_DESCRIPTION}"
262-
)
263-
endif()
226+
264227

265228
# Build examples if specified (only when BUILD_TESTING is enabled)
266229
if(BUILD_TESTING AND ARG_EXAMPLES)

templates/.clang-format

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Auto-generated from cpp-library (https://github.com/stlab/cpp-library)
2+
# Do not edit this file directly - it will be overwritten when templates are regenerated
3+
14
# Format style options described here:
25
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
36

@@ -49,7 +52,7 @@ BreakConstructorInitializers: AfterColon
4952
BreakAfterJavaFieldAnnotations: false
5053
BreakStringLiterals: false
5154
ColumnLimit: 100
52-
CommentPragmas: '^ IWYU pragma:'
55+
CommentPragmas: "^ IWYU pragma:"
5356
CompactNamespaces: false
5457
ConstructorInitializerAllOnOneLineOrOnePerLine: false
5558
ConstructorInitializerIndentWidth: 4
@@ -59,28 +62,28 @@ DerivePointerAlignment: false
5962
DisableFormat: false
6063
ExperimentalAutoDetectBinPacking: false
6164
FixNamespaceComments: true
62-
ForEachMacros:
65+
ForEachMacros:
6366
- foreach
6467
- Q_FOREACH
6568
- BOOST_FOREACH
66-
IncludeBlocks: Preserve
67-
IncludeCategories:
68-
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
69-
Priority: 2
70-
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
71-
Priority: 3
72-
- Regex: '.*'
73-
Priority: 1
74-
IncludeIsMainRegex: '$'
69+
IncludeBlocks: Preserve
70+
IncludeCategories:
71+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
72+
Priority: 2
73+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
74+
Priority: 3
75+
- Regex: ".*"
76+
Priority: 1
77+
IncludeIsMainRegex: "$"
7578
IndentCaseLabels: true
7679
IndentPPDirectives: None # Other option is AfterHash, which indents top level includes as well
7780
IndentWidth: 4
7881
IndentWrappedFunctionNames: true
7982
JavaScriptQuotes: Leave
8083
JavaScriptWrapImports: true
8184
KeepEmptyLinesAtTheStartOfBlocks: false
82-
MacroBlockBegin: ''
83-
MacroBlockEnd: ''
85+
MacroBlockBegin: ""
86+
MacroBlockEnd: ""
8487
MaxEmptyLinesToKeep: 1
8588
NamespaceIndentation: None
8689
ObjCBlockIndentWidth: 4
@@ -116,4 +119,3 @@ Language: Cpp
116119
---
117120
Language: ObjC
118121
PointerAlignment: Right
119-
...

templates/.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
# Auto-generated from cpp-library (https://github.com/stlab/cpp-library)
2+
# Do not edit this file directly - it will be overwritten when templates are regenerated
3+
14
# Auto detect text files and perform LF normalization
25
* text=auto

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Auto-generated from cpp-library (https://github.com/stlab/cpp-library)
2+
# Do not edit this file directly - it will be overwritten when templates are regenerated
3+
14
name: CI
25

36
on:

templates/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Auto-generated from cpp-library (https://github.com/stlab/cpp-library)
2+
# Do not edit this file directly - it will be overwritten when templates are regenerated
3+
14
/.cpm-cache
25
/.cache
36
/build

templates/.vscode/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"_comment": "Auto-generated from cpp-library (https://github.com/stlab/cpp-library) - Do not edit this file directly",
23
"recommendations": [
34
"matepek.vscode-catch2-test-adapter",
45
"llvm-vs-code-extensions.vscode-clangd",

0 commit comments

Comments
 (0)