Skip to content

Commit eeb1bcc

Browse files
authored
Maintenance update (#17)
Tweaks CMake usage, add optional vcpkg support
1 parent f208ef8 commit eeb1bcc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+27155
-13864
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: build with internal SQLite
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
strategy:
11+
matrix:
12+
build:
13+
- {
14+
os: ubuntu-latest,
15+
preset: ninja,
16+
17+
}
18+
- {
19+
os: macos-latest,
20+
preset: xcode,
21+
22+
}
23+
- {
24+
os: windows-2022,
25+
preset: msvc22,
26+
27+
}
28+
runs-on: ${{ matrix.build.os }}
29+
steps:
30+
- uses: lukka/get-cmake@latest
31+
with:
32+
cmakeVersion: "~3.30.0" # <--= optional, use most recent 3.25.x version
33+
ninjaVersion: "^1.11.1" # <--= optional, use most recent 1.x version
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
- name: Setup MSVC
37+
if: startsWith(matrix.build.os, 'windows')
38+
uses: ilammy/msvc-dev-cmd@v1
39+
- name: Configure project
40+
run: cmake --preset ${{ matrix.build.preset }} -DPROJECT_ADDONS='add-on/fetch-dependencies' -DUSE_INTERNAL_SQLITE3=ON
41+
- name: Build project
42+
run: cmake --build --preset ${{ matrix.build.preset }}-release --parallel --verbose
43+
- name: Run unit test
44+
run: ctest --preset ${{ matrix.build.preset }}-release --parallel
45+
46+

.github/workflows/build-project.yml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,40 @@ jobs:
1111
matrix:
1212
build:
1313
- {
14-
os: ubuntu-22.04,
15-
preset: default
14+
os: ubuntu-latest,
15+
preset: ninja,
16+
cmake_args: -DCMAKE_TOOLCHAIN_FILE=toolchain/use-vcpkg
1617
}
1718
- {
18-
os: macos-12,
19-
preset: xcode
19+
os: macos-latest,
20+
preset: xcode,
21+
cmake_args: -DPROJECT_ADDONS='add-on/fetch-dependencies'
2022
}
2123
- {
2224
os: windows-2022,
23-
preset: msvc
25+
preset: msvc22,
26+
cmake_args: -DCMAKE_TOOLCHAIN_FILE=toolchain/use-vcpkg
2427
}
2528
runs-on: ${{ matrix.build.os }}
2629
steps:
30+
- name: Cleanup for SQLite on macOS
31+
run: |
32+
sudo rm -rf /Library/Frameworks/Mono.framework
33+
# There is a sqlite header in a different version than the lib found in the system
34+
if: startsWith(matrix.build.os, 'macos')
35+
- uses: lukka/get-cmake@latest
36+
with:
37+
cmakeVersion: "~3.30.0" # <--= optional, use most recent 3.25.x version
38+
ninjaVersion: "^1.11.1" # <--= optional, use most recent 1.x version
2739
- name: Checkout repository
28-
uses: actions/checkout@v3
40+
uses: actions/checkout@v4
2941
- name: Setup MSVC
3042
if: startsWith(matrix.build.os, 'windows')
3143
uses: ilammy/msvc-dev-cmd@v1
32-
- run: sudo apt-get update && sudo apt-get install --no-install-recommends ninja-build xsltproc
33-
if: ${{ startsWith(matrix.build.os,'ubuntu') }}
3444
- name: Configure project
35-
run: cmake --preset ${{ matrix.build.preset }}
45+
run: cmake --preset ${{ matrix.build.preset }} ${{ matrix.build.cmake_args }}
3646
- name: Build project
37-
run: cmake --build --preset ${{ matrix.build.preset }}-release --parallel
47+
run: cmake --build --preset ${{ matrix.build.preset }}-release --parallel --verbose
3848
- name: Run unit test
3949
run: ctest --preset ${{ matrix.build.preset }}-release --parallel
4050

.github/workflows/docs.yml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
tags:
77
- 'v*'
88
branches: ["main"]
9+
pull_request:
910

1011
workflow_dispatch:
1112

@@ -20,24 +21,36 @@ concurrency:
2021

2122
jobs:
2223
build:
23-
runs-on: ubuntu-latest
24+
runs-on: ubuntu-24.04
2425
steps:
2526
- uses: ssciwr/doxygen-install@v1
2627
with:
27-
version: "1.9.6"
28-
- name: Install requirements
29-
run: sudo apt-get install -y ninja-build
28+
version: "1.12.0"
29+
- uses: lukka/get-cmake@latest
30+
with:
31+
cmakeVersion: "~3.30.0" # <--= optional, use most recent 3.25.x version
32+
ninjaVersion: "^1.11.1" # <--= optional, use most recent 1.x version
3033
- name: Checkout
31-
uses: actions/checkout@v3
34+
uses: actions/checkout@v4
35+
- name: Install lcov
36+
run: sudo apt-get install lcov
3237
# For doc gen present should not be used, since the multi config is not needed, but keep that for now
33-
- name: Configure project
34-
run: cmake -S . -B build/default
38+
- name: Run workflow to get coverage docs
39+
run: cmake --preset ninja -DTOOLCHAIN_INCLUDES=toolchain/use-vcpkg -DPROJECT_ADDONS='add-on/coverage-gcov' -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF
40+
- name: Build project
41+
run: cmake --build --preset ninja --parallel
42+
- name: Run tests
43+
run: ctest --preset ninja --parallel
3544
- name: Build documentation
36-
run: cmake --build build/default --parallel --target doc
45+
run: cmake --build --preset ninja --parallel --target doc
46+
- name: Build coverage docs
47+
run: cmake --build --preset ninja --target coverage
48+
- name: Add coverage to docs
49+
run: mv build/Linux/ninja/coverage/ build/Linux/ninja/doc/html/coverage
3750
- name: Upload site artifact
38-
uses: actions/upload-pages-artifact@v1
51+
uses: actions/upload-pages-artifact@v3
3952
with:
40-
path: 'build/default/doc/html/'
53+
path: 'build/Linux/ninja/doc/html/'
4154

4255

4356
deploy:
@@ -51,9 +64,9 @@ jobs:
5164
runs-on: ubuntu-latest
5265
steps:
5366
- name: Checkout
54-
uses: actions/checkout@v3
67+
uses: actions/checkout@v4
5568
- name: Setup Pages
56-
uses: actions/configure-pages@v2
69+
uses: actions/configure-pages@v5
5770
- name: Deploy to GitHub Pages
5871
id: deployment
59-
uses: actions/deploy-pages@v1
72+
uses: actions/deploy-pages@v4

CMake/add-on/coverage-clang.cmake

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
include_guard(GLOBAL)
2+
3+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
4+
message(STATUS "-- Clang Coverage enabled, CMAKE_CXX_COMPILER:" ${CMAKE_CXX_COMPILER})
5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
6+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
7+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-instr-generate")
8+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-instr-generate")
9+
else()
10+
message(FATAL_ERROR "Clang Coverage is only supported with Clang")
11+
endif()
12+
13+
set(COVERAGE_TOOL "llvm-profdata")
14+
15+
add_custom_target(coverage
16+
COMMAND ${CMAKE_COMMAND} -E env "PATH=$ENV{PATH}"
17+
${CMAKE_CURRENT_LIST_DIR}/coverage-report-clang.sh --build-dir ${CMAKE_BINARY_DIR}
18+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
19+
COMMENT "Generating coverage report using coverage-report-clang.sh"
20+
)
21+
22+
add_custom_target(clean_coverage
23+
COMMAND find . -name '*.profraw' -delete
24+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
25+
)
26+
27+

CMake/add-on/coverage-gcov.cmake

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
include_guard(GLOBAL)
2+
3+
# TODO , check that we are on GCC
4+
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
5+
message(FATAL_ERROR "This coverage implementation requires the GCC compiler")
6+
endif()
7+
8+
9+
message(STATUS "----- GNU Coverage enabled")
10+
# TODO, add -fprofile-abs-path when compiler is gcc
11+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
12+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
13+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
14+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
15+
16+
17+
18+
find_program(LCOV lcov)
19+
find_program(GCOV gcov)
20+
if(NOT GCOV)
21+
message(FATAL_ERROR "gcov tool not found for GCC version ${GCC_MAJOR_VERSION}")
22+
endif()
23+
24+
set(COVERAGE_BRANCHES "--rc branch_coverage=1")
25+
# these warnings are ridiculous, they depend on the lcov genhtml version
26+
set(COVERAGE_WARNINGS "--ignore-errors gcov --ignore-errors mismatch --ignore-errors unused")
27+
set(GENHTML_WARNINGS "")
28+
29+
set(COVERAGE_TOOL "lcov")
30+
31+
separate_arguments(COVERAGE_BRANCHES)
32+
separate_arguments(COVERAGE_WARNINGS)
33+
separate_arguments(GENHTML_WARNINGS)
34+
add_custom_target(coverage
35+
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/coverage
36+
COMMAND lcov --directory . --capture --output-file ${CMAKE_BINARY_DIR}/coverage/coverage.info ${COVERAGE_WARNINGS} ${COVERAGE_BRANCHES}
37+
COMMAND lcov --remove ${CMAKE_BINARY_DIR}/coverage/coverage.info '/usr/*' '*/tests/*' '*/vcpkg_installed/*' '${CMAKE_BINARY_DIR}/_deps/*' '${CMAKE_SOURCE_DIR}/external/*' --output-file ${CMAKE_BINARY_DIR}/coverage/coverage.info.cleaned ${COVERAGE_WARNINGS} ${COVERAGE_BRANCHES}
38+
COMMAND genhtml --branch-coverage ${CMAKE_BINARY_DIR}/coverage/coverage.info.cleaned --output-directory ${CMAKE_BINARY_DIR}/coverage ${GENHTML_WARNINGS} ${COVERAGE_BRANCHES}
39+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
40+
)
41+
42+
43+
add_custom_target(clean_coverage
44+
COMMAND find . -name '*.gcda' -delete
45+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
46+
)

CMake/add-on/coverage-report-clang.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/sh
2+
3+
# Directory containing the test binaries
4+
set -e
5+
6+
# Parse arguments
7+
TEST_BIN_DIR=""
8+
while [ "$#" -gt 0 ]; do
9+
case "$1" in
10+
--build-dir)
11+
TEST_BIN_DIR="$2"
12+
shift 2
13+
;;
14+
--build-dir=*)
15+
TEST_BIN_DIR="${1#*=}"
16+
shift 1
17+
;;
18+
*)
19+
echo "Unknown option: $1"
20+
exit 1
21+
;;
22+
esac
23+
done
24+
25+
if [ -z "${TEST_BIN_DIR}" ]; then
26+
echo "Please provide the build directory by using the --build-dir option"
27+
exit 1
28+
fi
29+
30+
# Set XCRUN based on the output of uname
31+
if [ "$(uname)" = "Darwin" ]; then
32+
XCRUN="xcrun"
33+
else
34+
XCRUN=""
35+
fi
36+
37+
# Directory to store the coverage report
38+
# TODO, add into build dir
39+
COVERAGE_REPORT_DIR="${TEST_BIN_DIR}/coverage_report"
40+
41+
# Remove any existing .profraw files
42+
# find ${TEST_BIN_DIR} -name "*.profraw" -delete
43+
44+
# Find all .profraw files
45+
ALL_PROFILES=$(find ${TEST_BIN_DIR} -name '*.profraw')
46+
ALL_BINARIES=''
47+
for profile in ${ALL_PROFILES}; do
48+
binary=$(basename -s .profraw "${profile}")
49+
binary_path=$(find "${TEST_BIN_DIR}" -type f -name "${binary}" -print -quit)
50+
if [ -z "${binary_path}" ]; then
51+
echo "Binary ${binary} for profile ${profile} not found in ${TEST_BIN_DIR}"
52+
# exit 1
53+
else
54+
ALL_BINARIES="${ALL_BINARIES} ${binary_path}"
55+
fi
56+
done
57+
58+
COVERAGE_COMBINED_FILE="${TEST_BIN_DIR}/coverage-all.profraw"
59+
60+
# Merge all .profraw files into a single .profdata file
61+
rm -f ${COVERAGE_COMBINED_FILE}
62+
echo "Merging profiles into ${COVERAGE_COMBINED_FILE}"
63+
${XCRUN} llvm-profdata merge -sparse ${ALL_PROFILES} -o ${COVERAGE_COMBINED_FILE}
64+
65+
IGNORE_REGEX="${TEST_BIN_DIR}/_deps/.*|tests/.*"
66+
echo "Generating plain coverage report"
67+
# Generate the plain text coverage report for each binary
68+
for binary in ${ALL_BINARIES}; do
69+
${XCRUN} llvm-cov show ${binary} \
70+
-instr-profile=${COVERAGE_COMBINED_FILE} \
71+
-ignore-filename-regex=${IGNORE_REGEX} \
72+
-output-dir=${COVERAGE_REPORT_DIR}/plain
73+
done
74+
75+
# Generate an HTML coverage report for each binary
76+
echo "Generating HTML coverage report"
77+
for binary in ${ALL_BINARIES}; do
78+
${XCRUN} llvm-cov show ${binary} \
79+
-instr-profile=${COVERAGE_COMBINED_FILE} \
80+
-ignore-filename-regex=${IGNORE_REGEX} \
81+
-format=html \
82+
-output-dir=${COVERAGE_REPORT_DIR}/html
83+
done
84+
85+
# Open the HTML report
86+
echo "Opening the HTML coverage report: ${COVERAGE_REPORT_DIR}/html/index.html"
87+
#open ${COVERAGE_REPORT_DIR}/html/index.html
88+

CMake/add-on/fetch-dependencies.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
include(FetchContent)
3+
FetchContent_Declare(
4+
commonCompilerWarnings
5+
GIT_REPOSITORY https://github.com/a4z/commonCompilerWarnings.git
6+
GIT_TAG main
7+
OVERRIDE_FIND_PACKAGE
8+
)
9+
10+
FetchContent_Declare(
11+
doctest
12+
SYSTEM
13+
GIT_REPOSITORY "https://github.com/onqtam/doctest"
14+
GIT_TAG "v2.4.11"
15+
OVERRIDE_FIND_PACKAGE
16+
)
17+
18+
set(DOCTEST_NO_INSTALL TRUE)
19+
20+
set(commonCompilerWarnings_NO_INSTALL TRUE)
21+
# now with this problem solved, we probably should always fetch that internally
22+
# so for users, this just works

CMake/brew-gcc-toolchain.cmake

Lines changed: 0 additions & 3 deletions
This file was deleted.

CMake/lib/debug.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
function(print_all_variables)
3+
message(STATUS "CMake Variables:")
4+
#get_cmake_property(_variableNames VARIABLES)
5+
get_cmake_property(_variableNames CACHE_VARIABLES)
6+
list(SORT _variableNames)
7+
foreach (_variableName ${_variableNames})
8+
message(STATUS "${_variableName}=${${_variableName}}")
9+
endforeach()
10+
endfunction()
11+
12+
# Call the function to print all variables
13+
# print_all_variables()
14+
15+
function(print_variable var_name)
16+
if(DEFINED ${var_name})
17+
message(STATUS "${var_name}=${${var_name}}")
18+
else()
19+
message(STATUS "${var_name} is not defined")
20+
endif()
21+
endfunction()

0 commit comments

Comments
 (0)