diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 00000000..47ef7fb7 --- /dev/null +++ b/.clang-tidy @@ -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 } +... diff --git a/.envrc b/.envrc index f965b508..0873c922 100644 --- a/.envrc +++ b/.envrc @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index aed292d2..de571c2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.21...3.27) +cmake_minimum_required(VERSION 3.25...3.28) # ---- Project ---- @@ -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 @@ -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} @@ -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) diff --git a/CMakePresets.json b/CMakePresets.json index d45c2403..7e7233c3 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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": { @@ -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" } } ], diff --git a/all/CMakeLists.txt b/all/CMakeLists.txt index 47532028..e3360da2 100644 --- a/all/CMakeLists.txt +++ b/all/CMakeLists.txt @@ -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) diff --git a/all/CMakePresets.json b/all/CMakePresets.json index bad98325..2f3b72e3 100644 --- a/all/CMakePresets.json +++ b/all/CMakePresets.json @@ -2,7 +2,7 @@ "version": 6, "cmakeMinimumRequired": { "major": 3, - "minor": 23, + "minor": 25, "patch": 0 }, "configurePresets": [ @@ -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}" } }, @@ -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": [ diff --git a/cmake/AddUninstallTarget.cmake b/cmake/AddUninstallTarget.cmake new file mode 100644 index 00000000..c539c0d7 --- /dev/null +++ b/cmake/AddUninstallTarget.cmake @@ -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") diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index f49d7434..cc25ec28 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -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") @@ -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}) diff --git a/documentation/CMakeLists.txt b/documentation/CMakeLists.txt index 3ae656d6..7a46881d 100644 --- a/documentation/CMakeLists.txt +++ b/documentation/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.21...3.27) +cmake_minimum_required(VERSION 3.25...3.28) project(GreeterDocs) diff --git a/include/greeter/greeter.h b/include/greeter/greeter.h index 77dfe3b8..19569eb1 100644 --- a/include/greeter/greeter.h +++ b/include/greeter/greeter.h @@ -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 diff --git a/standalone/CMakeLists.txt b/standalone/CMakeLists.txt index 67adf7f3..d1e43a66 100644 --- a/standalone/CMakeLists.txt +++ b/standalone/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.21...3.27) +cmake_minimum_required(VERSION 3.25...3.28) project( GreeterStandalone @@ -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() @@ -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}) diff --git a/standalone/CMakePresets.json b/standalone/CMakePresets.json index 9c807323..f33a3c07 100644 --- a/standalone/CMakePresets.json +++ b/standalone/CMakePresets.json @@ -2,7 +2,7 @@ "version": 6, "cmakeMinimumRequired": { "major": 3, - "minor": 23, + "minor": 25, "patch": 0 }, "configurePresets": [ @@ -19,13 +19,16 @@ "value": "${sourceParentDir}/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", - "CPM_USE_LOCAL_PACKAGES": "NO", - "BUILD_SHARED_LIBS": "YES" + "CMAKE_UNITY_BUILD": true, + "BUILD_SHARED_LIBS": true }, "environment": { "CPM_USE_LOCAL_PACKAGES": "YES", + "CPM_SOURCE_CACHE": "$env{HOME}/.cache/CPM", "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}" } }, @@ -34,17 +37,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" } } ], diff --git a/standalone/source/main.cpp b/standalone/source/main.cpp index 2ddd2ae9..a463ac5a 100644 --- a/standalone/source/main.cpp +++ b/standalone/source/main.cpp @@ -6,6 +6,7 @@ #include #include +// NOLINTNEXTLINE(bugprone-exception-escape) int main() { crow::SimpleApp app; @@ -23,9 +24,9 @@ int main() { // return bad request return crow::response(400, "please provide a 'language={en|de|es|fr}' argument"); } - const auto language = req.url_params.get("language"); + const auto language = req.url_params.get("language"); // NOLINT(readability-qualified-auto) - // see if langauge was found + // see if language was found const std::unordered_map languages{ {"en", greeter::LanguageCode::EN}, {"de", greeter::LanguageCode::DE}, diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6aadf7f2..1304b2ef 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.21...3.27) +cmake_minimum_required(VERSION 3.25...3.28) project(GreeterTests LANGUAGES CXX) diff --git a/test/CMakePresets.json b/test/CMakePresets.json index 65fd0d43..1323b7b4 100644 --- a/test/CMakePresets.json +++ b/test/CMakePresets.json @@ -2,7 +2,7 @@ "version": 6, "cmakeMinimumRequired": { "major": 3, - "minor": 23, + "minor": 25, "patch": 0 }, "configurePresets": [ @@ -19,14 +19,17 @@ "value": "${sourceParentDir}/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", - "CPM_USE_LOCAL_PACKAGES": "NO", - "BUILD_SHARED_LIBS": "YES", - "TEST_INSTALLED_VERSION": "YES" + "CMAKE_UNITY_BUILD": true, + "BUILD_SHARED_LIBS": true, + "TEST_INSTALLED_VERSION": true }, "environment": { "CPM_USE_LOCAL_PACKAGES": "YES", + "CPM_SOURCE_CACHE": "$env{HOME}/.cache/CPM", "PATH": "$env{HOME}/.local/bin${pathListSep}$penv{PATH}", "LD_LIBRARY_PATH": "${sourceParentDir}/stagedir/lib${pathListSep}penv{LD_LIBRARY_PATH}" } @@ -36,17 +39,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" } } ],