Skip to content

Commit efbdc4f

Browse files
committed
Cleanup
Removing more of install and updating dependency versions.
1 parent 6e83d11 commit efbdc4f

File tree

3 files changed

+75
-113
lines changed

3 files changed

+75
-113
lines changed

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Modern CMake template for C++ libraries with comprehensive infrastructure.
1212
`cpp-library` provides a standardized CMake infrastructure template for C++ libraries. It eliminates boilerplate and provides consistent patterns for:
1313

1414
- **Project Declaration**: Uses existing `project()` declaration with automatic git tag-based versioning
15-
- **Library Setup**: INTERFACE targets with proper installation and package config
1615
- **Testing**: Integrated doctest with CTest and compile-fail test support
1716
- **Documentation**: Doxygen with doxygen-awesome-css theme
1817
- **Development Tools**: clangd integration, CMakePresets.json, clang-tidy support
@@ -64,13 +63,13 @@ cpp_library_setup(
6463
DESCRIPTION description # e.g., "Type-safe operators for enums"
6564
NAMESPACE namespace # e.g., "stlab"
6665
HEADERS header_list # List of header filenames (e.g., "your_header.hpp")
67-
66+
6867
# Source specification for non-header-only libraries
6968
SOURCES source_list # List of source filenames (e.g., "your_library.cpp", omit for header-only libraries)
7069
7170
# Optional features
7271
[EXAMPLES example_list] # Example source files to build (e.g., "example.cpp example_fail.cpp")
73-
[TESTS test_list] # Test source files to build (e.g., "tests.cpp")
72+
[TESTS test_list] # Test source files to build (e.g., "tests.cpp")
7473
[DOCS_EXCLUDE_SYMBOLS symbols] # Symbols to exclude from docs
7574
[REQUIRES_CPP_VERSION 17|20|23] # C++ version (default: 17)
7675
)
@@ -118,6 +117,7 @@ The template automatically generates the full paths based on these conventions.
118117
### Library Types
119118

120119
**Header-only libraries**: Specify only `HEADERS`, omit `SOURCES`
120+
121121
```cmake
122122
cpp_library_setup(
123123
DESCRIPTION "Header-only library"
@@ -128,6 +128,7 @@ cpp_library_setup(
128128
```
129129

130130
**Non-header-only libraries**: Specify both `HEADERS` and `SOURCES`
131+
131132
```cmake
132133
cpp_library_setup(
133134
DESCRIPTION "Library with implementation"
@@ -138,15 +139,15 @@ cpp_library_setup(
138139
```
139140

140141
## Features
142+
141143
### Non-Header-Only Library Support
142144

143145
- **Non-header-only library support**: For libraries with source files, specify them explicitly with the `SOURCES` argument as filenames (e.g., `"your_library.cpp"`).
144-
Both header-only and compiled libraries are supported seamlessly.
146+
Both header-only and compiled libraries are supported seamlessly.
145147

146148
### Automated Infrastructure
147149

148150
- **CMakePresets.json**: Generates standard presets (default, test, docs, clang-tidy, init)
149-
- **Installation**: Modern CMake package config with FILE_SET headers
150151
- **Testing**: doctest integration with CTest and compile-fail test support
151152
- **Documentation**: Doxygen with doxygen-awesome-css theme
152153
- **Development**: clangd compile_commands.json symlink
@@ -155,12 +156,12 @@ cpp_library_setup(
155156
### Smart Defaults
156157

157158
- **C++17** standard requirement (configurable)
158-
- **Ninja** generator in presets
159+
- **Ninja** generator in presets
159160
- **Debug** builds for testing, **Release** for default
160161
- **Build isolation** with separate build directories
161162
- **Two-mode operation**: Full infrastructure when top-level, lightweight when consumed
162163
- **Automatic version detection**: Version is automatically extracted from git tags (e.g., `v1.2.3` becomes `1.2.3`)
163-
- **Always-enabled features**: CI/CD, CMakePresets.json, and proper installation are always generated
164+
- **Always-enabled features**: CI/CD, and CMakePresets.json, are always generated
164165

165166
### Testing Features
166167

@@ -244,13 +245,14 @@ cpp_library_setup(
244245
## Quick Start
245246

246247
1. **Initialize a new project**:
248+
247249
```bash
248250
# Clone or create your project
249251
mkdir my-library && cd my-library
250-
252+
251253
# Create basic structure
252254
mkdir -p include/your_namespace src examples tests cmake
253-
255+
254256
# Add CPM.cmake
255257
curl -L https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake -o cmake/CPM.cmake
256258
```
@@ -264,6 +266,7 @@ cpp_library_setup(
264266
5. **Add tests** to `tests/` (use `_fail` suffix for compile-fail tests, e.g., `tests.cpp`, `tests_fail.cpp`)
265267

266268
6. **Build and test**:
269+
267270
```bash
268271
cmake --preset=test
269272
cmake --build --preset=test
@@ -280,11 +283,11 @@ cpp_library_setup(
280283

281284
The template automatically generates:
282285

283-
- **CMakePresets.json**: Build configurations for different purposes
284-
- **.github/workflows/ci.yml**: Multi-platform CI/CD pipeline
285-
- **.gitignore**: Standard ignores for C++ projects
286-
- **src/**: Source directory for non-header-only libraries (auto-detected)
287-
- **Package config files**: For proper CMake integration
286+
- **CMakePresets.json**: Build configurations for different purposes
287+
- **.github/workflows/ci.yml**: Multi-platform CI/CD pipeline
288+
- **.gitignore**: Standard ignores for C++ projects
289+
- **src/**: Source directory for non-header-only libraries (auto-detected)
290+
- **Package config files**: For proper CMake integration
288291

289292
## License
290293

cmake/cpp-library-setup.cmake

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function(_cpp_library_get_git_version OUTPUT_VAR)
1212
OUTPUT_STRIP_TRAILING_WHITESPACE
1313
ERROR_QUIET
1414
)
15-
15+
1616
# If git tag found, use it (remove 'v' prefix if present)
1717
if(GIT_TAG_VERSION)
1818
string(REGEX REPLACE "^v" "" CLEAN_VERSION "${GIT_TAG_VERSION}")
@@ -27,7 +27,7 @@ endfunction()
2727
function(_cpp_library_setup_core)
2828
set(oneValueArgs
2929
NAME
30-
VERSION
30+
VERSION
3131
DESCRIPTION
3232
NAMESPACE
3333
REQUIRES_CPP_VERSION
@@ -37,28 +37,27 @@ function(_cpp_library_setup_core)
3737
HEADERS
3838
SOURCES
3939
)
40-
40+
4141
cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
42-
42+
4343
# Get version from git tags if not provided
4444
if(NOT ARG_VERSION)
4545
_cpp_library_get_git_version(GIT_VERSION)
4646
set(ARG_VERSION "${GIT_VERSION}")
4747
endif()
48-
48+
4949
# Note: Project declaration is now handled in the main cpp_library_setup function
5050
# No need to check ARG_TOP_LEVEL here for project declaration
51-
51+
5252
# Extract the library name without namespace prefix for target naming
5353
string(REPLACE "${ARG_NAMESPACE}-" "" CLEAN_NAME "${ARG_NAME}")
54-
54+
5555
if(ARG_SOURCES)
5656
# Create a regular library if sources are present
5757
add_library(${ARG_NAME} STATIC ${ARG_SOURCES})
5858
add_library(${ARG_NAMESPACE}::${CLEAN_NAME} ALIAS ${ARG_NAME})
5959
target_include_directories(${ARG_NAME} PUBLIC
6060
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
61-
$<INSTALL_INTERFACE:include>
6261
)
6362
target_compile_features(${ARG_NAME} PUBLIC cxx_std_${ARG_REQUIRES_CPP_VERSION})
6463
if(ARG_HEADERS)
@@ -75,7 +74,6 @@ function(_cpp_library_setup_core)
7574
add_library(${ARG_NAMESPACE}::${CLEAN_NAME} ALIAS ${ARG_NAME})
7675
target_include_directories(${ARG_NAME} INTERFACE
7776
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
78-
$<INSTALL_INTERFACE:include>
7977
)
8078
target_compile_features(${ARG_NAME} INTERFACE cxx_std_${ARG_REQUIRES_CPP_VERSION})
8179
if(ARG_HEADERS)
@@ -87,46 +85,7 @@ function(_cpp_library_setup_core)
8785
)
8886
endif()
8987
endif()
90-
91-
# Only set up full installation when building as top-level project
92-
if(ARG_TOP_LEVEL)
93-
include(GNUInstallDirs)
94-
include(CMakePackageConfigHelpers)
95-
96-
# Install the target
97-
install(TARGETS ${ARG_NAME}
98-
EXPORT ${ARG_NAME}Targets
99-
FILE_SET headers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
100-
)
101-
102-
# Generate package config files
103-
write_basic_package_version_file(
104-
"${CMAKE_CURRENT_BINARY_DIR}/${ARG_NAME}ConfigVersion.cmake"
105-
VERSION ${ARG_VERSION}
106-
COMPATIBILITY SameMajorVersion
107-
)
108-
109-
configure_file(
110-
"${CPP_LIBRARY_ROOT}/templates/Config.cmake.in"
111-
"${CMAKE_CURRENT_BINARY_DIR}/${ARG_NAME}Config.cmake"
112-
@ONLY
113-
)
114-
115-
# Install export targets
116-
install(EXPORT ${ARG_NAME}Targets
117-
FILE ${ARG_NAME}Targets.cmake
118-
NAMESPACE ${ARG_NAMESPACE}::
119-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${ARG_NAME}
120-
)
121-
122-
# Install config files
123-
install(FILES
124-
"${CMAKE_CURRENT_BINARY_DIR}/${ARG_NAME}Config.cmake"
125-
"${CMAKE_CURRENT_BINARY_DIR}/${ARG_NAME}ConfigVersion.cmake"
126-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${ARG_NAME}
127-
)
128-
endif()
129-
88+
13089
endfunction()
13190

13291
# Function to copy static template files
@@ -148,15 +107,15 @@ function(_cpp_library_copy_templates)
148107
foreach(template_file IN LISTS TEMPLATE_FILES)
149108
set(source_file "${CPP_LIBRARY_ROOT}/templates/${template_file}")
150109
set(dest_file "${CMAKE_CURRENT_SOURCE_DIR}/${template_file}")
151-
110+
152111
# Check if template file exists
153112
if(EXISTS "${source_file}")
154113
# Copy if file doesn't exist or FORCE_INIT is enabled
155114
if(NOT EXISTS "${dest_file}" OR ARG_FORCE_INIT)
156115
# Create directory if needed
157116
get_filename_component(dest_dir "${dest_file}" DIRECTORY)
158117
file(MAKE_DIRECTORY "${dest_dir}")
159-
118+
160119
# Copy the file
161120
file(COPY "${source_file}" DESTINATION "${dest_dir}")
162121
message(STATUS "Copied template file: ${template_file}")

templates/.github/workflows/ci.yml

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: CI
55

66
on:
77
push:
8-
branches: [ main, develop ]
8+
branches: [main, develop]
99
pull_request:
10-
branches: [ main ]
10+
branches: [main]
1111
release:
1212
types: [published]
1313

@@ -32,42 +32,42 @@ jobs:
3232
runs-on: ${{ matrix.os }}
3333

3434
steps:
35-
- uses: actions/checkout@v4
35+
- uses: actions/checkout@v5
3636

37-
- name: Configure CMake
38-
run: cmake --preset=test
37+
- name: Configure CMake
38+
run: cmake --preset=test
3939

40-
- name: Build
41-
run: cmake --build --preset=test
40+
- name: Build
41+
run: cmake --build --preset=test
4242

43-
- name: Test
44-
run: ctest --preset=test
43+
- name: Test
44+
run: ctest --preset=test
4545

4646
clang-tidy:
4747
runs-on: ubuntu-latest
48-
48+
4949
steps:
50-
- uses: actions/checkout@v4
50+
- uses: actions/checkout@v5
5151

52-
- name: Setup Ninja
53-
uses: ashutoshvarma/setup-ninja@master
52+
- name: Setup Ninja
53+
uses: ashutoshvarma/setup-ninja@v1
5454

55-
- name: Setup Clang
56-
uses: egor-tensin/setup-clang@v1
57-
with:
58-
version: latest
55+
- name: Setup Clang
56+
uses: egor-tensin/setup-clang@v1
57+
with:
58+
version: latest
5959

60-
- name: Install clang-tidy
61-
run: sudo apt-get update && sudo apt-get install -y clang-tidy
60+
- name: Install clang-tidy
61+
run: sudo apt-get update && sudo apt-get install -y clang-tidy
6262

63-
- name: Configure CMake with clang-tidy
64-
run: cmake --preset=clang-tidy
63+
- name: Configure CMake with clang-tidy
64+
run: cmake --preset=clang-tidy
6565

66-
- name: Build with clang-tidy
67-
run: cmake --build --preset=clang-tidy
66+
- name: Build with clang-tidy
67+
run: cmake --build --preset=clang-tidy
6868

69-
- name: Run tests with clang-tidy
70-
run: ctest --preset=clang-tidy
69+
- name: Run tests with clang-tidy
70+
run: ctest --preset=clang-tidy
7171

7272
docs:
7373
runs-on: ubuntu-latest
@@ -76,27 +76,27 @@ jobs:
7676
id-token: write
7777
pages: write
7878
contents: read
79-
79+
8080
steps:
81-
- uses: actions/checkout@v5
82-
83-
- name: Install Doxygen
84-
uses: ssciwr/doxygen-install@v1
85-
86-
- name: Configure CMake
87-
run: cmake --preset=docs
88-
89-
- name: Build Documentation
90-
run: cmake --build --preset=docs
91-
92-
- name: Setup Pages
93-
uses: actions/configure-pages@v5
94-
95-
- name: Upload artifact
96-
uses: actions/upload-pages-artifact@v3
97-
with:
98-
path: build/docs/html
99-
100-
- name: Deploy to GitHub Pages
101-
id: deployment
102-
uses: actions/deploy-pages@v4
81+
- uses: actions/checkout@v5
82+
83+
- name: Install Doxygen
84+
uses: ssciwr/doxygen-install@v1
85+
86+
- name: Configure CMake
87+
run: cmake --preset=docs
88+
89+
- name: Build Documentation
90+
run: cmake --build --preset=docs
91+
92+
- name: Setup Pages
93+
uses: actions/configure-pages@v5
94+
95+
- name: Upload artifact
96+
uses: actions/upload-pages-artifact@v4
97+
with:
98+
path: build/docs/html
99+
100+
- name: Deploy to GitHub Pages
101+
id: deployment
102+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)