Skip to content

Commit 638eafa

Browse files
authored
Merge pull request #12 from cpp-best-practices/develop
Develop
2 parents 54a0af9 + 3802856 commit 638eafa

File tree

9 files changed

+173
-90
lines changed

9 files changed

+173
-90
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ env:
1414
CONAN_SYSREQUIRES_MODE: enabled
1515
CONAN_USER_HOME: "${{ github.workspace }}/conan-cache"
1616
CONAN_USER_HOME_SHORT: "${{ github.workspace }}/conan-cache/short"
17+
CLANG_TIDY_VERSION: "13.0.0"
1718

1819
jobs:
1920
Test:
@@ -72,21 +73,25 @@ jobs:
7273
gcov_executable: gcov
7374
developer_mode: On
7475

76+
# Windows msvc builds
7577
- os: windows-2022
7678
compiler: msvc
7779
generator: "Visual Studio 17 2022"
7880
build_type: Debug
7981
developer_mode: On
82+
8083
- os: windows-2022
8184
compiler: msvc
8285
generator: "Visual Studio 17 2022"
8386
build_type: Release
8487
developer_mode: On
88+
8589
- os: windows-2022
8690
compiler: msvc
8791
generator: "Visual Studio 17 2022"
8892
build_type: Debug
8993
developer_mode: Off
94+
9095
- os: windows-2022
9196
compiler: msvc
9297
generator: "Visual Studio 17 2022"
@@ -95,10 +100,14 @@ jobs:
95100
package_generator: ZIP
96101

97102

98-
99-
100-
101103
steps:
104+
- name: Check for llvm version mismatches
105+
if: ${{ contains(matrix.compiler, 'llvm') && !contains(matrix.compiler, env.CLANG_TIDY_VERSION) }}
106+
uses: actions/github-script@v3
107+
with:
108+
script: |
109+
core.setFailed('There is a mismatch between configured llvm compiler and clang-tidy version chosen')
110+
102111
- uses: actions/checkout@v2
103112

104113
- name: Setup Cache
@@ -120,7 +129,8 @@ jobs:
120129
conan: true
121130
vcpkg: false
122131
ccache: true
123-
clangtidy: true
132+
clangtidy: ${{ env.CLANG_TIDY_VERSION }}
133+
124134

125135
cppcheck: true
126136

.github/workflows/template-janitor.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,23 @@ jobs:
6161
env:
6262
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6363

64+
- name: Use testing variables if still a template
65+
if: fromJson(steps.get_repo_meta.outputs.data).is_template == true
66+
run: |
67+
# This name is unsafe because it is not a valid C++ identifier
68+
echo "NEW_PROJECT=my-unsafe.project" >> $GITHUB_ENV
69+
70+
- name: Add safe replacement variable versions
71+
run: |
72+
# hyphens and dots in c++ identifiers are forbidden. Use underscores instead.
73+
NEW_SAFE_PROJECT=$(echo ${{ env.NEW_PROJECT }} | sed "s/-/_/g" | sed "s/\./_/g" )
74+
echo "NEW_SAFE_PROJECT=$NEW_SAFE_PROJECT" >> $GITHUB_ENV
75+
6476
# Rename all cpp_starter_project occurences to current repository and remove this workflow
6577
- name: Insert new org and project
6678
run: |
6779
# rename the CMake project to match the github project
68-
sed -i "s/myproject/${{ github.event.repository.name }}/gi" CMakeLists.txt configured_files/config.hpp.in src/main.cpp
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
6981
7082
# Update URL placeholders for project
7183
sed -i "s|%%myurl%%|${{ fromJson(steps.get_repo_meta.outputs.data).html_url }}|gi" CMakeLists.txt
@@ -120,7 +132,8 @@ jobs:
120132
- name: Test simple configuration to make sure nothing broke
121133
run: |
122134
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=OFF
123-
135+
# Build it because we may have broken something in the cpp/hpp files
136+
cmake --build build
124137
125138
- uses: EndBug/add-and-commit@v4
126139
# only commit and push if we are not a template project anymore!

.gitlab-ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ stages:
2020
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F
2121

2222
.setup_cpp: &setup_cpp |
23-
curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.5.8/setup_cpp_linux"
23+
curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.10.0/setup_cpp_linux"
2424
chmod +x setup_cpp_linux
25-
./setup_cpp_linux --compiler $compiler --cmake true --ninja true --conan true --ccache true
25+
./setup_cpp_linux --compiler $compiler --cmake true --ninja true --conan true --ccache true --clangtidy true --clangformat true --cppcheck true
2626
source ~/.profile
2727

2828
.test: &test |
@@ -46,4 +46,4 @@ test_linux_gcc:
4646
script:
4747
- *setup_linux
4848
- *setup_cpp
49-
- *test
49+
- *test

CMakeLists.txt

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.16)
1+
cmake_minimum_required(VERSION 3.16...3.23)
22

33
# Not ideal to use this global variable, but necessary to make sure
44
# that tooling and projects use the same version
@@ -22,10 +22,10 @@ set(ENABLE_DEVELOPER_MODE
2222
# Change this to false if you want to disable warnings_as_errors in developer mode
2323
set(OPT_WARNINGS_AS_ERRORS_DEVELOPER_DEFAULT TRUE)
2424

25-
# Add project_options v0.17.0
25+
# Add project_options v0.20.0
2626
# https://github.com/cpp-best-practices/project_options
27-
FetchContent_Declare(_project_options
28-
URL https://github.com/cpp-best-practices/project_options/archive/refs/tags/v0.17.0.zip)
27+
include(FetchContent)
28+
FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.20.0.zip)
2929
FetchContent_MakeAvailable(_project_options)
3030
include(${_project_options_SOURCE_DIR}/Index.cmake)
3131

@@ -41,6 +41,18 @@ project(
4141
HOMEPAGE_URL "%%myurl%%"
4242
LANGUAGES CXX C)
4343

44+
# This variable is set by project() in CMake 3.21+
45+
string(
46+
COMPARE EQUAL
47+
"${CMAKE_SOURCE_DIR}"
48+
"${PROJECT_SOURCE_DIR}"
49+
PROJECT_IS_TOP_LEVEL)
50+
if(PROJECT_IS_TOP_LEVEL)
51+
# Consider the CTest module, which creates targets and options!
52+
# Only needed if you want to enable submissions to a CDash server.
53+
include(CTest)
54+
endif()
55+
4456
set(GIT_SHA
4557
"Unknown"
4658
CACHE STRING "SHA this build was generated from")
@@ -93,14 +105,28 @@ dynamic_project_options(
93105
PCH_HEADERS
94106
<vector>
95107
<string> # This is a list of headers to pre-compile, here are some common ones
108+
ENABLE_CONAN
96109
# CONAN_OPTIONS # Extra options to pass to conan
97110
# MSVC_WARNINGS # Override the defaults for the MSVC warnings
98111
# CLANG_WARNINGS # Override the defaults for the CLANG warnings
99112
# GCC_WARNINGS # Override the defaults for the GCC warnings
100-
# CPPCHECK_OPTIONS # Override the defaults for CppCheck
113+
CPPCHECK_OPTIONS
114+
--enable=style,performance,warning,portability
115+
--inline-suppr
116+
# We cannot act on a bug/missing feature of cppcheck
117+
--suppress=cppcheckError
118+
--suppress=internalAstError
119+
# if a file does not have an internalAstError, we get an unmatchedSuppression error
120+
--suppress=unmatchedSuppression
121+
--suppress=passedByValue
122+
--suppress=syntaxError
123+
--inconclusive
101124
)
102125

103126
target_compile_features(project_options INTERFACE cxx_std_${CMAKE_CXX_STANDARD})
127+
# TODO: The INTERFACE library NAMESPACE ALIAS are missing! CK
128+
add_library(myproject::project_options INTERFACE IMPORTED)
129+
add_library(myproject::project_warnings INTERFACE IMPORTED)
104130

105131
# configure files based on CMake configuration options
106132
add_subdirectory(configured_files)
@@ -109,33 +135,42 @@ add_subdirectory(configured_files)
109135
add_subdirectory(src)
110136

111137
# Adding the tests:
112-
option(ENABLE_TESTING "Enable the tests" ON)
138+
option(ENABLE_TESTING "Enable the tests" ${PROJECT_IS_TOP_LEVEL})
113139
if(ENABLE_TESTING)
114140
enable_testing()
115-
message("Building Tests. Be sure to check out test/constexpr_tests for constexpr
116-
testing")
141+
message(AUTHOR_WARNING "Building Tests. Be sure to check out test/constexpr_tests.cpp for constexpr testing")
117142
add_subdirectory(test)
118143
endif()
119144

120145
option(ENABLE_FUZZING "Enable the fuzz tests" OFF)
121146
if(ENABLE_FUZZING)
122-
message("Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
147+
message(AUTHOR_WARNING "Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
123148
add_subdirectory(fuzz_test)
124149
endif()
125150

126151
# If MSVC is being used, and ASAN is enabled, we need to set the debugger environment
127152
# so that it behaves well with MSVC's debugger, and we can run the target from visual studio
128153
if(MSVC)
129-
get_all_targets(all_targets)
154+
get_all_installable_targets(all_targets)
155+
message("all_targets=${all_targets}")
130156
set_target_properties(${all_targets} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=$(VC_ExecutablePath_x64);%PATH%")
131157
endif()
132158

133159
# set the startup project for the "play" button in MSVC
134160
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT intro)
135161

162+
if(CMAKE_SKIP_INSTALL_RULES)
163+
return()
164+
elseif(NOT PROJECT_IS_TOP_LEVEL)
165+
return()
166+
endif()
167+
136168
# Add other targets that you want installed here, be default we just package the one executable
137169
# we know we want to ship
138-
package_project(TARGETS intro)
170+
package_project(TARGETS intro project_options project_warnings
171+
# FIXME: this does not work! CK
172+
# PRIVATE_DEPENDENCIES_CONFIGURED project_options project_warnings
173+
)
139174

140175
# Experience shows that explicit package naming can help make it easier to sort
141176
# out potential ABI related issues before they start, while helping you

CMakePresets.json

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@
3838
}
3939
},
4040
{
41-
"name": "conf-linux-common",
42-
"description": "Linux settings for gcc and clang toolchains",
41+
"name": "conf-unixlike-common",
42+
"description": "Unix-like OS settings for gcc and clang toolchains",
4343
"hidden": true,
4444
"inherits": "conf-common",
4545
"condition": {
46-
"type": "equals",
47-
"lhs": "${hostSystemName}",
48-
"rhs": "Linux"
46+
"type": "inList",
47+
"string": "${hostSystemName}",
48+
"list": [
49+
"Linux",
50+
"Darwin"
51+
]
4952
},
5053
"vendor": {
5154
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
@@ -75,7 +78,7 @@
7578
"CMAKE_CXX_COMPILER": "cl",
7679
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
7780
"ENABLE_DEVELOPER_MODE": "ON"
78-
}
81+
}
7982
},
8083
{
8184
"name": "windows-msvc-debug-user-mode",
@@ -87,7 +90,7 @@
8790
"CMAKE_CXX_COMPILER": "cl",
8891
"CMAKE_BUILD_TYPE": "Debug",
8992
"ENABLE_DEVELOPER_MODE": "OFF"
90-
}
93+
}
9194
},
9295
{
9396
"name": "windows-msvc-release-user-mode",
@@ -99,7 +102,7 @@
99102
"CMAKE_CXX_COMPILER": "cl",
100103
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
101104
"ENABLE_DEVELOPER_MODE": "OFF"
102-
}
105+
}
103106
},
104107
{
105108
"name": "windows-clang-debug",
@@ -134,43 +137,43 @@
134137
}
135138
},
136139
{
137-
"name": "linux-gcc-debug",
140+
"name": "unixlike-gcc-debug",
138141
"displayName": "gcc Debug",
139-
"description": "Target Linux with the gcc compiler, debug build type",
140-
"inherits": "conf-linux-common",
142+
"description": "Target Unix-like OS with the gcc compiler, debug build type",
143+
"inherits": "conf-unixlike-common",
141144
"cacheVariables": {
142145
"CMAKE_C_COMPILER": "gcc",
143146
"CMAKE_CXX_COMPILER": "g++",
144147
"CMAKE_BUILD_TYPE": "Debug"
145148
}
146149
},
147150
{
148-
"name": "linux-gcc-release",
151+
"name": "unixlike-gcc-release",
149152
"displayName": "gcc Release",
150-
"description": "Target Linux with the gcc compiler, release build type",
151-
"inherits": "conf-linux-common",
153+
"description": "Target Unix-like OS with the gcc compiler, release build type",
154+
"inherits": "conf-unixlike-common",
152155
"cacheVariables": {
153156
"CMAKE_C_COMPILER": "gcc",
154157
"CMAKE_CXX_COMPILER": "g++",
155158
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
156159
}
157160
},
158161
{
159-
"name": "linux-clang-debug",
162+
"name": "unixlike-clang-debug",
160163
"displayName": "clang Debug",
161-
"description": "Target Linux with the clang compiler, debug build type",
162-
"inherits": "conf-linux-common",
164+
"description": "Target Unix-like OS with the clang compiler, debug build type",
165+
"inherits": "conf-unixlike-common",
163166
"cacheVariables": {
164167
"CMAKE_C_COMPILER": "clang",
165168
"CMAKE_CXX_COMPILER": "clang++",
166169
"CMAKE_BUILD_TYPE": "Debug"
167170
}
168171
},
169172
{
170-
"name": "linux-clang-release",
173+
"name": "unixlike-clang-release",
171174
"displayName": "clang Release",
172-
"description": "Target Linux with the clang compiler, release build type",
173-
"inherits": "conf-linux-common",
175+
"description": "Target Unix-like OS with the clang compiler, release build type",
176+
"inherits": "conf-unixlike-common",
174177
"cacheVariables": {
175178
"CMAKE_C_COMPILER": "clang",
176179
"CMAKE_CXX_COMPILER": "clang++",
@@ -220,32 +223,32 @@
220223
"configurePreset": "windows-clang-release"
221224
},
222225
{
223-
"name": "test-linux-gcc-debug",
226+
"name": "test-unixlike-gcc-debug",
224227
"displayName": "Strict",
225228
"description": "Enable output and stop on failure",
226229
"inherits": "test-common",
227-
"configurePreset": "linux-gcc-debug"
230+
"configurePreset": "unixlike-gcc-debug"
228231
},
229232
{
230-
"name": "test-linux-gcc-release",
233+
"name": "test-unixlike-gcc-release",
231234
"displayName": "Strict",
232235
"description": "Enable output and stop on failure",
233236
"inherits": "test-common",
234-
"configurePreset": "linux-gcc-release"
237+
"configurePreset": "unixlike-gcc-release"
235238
},
236239
{
237-
"name": "test-linux-clang-debug",
240+
"name": "test-unixlike-clang-debug",
238241
"displayName": "Strict",
239242
"description": "Enable output and stop on failure",
240243
"inherits": "test-common",
241-
"configurePreset": "linux-clang-debug"
244+
"configurePreset": "unixlike-clang-debug"
242245
},
243246
{
244-
"name": "test-linux-clang-release",
247+
"name": "test-unixlike-clang-release",
245248
"displayName": "Strict",
246249
"description": "Enable output and stop on failure",
247250
"inherits": "test-common",
248-
"configurePreset": "linux-clang-release"
251+
"configurePreset": "unixlike-clang-release"
249252
}
250253
]
251-
}
254+
}

conanfile.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# Docs at https://docs.conan.io/en/latest/reference/conanfile_txt.html
22

33
[requires]
4-
catch2/2.13.8
5-
docopt.cpp/0.6.3
6-
#fmt/8.1.1
7-
spdlog/1.9.2
4+
catch2/2.13.9
5+
cli11/2.2.0
6+
spdlog/1.10.0
87
ftxui/2.0.0
98

109
[generators]

0 commit comments

Comments
 (0)