Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit 849f985

Browse files
authored
Merge pull request #217 from cpp-best-practices/change_project_name
Update README.md
2 parents 2b9c3c9 + 9ab32f9 commit 849f985

13 files changed

+174
-108
lines changed

.github/template/template_name

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cpp_starter_project
1+
gui_starter_template

.github/template/template_repository

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cpp-best-practices/cpp_starter_project
1+
cpp-best-practices/gui_starter_template

.github/workflows/ci.yml

Lines changed: 15 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:
@@ -69,17 +70,20 @@ jobs:
6970
compiler: msvc
7071
generator: "Visual Studio 17 2022"
7172
build_type: Debug
72-
developer_mode: ON
73+
developer_mode: On
74+
7375
- os: windows-2022
7476
compiler: msvc
7577
generator: "Visual Studio 17 2022"
7678
build_type: Release
77-
developer_mode: ON
79+
developer_mode: On
80+
7881
- os: windows-2022
7982
compiler: msvc
8083
generator: "Visual Studio 17 2022"
8184
build_type: Debug
8285
developer_mode: OFF
86+
8387
- os: windows-2022
8488
compiler: msvc
8589
generator: "Visual Studio 17 2022"
@@ -88,8 +92,14 @@ jobs:
8892
package_generator: ZIP
8993

9094

91-
9295
steps:
96+
- name: Check for llvm version mismatches
97+
if: ${{ contains(matrix.compiler, 'llvm') && !contains(matrix.compiler, env.CLANG_TIDY_VERSION) }}
98+
uses: actions/github-script@v3
99+
with:
100+
script: |
101+
core.setFailed('There is a mismatch between configured llvm compiler and clang-tidy version chosen')
102+
93103
- uses: actions/checkout@v2
94104

95105
- name: Setup Cache
@@ -111,7 +121,8 @@ jobs:
111121
conan: true
112122
vcpkg: false
113123
ccache: true
114-
clangtidy: true
124+
clangtidy: ${{ env.CLANG_TIDY_VERSION }}
125+
115126

116127
cppcheck: true
117128

.github/workflows/template-janitor.yml

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

63+
- name: Use testing variables if still a template
64+
if: fromJson(steps.get_repo_meta.outputs.data).is_template == true
65+
run: |
66+
# This name is unsafe because it is not a valid C++ identifier
67+
echo "NEW_PROJECT=my-unsafe.project" >> $GITHUB_ENV
68+
69+
- name: Add safe replacement variable versions
70+
run: |
71+
# hyphens and dots in c++ identifiers are forbidden. Use underscores instead.
72+
NEW_SAFE_PROJECT=$(echo ${{ env.NEW_PROJECT }} | sed "s/-/_/g" | sed "s/\./_/g" )
73+
echo "NEW_SAFE_PROJECT=$NEW_SAFE_PROJECT" >> $GITHUB_ENV
74+
6375
# Rename all cpp_starter_project occurences to current repository and remove this workflow
6476
- name: Insert new org and project
6577
run: |
6678
# rename the CMake project to match the github project
67-
sed -i "s/myproject/${{ github.event.repository.name }}/gi" CMakeLists.txt configured_files/config.hpp.in src/main.cpp
79+
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
6880
6981
# Update URL placeholders for project
7082
sed -i "s|%%myurl%%|${{ fromJson(steps.get_repo_meta.outputs.data).html_url }}|gi" CMakeLists.txt
@@ -119,7 +131,8 @@ jobs:
119131
- name: Test simple configuration to make sure nothing broke
120132
run: |
121133
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
122-
134+
# Build it because we may have broken something in the cpp/hpp files
135+
cmake --build build
123136
124137
- uses: EndBug/add-and-commit@v4
125138
# 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: 45 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
@@ -20,11 +20,10 @@ set(ENABLE_DEVELOPER_MODE
2020
# Change this to false if you want to disable warnings_as_errors in developer mode
2121
set(OPT_WARNINGS_AS_ERRORS_DEVELOPER_DEFAULT TRUE)
2222

23-
# Add project_options v0.17.0
23+
# Add project_options v0.20.0
2424
# https://github.com/cpp-best-practices/project_options
2525
include(FetchContent)
26-
FetchContent_Declare(_project_options
27-
URL https://github.com/cpp-best-practices/project_options/archive/refs/tags/v0.17.0.zip)
26+
FetchContent_Declare(_project_options URL https://github.com/aminya/project_options/archive/refs/tags/v0.20.0.zip)
2827
FetchContent_MakeAvailable(_project_options)
2928
include(${_project_options_SOURCE_DIR}/Index.cmake)
3029

@@ -40,6 +39,18 @@ project(
4039
HOMEPAGE_URL "%%myurl%%"
4140
LANGUAGES CXX C)
4241

42+
# This variable is set by project() in CMake 3.21+
43+
string(
44+
COMPARE EQUAL
45+
"${CMAKE_SOURCE_DIR}"
46+
"${PROJECT_SOURCE_DIR}"
47+
PROJECT_IS_TOP_LEVEL)
48+
if(PROJECT_IS_TOP_LEVEL)
49+
# Consider the CTest module, which creates targets and options!
50+
# Only needed if you want to enable submissions to a CDash server.
51+
include(CTest)
52+
endif()
53+
4354
set(GIT_SHA
4455
"Unknown"
4556
CACHE STRING "SHA this build was generated from")
@@ -92,14 +103,28 @@ dynamic_project_options(
92103
PCH_HEADERS
93104
<vector>
94105
<string> # This is a list of headers to pre-compile, here are some common ones
106+
ENABLE_CONAN
95107
# CONAN_OPTIONS # Extra options to pass to conan
96108
# MSVC_WARNINGS # Override the defaults for the MSVC warnings
97109
# CLANG_WARNINGS # Override the defaults for the CLANG warnings
98110
# GCC_WARNINGS # Override the defaults for the GCC warnings
99-
# CPPCHECK_OPTIONS # Override the defaults for CppCheck
111+
CPPCHECK_OPTIONS
112+
--enable=style,performance,warning,portability
113+
--inline-suppr
114+
# We cannot act on a bug/missing feature of cppcheck
115+
--suppress=cppcheckError
116+
--suppress=internalAstError
117+
# if a file does not have an internalAstError, we get an unmatchedSuppression error
118+
--suppress=unmatchedSuppression
119+
--suppress=passedByValue
120+
--suppress=syntaxError
121+
--inconclusive
100122
)
101123

102124
target_compile_features(project_options INTERFACE cxx_std_${CMAKE_CXX_STANDARD})
125+
# TODO: The INTERFACE library NAMESPACE ALIAS are missing! CK
126+
add_library(myproject::project_options INTERFACE IMPORTED)
127+
add_library(myproject::project_warnings INTERFACE IMPORTED)
103128

104129
# configure files based on CMake configuration options
105130
add_subdirectory(configured_files)
@@ -108,33 +133,42 @@ add_subdirectory(configured_files)
108133
add_subdirectory(src)
109134

110135
# Adding the tests:
111-
option(ENABLE_TESTING "Enable the tests" ON)
136+
option(ENABLE_TESTING "Enable the tests" ${PROJECT_IS_TOP_LEVEL})
112137
if(ENABLE_TESTING)
113138
enable_testing()
114-
message("Building Tests. Be sure to check out test/constexpr_tests for constexpr
115-
testing")
139+
message(AUTHOR_WARNING "Building Tests. Be sure to check out test/constexpr_tests.cpp for constexpr testing")
116140
add_subdirectory(test)
117141
endif()
118142

119143
option(ENABLE_FUZZING "Enable the fuzz tests" OFF)
120144
if(ENABLE_FUZZING)
121-
message("Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
145+
message(AUTHOR_WARNING "Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
122146
add_subdirectory(fuzz_test)
123147
endif()
124148

125149
# If MSVC is being used, and ASAN is enabled, we need to set the debugger environment
126150
# so that it behaves well with MSVC's debugger, and we can run the target from visual studio
127151
if(MSVC)
128-
get_all_targets(all_targets)
152+
get_all_installable_targets(all_targets)
153+
message("all_targets=${all_targets}")
129154
set_target_properties(${all_targets} PROPERTIES VS_DEBUGGER_ENVIRONMENT "PATH=$(VC_ExecutablePath_x64);%PATH%")
130155
endif()
131156

132157
# set the startup project for the "play" button in MSVC
133158
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT intro)
134159

160+
if(CMAKE_SKIP_INSTALL_RULES)
161+
return()
162+
elseif(NOT PROJECT_IS_TOP_LEVEL)
163+
return()
164+
endif()
165+
135166
# Add other targets that you want installed here, be default we just package the one executable
136167
# we know we want to ship
137-
package_project(TARGETS intro)
168+
package_project(TARGETS intro project_options project_warnings
169+
# FIXME: this does not work! CK
170+
# PRIVATE_DEPENDENCIES_CONFIGURED project_options project_warnings
171+
)
138172

139173
# Experience shows that explicit package naming can help make it easier to sort
140174
# 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+
}

0 commit comments

Comments
 (0)