Skip to content

Commit 5bf4f34

Browse files
authored
Move to CPM, simplify (#15)
* Remove external dependencies for project_options * drastically simplify the way options are managed, using simple CMake `option` commands * move from Conan to CPM (better control over build flags, less likely to accidentally have ABI/ODR issues) * enhance defaults to focus on safety: * C++ hardening flags enabled by default * UBSan `minimal-runtime` enabled for shipping binaries when possible, for hardening * Static libraries + LTO enabled for better performance and detection of ODR violations * _FORTIFY_SOURCE level 3 enabled * checked STL for GCC enabled * basic example of a library added * automatic enabling of fuzz testing binary when possible * many various bug fixes to the build system * projects made with this template should now be fetch-content-able
1 parent c655234 commit 5bf4f34

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1727
-434
lines changed

.clang-tidy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ WarningsAsErrors: ''
1818
HeaderFilterRegex: ''
1919
FormatStyle: none
2020

21+
CheckOptions:
22+
- key: readability-identifier-length.IgnoredVariableNames
23+
value: 'x|y|z'
24+
- key: readability-identifier-length.IgnoredParameterNames
25+
value: 'x|y|z'
2126

2227

2328

.github/actions/setup_cache/action.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@ runs:
2424
with:
2525
# You might want to add .ccache to your cache configuration?
2626
path: |
27-
~/vcpkg
28-
./build/vcpkg_installed
29-
${{ env.CONAN_USER_HOME }}
3027
~/.cache/pip
3128
${{ env.HOME }}/.cache/vcpkg/archives
3229
${{ env.XDG_CACHE_HOME }}/vcpkg/archives
3330
${{ env.LOCALAPPDATA }}\vcpkg\archives
3431
${{ env.APPDATA }}\vcpkg\archives
35-
key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.build_type }}-${{ hashFiles('./conanfile.txt')}}-${{ inputs.generator }}-${{ inputs.developer_mode }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}
32+
key: ${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.build_type }}-${{ inputs.generator }}-${{ inputs.developer_mode }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}
3633
restore-keys: |
37-
${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.build_type }}-${{ hashFiles('./conanfile.txt') }}
34+
${{ runner.os }}-${{ inputs.compiler }}-${{ inputs.build_type }}
3835

.github/workflows/ci.yml

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ on:
1010
- develop
1111

1212
env:
13-
# Conan cache environment variables
14-
CONAN_SYSREQUIRES_MODE: enabled
15-
CONAN_USER_HOME: "${{ github.workspace }}/conan-cache"
16-
CONAN_USER_HOME_SHORT: "${{ github.workspace }}/conan-cache/short"
17-
CLANG_TIDY_VERSION: "13.0.0"
13+
CLANG_TIDY_VERSION: "15.0.2"
14+
VERBOSE: 1
1815

1916
jobs:
2017
Test:
@@ -35,17 +32,19 @@ jobs:
3532
- macos-10.15
3633
- windows-2019
3734
compiler:
38-
# you can specify the version after `-` like "llvm-13.0.0".
39-
- llvm-13.0.0
35+
# you can specify the version after `-` like "llvm-15.0.2".
36+
- llvm-15.0.2
4037
- gcc-11
4138
generator:
4239
- "Ninja Multi-Config"
4340
build_type:
4441
- Release
4542
- Debug
46-
developer_mode:
43+
package_maintainer_mode:
4744
- ON
4845
- OFF
46+
build_shared:
47+
- OFF
4948

5049
exclude:
5150
# mingw is determined by this author to be too buggy to support
@@ -57,12 +56,18 @@ jobs:
5756
# if you try to use a compiler that does not have gcov set
5857
- compiler: gcc-11
5958
gcov_executable: gcov
60-
- compiler: llvm-13.0.0
59+
enable_ipo: On
60+
61+
- compiler: llvm-15.0.2
62+
enable_ipo: Off
6163
gcov_executable: "llvm-cov gcov"
6264

65+
- os: macos-10.15
66+
enable_ipo: Off
67+
6368
# Set up preferred package generators, for given build configurations
6469
- build_type: Release
65-
developer_mode: OFF
70+
package_maintainer_mode: OFF
6671
package_generator: TBZ2
6772

6873
# This exists solely to make sure a non-multiconfig build works
@@ -71,34 +76,45 @@ jobs:
7176
generator: "Unix Makefiles"
7277
build_type: Debug
7378
gcov_executable: gcov
74-
developer_mode: On
79+
package_maintainer_mode: On
80+
enable_ipo: Off
7581

7682
# Windows msvc builds
7783
- os: windows-2022
7884
compiler: msvc
7985
generator: "Visual Studio 17 2022"
8086
build_type: Debug
81-
developer_mode: On
87+
package_maintainer_mode: On
88+
enable_ipo: On
8289

8390
- os: windows-2022
8491
compiler: msvc
8592
generator: "Visual Studio 17 2022"
8693
build_type: Release
87-
developer_mode: On
94+
package_maintainer_mode: On
95+
enable_ipo: On
8896

8997
- os: windows-2022
9098
compiler: msvc
9199
generator: "Visual Studio 17 2022"
92100
build_type: Debug
93-
developer_mode: Off
101+
package_maintainer_mode: Off
94102

95103
- os: windows-2022
96104
compiler: msvc
97105
generator: "Visual Studio 17 2022"
98106
build_type: Release
99-
developer_mode: Off
107+
package_maintainer_mode: Off
100108
package_generator: ZIP
101109

110+
- os: windows-2022
111+
compiler: msvc
112+
generator: "Visual Studio 17 2022"
113+
build_type: Release
114+
package_maintainer_mode: On
115+
enable_ipo: On
116+
build_shared: On
117+
102118

103119
steps:
104120
- name: Check for llvm version mismatches
@@ -115,7 +131,7 @@ jobs:
115131
with:
116132
compiler: ${{ matrix.compiler }}
117133
build_type: ${{ matrix.build_type }}
118-
developer_mode: ${{ matrix.developer_mode }}
134+
package_maintainer_mode: ${{ matrix.package_maintainer_mode }}
119135
generator: ${{ matrix.generator }}
120136

121137
- name: Setup Cpp
@@ -126,7 +142,6 @@ jobs:
126142

127143
cmake: true
128144
ninja: true
129-
conan: true
130145
vcpkg: false
131146
ccache: true
132147
clangtidy: ${{ env.CLANG_TIDY_VERSION }}
@@ -137,15 +152,9 @@ jobs:
137152
gcovr: true
138153
opencppcoverage: true
139154

140-
- name: Cleanup Conan system packages (they are not properly cached)
141-
run: |
142-
conan remove -f '*/system'
143-
144-
# make sure coverage is only enabled for Debug builds, since it sets -O0 to make sure coverage
145-
# has meaningful results
146155
- name: Configure CMake
147156
run: |
148-
cmake -S . -B ./build -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -DENABLE_DEVELOPER_MODE:BOOL=${{matrix.developer_mode}} -DOPT_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }} -DGIT_SHA:STRING=${{ github.sha }}
157+
cmake -S . -B ./build -G "${{matrix.generator}}" -Dmyproject_ENABLE_IPO=${{matrix.enable_ipo }} -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -Dmyproject_PACKAGING_MAINTAINER_MODE:BOOL=${{matrix.package_maintainer_mode}} -Dmyproject_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }} -DGIT_SHA:STRING=${{ github.sha }}
149158
150159
- name: Build
151160
# Execute the build. You can specify a specific target with "--target <NAME>"

.github/workflows/codeql-analysis.yml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ on:
2020
schedule:
2121
- cron: '38 0 * * 5'
2222

23-
env:
24-
# Conan cache environment variables
25-
CONAN_SYSREQUIRES_MODE: enabled
26-
CONAN_USER_HOME: "${{ github.workspace }}/conan-cache"
27-
CONAN_USER_HOME_SHORT: "${{ github.workspace }}/conan-cache/short"
28-
2923

3024
jobs:
3125
analyze:
@@ -49,8 +43,8 @@ jobs:
4943
- "Ninja Multi-Config"
5044
build_type:
5145
- Debug
52-
developer_mode:
53-
- OFF
46+
packaging_maintainer_mode:
47+
- ON
5448

5549

5650
steps:
@@ -61,7 +55,7 @@ jobs:
6155
with:
6256
compiler: ${{ matrix.compiler }}
6357
build_type: ${{ matrix.build_type }}
64-
developer_mode: ${{ matrix.developer_mode }}
58+
packaging_maintainer_mode: ${{ matrix.packaging_maintainer_mode }}
6559
generator: ${{ matrix.generator }}
6660

6761

@@ -73,7 +67,6 @@ jobs:
7367

7468
cmake: true
7569
ninja: true
76-
conan: true
7770
vcpkg: false
7871
ccache: true
7972
clangtidy: false
@@ -83,15 +76,11 @@ jobs:
8376
gcovr: false
8477
opencppcoverage: false
8578

86-
- name: Cleanup Conan system packages (they are not properly cached)
87-
run: |
88-
conan remove -f '*/system'
89-
9079
# make sure coverage is only enabled for Debug builds, since it sets -O0 to make sure coverage
9180
# has meaningful results
9281
- name: Configure CMake
9382
run: |
94-
cmake -S . -B ./build -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -DENABLE_DEVELOPER_MODE:BOOL=${{matrix.developer_mode}} -DOPT_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }}
83+
cmake -S . -B ./build -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -Dmyproject_PACKAGING_MAINTAINER_MODE:BOOL=${{matrix.packaging_maintainer_mode}} -DOPT_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }}
9584
9685
# Initializes the CodeQL tools for scanning.
9786
- name: Initialize CodeQL

.github/workflows/template-janitor.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ on:
1414

1515
env:
1616
TEMPLATES_PATH: ".github/template"
17-
CONAN_SYSREQUIRES_MODE: enabled
18-
CONAN_USER_HOME: "${{ github.workspace }}/conan-cache"
19-
CONAN_USER_HOME_SHORT: "${{ github.workspace }}/conan-cache/short"
2017

21-
18+
2219
jobs:
2320

2421
template-cleanup:
@@ -77,7 +74,7 @@ jobs:
7774
- name: Insert new org and project
7875
run: |
7976
# rename the CMake project to match the github project
80-
sed -i "s/myproject/${{ env.NEW_SAFE_PROJECT }}/gi" CMakeLists.txt configured_files/config.hpp.in src/main.cpp test/CMakeLists.txt fuzz_test/CMakeLists.txt
77+
find src include test fuzz_test -type f -exec sed -i "s/myproject/${{ env.NEW_SAFE_PROJECT }}/gi" CMakeLists.txt ProjectOptions.cmake .github/workflows/ci.yml .github/workflows/codeql-analysis.yml configured_files/config.hpp.in {} +
8178
8279
# Update URL placeholders for project
8380
sed -i "s|%%myurl%%|${{ fromJson(steps.get_repo_meta.outputs.data).html_url }}|gi" CMakeLists.txt
@@ -86,6 +83,7 @@ jobs:
8683
sed -i "s/%%myorg%%/${{ env.NEW_ORG }}/g" ${{ env.TEMPLATES_PATH }}/README.md
8784
sed -i "s/%%myproject%%/${{ env.NEW_PROJECT }}/g" ${{ env.TEMPLATES_PATH }}/README.md
8885
sed -i "s|%%description%%|${{ fromJson(steps.get_repo_meta.outputs.data).description }}|g" ${{ env.TEMPLATES_PATH }}/README.md
86+
mv include/myproject include/${{ env.NEW_SAFE_PROJECT }}
8987
cp ${{ env.TEMPLATES_PATH }}/README.md README.md
9088
9189
- name: Print diff after replacement
@@ -115,7 +113,6 @@ jobs:
115113

116114
cmake: true
117115
ninja: false
118-
conan: true
119116
vcpkg: false
120117
ccache: false
121118
clangtidy: false
@@ -125,9 +122,6 @@ jobs:
125122
gcovr: false
126123
opencppcoverage: false
127124

128-
- name: Cleanup Conan system packages (they are not properly cached)
129-
run: |
130-
conan remove -f '*/system'
131125

132126
- name: Test simple configuration to make sure nothing broke
133127
run: |
@@ -217,7 +211,6 @@ jobs:
217211

218212
cmake: true
219213
ninja: false
220-
conan: true
221214
vcpkg: false
222215
ccache: false
223216
clangtidy: false
@@ -227,9 +220,6 @@ jobs:
227220
gcovr: false
228221
opencppcoverage: false
229222

230-
- name: Cleanup Conan system packages (they are not properly cached)
231-
run: |
232-
conan remove -f '*/system'
233223

234224
- name: Test simple configuration to make sure nothing broke (default compiler,cmake,developer_mode OFF)
235225
run: |

0 commit comments

Comments
 (0)