From b89c8ef7c0cd0ff2f869fd67cf9b247fa7b9b751 Mon Sep 17 00:00:00 2001 From: franneck94 Date: Mon, 4 Mar 2024 10:30:05 +0100 Subject: [PATCH] up --- .gitignore | 10 +- .vscode/cmake-kits.json | 37 ++++++ .vscode/cmake-variants.json | 24 ++++ .vscode/settings.json | 3 +- CMakeLists.txt | 60 +++++++-- _CMakePresets.json | 235 ++++++++++++++++++------------------ cmake/Sanitizer.cmake | 44 ++----- conanfile.py | 6 +- 8 files changed, 248 insertions(+), 171 deletions(-) create mode 100644 .vscode/cmake-kits.json create mode 100644 .vscode/cmake-variants.json diff --git a/.gitignore b/.gitignore index 6c7e869..0dce4f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,19 +1,14 @@ ################################ ########### FILES ############ ################################ -TODO*.* *.pptx -*.pdf -CMakeUserPresets.json ################################ ########### FOLDERS ############ ################################ build/ +build-*/ html/ -lectures/ -.mypy_cache/ -.ruff_cache/ ################################ ############ C/C++ ############# @@ -63,7 +58,8 @@ lectures/ ################################ ########### VS CODE ############ ################################ -.vscode +.vscode/settings.json +.vscode/c_cpp_properties.json *.code-workspace .history diff --git a/.vscode/cmake-kits.json b/.vscode/cmake-kits.json new file mode 100644 index 0000000..ec65e53 --- /dev/null +++ b/.vscode/cmake-kits.json @@ -0,0 +1,37 @@ +[ + { + "name": "linux-default", + "compilers": { + "C": "gcc", + "CXX": "g++" + } + }, + { + "name": "mac-default", + "compilers": { + "C": "clang", + "CXX": "clang++" + } + }, + { + "name": "win32-default", + "visualStudio": "1ad26ee0", + "visualStudioArchitecture": "x86_amd64" + }, + { + "name": "arm32-cross", + "toolchainFile": "${workspaceFolder}/cmake/toolchains/arm32-cross-toolchain.cmake" + }, + { + "name": "arm32-native", + "toolchainFile": "${workspaceFolder}/cmake/toolchains/arm32-native-toolchain.cmake" + }, + { + "name": "x86-64-mingw", + "toolchainFile": "${workspaceFolder}/cmake/toolchains/x86-64-mingw-toolchain.cmake" + }, + { + "name": "x86-64-native", + "toolchainFile": "${workspaceFolder}/cmake/toolchains/x86-64-native-toolchain.cmake" + } +] diff --git a/.vscode/cmake-variants.json b/.vscode/cmake-variants.json new file mode 100644 index 0000000..5ced995 --- /dev/null +++ b/.vscode/cmake-variants.json @@ -0,0 +1,24 @@ +{ + "buildType": { + "default": "Debug", + "description": "Enable debug or release build", + "choices": { + "Debug": { + "short": "Debug", + "long": "Build with no optimizations and debugging information", + "buildType": "Debug", + "settings": { + "CMAKE_CXX_FLAGS_DEBUG": "-g3 -O0" + } + }, + "Release": { + "short": "Release", + "long": "Build with optimizations and some debuging information", + "buildType": "Release", + "settings": { + "CMAKE_CXX_FLAGS_RELEASE": "-g -O3" + } + } + } + } +} diff --git a/.vscode/settings.json b/.vscode/settings.json index 554a2f4..9d5eb31 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,5 +8,6 @@ "${workspaceFolder}/app/test.json" ], "externalConsole": true - } + }, + "cmake.buildDirectory": "${workspaceFolder}/build-${buildKit}" } diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f012bc..445d7b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,7 @@ add_clang_format_target() if(ENABLE_SANITIZE_ADDR OR ENABLE_SANITIZE_UNDEF) include(Sanitizer) - add_sanitizer_flags() + add_sanitizer_flags(ENABLE_SANITIZE_ADDR ENABLE_SANITIZE_UNDEF) endif() if(ENABLE_COVERAGE) @@ -69,30 +69,66 @@ endif() # EXTERNAL LIBRARIES -if(USE_CONAN) +if(USE_CPM) + message(STATUS "Using CPM") + include(CPM) + cpmaddpackage("gh:nlohmann/json#v3.11.3") + cpmaddpackage("gh:fmtlib/fmt#10.2.1") + cpmaddpackage("gh:gabime/spdlog#v1.13.0") + cpmaddpackage("gh:jarro2783/cxxopts#v3.1.1") + cpmaddpackage("gh:catchorg/Catch2#v2.13.9") +elseif(USE_CONAN) message(STATUS "Using Conan") include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake) find_package(nlohmann_json REQUIRED) find_package(fmt REQUIRED) find_package(spdlog REQUIRED) - find_package(Catch2 REQUIRED) find_package(cxxopts REQUIRED) + find_package(Catch2 REQUIRED) elseif(USE_VCPKG) message(STATUS "Using VCPKG") include(${CMAKE_SOURCE_DIR}/external/vcpkg/scripts/buildsystems/vcpkg.cmake) find_package(nlohmann_json REQUIRED) find_package(fmt REQUIRED) find_package(spdlog REQUIRED) - find_package(Catch2 REQUIRED) find_package(cxxopts REQUIRED) -else(USE_CPM) - message(STATUS "Using CPM") - include(CPM) - cpmaddpackage("gh:fmtlib/fmt#9.1.0") - cpmaddpackage("gh:nlohmann/json@3.11.2") - cpmaddpackage("gh:catchorg/Catch2@2.13.9") - cpmaddpackage("gh:jarro2783/cxxopts@3.1.1") - cpmaddpackage("gh:gabime/spdlog@1.11.0") + find_package(Catch2 REQUIRED) +else() + message(STATUS "Using FetchContent") + FetchContent_Declare( + nlohmann_json + GIT_REPOSITORY https://github.com/nlohmann/json + GIT_TAG v3.11.3 + GIT_SHALLOW TRUE) + FetchContent_MakeAvailable(nlohmann_json) + + FetchContent_Declare( + fmt + GIT_REPOSITORY https://github.com/fmtlib/fmt + GIT_TAG 10.2.1 + GIT_SHALLOW TRUE) + FetchContent_MakeAvailable(fmt) + + FetchContent_Declare( + spdlog + GIT_REPOSITORY https://github.com/gabime/spdlog + GIT_TAG v1.13.0 + GIT_SHALLOW TRUE) + FetchContent_MakeAvailable(spdlog) + + FetchContent_Declare( + cxxopts + GIT_REPOSITORY https://github.com/jarro2783/cxxopts + GIT_TAG v3.1.1 + GIT_SHALLOW TRUE) + FetchContent_MakeAvailable(cxxopts) + + FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2 + GIT_TAG v2.13.9 + GIT_SHALLOW TRUE) + FetchContent_MakeAvailable(Catch2) endif() # SUB DIRECTORIES diff --git a/_CMakePresets.json b/_CMakePresets.json index f2e6057..132b67e 100644 --- a/_CMakePresets.json +++ b/_CMakePresets.json @@ -1,123 +1,128 @@ { "version": 3, - "cmakeMinimumRequired": { - "major": 3, - "minor": 21, - "patch": 0 - }, "configurePresets": [ - { - "name": "conf-common", - "description": "General settings that apply to all configurations.", - "hidden": true, - "generator": "Ninja", - "binaryDir": "${sourceDir}/out/build/${presetName}", - "installDir": "${sourceDir}/out/install/${presetName}" - }, - { - "name": "conf-windows-common", - "description": "Windows settings for MSBuild toolchain.", - "hidden": true, - "inherits": "conf-common", - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - }, - "architecture": { - "value": "x64", - "strategy": "external" - }, - "toolset": { - "value": "host=x64", - "strategy": "external" - }, - "cacheVariables": { - "ENABLE_COVERAGE": "FALSE", - "ENABLE_SANITIZE_UNDEF": "FALSE", - "ENABLE_SANITIZE_LEAK": "FALSE", - "ENABLE_SANITIZE_THREAD": "FALSE" - } - }, - { - "name": "conf-unix-common", - "description": "Unix-like OS settings for gcc and clang toolchains", - "hidden": true, - "inherits": "conf-common", - "condition": { - "type": "inList", - "string": "${hostSystemName}", - "list": [ - "Linux", - "Darwin" - ] - } - }, - { - "name": "windows-msvc-debug-mode", - "displayName": "msvc Debug", - "description": "Target Windows (MSVC), debug build type", - "inherits": "conf-windows-common", - "cacheVariables": { - "CMAKE_C_COMPILER": "cl", - "CMAKE_CXX_COMPILER": "cl", - "CMAKE_BUILD_TYPE": "Debug" - } - }, - { - "name": "windows-msvc-release-mode", - "displayName": "msvc Release", - "description": "Target Windows (MSVC), release build type", - "inherits": "conf-windows-common", - "cacheVariables": { - "CMAKE_C_COMPILER": "cl", - "CMAKE_CXX_COMPILER": "cl", - "CMAKE_BUILD_TYPE": "RelWithDebInfo" - } - }, - { - "name": "unix-gcc-debug", - "displayName": "gcc Debug", - "description": "Target Unix-like OS with the gcc compiler, debug build type", - "inherits": "conf-unix-common", - "cacheVariables": { - "CMAKE_C_COMPILER": "gcc", - "CMAKE_CXX_COMPILER": "g++", - "CMAKE_BUILD_TYPE": "Debug" - } + { + "name": "base", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build-${presetName}", + "installDir": "${sourceDir}/install/${presetName}", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "x64-debug", + "displayName": "x64 Debug", + "description": "Sets debug build type and x64 arch", + "inherits": "base", + "architecture": { + "value": "x64", + "strategy": "external" }, - { - "name": "unix-gcc-release", - "displayName": "gcc Release", - "description": "Target Unix-like OS with the gcc compiler, release build type", - "inherits": "conf-unix-common", - "cacheVariables": { - "CMAKE_C_COMPILER": "gcc", - "CMAKE_CXX_COMPILER": "g++", - "CMAKE_BUILD_TYPE": "RelWithDebInfo" - } + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "x64-release", + "displayName": "x64 Release", + "description": "Sets release build type", + "inherits": "x64-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "x86-debug", + "displayName": "x86 Debug ", + "description": "Sets debug build type and x86 arch", + "inherits": "base", + "architecture": { + "value": "x86", + "strategy": "external" }, - { - "name": "unix-clang-debug", - "displayName": "clang Debug", - "description": "Target Unix-like OS with the clang compiler, debug build type", - "inherits": "conf-unix-common", - "cacheVariables": { - "CMAKE_C_COMPILER": "clang", - "CMAKE_CXX_COMPILER": "clang++", - "CMAKE_BUILD_TYPE": "Debug" - } + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "x86-release", + "displayName": "x86 Release", + "description": "Sets release build type", + "inherits": "x86-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "linux-debug", + "displayName": "Linux Debug", + "description": "Sets GCC", + "inherits": "base", + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++", + "CMAKE_BUILD_TYPE": "Debug" }, - { - "name": "unix-clang-release", - "displayName": "clang Release", - "description": "Target Unix-like OS with the clang compiler, release build type", - "inherits": "conf-unix-common", - "cacheVariables": { - "CMAKE_C_COMPILER": "clang", - "CMAKE_CXX_COMPILER": "clang++", - "CMAKE_BUILD_TYPE": "RelWithDebInfo" - } + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "linux-release", + "displayName": "Linux Release", + "description": "Sets release build type", + "inherits": "linux-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + } + ], + "buildPresets": [ + { + "name": "default-build-linux", + "displayName": "Default", + "configurePreset": "linux-debug", + "description": "Vanilla build" + }, + { + "name": "default-build-windows", + "displayName": "Default", + "configurePreset": "x64-debug", + "description": "Vanilla build" + }, + { + "name": "verbose-build-linux", + "displayName": "Verbose Build", + "description": "Passes -v to Ninja", + "configurePreset": "linux-debug", + "nativeToolOptions": [ "-v" ] + }, + { + "name": "verbose-build-windows", + "displayName": "Verbose Build", + "configurePreset": "x64-debug", + "inherits": "verbose-build-linux" + } + ], + "testPresets": [ + { + "name": "core-test-linux", + "description": "Enable output on failure", + "configurePreset": "linux-debug", + "output": { + "outputOnFailure": true } + }, + { + "name": "core-test-windows", + "inherits": "core-test-linux", + "configurePreset": "x64-debug" + } ] -} + } diff --git a/cmake/Sanitizer.cmake b/cmake/Sanitizer.cmake index d819ae1..60d193c 100644 --- a/cmake/Sanitizer.cmake +++ b/cmake/Sanitizer.cmake @@ -1,53 +1,31 @@ -function(add_sanitizer_flags) - if(NOT ENABLE_SANITIZE_ADDR AND NOT ENABLE_SANITIZE_UNDEF) +function(add_sanitizer_flags enable_sanitize_addr enable_sanitize_undef) + if (NOT enable_sanitize_addr AND NOT enable_sanitize_undef) + message(STATUS "Sanitizers deactivated.") return() endif() - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES - "GNU") + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") add_compile_options("-fno-omit-frame-pointer") add_link_options("-fno-omit-frame-pointer") - if(ENABLE_SANITIZE_ADDR) + if(enable_sanitize_addr) add_compile_options("-fsanitize=address") add_link_options("-fsanitize=address") endif() - if(ENABLE_SANITIZE_UNDEF) + if(enable_sanitize_undef) add_compile_options("-fsanitize=undefined") add_link_options("-fsanitize=undefined") endif() - - if(ENABLE_SANITIZE_LEAK) - add_compile_options("-fsanitize=leak") - add_link_options("-fsanitize=leak") - endif() - - if(ENABLE_SANITIZE_THREAD) - if(ENABLE_SANITIZE_ADDR OR ENABLE_SANITIZE_LEAK) - message(WARNING "thread does not work with: address and leak") - endif() - add_compile_options("-fsanitize=thread") - add_link_options("-fsanitize=thread") - endif() - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - if(ENABLE_SANITIZE_ADDR) + elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + if(enable_sanitize_addr) add_compile_options("/fsanitize=address") endif() - if(ENABLE_SANITIZE_UNDEF) - message(STATUS "sanitize=undefined not avail. for MSVC") - endif() - - if(ENABLE_SANITIZE_LEAK) - message(STATUS "sanitize=leak not avail. for MSVC") - endif() - - if(ENABLE_SANITIZE_THREAD) - message(STATUS "sanitize=thread not avail. for MSVC") + if(enable_sanitize_undef) + message(STATUS "Undefined sanitizer not impl. for MSVC!") endif() else() - message(WARNING "This sanitizer not supported in this environment") - return() + message(STATUS "Sanitizer not supported in this environment!") endif() endfunction(add_sanitizer_flags) diff --git a/conanfile.py b/conanfile.py index e2cabcc..ee0ef1b 100644 --- a/conanfile.py +++ b/conanfile.py @@ -7,9 +7,9 @@ class CompressorRecipe(ConanFile): generators = "CMakeDeps" def requirements(self): - self.requires("nlohmann_json/3.11.2") - self.requires("fmt/9.1.0") - self.requires("spdlog/1.11.0") + self.requires("nlohmann_json/3.11.3") + self.requires("fmt/10.2.1") + self.requires("spdlog/1.13.0") self.requires("catch2/2.13.9") self.requires("cxxopts/3.1.1")