Skip to content

Commit

Permalink
Fix: vcpkg compatibility (#15)
Browse files Browse the repository at this point in the history
* feature: testing as vcpkg feature

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>

* fix: vcpkg compatibility

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>

* fix: c++ standard over vcpkg

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>

* fix: CI

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>

* fix: coverage

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>

* update: hunter

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>

* fix: use CLT in macos

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>

* fix: c++ standard and toolchain file

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>

---------

Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
(cherry picked from commit c13d77d)
  • Loading branch information
xDimon committed Jan 10, 2025
1 parent 348299a commit 08dad9b
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 47 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion .github/workflows/compilers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
58 changes: 33 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -88,7 +96,7 @@ endif()

add_subdirectory(src)

if(TESTING OR COVERAGE)
if (BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
Expand Down
4 changes: 2 additions & 2 deletions cmake/Hunter/init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
11 changes: 6 additions & 5 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
# 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)
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()
13 changes: 10 additions & 3 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
}

0 comments on commit 08dad9b

Please sign in to comment.