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

Commit

Permalink
Merge pull request #217 from cpp-best-practices/change_project_name
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
lefticus authored Apr 27, 2022
2 parents 2b9c3c9 + 9ab32f9 commit 849f985
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .github/template/template_name
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cpp_starter_project
gui_starter_template
2 changes: 1 addition & 1 deletion .github/template/template_repository
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cpp-best-practices/cpp_starter_project
cpp-best-practices/gui_starter_template
19 changes: 15 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
CONAN_SYSREQUIRES_MODE: enabled
CONAN_USER_HOME: "${{ github.workspace }}/conan-cache"
CONAN_USER_HOME_SHORT: "${{ github.workspace }}/conan-cache/short"
CLANG_TIDY_VERSION: "13.0.0"

jobs:
Test:
Expand Down Expand Up @@ -69,17 +70,20 @@ jobs:
compiler: msvc
generator: "Visual Studio 17 2022"
build_type: Debug
developer_mode: ON
developer_mode: On

- os: windows-2022
compiler: msvc
generator: "Visual Studio 17 2022"
build_type: Release
developer_mode: ON
developer_mode: On

- os: windows-2022
compiler: msvc
generator: "Visual Studio 17 2022"
build_type: Debug
developer_mode: OFF

- os: windows-2022
compiler: msvc
generator: "Visual Studio 17 2022"
Expand All @@ -88,8 +92,14 @@ jobs:
package_generator: ZIP



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

- name: Setup Cache
Expand All @@ -111,7 +121,8 @@ jobs:
conan: true
vcpkg: false
ccache: true
clangtidy: true
clangtidy: ${{ env.CLANG_TIDY_VERSION }}


cppcheck: true

Expand Down
17 changes: 15 additions & 2 deletions .github/workflows/template-janitor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,23 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Use testing variables if still a template
if: fromJson(steps.get_repo_meta.outputs.data).is_template == true
run: |
# This name is unsafe because it is not a valid C++ identifier
echo "NEW_PROJECT=my-unsafe.project" >> $GITHUB_ENV
- name: Add safe replacement variable versions
run: |
# hyphens and dots in c++ identifiers are forbidden. Use underscores instead.
NEW_SAFE_PROJECT=$(echo ${{ env.NEW_PROJECT }} | sed "s/-/_/g" | sed "s/\./_/g" )
echo "NEW_SAFE_PROJECT=$NEW_SAFE_PROJECT" >> $GITHUB_ENV
# Rename all cpp_starter_project occurences to current repository and remove this workflow
- name: Insert new org and project
run: |
# rename the CMake project to match the github project
sed -i "s/myproject/${{ github.event.repository.name }}/gi" CMakeLists.txt configured_files/config.hpp.in src/main.cpp
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
# Update URL placeholders for project
sed -i "s|%%myurl%%|${{ fromJson(steps.get_repo_meta.outputs.data).html_url }}|gi" CMakeLists.txt
Expand Down Expand Up @@ -119,7 +131,8 @@ jobs:
- name: Test simple configuration to make sure nothing broke
run: |
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
# Build it because we may have broken something in the cpp/hpp files
cmake --build build
- uses: EndBug/add-and-commit@v4
# only commit and push if we are not a template project anymore!
Expand Down
6 changes: 3 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ stages:
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F

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

.test: &test |
Expand All @@ -46,4 +46,4 @@ test_linux_gcc:
script:
- *setup_linux
- *setup_cpp
- *test
- *test
56 changes: 45 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.16...3.23)

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

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

Expand All @@ -40,6 +39,18 @@ project(
HOMEPAGE_URL "%%myurl%%"
LANGUAGES CXX C)

# This variable is set by project() in CMake 3.21+
string(
COMPARE EQUAL
"${CMAKE_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}"
PROJECT_IS_TOP_LEVEL)
if(PROJECT_IS_TOP_LEVEL)
# Consider the CTest module, which creates targets and options!
# Only needed if you want to enable submissions to a CDash server.
include(CTest)
endif()

set(GIT_SHA
"Unknown"
CACHE STRING "SHA this build was generated from")
Expand Down Expand Up @@ -92,14 +103,28 @@ dynamic_project_options(
PCH_HEADERS
<vector>
<string> # This is a list of headers to pre-compile, here are some common ones
ENABLE_CONAN
# CONAN_OPTIONS # Extra options to pass to conan
# MSVC_WARNINGS # Override the defaults for the MSVC warnings
# CLANG_WARNINGS # Override the defaults for the CLANG warnings
# GCC_WARNINGS # Override the defaults for the GCC warnings
# CPPCHECK_OPTIONS # Override the defaults for CppCheck
CPPCHECK_OPTIONS
--enable=style,performance,warning,portability
--inline-suppr
# We cannot act on a bug/missing feature of cppcheck
--suppress=cppcheckError
--suppress=internalAstError
# if a file does not have an internalAstError, we get an unmatchedSuppression error
--suppress=unmatchedSuppression
--suppress=passedByValue
--suppress=syntaxError
--inconclusive
)

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

# configure files based on CMake configuration options
add_subdirectory(configured_files)
Expand All @@ -108,33 +133,42 @@ add_subdirectory(configured_files)
add_subdirectory(src)

# Adding the tests:
option(ENABLE_TESTING "Enable the tests" ON)
option(ENABLE_TESTING "Enable the tests" ${PROJECT_IS_TOP_LEVEL})
if(ENABLE_TESTING)
enable_testing()
message("Building Tests. Be sure to check out test/constexpr_tests for constexpr
testing")
message(AUTHOR_WARNING "Building Tests. Be sure to check out test/constexpr_tests.cpp for constexpr testing")
add_subdirectory(test)
endif()

option(ENABLE_FUZZING "Enable the fuzz tests" OFF)
if(ENABLE_FUZZING)
message("Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
message(AUTHOR_WARNING "Building Fuzz Tests, using fuzzing sanitizer https://www.llvm.org/docs/LibFuzzer.html")
add_subdirectory(fuzz_test)
endif()

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

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

if(CMAKE_SKIP_INSTALL_RULES)
return()
elseif(NOT PROJECT_IS_TOP_LEVEL)
return()
endif()

# Add other targets that you want installed here, be default we just package the one executable
# we know we want to ship
package_project(TARGETS intro)
package_project(TARGETS intro project_options project_warnings
# FIXME: this does not work! CK
# PRIVATE_DEPENDENCIES_CONFIGURED project_options project_warnings
)

# Experience shows that explicit package naming can help make it easier to sort
# out potential ABI related issues before they start, while helping you
Expand Down
61 changes: 32 additions & 29 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@
}
},
{
"name": "conf-linux-common",
"description": "Linux settings for gcc and clang toolchains",
"name": "conf-unixlike-common",
"description": "Unix-like OS settings for gcc and clang toolchains",
"hidden": true,
"inherits": "conf-common",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
"type": "inList",
"string": "${hostSystemName}",
"list": [
"Linux",
"Darwin"
]
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
Expand Down Expand Up @@ -75,7 +78,7 @@
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"ENABLE_DEVELOPER_MODE": "ON"
}
}
},
{
"name": "windows-msvc-debug-user-mode",
Expand All @@ -87,7 +90,7 @@
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_BUILD_TYPE": "Debug",
"ENABLE_DEVELOPER_MODE": "OFF"
}
}
},
{
"name": "windows-msvc-release-user-mode",
Expand All @@ -99,7 +102,7 @@
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"ENABLE_DEVELOPER_MODE": "OFF"
}
}
},
{
"name": "windows-clang-debug",
Expand Down Expand Up @@ -134,43 +137,43 @@
}
},
{
"name": "linux-gcc-debug",
"name": "unixlike-gcc-debug",
"displayName": "gcc Debug",
"description": "Target Linux with the gcc compiler, debug build type",
"inherits": "conf-linux-common",
"description": "Target Unix-like OS with the gcc compiler, debug build type",
"inherits": "conf-unixlike-common",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "linux-gcc-release",
"name": "unixlike-gcc-release",
"displayName": "gcc Release",
"description": "Target Linux with the gcc compiler, release build type",
"inherits": "conf-linux-common",
"description": "Target Unix-like OS with the gcc compiler, release build type",
"inherits": "conf-unixlike-common",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "linux-clang-debug",
"name": "unixlike-clang-debug",
"displayName": "clang Debug",
"description": "Target Linux with the clang compiler, debug build type",
"inherits": "conf-linux-common",
"description": "Target Unix-like OS with the clang compiler, debug build type",
"inherits": "conf-unixlike-common",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "linux-clang-release",
"name": "unixlike-clang-release",
"displayName": "clang Release",
"description": "Target Linux with the clang compiler, release build type",
"inherits": "conf-linux-common",
"description": "Target Unix-like OS with the clang compiler, release build type",
"inherits": "conf-unixlike-common",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++",
Expand Down Expand Up @@ -220,32 +223,32 @@
"configurePreset": "windows-clang-release"
},
{
"name": "test-linux-gcc-debug",
"name": "test-unixlike-gcc-debug",
"displayName": "Strict",
"description": "Enable output and stop on failure",
"inherits": "test-common",
"configurePreset": "linux-gcc-debug"
"configurePreset": "unixlike-gcc-debug"
},
{
"name": "test-linux-gcc-release",
"name": "test-unixlike-gcc-release",
"displayName": "Strict",
"description": "Enable output and stop on failure",
"inherits": "test-common",
"configurePreset": "linux-gcc-release"
"configurePreset": "unixlike-gcc-release"
},
{
"name": "test-linux-clang-debug",
"name": "test-unixlike-clang-debug",
"displayName": "Strict",
"description": "Enable output and stop on failure",
"inherits": "test-common",
"configurePreset": "linux-clang-debug"
"configurePreset": "unixlike-clang-debug"
},
{
"name": "test-linux-clang-release",
"name": "test-unixlike-clang-release",
"displayName": "Strict",
"description": "Enable output and stop on failure",
"inherits": "test-common",
"configurePreset": "linux-clang-release"
"configurePreset": "unixlike-clang-release"
}
]
}
}
Loading

0 comments on commit 849f985

Please sign in to comment.