Skip to content

Commit 8b3adce

Browse files
committed
Simplifying by removing customization options.
1 parent ad0505a commit 8b3adce

File tree

3 files changed

+27
-66
lines changed

3 files changed

+27
-66
lines changed

README.md

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ set(CPM_SOURCE_CACHE ${CMAKE_SOURCE_DIR}/.cpm-cache CACHE PATH "CPM cache")
3333
include(cmake/CPM.cmake)
3434
3535
# Fetch cpp-library via CPM
36-
CPMAddPackage("gh:stlab/cpp-library@1.0.0")
36+
CPMAddPackage("gh:stlab/cpp-library@3.0.0")
3737
include(${cpp-library_SOURCE_DIR}/cpp-library.cmake)
3838
3939
cpp_library_setup(
@@ -63,33 +63,21 @@ cpp_library_setup(
6363
# Required parameters
6464
DESCRIPTION description # e.g., "Type-safe operators for enums"
6565
NAMESPACE namespace # e.g., "stlab"
66-
67-
# Optional parameters
68-
VERSION version_string # e.g., "1.0.0" (auto-detected from git tags if not provided)
69-
70-
# Header specification (one required)
7166
HEADERS header_list # List of header files
72-
HEADER_DIR directory # Directory to install recursively
73-
67+
7468
# Optional: source specification for non-header-only libraries
75-
SOURCES source_list # List of source files (e.g., src/*.cpp)
69+
SOURCES source_list # List of source files (auto-detected from src/ if not provided)
7670
7771
# Optional features
7872
[EXAMPLES example_list] # Example executables to build
7973
[TESTS test_list] # Test executables to build
8074
[DOCS_EXCLUDE_SYMBOLS symbols] # Symbols to exclude from docs
8175
[REQUIRES_CPP_VERSION 17|20|23] # C++ version (default: 17)
82-
[ADDITIONAL_DEPS dep_list] # Extra CPM dependencies
83-
84-
# Optional flags
85-
[CUSTOM_INSTALL] # Skip default installation
86-
[NO_PRESETS] # Skip CMakePresets.json generation
87-
[NO_CI] # Skip CI generation (enabled by default)
8876
[FORCE_INIT] # Force regeneration of template files
8977
)
9078
```
9179

92-
**Note**: The project name is automatically taken from `PROJECT_NAME` (set by the `project()` command). You must call `project(your-library)` before `cpp_library_setup()`.
80+
**Note**: The project name is automatically taken from `PROJECT_NAME` (set by the `project()` command). You must call `project(your-library)` before `cpp_library_setup()`. Version is automatically detected from git tags.
9381

9482
## Features
9583
### Non-Header-Only Library Support
@@ -115,6 +103,7 @@ cpp_library_setup(
115103
- **Build isolation** with separate build directories
116104
- **Two-mode operation**: Full infrastructure when top-level, lightweight when consumed
117105
- **Automatic version detection**: Version is automatically extracted from git tags (e.g., `v1.2.3` becomes `1.2.3`)
106+
- **Always-enabled features**: CI/CD, CMakePresets.json, and proper installation are always generated
118107

119108
### Testing Features
120109

@@ -161,7 +150,6 @@ cpp_library_setup(
161150

162151
- **Automatic git tag detection**: Version is automatically extracted from the latest git tag
163152
- **Fallback versioning**: Uses `0.0.0` if no git tag is found (with warning)
164-
- **Manual override**: You can still specify `VERSION` parameter to override automatic detection
165153
- **Tag format support**: Supports both `v1.2.3` and `1.2.3` tag formats
166154

167155
## Example Projects
@@ -175,21 +163,18 @@ This template is used by:
175163

176164
```cmake
177165
cmake_minimum_required(VERSION 3.20)
166+
project(enum-ops)
178167
179168
# Setup cpp-library infrastructure
180169
set(CPM_SOURCE_CACHE ${CMAKE_SOURCE_DIR}/.cpm-cache CACHE PATH "CPM cache" FORCE)
181170
include(cmake/CPM.cmake)
182171
183172
# Fetch cpp-library via CPM (using local path for development)
184-
CPMAddPackage(
185-
URI gh:stlab/[email protected]
186-
DOWNLOAD_ONLY YES
187-
)
173+
CPMAddPackage("gh:stlab/[email protected]")
188174
include(${cpp-library_SOURCE_DIR}/cpp-library.cmake)
189175
190176
# Configure library (handles both lightweight and full modes automatically)
191177
cpp_library_setup(
192-
NAME stlab-enum-ops
193178
DESCRIPTION "Type-safe operators for enums"
194179
NAMESPACE stlab
195180
HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/stlab/enum_ops.hpp

cmake/cpp-library-setup.cmake

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ function(_cpp_library_setup_core)
3030
VERSION
3131
DESCRIPTION
3232
NAMESPACE
33-
HEADER_DIR
3433
REQUIRES_CPP_VERSION
3534
TOP_LEVEL
3635
)
@@ -100,14 +99,6 @@ function(_cpp_library_setup_core)
10099
FILE_SET headers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
101100
)
102101

103-
# Install header directory if specified (fallback for older CMake)
104-
if(ARG_HEADER_DIR)
105-
install(DIRECTORY ${ARG_HEADER_DIR}/
106-
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
107-
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h"
108-
)
109-
endif()
110-
111102
# Generate package config files
112103
write_basic_package_version_file(
113104
"${CMAKE_CURRENT_BINARY_DIR}/${ARG_NAME}ConfigVersion.cmake"

cpp-library.cmake

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,19 @@ include("${CPP_LIBRARY_ROOT}/cmake/cpp-library-ci.cmake")
2222
function(cpp_library_setup)
2323
# Parse arguments
2424
set(options
25-
CUSTOM_INSTALL # Skip default installation
26-
NO_PRESETS # Skip CMakePresets.json generation
27-
NO_CI # Skip CI generation (CI enabled by default)
2825
FORCE_INIT # Force regeneration of template files
2926
)
3027
set(oneValueArgs
31-
VERSION # Version string (e.g., "1.0.0")
3228
DESCRIPTION # Description string
3329
NAMESPACE # Namespace (e.g., "stlab")
3430
REQUIRES_CPP_VERSION # C++ version (default: 17)
35-
HEADER_DIR # Directory to install recursively
3631
)
3732
set(multiValueArgs
3833
HEADERS # List of header files
3934
SOURCES # List of source files (optional, for non-header-only)
4035
EXAMPLES # Example executables to build
4136
TESTS # Test executables to build
4237
DOCS_EXCLUDE_SYMBOLS # Symbols to exclude from docs
43-
ADDITIONAL_DEPS # Extra CPM dependencies
4438
)
4539

4640
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
@@ -60,8 +54,8 @@ function(cpp_library_setup)
6054
if(NOT ARG_NAMESPACE)
6155
message(FATAL_ERROR "cpp_library_setup: NAMESPACE is required")
6256
endif()
63-
if(NOT ARG_HEADERS AND NOT ARG_HEADER_DIR)
64-
message(FATAL_ERROR "cpp_library_setup: Either HEADERS or HEADER_DIR is required")
57+
if(NOT ARG_HEADERS)
58+
message(FATAL_ERROR "cpp_library_setup: HEADERS is required")
6559
endif()
6660

6761
# Use PROJECT_NAME as the library name
@@ -83,13 +77,11 @@ function(cpp_library_setup)
8377
set(ARG_FORCE_INIT TRUE)
8478
endif()
8579

86-
# Get version from git tags if not provided
87-
if(NOT ARG_VERSION)
88-
_cpp_library_get_git_version(GIT_VERSION)
89-
set(ARG_VERSION "${GIT_VERSION}")
90-
endif()
80+
# Get version from git tags
81+
_cpp_library_get_git_version(GIT_VERSION)
82+
set(ARG_VERSION "${GIT_VERSION}")
9183

92-
# Parse version components for manual setting
84+
# Parse version components
9385
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" VERSION_MATCH "${ARG_VERSION}")
9486
if(VERSION_MATCH)
9587
set(ARG_VERSION_MAJOR ${CMAKE_MATCH_1})
@@ -101,13 +93,11 @@ function(cpp_library_setup)
10193
set(ARG_VERSION_PATCH 0)
10294
endif()
10395

104-
# Update project version if it was detected from git
105-
if(NOT DEFINED PROJECT_VERSION OR PROJECT_VERSION STREQUAL "")
106-
set(PROJECT_VERSION ${ARG_VERSION} PARENT_SCOPE)
107-
set(PROJECT_VERSION_MAJOR ${ARG_VERSION_MAJOR} PARENT_SCOPE)
108-
set(PROJECT_VERSION_MINOR ${ARG_VERSION_MINOR} PARENT_SCOPE)
109-
set(PROJECT_VERSION_PATCH ${ARG_VERSION_PATCH} PARENT_SCOPE)
110-
endif()
96+
# Update project version
97+
set(PROJECT_VERSION ${ARG_VERSION} PARENT_SCOPE)
98+
set(PROJECT_VERSION_MAJOR ${ARG_VERSION_MAJOR} PARENT_SCOPE)
99+
set(PROJECT_VERSION_MINOR ${ARG_VERSION_MINOR} PARENT_SCOPE)
100+
set(PROJECT_VERSION_PATCH ${ARG_VERSION_PATCH} PARENT_SCOPE)
111101

112102
# Create the basic library target (always done)
113103
_cpp_library_setup_core(
@@ -117,7 +107,6 @@ function(cpp_library_setup)
117107
NAMESPACE "${ARG_NAMESPACE}"
118108
HEADERS "${ARG_HEADERS}"
119109
SOURCES "${ARG_SOURCES}"
120-
HEADER_DIR "${ARG_HEADER_DIR}"
121110
REQUIRES_CPP_VERSION "${ARG_REQUIRES_CPP_VERSION}"
122111
TOP_LEVEL "${PROJECT_IS_TOP_LEVEL}"
123112
)
@@ -137,10 +126,8 @@ function(cpp_library_setup)
137126
)
138127
endif()
139128

140-
# Generate CMakePresets.json (unless disabled)
141-
if(NOT ARG_NO_PRESETS)
142-
_cpp_library_generate_presets(FORCE_INIT ${ARG_FORCE_INIT})
143-
endif()
129+
# Generate CMakePresets.json
130+
_cpp_library_generate_presets(FORCE_INIT ${ARG_FORCE_INIT})
144131

145132
# Copy static template files (like .clang-format, .gitignore, etc.)
146133
_cpp_library_copy_templates(FORCE_INIT ${ARG_FORCE_INIT})
@@ -164,15 +151,13 @@ function(cpp_library_setup)
164151
)
165152
endif()
166153

167-
# Setup CI (unless disabled)
168-
if(NOT ARG_NO_CI)
169-
_cpp_library_setup_ci(
170-
NAME "${ARG_NAME}"
171-
VERSION "${ARG_VERSION}"
172-
DESCRIPTION "${ARG_DESCRIPTION}"
173-
FORCE_INIT ${ARG_FORCE_INIT}
174-
)
175-
endif()
154+
# Setup CI
155+
_cpp_library_setup_ci(
156+
NAME "${ARG_NAME}"
157+
VERSION "${ARG_VERSION}"
158+
DESCRIPTION "${ARG_DESCRIPTION}"
159+
FORCE_INIT ${ARG_FORCE_INIT}
160+
)
176161

177162
# Build examples if specified
178163
if(ARG_EXAMPLES)

0 commit comments

Comments
 (0)