diff --git a/.clang-tidy b/.clang-tidy index 203d5ae..403e6bb 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,4 +1,17 @@ --- -Checks: 'bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,hicpp-*,misc-*,modernize-*,performance-*,portability-*,readability-*,-modernize-use-trailing-return-type,-bugprone-easily-swappable-parameters,-readability-identifier-length,-readability-named-parameter,-hicpp-special-member-functions,-hicpp-use-equals-default,-hicpp-move-const-arg,-hicpp-named-parameter,-hicpp-vararg,-misc-include-cleaner,-cppcoreguidelines-pro-type-union-access,-misc-non-private-member-variables-in-classes,-*-avoid-do-while' +Checks: < + bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,hicpp-*,misc-*,modernize-*,performance-*,portability-*,readability-*, + + -bugprone-easily-swappable-parameters, + -cppcoreguidelines-avoid-do-while,-cppcoreguidelines-pro-type-union-access, + -misc-include-cleaner, + -modernize-use-trailing-return-type, + -readability-identifier-length,-readability-named-parameter, + + -bugprone-narrowing-conversions, + -cert-arr39-c,-cert-con36-c,-cert-con54-cpp,-cert-ctr56-cpp,-cert-dcl03-c,-cert-dcl16-c,-cert-dcl37-c,-cert-dcl51-cpp,-cert-dcl54-cpp,-cert-dcl59-cpp,-cert-err09-cpp,-cert-err61-cpp,-cert-exp42-c,-cert-fio38-c,-cert-flp37-c,-cert-int09-c,-cert-msc24-c,-cert-msc30-c,-cert-msc32-c,-cert-msc33-c,-cert-msc54-cpp,-cert-oop11-cpp,-cert-oop54-cpp,-cert-pos44-c,-cert-pos47-c,-cert-sig30-c,-cert-str34-c, + -cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-c-copy-assignment-signature,-cppcoreguidelines-explicit-virtual-functions,-cppcoreguidelines-macro-to-enum,-cppcoreguidelines-noexcept-destructor,-cppcoreguidelines-noexcept-move-operations,-cppcoreguidelines-noexcept-swap,-cppcoreguidelines-non-private-member-variables-in-classes,-cppcoreguidelines-use-default-member-init, + -hicpp-avoid-c-arrays,-hicpp-avoid-goto,-hicpp-braces-around-statements,-hicpp-deprecated-headers,-hicpp-explicit-conversions,-hicpp-function-size,-hicpp-invalid-access-moved,-hicpp-member-init,-hicpp-move-const-arg,-hicpp-named-parameter,-hicpp-new-delete-operators,-hicpp-no-array-decay,-hicpp-no-malloc,-hicpp-noexcept-move,-hicpp-special-member-functions,-hicpp-static-assert,-hicpp-undelegated-constructor,-hicpp-uppercase-literal-suffix,-hicpp-use-auto,-hicpp-use-emplace,-hicpp-use-equals-default,-hicpp-use-equals-delete,-hicpp-use-noexcept,-hicpp-use-nullptr,-hicpp-use-override,-hicpp-vararg + FormatStyle: none HeaderFilterRegex: '.*' diff --git a/.gitignore b/.gitignore index 6513c6d..f0bba12 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +/.cache/ /.vscode/ -/build/ +/build*/ diff --git a/CMakeLists.txt b/CMakeLists.txt index ebee77b..05175e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,8 @@ set(CMAKE_VERBOSE_MAKEFILE ON) option(WITH_TESTING "Whether to enable tests" ON) option(INSTALL_SYSLOG_EXPORTER "Whether to install the syslog exporter" ON) +include(FetchContent) + # Logs signal became stable in v1.11.0, see https://github.com/open-telemetry/opentelemetry-cpp/pull/2229, https://github.com/open-telemetry/opentelemetry-cpp/blob/v1.11.0/CHANGELOG.md find_package(opentelemetry-cpp CONFIG REQUIRED) if(opentelemetry-cpp_VERSION VERSION_LESS 1.11.0) @@ -25,13 +27,24 @@ add_subdirectory(src) if(WITH_TESTING) include(FindGTest) find_package(GTest CONFIG COMPONENTS gtest gmock) - if(TARGET GTest::gtest AND TARGET GTest::gmock) - include(CTest) - enable_testing() - add_subdirectory(test) - else() - message(WARNING "GTest not found, tests will not be built") + if(NOT TARGET GTest::gtest OR NOT TARGET GTest::gmock) + message(STATUS "Google Test not found, fetching it from GitHub") + # renovate: datasource=github-tags depName=google/googletest + set(GTEST_VERSION "v1.15.2") + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest + GIT_TAG "${GTEST_VERSION}" + GIT_SHALLOW ON + ) + + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) endif() + + include(CTest) + enable_testing() + add_subdirectory(test) endif() find_program(CLANG_FORMAT NAMES clang-format) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..3612559 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,127 @@ +{ + "version": 4, + "cmakeMinimumRequired": { + "major": 3, + "minor": 23, + "patch": 0 + }, + "configurePresets": [ + { + "name": "base", + "hidden": true, + "binaryDir": "${sourceDir}/build-${presetName}", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", + "WITH_TESTING": "ON" + } + }, + { + "name": "base-vcpkg", + "hidden": true, + "inherits": "base", + "toolchainFile": "${fileDir}/vcpkg/scripts/buildsystems/vcpkg.cmake" + }, + { + "name": "default", + "description": "Default build", + "inherits": "base", + "hidden": false, + "binaryDir": "${sourceDir}/build" + }, + { + "name": "debug", + "description": "Debug build", + "inherits": "base", + "hidden": false + }, + { + "name": "release", + "description": "Release build", + "inherits": "base", + "hidden": false, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "debug-vcpkg", + "description": "Debug + vcpkg", + "inherits": "base-vcpkg", + "hidden": false + } + ], + "buildPresets": [ + { + "name": "base", + "hidden": true, + "verbose": true + }, + { + "name": "default", + "description": "Default build", + "inherits": "base", + "hidden": false, + "configurePreset": "default" + }, + { + "name": "debug", + "description": "Debug build", + "inherits": "base", + "hidden": false, + "configurePreset": "debug" + }, + { + "name": "release", + "description": "Release build", + "inherits": "base", + "hidden": false, + "configurePreset": "release" + }, + { + "name": "debug-vcpkg", + "description": "Debug + vcpkg", + "inherits": "base", + "hidden": false, + "configurePreset": "debug-vcpkg" + } + ], + "testPresets": [ + { + "name": "base", + "hidden": true, + "output": { + "outputOnFailure": true, + "quiet": false + } + }, + { + "name": "default", + "description": "Default build", + "inherits": "base", + "hidden": false, + "configurePreset": "default" + }, + { + "name": "debug", + "description": "Debug build", + "inherits": "base", + "hidden": false, + "configurePreset": "debug" + }, + { + "name": "release", + "description": "Release build", + "inherits": "base", + "hidden": false, + "configurePreset": "release" + }, + { + "name": "debug-vcpkg", + "description": "Debug + vcpkg", + "inherits": "base", + "hidden": false, + "configurePreset": "debug-vcpkg" + } + ] +} diff --git a/Dockerfile b/Dockerfile index 452931c..add2cbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ RUN \ cd opentelemetry-cpp && \ cmake \ -B build \ - -DWITH_DEPRECATED_SDK_FACTORY=OFF -DWITH_NO_DEPRECATED_CODE=ON -DWITH_OTLP_HTTP=OFF \ + -DWITH_NO_DEPRECATED_CODE=ON -DWITH_OTLP_HTTP=OFF \ -DBUILD_TESTING=OFF -DWITH_BENCHMARK=OFF -DWITH_FUNC_TESTS=OFF -DWITH_EXAMPLES=OFF && \ cmake --build build -j "$(nproc)" && \ cmake --install build