Skip to content

Commit

Permalink
Modernize project
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausKlein committed Feb 11, 2024
1 parent 24501d9 commit 05aae56
Show file tree
Hide file tree
Showing 15 changed files with 232 additions and 95 deletions.
59 changes: 59 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
#
# clang-tidy v17.0.0
#
Checks:
'-*,
#TBD llvm-header-guard,
boost-*,
bugprone-*,
-bugprone-suspicious-include,
cert-*,
clang-analyzer-*,
-cppcoreguidelines-*,
cppcoreguidelines-pro-*,
cppcoreguidelines-slicing,
concurrency-*,
google-*,
-google-build-using-namespace,
-google-global-names-in-headers,
hicpp-*,
misc-*,
-misc-include-cleaner,
modernize-*,
-modernize-use-trailing-return-type,
performance-*,
portability-*,
readability-*,
-readability-identifier-naming,
-readability-magic-numbers,
'

HeaderFilterRegex: '.*'
WarningsAsErrors: '*'
FormatStyle: file
UseColor: false
User: klein_cl

CheckOptions:
- { key: readability-identifier-naming.NamespaceCase, value: CamelCase }
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.MemberCase, value: camelBack }
- { key: readability-identifier-naming.MemberPrefix, value: m_ }
- { key: readability-identifier-naming.StructCase, value: lower_case }
- { key: readability-identifier-naming.UnionCase, value: lower_case }
- { key: readability-identifier-naming.TypedefCase, value: lower_case }
- { key: readability-identifier-naming.TypedefSuffix, value: _type }
- { key: readability-identifier-naming.FunctionCase, value: camelBack }
- { key: readability-identifier-naming.EnumCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprFunctionCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprMethodCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
- { key: readability-identifier-naming.ClassConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.GlobalConstantPointerCase, value: UPPER_CASE }
- { key: readability-identifier-naming.LocalConstantPointerCase, value: UPPER_CASE }
- { key: readability-identifier-naming.ScopedEnumConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.StaticConstantCase, value: UPPER_CASE }
...
6 changes: 5 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export CMAKE_EXPORT_COMPILE_COMMANDS=YES
export CTEST_OUTPUT_ON_FAILURE=YES

export CPM_USE_LOCAL_PACKAGES=YES
export CPM_SOURCE_CACHE=${PWD}/.cache/CPM
export CPM_SOURCE_CACHE=${HOME}/.cache/CPM

export LD_LIBRARY_PATH=${CMAKE_PREFIX_PATH}/lib
export BUILD_DIR=${PWD}/build

export PATH="/usr/local/opt/llvm/bin:$PATH"
export CXX=/usr/local/opt/llvm/bin/clang++
export CC=/usr/local/opt/llvm/bin/clang
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.21...3.27)
cmake_minimum_required(VERSION 3.25...3.28)

# ---- Project ----

Expand Down Expand Up @@ -30,11 +30,11 @@ option(OPTION_ENABLE_UNITY "Enable Unity builds of project" ON)
include(cmake/CPM.cmake)

# PackageProject.cmake will be used to make our target installable
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.10.0")
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.11.2")

CPMAddPackage(
NAME fmt
GIT_TAG 9.1.0
GIT_TAG 10.2.1
GITHUB_REPOSITORY fmtlib/fmt
SYSTEM ON # used in case of cmake v3.25
OPTIONS "FMT_INSTALL YES" # create an installable target
Expand Down Expand Up @@ -78,6 +78,8 @@ target_include_directories(
# header paths
string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION)

include(cmake/AddUninstallTarget.cmake)

packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
Expand All @@ -87,7 +89,7 @@ packageProject(
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "${VERSION_HEADER_LOCATION}"
COMPATIBILITY SameMajorVersion
DEPENDENCIES "fmt 9.1.0"
DEPENDENCIES "fmt 10.2.1"
)

include(CPack)
24 changes: 10 additions & 14 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
"value": "${sourceDir}/stagedir"
},
"CMAKE_CXX_STANDARD": "20",
"CMAKE_CXX_EXTENSIONS": false,
"CMAKE_CXX_STANDARD_REQUIRED": true,
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_DEBUG_POSTFIX": "D",
"BUILD_SHARED_LIBS": "YES"
"CMAKE_UNITY_BUILD": true,
"BUILD_SHARED_LIBS": true
},
"environment": {
"CPM_USE_LOCAL_PACKAGES": "NO",
"CPM_USE_LOCAL_PACKAGES": "YES",
"CPM_SOURCE_CACHE": "$env{HOME}/.cache/CPM",
"PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}"
},
"warnings": {
Expand All @@ -37,17 +41,9 @@
"inherits": "default",
"displayName": "Ninja Multi-Config",
"description": "Default build using Ninja Multi-Config generator",
"generator": "Ninja Multi-Config"
},
{
"name": "windows-only",
"inherits": "default",
"displayName": "Windows-only configuration",
"description": "This build is only available on Windows",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
"generator": "Ninja Multi-Config",
"cacheVariables": {
"CMAKE_DEBUG_POSTFIX": "D"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# this script adds all subprojects to a single build to allow IDEs understand the full project
# structure.

cmake_minimum_required(VERSION 3.21...3.27)
cmake_minimum_required(VERSION 3.25...3.28)

project(BuildAll LANGUAGES CXX)

Expand Down
25 changes: 9 additions & 16 deletions all/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 23,
"minor": 25,
"patch": 0
},
"configurePresets": [
Expand All @@ -19,14 +19,18 @@
"value": "${sourceParentDir}/stagedir"
},
"CMAKE_CXX_STANDARD": "20",
"CMAKE_CXX_EXTENSIONS": false,
"CMAKE_CXX_STANDARD_REQUIRED": true,
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_DEBUG_POSTFIX": "D",
"CPM_USE_LOCAL_PACKAGES": "NO",
"BUILD_SHARED_LIBS": "YES",
"ENABLE_TEST_COVERAGE": "YES"
"CMAKE_UNITY_BUILD": false,
"BUILD_SHARED_LIBS": true,
"ENABLE_TEST_COVERAGE": true
},
"environment": {
"CPM_USE_LOCAL_PACKAGES": "YES",
"CPM_USE_LOCAL_PACKAGES": "NO",
"CPM_SOURCE_CACHE": "$env{HOME}/.cache/CPM",
"PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}"
}
},
Expand All @@ -36,17 +40,6 @@
"displayName": "Ninja Multi-Config",
"description": "Default build using Ninja Multi-Config generator",
"generator": "Ninja Multi-Config"
},
{
"name": "windows-only",
"inherits": "default",
"displayName": "Windows-only configuration",
"description": "This build is only available on Windows",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
}
],
"buildPresets": [
Expand Down
101 changes: 101 additions & 0 deletions cmake/AddUninstallTarget.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# SPDX-FileCopyrightText: 2012-2021 Istituto Italiano di Tecnologia (IIT) SPDX-FileCopyrightText:
# 2008-2013 Kitware Inc. SPDX-License-Identifier: BSD-3-Clause

#[=======================================================================[.rst:
AddUninstallTarget
------------------

Add the "uninstall" target for your project::

include(AddUninstallTarget)


will create a file ``cmake_uninstall.cmake`` in the build directory and add a
custom target ``uninstall`` (or ``UNINSTALL`` on Visual Studio and Xcode) that
will remove the files installed by your package (using
``install_manifest.txt``).
See also
https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake

The :module:`AddUninstallTarget` module must be included in your main
``CMakeLists.txt``. If included in a subdirectory it does nothing.
This allows you to use it safely in your main ``CMakeLists.txt`` and include
your project using ``add_subdirectory`` (for example when using it with
:cmake:module:`FetchContent`).

If the ``uninstall`` target already exists, the module does nothing.
#]=======================================================================]

# AddUninstallTarget works only when included in the main CMakeLists.txt
if(NOT "${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
return()
endif()

# The name of the target is uppercase in MSVC and Xcode (for coherence with the other standard
# targets)
if("${CMAKE_GENERATOR}" MATCHES "^(Visual Studio|Xcode)")
set(_uninstall "UNINSTALL")
else()
set(_uninstall "uninstall")
endif()

# If target is already defined don't do anything
if(TARGET ${_uninstall})
return()
endif()

set(_filename cmake_uninstall.cmake)

file(
WRITE "${CMAKE_CURRENT_BINARY_DIR}/${_filename}"
"if(NOT EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\")
message(WARNING \"Cannot find install manifest: \\\"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\\\"\")
return()
endif()
file(READ \"${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt\" files)
string(STRIP \"\${files}\" files)
string(REGEX REPLACE \"\\n\" \";\" files \"\${files}\")
list(REVERSE files)
foreach(file \${files})
if(IS_SYMLINK \"\$ENV{DESTDIR}\${file}\" OR EXISTS \"\$ENV{DESTDIR}\${file}\")
message(STATUS \"Uninstalling: \$ENV{DESTDIR}\${file}\")
execute_process(
COMMAND \${CMAKE_COMMAND} -E remove \"\$ENV{DESTDIR}\${file}\"
OUTPUT_VARIABLE rm_out
RESULT_VARIABLE rm_retval)
if(NOT \"\${rm_retval}\" EQUAL 0)
message(FATAL_ERROR \"Problem when removing \\\"\$ENV{DESTDIR}\${file}\\\"\")
endif()
else()
message(STATUS \"Not-found: \$ENV{DESTDIR}\${file}\")
endif()
endforeach(file)
"
)

set(_desc "Uninstall the project...")
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(_comment
COMMAND
\$\(CMAKE_COMMAND\)
-E
cmake_echo_color
--switch=$\(COLOR\)
--cyan
"${_desc}"
)
else()
set(_comment COMMENT "${_desc}")
endif()
add_custom_target(
${_uninstall}
${_comment}
COMMAND ${CMAKE_COMMAND} -P ${_filename}
USES_TERMINAL
BYPRODUCTS uninstall_byproduct
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
set_property(SOURCE uninstall_byproduct PROPERTY SYMBOLIC 1)

set_property(TARGET ${_uninstall} PROPERTY FOLDER "CMakePredefinedTargets")
29 changes: 10 additions & 19 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
set(CPM_DOWNLOAD_VERSION 0.38.2)
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.38.7)
set(CPM_HASH_SUM "83e5eb71b2bbb8b1f2ad38f1950287a057624e385c238f6087f94cdfc44af9c5")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
Expand All @@ -11,23 +16,9 @@ endif()
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

function(download_cpm)
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endfunction()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
download_cpm()
else()
# resume download if it previously failed
file(READ ${CPM_DOWNLOAD_LOCATION} check)
if("${check}" STREQUAL "")
download_cpm()
endif()
unset(check)
endif()
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})
2 changes: 1 addition & 1 deletion documentation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.21...3.27)
cmake_minimum_required(VERSION 3.25...3.28)

project(GreeterDocs)

Expand Down
4 changes: 2 additions & 2 deletions include/greeter/greeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ namespace greeter {
* @brief Creates a new greeter
* @param name the name to greet
*/
Greeter(std::string name);
explicit Greeter(std::string name);

/**
* @brief Creates a localized string containing the greeting
* @param lang the language to greet in
* @return a string containing the greeting
*/
std::string greet(LanguageCode lang = LanguageCode::EN) const;
[[nodiscard]] std::string greet(LanguageCode lang = LanguageCode::EN) const;
};

} // namespace greeter
6 changes: 3 additions & 3 deletions standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.21...3.27)
cmake_minimum_required(VERSION 3.25...3.28)

project(
GreeterStandalone
Expand Down Expand Up @@ -40,7 +40,7 @@ if(NOT Boost_FOUND)
# Use CPM.cmake to get Boost from the official repo if not found
message(WARNING "GreeterStandalone: Boost libs NOT found!")
option(BUILD_SHARED_LIBS "Build shared libraries" NO)
CPMAddPackage("gh:ClausKlein/boost-cmake@1.80.0")
CPMAddPackage("gh:ClausKlein/boost-cmake@1.81.0")
else()
message(STATUS "GreeterStandalone: Boost libs found")
endif()
Expand Down Expand Up @@ -70,7 +70,7 @@ add_executable(${PROJECT_NAME} ${sources})
if(CMAKE_DEBUG_POSTFIX)
set_property(TARGET ${PROJECT_NAME} PROPERTY DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
endif()
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
target_link_libraries(${PROJECT_NAME} Greeter::Greeter Crow::Crow)
set_target_properties(${PROJECT_NAME} PROPERTIES UNITY_BUILD ${OPTION_ENABLE_UNITY})

Expand Down

0 comments on commit 05aae56

Please sign in to comment.