Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build-external.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ jobs:
# We remove the pinned CMake if it's installed so commands below can succeed
# TODO: remove when not needed anymore
brew tap KDAB/tap
brew install fmt spdlog KDBindings mosquitto
brew install doctest fmt spdlog KDBindings mosquitto

- name: Configure project
run: >
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Debug -G Ninja
-DKDUTILS_BUILD_TESTS=ON
-DKDUTILS_USE_EXTERNAL_DEPENDENCIES=ON
-DBUILD_SHARED_LIBS=${{ matrix.shared }}

- name: Check if external dependencies were used
Expand Down
20 changes: 3 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ jobs:
link_type:
- static
- shared

env:
MOSQUITTO_VERSION: 2.0.20

steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: true

- name: Install ninja-build tool
if: ${{ runner.os != 'Linux' }}
Expand All @@ -54,19 +52,7 @@ jobs:
sudo apt install -y libxkbcommon-dev libxcb-xkb-dev \
libxkbcommon-x11-dev wayland-scanner++ wayland-protocols \
libwayland-dev xvfb ninja-build \
libmosquitto-dev gcovr

- name: Download mosquitto (MacOS)
if: runner.os == 'macOS'
run: |
brew install mosquitto

- name: Download mosquitto (Windows)
if: runner.os == 'Windows'
run: |
curl --no-progress-meter --location --remote-name `
https://mosquitto.org/files/binary/win64/mosquitto-$env:MOSQUITTO_VERSION-install-windows-x64.exe
& .\mosquitto-$env:MOSQUITTO_VERSION-install-windows-x64.exe /S
gcovr

- name: Configure project
run: >
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/dependency-bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: true

- name: Checkout ci-release-tools
run: |
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: true

- name: Install ninja-build tool
if: runner.os == 'Windows'
Expand Down Expand Up @@ -66,6 +68,8 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: true

- name: Install Cppcheck
run: sudo apt update -qq && sudo apt install -y cppcheck
Expand All @@ -77,7 +81,7 @@ jobs:
cppcheck --quiet --language=c++ --force --inline-suppr
--enable=warning,performance,portability,information
--disable=missingInclude --check-level=exhaustive
-i build --library=std.cfg --error-exitcode=42 .
-i build -i vcpkg --library=std.cfg --error-exitcode=42 .

if($LASTEXITCODE -eq 42) {
echo "::error title=Cppcheck failed::See job log for details"
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg.git
shallow = true
50 changes: 31 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@
#

cmake_minimum_required(VERSION 3.16)
project(
KDUtils
DESCRIPTION "A set of C++ helpers and wrappers around the C++ standard library"
LANGUAGES CXX C
VERSION 0.1.10
HOMEPAGE_URL "https://github.com/KDAB/KDUtils"

option(KDUTILS_USE_EXTERNAL_DEPENDENCIES
"Assume all project dependencies are available on the system. Don't fetch through vcpkg." OFF
)

# vcpkg manifest mode
if(NOT KDUTILS_USE_EXTERNAL_DEPENDENCIES)
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
include(cmake/KDUtilsFunctions.cmake)
kdutils_check_submodule_exists(vcpkg vcpkg)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake)
endif()
endif()

option(KDUTILS_BUILD_EXAMPLES "Build examples" ON)
option(KDUTILS_BUILD_MQTT_SUPPORT "EXPERIMENTAL: Build KDMqtt" OFF)

if(ANDROID)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(KDUTILS_BUILD_TESTS "Build the tests" OFF)
Expand All @@ -39,7 +48,22 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
cmake_policy(SET CMP0090 NEW) # Stop export(PACKAGE) from modifying the system-wide cmake package system
cmake_policy(SET CMP0117 NEW) # Do not add /GR to CMAKE_CXX_FLAGS

option(KDUTILS_BUILD_EXAMPLES "Build examples" ON)
# VCPKG manifest must be set before the call to project
if(KDUTILS_BUILD_MQTT_SUPPORT)
list(APPEND VCPKG_MANIFEST_FEATURES "mqtt")
endif()

if(KDUTILS_BUILD_TESTS)
list(APPEND VCPKG_MANIFEST_FEATURES "testing")
endif()

project(
KDUtils
DESCRIPTION "A set of C++ helpers and wrappers around the C++ standard library"
LANGUAGES CXX C
VERSION 0.1.10
HOMEPAGE_URL "https://github.com/KDAB/KDUtils"
)

include(FeatureSummary)
include(CMakeDependentOption)
Expand All @@ -48,18 +72,6 @@ include(GenerateExportHeader)
include(GNUInstallDirs)
include(CTest)

if(UNIX)
cmake_dependent_option(
KDUTILS_BUILD_MQTT_SUPPORT
"EXPERIMENTAL: Build KDMqtt"
ON
"Mosquitto_FOUND"
OFF
)
else()
option(KDUTILS_BUILD_MQTT_SUPPORT "EXPERIMENTAL: Build KDMqtt" OFF)
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
option(KDUTILS_CODE_COVERAGE "Code Coverage" OFF)

Expand Down
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SPDX-License-Identifier = "MIT"

#misc config files
[[annotations]]
path = [".pre-commit-config.yaml", ".codespellrc", ".krazy", ".cmake-format.py", "**.clang-format", ".clang-tidy", "**.gitignore", ".gitreview", ".markdownlint.jsonc", "appveyor.yml", "REUSE.toml"]
path = [".pre-commit-config.yaml", ".codespellrc", ".krazy", ".cmake-format.py", "**.clang-format", ".clang-tidy", "**.gitignore", ".gitmodules", ".gitreview", ".markdownlint.jsonc", "appveyor.yml", "REUSE.toml", "vcpkg.json", "vcpkg-configuration.json"]
precedence = "aggregate"
SPDX-FileCopyrightText = "Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>"
SPDX-License-Identifier = "BSD-3-Clause"
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions cmake/KDUtilsFunctions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file is part of KDUtils.
#
# SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
# Author: Miłosz Kosobucki <[email protected]>
#
# SPDX-License-Identifier: MIT
#
# Contact KDAB at <[email protected]> for commercial licensing options.
#
function(kdutils_check_submodule_exists name path)
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${path}/.git")
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
message(
FATAL_ERROR
"The ${name} git submodule is not initialized.\n"
"Please run the following commands in the source directory (${PROJECT_SOURCE_DIR}):\n"
" git submodule update --init --recursive\n"
)
else()
message(FATAL_ERROR "The ${name} submodule is missing - please report a broken source package.\n")
endif()
endif()
endfunction()
77 changes: 8 additions & 69 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,76 +12,14 @@ include(FetchContent)

message(STATUS "Looking for KDUtils dependencies")

# spdlog Logging Library
# spdlog needs to be installed. If already exists in the prefix,
# we don't want to override it, so first we try to find it.
# If we don't find it, then we fetch it and install it
find_package(spdlog 1.14.1 QUIET)
find_package(spdlog REQUIRED)
find_package(KDBindings REQUIRED)

if(NOT TARGET spdlog::spdlog)
# We need to use external fmt because the one bundled with spldog 1.x throws
# warnings in newer Visual Studio MSVC compiler versions.
# See https://github.com/gabime/spdlog/issues/2912
# TODO(spdlog2): external fmt can possibly be removed once splog 2.x is used
# which bundles newer fmt version
find_package(fmt 10.2.1 QUIET)
if(NOT TARGET fmt)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG e69e5f977d458f2650bb346dadf2ad30c5320281 # 10.2.1
)
FetchContent_MakeAvailable(fmt)
set_target_properties(fmt PROPERTIES CXX_CLANG_TIDY "")
endif()
set(SPDLOG_FMT_EXTERNAL_HO ON)
# with this spdlog is included as a system library and won't e.g. trigger
# linter warnings
set(SPDLOG_SYSTEM_INCLUDES ON)

get_property(tmp GLOBAL PROPERTY PACKAGES_NOT_FOUND)
list(
FILTER
tmp
EXCLUDE
REGEX
spdlog
)
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND ${tmp})

FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG 27cb4c76708608465c413f6d0e6b8d99a4d84302 # v1.14.1
)
set(SPDLOG_INSTALL
ON
CACHE BOOL "Install spdlog" FORCE
)
FetchContent_MakeAvailable(spdlog)

set_target_properties(
spdlog
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
endif()

# KDBindings library
find_package(KDBindings QUIET)
if(NOT TARGET KDAB::KDBindings)
fetchcontent_declare(
KDBindings
GIT_REPOSITORY https://github.com/KDAB/KDBindings.git
GIT_TAG efb54c58c3c2fce280d7089617935ec265fe4e2d # v1.1.0
USES_TERMINAL_DOWNLOAD YES USES_TERMINAL_UPDATE YES
)
fetchcontent_makeavailable(KDBindings)
endif()
# Following two packages are still acquired via fetchcontent because they aren't
# available in brew on macOS so the non-vcpkg build would be hard to set up there

# whereami library
find_package(Whereami QUIET)
find_package(whereami QUIET)
if(NOT TARGET whereami::whereami)
fetchcontent_declare(
whereami
Expand All @@ -102,5 +40,6 @@ if(NOT TARGET mio::mio)
fetchcontent_makeavailable(mio)
endif()

# mosquitto library
find_package(Mosquitto QUIET)
if(KDUTILS_BUILD_MQTT_SUPPORT)
find_package(mosquitto REQUIRED)
endif()
2 changes: 1 addition & 1 deletion src/KDMqtt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_library(

target_link_libraries(
KDMqtt
PUBLIC KDUtils::KDFoundation Mosquitto::Mosquitto
PUBLIC KDUtils::KDFoundation ${MOSQUITTO_LIBRARIES}
)

target_include_directories(
Expand Down
43 changes: 8 additions & 35 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,14 @@
#

# doctest library
find_package(doctest QUIET)
if(TARGET doctest::doctest)
# Apply https://github.com/doctest/doctest/pull/812
# to be able to #include <doctest.h> instead of #include <doctest/doctest.h>
get_target_property(DOCTEST_INTERFACE_INCLUDE_DIRECTORIES doctest::doctest INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(
doctest::doctest SYSTEM
INTERFACE "${DOCTEST_INTERFACE_INCLUDE_DIRECTORIES};${DOCTEST_INTERFACE_INCLUDE_DIRECTORIES}/doctest"
)
else()
fetchcontent_declare(
doctest
GIT_REPOSITORY https://github.com/doctest/doctest.git
GIT_TAG 3a01ec37828affe4c9650004edb5b304fb9d5b75 # dev branch commit with CMake compatibility fix
)
fetchcontent_makeavailable(doctest)

list(APPEND CMAKE_MODULE_PATH ${doctest_SOURCE_DIR}/scripts/cmake)

target_include_directories(
doctest SYSTEM INTERFACE $<BUILD_INTERFACE:${doctest_SOURCE_DIR}/doctest>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/KDUtils/doctest>
)

# Copy all include directories to SYSTEM property so we don't get warnings from doctest
#TODO(cmake >=3.25): remove these two lines and add SYSTEM to doctest's FetchContent_Declare
get_target_property(DOCTEST_IID doctest INTERFACE_INCLUDE_DIRECTORIES)
set_target_properties(doctest PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${DOCTEST_IID}")

if(APPLE)
target_compile_options(doctest INTERFACE -Wno-deprecated-declarations)
endif()

install(DIRECTORY ${doctest_SOURCE_DIR}/doctest/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/KDUtils/doctest)
endif()
find_package(doctest CONFIG REQUIRED)
# Apply https://github.com/doctest/doctest/pull/812
# to be able to #include <doctest.h> instead of #include <doctest/doctest.h>
get_target_property(DOCTEST_INTERFACE_INCLUDE_DIRECTORIES doctest::doctest INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(
doctest::doctest SYSTEM
INTERFACE "${DOCTEST_INTERFACE_INCLUDE_DIRECTORIES};${DOCTEST_INTERFACE_INCLUDE_DIRECTORIES}/doctest"
)

if(CMAKE_SYSTEM_NAME STREQUAL "Android")
add_compile_definitions(PLATFORM_ANDROID)
Expand Down
Loading