From 2c822ce7735421f35a0177b955715eb7b0a50f13 Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Fri, 6 Oct 2023 07:10:26 +0200 Subject: [PATCH 01/11] feat: added woodpecker config Reviewed-on: https://git.schmidl.dev/schtobia/glimpses/pulls/1 Co-authored-by: Tobias Schmidl Co-committed-by: Tobias Schmidl --- .cmake-format.yaml | 6 +-- .ecrc | 8 ++++ .ecrc.license | 3 ++ .editorconfig | 25 +++++++++++ .pre-commit-config.yaml | 12 ++++++ .woodpecker.yml | 16 +++++++ CMakeLists.txt | 31 +++----------- LICENSES/MIT.txt | 9 ++++ all/CMakeLists.txt | 3 +- cmake/CPM.cmake | 11 +++-- cmake/tools.cmake | 81 ++++++++++++++---------------------- cmake/version-from-git.cmake | 7 +--- documentation/CMakeLists.txt | 5 +-- standalone/CMakeLists.txt | 7 +--- test/CMakeLists.txt | 34 +++------------ 15 files changed, 129 insertions(+), 129 deletions(-) create mode 100644 .ecrc create mode 100644 .ecrc.license create mode 100644 .editorconfig create mode 100644 .woodpecker.yml create mode 100644 LICENSES/MIT.txt diff --git a/.cmake-format.yaml b/.cmake-format.yaml index 4594291..51a8fd3 100644 --- a/.cmake-format.yaml +++ b/.cmake-format.yaml @@ -3,12 +3,12 @@ # SPDX-License-Identifier: AGPL-3.0-or-later --- format: - line_width: 120 + line_width: 140 tab_size: 4 use_tabchars: true fractional_tab_policy: round-up - max_subgroups_hwrap: 2 - max_pargs_hwrap: 3 + max_subgroups_hwrap: 3 + max_pargs_hwrap: 6 dangle_parens: true dangle_align: prefix min_prefix_chars: 0 diff --git a/.ecrc b/.ecrc new file mode 100644 index 0000000..43ccb09 --- /dev/null +++ b/.ecrc @@ -0,0 +1,8 @@ +{ + "IgnoreDefaults": false, + "Exclude": [ + "^LICENSE$", + "^LICENSES/.*", + "documentation/pages/about.dox" + ] +} diff --git a/.ecrc.license b/.ecrc.license new file mode 100644 index 0000000..37bf852 --- /dev/null +++ b/.ecrc.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Tobias Schmidl + +SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..35187b6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,25 @@ +# SPDX-FileCopyrightText: 2023 Tobias Schmidl +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{yaml,yml}] +indent_size = 2 + +[*.{cpp,hpp,h}] +indent_size = 2 + +[{CMakeLists.txt,*.cmake}] +indent_style = tabs diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 37e2524..22e4933 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,6 +11,7 @@ repos: - id: trailing-whitespace - id: check-merge-conflict - id: check-ast + - id: check-byte-order-marker - repo: https://github.com/fsfe/reuse-tool rev: v2.1.0 hooks: @@ -29,4 +30,15 @@ repos: hooks: - id: clang-format - id: clang-tidy +- repo: https://github.com/editorconfig-checker/editorconfig-checker.python + rev: '2.7.2' + hooks: + - id: editorconfig-checker + alias: ec + stages: [commit] +- repo: https://github.com/compilerla/conventional-pre-commit + rev: v2.4.0 + hooks: + - id: conventional-pre-commit + stages: [commit-msg] ... diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..dde54e0 --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,16 @@ +# SPDX-FileCopyrightText: 2023 Tobias Schmidl +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +--- +steps: + + editor-config: + image: mstruebing/editorconfig-checker + group: lint + + reuse: + image: fsfe/reuse:latest + group: lint + +... diff --git a/CMakeLists.txt b/CMakeLists.txt index cac0369..e8720d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,18 +8,11 @@ include(cmake/version-from-git.cmake) # ---- Project ---- -project( - Glimpses - VERSION ${VERSION_STRING} - LANGUAGES CXX -) +project(Glimpses VERSION ${VERSION_STRING} LANGUAGES CXX) # ---- Include guards ---- if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) - message( - FATAL_ERROR - "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there." - ) + message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.") endif() # ---- Add dependencies via CPM ---- @@ -30,22 +23,11 @@ include(cmake/CPM.cmake) # PackageProject.cmake will be used to make our target installable CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.8.0") -# CPMAddPackage( NAME fmt GIT_TAG 9.1.0 GITHUB_REPOSITORY fmtlib/fmt OPTIONS "FMT_INSTALL YES" # create an installable -# target ) +# CPMAddPackage( NAME fmt GIT_TAG 9.1.0 GITHUB_REPOSITORY fmtlib/fmt OPTIONS "FMT_INSTALL YES" # create an installable target ) # ---- Add source files ---- -file( - GLOB_RECURSE - headers - CONFIGURE_DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h" -) -file( - GLOB_RECURSE - sources - CONFIGURE_DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp" -) +file(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") +file(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp") # ---- Create library ---- @@ -60,8 +42,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE # fmt::fmt ) target_include_directories( - ${PROJECT_NAME} PUBLIC $ - $ + ${PROJECT_NAME} PUBLIC $ $ ) # the location where the project's version header will be placed should match the project's regular header paths diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..2071b23 --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/all/CMakeLists.txt b/all/CMakeLists.txt index bb66c26..ade8fd0 100644 --- a/all/CMakeLists.txt +++ b/all/CMakeLists.txt @@ -2,8 +2,7 @@ # # SPDX-License-Identifier: CC0-1.0 -# this script adds all subprojects to a single build to allow IDEs understand the full project -# structure. +# this script adds all subprojects to a single build to allow IDEs understand the full project structure. cmake_minimum_required(VERSION 3.14...3.22) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake index a786712..f606c11 100644 --- a/cmake/CPM.cmake +++ b/cmake/CPM.cmake @@ -6,19 +6,18 @@ set(CPM_DOWNLOAD_VERSION 0.38.5) set(CPM_HASH_SUM "192aa0ccdc57dfe75bd9e4b176bf7fb5692fd2b3e3f7b09c74856fc39572b31c") if(CPM_SOURCE_CACHE) - set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") elseif(DEFINED ENV{CPM_SOURCE_CACHE}) - set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") else() - set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") endif() # Expand relative path. This is important if the provided path contains a tilde (~) get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) -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} +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/cmake/tools.cmake b/cmake/tools.cmake index d693dbb..027609b 100644 --- a/cmake/tools.cmake +++ b/cmake/tools.cmake @@ -2,69 +2,52 @@ # # SPDX-License-Identifier: CC0-1.0 -# this file contains a list of tools that can be activated and downloaded on-demand each tool is -# enabled during configuration by passing an additional `-DUSE_=` argument to CMake +# this file contains a list of tools that can be activated and downloaded on-demand each tool is enabled during configuration by passing an +# additional `-DUSE_=` argument to CMake # only activate tools for top level project if(NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) - return() + return() endif() include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) -# enables sanitizers support using the the `USE_SANITIZER` flag available values are: Address, -# Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined' +# enables sanitizers support using the the `USE_SANITIZER` flag available values are: Address, Memory, MemoryWithOrigins, Undefined, Thread, +# Leak, 'Address;Undefined' if(USE_SANITIZER OR USE_STATIC_ANALYZER) - CPMAddPackage("gh:StableCoder/cmake-scripts#1f822d1fc87c8d7720c074cde8a278b44963c354") + CPMAddPackage("gh:StableCoder/cmake-scripts#1f822d1fc87c8d7720c074cde8a278b44963c354") - if(USE_SANITIZER) - include(${cmake-scripts_SOURCE_DIR}/sanitizers.cmake) - endif() + if(USE_SANITIZER) + include(${cmake-scripts_SOURCE_DIR}/sanitizers.cmake) + endif() - if(USE_STATIC_ANALYZER) - if("clang-tidy" IN_LIST USE_STATIC_ANALYZER) - set(CLANG_TIDY - ON - CACHE INTERNAL "" - ) - else() - set(CLANG_TIDY - OFF - CACHE INTERNAL "" - ) - endif() - if("iwyu" IN_LIST USE_STATIC_ANALYZER) - set(IWYU - ON - CACHE INTERNAL "" - ) - else() - set(IWYU - OFF - CACHE INTERNAL "" - ) - endif() - if("cppcheck" IN_LIST USE_STATIC_ANALYZER) - set(CPPCHECK - ON - CACHE INTERNAL "" - ) - else() - set(CPPCHECK - OFF - CACHE INTERNAL "" - ) - endif() + # cmake-lint: disable=C0103 + if(USE_STATIC_ANALYZER) + if("clang-tidy" IN_LIST USE_STATIC_ANALYZER) + set(CLANG_TIDY ON CACHE INTERNAL "") + else() + set(CLANG_TIDY OFF CACHE INTERNAL "") + endif() + if("iwyu" IN_LIST USE_STATIC_ANALYZER) + set(IWYU ON CACHE INTERNAL "") + else() + set(IWYU OFF CACHE INTERNAL "") + endif() + if("cppcheck" IN_LIST USE_STATIC_ANALYZER) + set(CPPCHECK ON CACHE INTERNAL "") + else() + set(CPPCHECK OFF CACHE INTERNAL "") + endif() - include(${cmake-scripts_SOURCE_DIR}/tools.cmake) + include(${cmake-scripts_SOURCE_DIR}/tools.cmake) - clang_tidy(${CLANG_TIDY_ARGS}) - include_what_you_use(${IWYU_ARGS}) - cppcheck(${CPPCHECK_ARGS}) - endif() + clang_tidy(${CLANG_TIDY_ARGS}) + include_what_you_use(${IWYU_ARGS}) + cppcheck(${CPPCHECK_ARGS}) + endif() endif() # enables CCACHE support through the USE_CCACHE flag possible values are: YES, NO or equivalent if(USE_CCACHE) - CPMAddPackage("gh:TheLartians/Ccache.cmake@1.2.3") + CPMAddPackage("gh:TheLartians/Ccache.cmake@1.2.3") endif() diff --git a/cmake/version-from-git.cmake b/cmake/version-from-git.cmake index e25c9ba..06bb60e 100644 --- a/cmake/version-from-git.cmake +++ b/cmake/version-from-git.cmake @@ -12,12 +12,7 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ) if(GIT_DESCRIBE_ERROR_CODE EQUAL 0) - string( - REGEX MATCH - "^v?([0-9]+)(\\.([0-9]+))?(\\.([0-9]+))?(\\.([0-9]+))?.*$" - _ - "${GIT_DESCRIBE_VERSION_STRING}" - ) + string(REGEX MATCH "^v?([0-9]+)(\\.([0-9]+))?(\\.([0-9]+))?(\\.([0-9]+))?.*$" _ "${GIT_DESCRIBE_VERSION_STRING}") if(DEFINED CMAKE_MATCH_1) set(VERSION_STRING "${CMAKE_MATCH_1}") if(DEFINED CMAKE_MATCH_3) diff --git a/documentation/CMakeLists.txt b/documentation/CMakeLists.txt index 4a8b34b..9652aa6 100644 --- a/documentation/CMakeLists.txt +++ b/documentation/CMakeLists.txt @@ -28,10 +28,7 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/conf.py ${CMAKE_CURRENT_BINARY_DIR}/con # cmake-lint: disable=C0113 add_custom_target( GenerateDocs - ${CMAKE_COMMAND} - -E - make_directory - "${DOXYGEN_OUTPUT_DIRECTORY}" + ${CMAKE_COMMAND} -E make_directory "${DOXYGEN_OUTPUT_DIRECTORY}" COMMAND "${m.css_SOURCE_DIR}/documentation/doxygen.py" "${CMAKE_CURRENT_BINARY_DIR}/conf.py" COMMAND echo "Docs written to: ${DOXYGEN_OUTPUT_DIRECTORY}" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" diff --git a/standalone/CMakeLists.txt b/standalone/CMakeLists.txt index b6142bc..bf9e55d 100644 --- a/standalone/CMakeLists.txt +++ b/standalone/CMakeLists.txt @@ -18,12 +18,7 @@ CPMAddPackage(NAME Glimpses SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..) # ---- Create standalone executable ---- -file( - GLOB - sources - CONFIGURE_DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp -) +file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp) add_executable(${PROJECT_NAME} ${sources}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 06da936..21dc941 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -29,12 +29,7 @@ endif() # ---- Create binary ---- -file( - GLOB - sources - CONFIGURE_DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp -) +file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp) add_executable(${PROJECT_NAME} ${sources}) target_link_libraries( ${PROJECT_NAME} @@ -46,13 +41,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17) # enable compiler warnings if(NOT TEST_INSTALLED_VERSION) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") - target_compile_options( - Glimpses - PUBLIC -Wall - -Wpedantic - -Wextra - -Werror - ) + target_compile_options(Glimpses PUBLIC -Wall -Wpedantic -Wextra -Werror) elseif(MSVC) target_compile_options(Glimpses PUBLIC /W4 /WX) target_compile_definitions(${PROJECT_NAME} PUBLIC DOCTEST_CONFIG_USE_STD_HEADERS) @@ -63,25 +52,14 @@ endif() enable_testing() -# Note: doctest and similar testing frameworks can automatically configure CMake tests. For other testing frameworks add -# the tests target instead: add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) +# Note: doctest and similar testing frameworks can automatically configure CMake tests. For other testing frameworks add the tests target +# instead: add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) # include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake) doctest_discover_tests(${PROJECT_NAME}) # ---- code coverage ---- if(ENABLE_TEST_COVERAGE) - target_compile_options( - Glimpses - PUBLIC -O0 - -g - -fprofile-arcs - -ftest-coverage - ) - target_link_options( - Glimpses - PUBLIC - -fprofile-arcs - -ftest-coverage - ) + target_compile_options(Glimpses PUBLIC -O0 -g -fprofile-arcs -ftest-coverage) + target_link_options(Glimpses PUBLIC -fprofile-arcs -ftest-coverage) endif() From 3d417b4fad8731c33ea1df026790dce0f762d98c Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Mon, 13 Nov 2023 16:18:17 +0100 Subject: [PATCH 02/11] feat: Added workspace recommendations for VSCode/VSCodium --- .vscode/extensions.json | 11 +++++++++++ .vscode/extensions.json.license | 3 +++ 2 files changed, 14 insertions(+) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/extensions.json.license diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..94d2355 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,11 @@ +{ + "recommendations": [ + "bbenoist.doxygen", + "editorconfig.editorconfig", + "elagil.pre-commit-helper", + "ms-vscode.cmake-tools", + "ms-vscode.cpptools", + "vivaxy.vscode-conventional-commits", + "xaver.clang-format", + ] +} diff --git a/.vscode/extensions.json.license b/.vscode/extensions.json.license new file mode 100644 index 0000000..37bf852 --- /dev/null +++ b/.vscode/extensions.json.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2023 Tobias Schmidl + +SPDX-License-Identifier: AGPL-3.0-or-later From 23d315c4d1be5936c340fcd3b1955fa1e63797e1 Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Mon, 13 Nov 2023 16:36:24 +0100 Subject: [PATCH 03/11] feat: Added pre-commit badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d513eea..379423b 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,6 @@ SPDX-License-Identifier: AGPL-3.0-or-later # glimpses +[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://pre-commit.com/) + T.B.D. From 33b77679b4ab5741a73142846115bd1fa3f7ea1a Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Tue, 21 Nov 2023 14:47:10 +0100 Subject: [PATCH 04/11] feat: changed clang-format to Microsft --- .clang-format | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index f0a9aa9..094e88e 100644 --- a/.clang-format +++ b/.clang-format @@ -3,7 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-or-later --- -BasedOnStyle: Mozilla +BasedOnStyle: Microsoft +AlwaysBreakTemplateDeclarations: true IndentWidth: 4 ... # vim: set filetype=yaml: From 7e9458da0c832a59818bff2a8e40504bd11d8e52 Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Mon, 16 Jun 2025 07:58:26 +0200 Subject: [PATCH 05/11] chore: updated pre-commit-config, updated copyright --- .clang-format | 3 +-- .cmake-format.yaml | 2 +- .ecrc.license | 2 +- .editorconfig | 2 +- .gitignore | 2 +- .pre-commit-config.yaml | 20 ++++++++++++++------ .vscode/extensions.json.license | 2 +- .woodpecker.yml | 16 ---------------- CMakeLists.txt | 2 +- README.md | 2 +- 10 files changed, 22 insertions(+), 31 deletions(-) delete mode 100644 .woodpecker.yml diff --git a/.clang-format b/.clang-format index 094e88e..092125a 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023 Tobias Schmidl +# SPDX-FileCopyrightText: 2025 Tobias Schmidl # # SPDX-License-Identifier: AGPL-3.0-or-later @@ -7,4 +7,3 @@ BasedOnStyle: Microsoft AlwaysBreakTemplateDeclarations: true IndentWidth: 4 ... -# vim: set filetype=yaml: diff --git a/.cmake-format.yaml b/.cmake-format.yaml index 51a8fd3..8be1643 100644 --- a/.cmake-format.yaml +++ b/.cmake-format.yaml @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023 Tobias Schmidl +# SPDX-FileCopyrightText: 2025 Tobias Schmidl # # SPDX-License-Identifier: AGPL-3.0-or-later --- diff --git a/.ecrc.license b/.ecrc.license index 37bf852..10da8d0 100644 --- a/.ecrc.license +++ b/.ecrc.license @@ -1,3 +1,3 @@ -SPDX-FileCopyrightText: 2023 Tobias Schmidl +SPDX-FileCopyrightText: 2025 Tobias Schmidl SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/.editorconfig b/.editorconfig index 35187b6..e61dfae 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023 Tobias Schmidl +# SPDX-FileCopyrightText: 2025 Tobias Schmidl # # SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/.gitignore b/.gitignore index 6211f64..bab7360 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023 Tobias Schmidl +# SPDX-FileCopyrightText: 2025 Tobias Schmidl # # SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 22e4933..babb286 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,10 @@ -# SPDX-FileCopyrightText: 2023 Tobias Schmidl +# SPDX-FileCopyrightText: 2025 Tobias Schmidl # # SPDX-License-Identifier: AGPL-3.0-or-later --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v5.0.0 hooks: - id: check-yaml - id: end-of-file-fixer @@ -13,7 +13,7 @@ repos: - id: check-ast - id: check-byte-order-marker - repo: https://github.com/fsfe/reuse-tool - rev: v2.1.0 + rev: v5.0.2 hooks: - id: reuse - repo: https://github.com/cheshirekow/cmake-format-precommit @@ -31,14 +31,22 @@ repos: - id: clang-format - id: clang-tidy - repo: https://github.com/editorconfig-checker/editorconfig-checker.python - rev: '2.7.2' + rev: '3.2.1' hooks: - id: editorconfig-checker alias: ec - stages: [commit] + stages: [pre-commit] +- repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.10.0.1 + hooks: + - id: shellcheck - repo: https://github.com/compilerla/conventional-pre-commit - rev: v2.4.0 + rev: v4.2.0 hooks: - id: conventional-pre-commit stages: [commit-msg] +- repo: https://github.com/igorshubovych/markdownlint-cli + rev: v0.45.0 + hooks: + - id: markdownlint ... diff --git a/.vscode/extensions.json.license b/.vscode/extensions.json.license index 37bf852..10da8d0 100644 --- a/.vscode/extensions.json.license +++ b/.vscode/extensions.json.license @@ -1,3 +1,3 @@ -SPDX-FileCopyrightText: 2023 Tobias Schmidl +SPDX-FileCopyrightText: 2025 Tobias Schmidl SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/.woodpecker.yml b/.woodpecker.yml deleted file mode 100644 index dde54e0..0000000 --- a/.woodpecker.yml +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-FileCopyrightText: 2023 Tobias Schmidl -# -# SPDX-License-Identifier: AGPL-3.0-or-later - ---- -steps: - - editor-config: - image: mstruebing/editorconfig-checker - group: lint - - reuse: - image: fsfe/reuse:latest - group: lint - -... diff --git a/CMakeLists.txt b/CMakeLists.txt index e8720d5..0c8c920 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2023 Tobias Schmidl +# SPDX-FileCopyrightText: 2025 Tobias Schmidl # # SPDX-License-Identifier: AGPL-3.0-or-later diff --git a/README.md b/README.md index 379423b..fce155d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ From 90f9d9a656ecf98430cff25c752e9c6efe690544 Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Mon, 16 Jun 2025 08:04:41 +0200 Subject: [PATCH 06/11] chore: update to CPM --- CMakeLists.txt | 2 +- cmake/{CPM.cmake => get_cpm.cmake} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename cmake/{CPM.cmake => get_cpm.cmake} (87%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c8c920..cd80f65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ endif() # ---- Add dependencies via CPM ---- # see https://github.com/TheLartians/CPM.cmake for more info -include(cmake/CPM.cmake) +include(cmake/get_cpm.cmake) # PackageProject.cmake will be used to make our target installable CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.8.0") diff --git a/cmake/CPM.cmake b/cmake/get_cpm.cmake similarity index 87% rename from cmake/CPM.cmake rename to cmake/get_cpm.cmake index f606c11..58aa4d0 100644 --- a/cmake/CPM.cmake +++ b/cmake/get_cpm.cmake @@ -2,8 +2,8 @@ # # SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors -set(CPM_DOWNLOAD_VERSION 0.38.5) -set(CPM_HASH_SUM "192aa0ccdc57dfe75bd9e4b176bf7fb5692fd2b3e3f7b09c74856fc39572b31c") +set(CPM_DOWNLOAD_VERSION 0.42.0) +set(CPM_HASH_SUM "2020b4fc42dba44817983e06342e682ecfc3d2f484a581f11cc5731fbe4dce8a") if(CPM_SOURCE_CACHE) set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") From 781fa188efea71e4b2e736a4030f73db165fdc96 Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Mon, 16 Jun 2025 21:00:22 +0200 Subject: [PATCH 07/11] feat: Added devcontainer --- .devcontainer/devcontainer.json | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..88864c7 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: 2025 Tobias Schmidl +// +// SPDX-License-Identifier: AGPL-3.0-or-later +// +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/cpp +{ + "name": "glimpses-devcontainer", + "image": "mcr.microsoft.com/devcontainers/cpp:1", + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/devcontainers-extra/features/cmake:1": {}, + "ghcr.io/devcontainers-extra/features/pre-commit:2": {}, + "ghcr.io/devcontainers/features/common-utils:2": { + "username": "vscode", + "uid": "${localEnv:UID}", + "gid": "${localEnv:GID}" + }, + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}, + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers/features/python:1": {} + }, + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + "settings": {}, + "extensions": [ + "editorconfig.editorconfig", + "elagil.pre-commit-helper", + "llvm-vs-code-extensions.vscode-clangd", + "ms-vscode.cmake-tools", + "ms-vscode.cpptools", + "streetsidesoftware.code-spell-checker", + "vivaxy.vscode-conventional-commits" + ] + } + }, + "containerEnv": { + "CC": "clang", + "CXX": "clang++", + "CMAKE_BUILD_PARALLEL_LEVEL": "${localEnv:NUMBER_OF_PROCESSORS}", + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_EXPORT_COMPILE_COMMANDS": "1", + "CMAKE_PREFIX_PATH": "/usr/local/cmake" + }, + "mounts": [ + "source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,readonly", + "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" + ], + "workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind", + "workspaceFolder": "${localWorkspaceFolder}" +} From 002bd3918dffbb7580201846671db2d422ada96f Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Mon, 16 Jun 2025 21:04:10 +0200 Subject: [PATCH 08/11] fixup! chore: update to CPM --- cmake/tools.cmake | 2 +- documentation/CMakeLists.txt | 2 +- standalone/CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/tools.cmake b/cmake/tools.cmake index 027609b..b7d70f6 100644 --- a/cmake/tools.cmake +++ b/cmake/tools.cmake @@ -10,7 +10,7 @@ if(NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) return() endif() -include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/get_cpm.cmake) # enables sanitizers support using the the `USE_SANITIZER` flag available values are: Address, Memory, MemoryWithOrigins, Undefined, Thread, # Leak, 'Address;Undefined' diff --git a/documentation/CMakeLists.txt b/documentation/CMakeLists.txt index 9652aa6..1b1d1fc 100644 --- a/documentation/CMakeLists.txt +++ b/documentation/CMakeLists.txt @@ -8,7 +8,7 @@ project(GlimpsesDocs) # ---- Dependencies ---- -include(../cmake/CPM.cmake) +include(../cmake/get_cpm.cmake) CPMAddPackage("gh:mosra/m.css#a0d292ec311b97fefd21e93cdefb60f88d19ede6") CPMAddPackage(NAME Glimpses SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..) diff --git a/standalone/CMakeLists.txt b/standalone/CMakeLists.txt index bf9e55d..3af0e8b 100644 --- a/standalone/CMakeLists.txt +++ b/standalone/CMakeLists.txt @@ -12,7 +12,7 @@ include(../cmake/tools.cmake) # ---- Dependencies ---- -include(../cmake/CPM.cmake) +include(../cmake/get_cpm.cmake) CPMAddPackage(NAME Glimpses SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 21dc941..0bf5ae3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,7 +16,7 @@ include(../cmake/tools.cmake) # ---- Dependencies ---- -include(../cmake/CPM.cmake) +include(../cmake/get_cpm.cmake) # CPMAddPackage("gh:doctest/doctest@2.4.9") CPMAddPackage("gh:TheLartians/Format.cmake@1.7.3") From cccebf674ab26bba145cfbea0ecc8896eeb3952f Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Mon, 16 Jun 2025 21:04:50 +0200 Subject: [PATCH 09/11] chore: updated plugin recommendations --- .vscode/extensions.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 94d2355..5364ee4 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,11 +1,12 @@ { "recommendations": [ - "bbenoist.doxygen", + "cschlosser.doxdocgen", "editorconfig.editorconfig", "elagil.pre-commit-helper", + "llvm-vs-code-extensions.vscode-clangd", "ms-vscode.cmake-tools", "ms-vscode.cpptools", - "vivaxy.vscode-conventional-commits", - "xaver.clang-format", + "streetsidesoftware.code-spell-checker", + "vivaxy.vscode-conventional-commits" ] } From bed7360063629c9949cc188c432c566b8a972ce4 Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Mon, 16 Jun 2025 21:22:22 +0200 Subject: [PATCH 10/11] feat: first working set --- include/glimpses/glimpses.hpp | 35 ++++++++++++++++++++++++++--------- source/glimpses.cpp | 20 +++++++++++++++++++- test/CMakeLists.txt | 13 ++++++------- test/source/glimpses.cpp | 19 ++++++++----------- test/source/main.cpp | 14 -------------- 5 files changed, 59 insertions(+), 42 deletions(-) delete mode 100644 test/source/main.cpp diff --git a/include/glimpses/glimpses.hpp b/include/glimpses/glimpses.hpp index 7d8fc02..eeed973 100644 --- a/include/glimpses/glimpses.hpp +++ b/include/glimpses/glimpses.hpp @@ -4,22 +4,39 @@ #pragma once +#include +#include #include -namespace glimpses { +#include "glimpses/version.h" -/** - * @brief A class for saying hello in multiple languages - */ -class Glimpses +namespace glimpses { +/** @brief A class for saying retrieving system information */ +class Glimpses +{ public: - /** - * @brief Creates a new glimpses - * @param name the name to greet - */ + /** @brief Type for representing the number of CPU cores. */ + using CPUCount = uint32_t; + + /** @brief Type for representing a set of CPU cores, mapped by their names. */ + using CPUSet = std::map; + + /** @brief Maximum number of CPU cores supported by Glimpses. */ + constexpr static CPUCount MAX_CPU_COUNT = 1024; + + /** @brief Version of the Glimpses library. */ + constexpr static const char *VERSION = GLIMPSES_VERSION; + + /** @brief Creates a new glimpses */ Glimpses(); + + /** + * @brief Returns the number of CPU cores available on the system. + * @return The number of CPU cores available on the system. + */ + CPUSet getCPUCount() const; }; } // namespace glimpses diff --git a/source/glimpses.cpp b/source/glimpses.cpp index 80aed49..b7071c0 100644 --- a/source/glimpses.cpp +++ b/source/glimpses.cpp @@ -3,7 +3,25 @@ // SPDX-License-Identifier: AGPL-3.0-or-later #include +#include +#include +#include using namespace glimpses; -Glimpses::Glimpses() {} +Glimpses::Glimpses() +{ +} + +Glimpses::CPUSet Glimpses::getCPUCount() const +{ + cpu_set_t cpuset; + auto minmax = [](int64_t min, int64_t value, int64_t max) -> CPUCount { + return std::min(std::max(value, min), max); + }; + sched_getaffinity(0, sizeof(cpuset), &cpuset); + return CPUSet{{"configured", minmax(0, sysconf(_SC_NPROCESSORS_CONF), MAX_CPU_COUNT)}, + {"logical", minmax(0, std::thread::hardware_concurrency(), MAX_CPU_COUNT)}, + {"online", minmax(0, sysconf(_SC_NPROCESSORS_ONLN), MAX_CPU_COUNT)}, + {"allowed", minmax(0, CPU_COUNT(&cpuset), MAX_CPU_COUNT)}}; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0bf5ae3..29beb72 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,8 +18,8 @@ include(../cmake/tools.cmake) include(../cmake/get_cpm.cmake) -# CPMAddPackage("gh:doctest/doctest@2.4.9") -CPMAddPackage("gh:TheLartians/Format.cmake@1.7.3") +CPMAddPackage(NAME Catch2 GITHUB_REPOSITORY catchorg/Catch2 VERSION 3.8.1) +CPMAddPackage("gh:TheLartians/Format.cmake@1.8.3") if(TEST_INSTALLED_VERSION) find_package(Glimpses REQUIRED) @@ -31,11 +31,7 @@ endif() file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp) add_executable(${PROJECT_NAME} ${sources}) -target_link_libraries( - ${PROJECT_NAME} - # doctest::doctest - Glimpses::Glimpses -) +target_link_libraries(${PROJECT_NAME} Catch2::Catch2WithMain Glimpses::Glimpses) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17) # enable compiler warnings @@ -52,6 +48,9 @@ endif() enable_testing() +include(CTest) +add_test(GlimpsesTests GlimpsesTests) + # Note: doctest and similar testing frameworks can automatically configure CMake tests. For other testing frameworks add the tests target # instead: add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) diff --git a/test/source/glimpses.cpp b/test/source/glimpses.cpp index 82e9090..29caf68 100644 --- a/test/source/glimpses.cpp +++ b/test/source/glimpses.cpp @@ -2,24 +2,21 @@ // // SPDX-License-Identifier: AGPL-3.0-or-later +#include #include #include - #include -/* -TEST_CASE("Glimpses") { - using namespace greeter; - Glimpses greeter("Tests"); +TEST_CASE("CPU count") +{ - CHECK(greeter.greet(LanguageCode::EN) == "Hello, Tests!"); - CHECK(greeter.greet(LanguageCode::DE) == "Hallo Tests!"); - CHECK(greeter.greet(LanguageCode::ES) == "¡Hola Tests!"); - CHECK(greeter.greet(LanguageCode::FR) == "Bonjour Tests!"); + glimpses::Glimpses glimpses{}; + + CHECK(glimpses.getCPUCount().size() > 0); } -TEST_CASE("Glimpses version") { - static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0")); +/* +TEST_CASE("Glimpses version") { static_assert(std::string_view(GREETER_VERSION) == std::string_view("0.1.0")); CHECK(std::string(GREETER_VERSION) == std::string("1.0")); } */ diff --git a/test/source/main.cpp b/test/source/main.cpp deleted file mode 100644 index ef34b77..0000000 --- a/test/source/main.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-FileCopyrightText: 2023 Tobias Schmidl -// -// SPDX-License-Identifier: AGPL-3.0-or-later -#if 0 -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN - -#include -#endif - -int -main() -{ - return 0; -} From d2615a0c47675a3367deaec2e39633d533a04ed0 Mon Sep 17 00:00:00 2001 From: Tobias Schmidl Date: Mon, 16 Jun 2025 22:11:32 +0200 Subject: [PATCH 11/11] chore: version bump to m.css --- documentation/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/CMakeLists.txt b/documentation/CMakeLists.txt index 1b1d1fc..50b2ee1 100644 --- a/documentation/CMakeLists.txt +++ b/documentation/CMakeLists.txt @@ -10,7 +10,7 @@ project(GlimpsesDocs) include(../cmake/get_cpm.cmake) -CPMAddPackage("gh:mosra/m.css#a0d292ec311b97fefd21e93cdefb60f88d19ede6") +CPMAddPackage("gh:mosra/m.css#0a460a7a9973a41db48f735e7b49e4da9a876325") CPMAddPackage(NAME Glimpses SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..) # ---- Doxygen variables ----