From 08dad9b639d370e5f6b21f2c35758635172d36ea Mon Sep 17 00:00:00 2001 From: Dmitriy Khaustov Date: Sat, 11 Jan 2025 02:49:44 +0800 Subject: [PATCH] Fix: vcpkg compatibility (#15) * feature: testing as vcpkg feature Signed-off-by: Dmitriy Khaustov aka xDimon * fix: vcpkg compatibility Signed-off-by: Dmitriy Khaustov aka xDimon * fix: c++ standard over vcpkg Signed-off-by: Dmitriy Khaustov aka xDimon * fix: CI Signed-off-by: Dmitriy Khaustov aka xDimon * fix: coverage Signed-off-by: Dmitriy Khaustov aka xDimon * update: hunter Signed-off-by: Dmitriy Khaustov aka xDimon * fix: use CLT in macos Signed-off-by: Dmitriy Khaustov aka xDimon * fix: c++ standard and toolchain file Signed-off-by: Dmitriy Khaustov aka xDimon --------- Signed-off-by: Dmitriy Khaustov aka xDimon (cherry picked from commit c13d77dd67e8e380f1c16065c988416d53cadbeb) --- .github/workflows/clang-tidy.yml | 5 +-- .github/workflows/compilers.yml | 3 +- .github/workflows/coverage.yml | 4 --- .github/workflows/tests.yml | 4 +-- CMakeLists.txt | 58 ++++++++++++++++++-------------- cmake/Hunter/init.cmake | 4 +-- cmake/dependencies.cmake | 11 +++--- vcpkg.json | 13 +++++-- 8 files changed, 55 insertions(+), 47 deletions(-) diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml index 5fd86c7..6f8ef7a 100644 --- a/.github/workflows/clang-tidy.yml +++ b/.github/workflows/clang-tidy.yml @@ -40,9 +40,6 @@ jobs: sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 90 sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-13 90 -# sudo python3 -m pip install --upgrade pip -# sudo python3 -m pip install scikit-build -# sudo python3 -m pip install cmake==3.25 requests gitpython gcovr pyyaml - name: run checks run: | #!/bin/bash @@ -51,5 +48,5 @@ jobs: test ${VER_COUNT} -eq 0 && echo "no llvm version detected" && exit 1 export LLVM_ROOT=$(ls -r -d -1 ${LLVM_DIR} | head -1) export PATH=${LLVM_ROOT}/bin:${LLVM_ROOT}/share/clang:${PATH} - cmake . -Bbuild + cmake . -Bbuild -DBUILD_TESTS=ON .github/aux/clang-tidy.sh build diff --git a/.github/workflows/compilers.yml b/.github/workflows/compilers.yml index 17fd9c7..f5e068a 100644 --- a/.github/workflows/compilers.yml +++ b/.github/workflows/compilers.yml @@ -50,6 +50,7 @@ jobs: if [ "$RUNNER_OS" = "macOS" ]; then brew install ninja + sudo xcode-select --switch /Library/Developer/CommandLineTools else sudo apt-get update || true sudo apt-get install -y ninja-build gcovr gcc-13 g++-13 clang-18 clang++-18 clang-tidy-18 clang-format-18 @@ -74,7 +75,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # has to be included to access other secrets GITHUB_HUNTER_USERNAME: ${{ secrets.GITHUB_HUNTER_USERNAME }} GITHUB_HUNTER_TOKEN: ${{ secrets.GITHUB_HUNTER_TOKEN }} - run: cmake . -Bbuild + run: cmake . -Bbuild -DBUILD_TESTS=ON - name: build run: cmake --build build -- -j4 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index fb3664f..e1d5bdb 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -41,10 +41,6 @@ jobs: sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 90 sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-13 90 -# sudo python3 -m pip install --upgrade pip -# sudo python3 -m pip install scikit-build -# sudo python3 -m pip install cmake==3.25 requests gitpython gcovr pyyaml - - name: "cmake" env: CC: clang diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 12d6417..cc9069e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -52,8 +52,6 @@ jobs: set -e sudo apt-get update || true sudo apt-get install -y ninja-build -# sudo python3 -m pip install --upgrade pip -# sudo pip3 install cmake requests gitpython gcovr pyyaml - name: cmake env: @@ -62,7 +60,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # has to be included to access other secrets GITHUB_HUNTER_USERNAME: ${{ secrets.GITHUB_HUNTER_USERNAME }} GITHUB_HUNTER_TOKEN: ${{ secrets.GITHUB_HUNTER_TOKEN }} - run: cmake . -Bbuild -D${{ matrix.options.sanitizer }}=ON + run: cmake . -Bbuild -DBUILD_TESTS=ON -D${{ matrix.options.sanitizer }}=ON - name: build run: cmake --build build -- -j4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f21775..98f84f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,23 @@ cmake_minimum_required(VERSION 3.12) +option(BUILD_TESTS "Build tests" OFF) +option(EXAMPLES "Build examples" ON) +option(CLANG_FORMAT "Enable clang-format target" OFF) +option(CLANG_TIDY "Enable clang-tidy checks during compilation" OFF) +option(COVERAGE "Enable generation of coverage info" OFF) + +# Sanitizers enables only for this project, and will be disabled for dependencies +option(ASAN "Enable address sanitizer" OFF) +option(LSAN "Enable leak sanitizer" OFF) +option(MSAN "Enable memory sanitizer" OFF) +option(TSAN "Enable thread sanitizer" OFF) +option(UBSAN "Enable UB sanitizer" OFF) + +if (COVERAGE) + set(BUILD_TESTS ON) # tests are needed to generate coverage info +endif () + if (PACKAGE_MANAGER) if(PACKAGE_MANAGER NOT MATCHES "^(hunter|vcpkg)$") message(FATAL_ERROR "PACKAGE_MANAGER must be set to 'hunter', 'vcpkg' or isn't set") @@ -27,7 +44,14 @@ if (PACKAGE_MANAGER STREQUAL "hunter") include("cmake/Hunter/init.cmake") endif () +if(BUILD_TESTS) + if (PACKAGE_MANAGER STREQUAL "vcpkg") + list(APPEND VCPKG_MANIFEST_FEATURES soralog-tests) + endif() +endif() + cmake_policy(SET CMP0048 NEW) + project(soralog VERSION 0.2.5 LANGUAGES CXX) find_program(CCACHE_FOUND ccache) @@ -40,37 +64,21 @@ include(cmake/functions.cmake) include(cmake/toolchain/compiler.cmake) -if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) +if (NOT DEFINED CMAKE_TOOLCHAIN_FILE OR NOT DEFINED CMAKE_CXX_STANDARD) if (MAX_SUPPORTED_CXX_STANDARD GREATER_EQUAL 20) - set(CMAKE_TOOLCHAIN_FILE - "${CMAKE_SOURCE_DIR}/cmake/toolchain/cxx20.cmake" - CACHE FILEPATH "Default toolchain" - ) + set(CXXSTD 20) else () - set(CMAKE_TOOLCHAIN_FILE - "${CMAKE_SOURCE_DIR}/cmake/toolchain/cxx17.cmake" - CACHE FILEPATH "Default toolchain" - ) + set(CXXSTD 17) + endif () + include("${CMAKE_SOURCE_DIR}/cmake/toolchain/cxx${CXXSTD}.cmake") + print("Using C++${CXXSTD} standard") + if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) + set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/cmake/toolchain/cxx${CXXSTD}.cmake") endif () - print("Toolchain: ${CMAKE_TOOLCHAIN_FILE}") - include(${CMAKE_TOOLCHAIN_FILE}) endif () set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -option(TESTING "Build tests" ON) -option(EXAMPLES "Build examples" ON) -option(CLANG_FORMAT "Enable clang-format target" OFF) -option(CLANG_TIDY "Enable clang-tidy checks during compilation" OFF) -option(COVERAGE "Enable generation of coverage info" OFF) - -# Sanitizers enables only for this project, and will be disabled for dependencies -option(ASAN "Enable address sanitizer" OFF) -option(LSAN "Enable leak sanitizer" OFF) -option(MSAN "Enable memory sanitizer" OFF) -option(TSAN "Enable thread sanitizer" OFF) -option(UBSAN "Enable UB sanitizer" OFF) - # the property is out of "if TESTING" scope due to addtest func is out too set_property(GLOBAL PROPERTY TEST_TARGETS) @@ -88,7 +96,7 @@ endif() add_subdirectory(src) -if(TESTING OR COVERAGE) +if (BUILD_TESTS) enable_testing() add_subdirectory(test) endif() diff --git a/cmake/Hunter/init.cmake b/cmake/Hunter/init.cmake index b275bf4..5e667c5 100644 --- a/cmake/Hunter/init.cmake +++ b/cmake/Hunter/init.cmake @@ -34,7 +34,7 @@ set( include(${CMAKE_CURRENT_LIST_DIR}/HunterGate.cmake) HunterGate( - URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm3.zip - SHA1 8989599eaa462f367805e2d36a30150c93b1d660 + URL https://github.com/qdrvm/hunter/archive/refs/tags/v0.25.3-qdrvm26.zip + SHA1 21e8e29f562962e97fc8bcd35a4ad5244794c7fc LOCAL ) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index bc9c56f..6dba01c 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -5,8 +5,12 @@ # SPDX-License-Identifier: Apache-2.0 # +if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.27") + cmake_policy(SET CMP0144 NEW) +endif () + function(reg_dependency name) - if (${HUNTER_ENABLED}) + if (PACKAGE_MANAGER STREQUAL "hunter") hunter_add_package(${name}) endif () find_package(${name} CONFIG REQUIRED) @@ -14,12 +18,9 @@ endfunction() reg_dependency(yaml-cpp) -if (NOT TARGET yaml-cpp::yaml-cpp) - add_library(yaml-cpp::yaml-cpp ALIAS yaml-cpp) -endif() reg_dependency(fmt) -if (TESTING OR COVERAGE) +if (BUILD_TESTS) reg_dependency(GTest) endif() diff --git a/vcpkg.json b/vcpkg.json index c3e159e..59d7c24 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -3,7 +3,14 @@ "version": "0.2.5", "dependencies": [ "fmt", - "yaml-cpp", - "gtest" - ] + "yaml-cpp" + ], + "features": { + "soralog-tests": { + "description": "Test of soralog's mechanisms", + "dependencies": [ + "gtest" + ] + } + } }