Skip to content

Commit a145853

Browse files
committed
Switch to vcpkg to fetch dependencies
Change-Id: Ic1a6ef5cf5af5b0567817392ce5fc61358b690ca
1 parent bbb82aa commit a145853

File tree

9 files changed

+109
-156
lines changed

9 files changed

+109
-156
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "vcpkg/vcpkg"]
2+
path = vcpkg/vcpkg
3+
url = https://github.com/microsoft/vcpkg.git

CMakeLists.txt

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
#
1010

1111
cmake_minimum_required(VERSION 3.16)
12-
project(
13-
KDUtils
14-
DESCRIPTION "A set of C++ helpers and wrappers around the C++ standard library"
15-
LANGUAGES CXX C
16-
VERSION 0.1.10
17-
HOMEPAGE_URL "https://github.com/KDAB/KDUtils"
18-
)
12+
13+
# vcpkg manifest mode
14+
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
15+
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake)
16+
endif()
17+
18+
option(KDUTILS_BUILD_EXAMPLES "Build examples" ON)
19+
option(KDUTILS_BUILD_MQTT_SUPPORT "EXPERIMENTAL: Build KDMqtt" OFF)
1920

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

42-
option(KDUTILS_BUILD_EXAMPLES "Build examples" ON)
43+
# VCPKG manifest must be set before the call to project
44+
if(KDUTILS_BUILD_MQTT_SUPPORT)
45+
list(APPEND VCPKG_MANIFEST_FEATURES "mqtt")
46+
endif()
47+
48+
if(KDUTILS_BUILD_TESTS)
49+
list(APPEND VCPKG_MANIFEST_FEATURES "testing")
50+
endif()
51+
52+
project(
53+
KDUtils
54+
DESCRIPTION "A set of C++ helpers and wrappers around the C++ standard library"
55+
LANGUAGES CXX C
56+
VERSION 0.1.10
57+
HOMEPAGE_URL "https://github.com/KDAB/KDUtils"
58+
)
4359

4460
include(FeatureSummary)
4561
include(CMakeDependentOption)
@@ -48,18 +64,6 @@ include(GenerateExportHeader)
4864
include(GNUInstallDirs)
4965
include(CTest)
5066

51-
if(UNIX)
52-
cmake_dependent_option(
53-
KDUTILS_BUILD_MQTT_SUPPORT
54-
"EXPERIMENTAL: Build KDMqtt"
55-
ON
56-
"Mosquitto_FOUND"
57-
OFF
58-
)
59-
else()
60-
option(KDUTILS_BUILD_MQTT_SUPPORT "EXPERIMENTAL: Build KDMqtt" OFF)
61-
endif()
62-
6367
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
6468
option(KDUTILS_CODE_COVERAGE "Code Coverage" OFF)
6569

cmake/dependencies.cmake

Lines changed: 6 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -8,99 +8,13 @@
88
# Contact KDAB at <info@kdab.com> for commercial licensing options.
99
#
1010

11-
include(FetchContent)
12-
1311
message(STATUS "Looking for KDUtils dependencies")
1412

15-
# spdlog Logging Library
16-
# spdlog needs to be installed. If already exists in the prefix,
17-
# we don't want to override it, so first we try to find it.
18-
# If we don't find it, then we fetch it and install it
19-
find_package(spdlog 1.14.1 QUIET)
20-
21-
if(NOT TARGET spdlog::spdlog)
22-
# We need to use external fmt because the one bundled with spldog 1.x throws
23-
# warnings in newer Visual Studio MSVC compiler versions.
24-
# See https://github.com/gabime/spdlog/issues/2912
25-
# TODO(spdlog2): external fmt can possibly be removed once splog 2.x is used
26-
# which bundles newer fmt version
27-
find_package(fmt 10.2.1 QUIET)
28-
if(NOT TARGET fmt)
29-
FetchContent_Declare(
30-
fmt
31-
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
32-
GIT_TAG e69e5f977d458f2650bb346dadf2ad30c5320281 # 10.2.1
33-
)
34-
FetchContent_MakeAvailable(fmt)
35-
set_target_properties(fmt PROPERTIES CXX_CLANG_TIDY "")
36-
endif()
37-
set(SPDLOG_FMT_EXTERNAL_HO ON)
38-
# with this spdlog is included as a system library and won't e.g. trigger
39-
# linter warnings
40-
set(SPDLOG_SYSTEM_INCLUDES ON)
41-
42-
get_property(tmp GLOBAL PROPERTY PACKAGES_NOT_FOUND)
43-
list(
44-
FILTER
45-
tmp
46-
EXCLUDE
47-
REGEX
48-
spdlog
49-
)
50-
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND ${tmp})
51-
52-
FetchContent_Declare(
53-
spdlog
54-
GIT_REPOSITORY https://github.com/gabime/spdlog.git
55-
GIT_TAG 27cb4c76708608465c413f6d0e6b8d99a4d84302 # v1.14.1
56-
)
57-
set(SPDLOG_INSTALL
58-
ON
59-
CACHE BOOL "Install spdlog" FORCE
60-
)
61-
FetchContent_MakeAvailable(spdlog)
62-
63-
set_target_properties(
64-
spdlog
65-
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
66-
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
67-
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
68-
)
69-
endif()
13+
find_package(spdlog REQUIRED)
14+
find_package(KDBindings REQUIRED)
15+
find_package(whereami REQUIRED)
16+
find_package(mio REQUIRED)
7017

71-
# KDBindings library
72-
find_package(KDBindings QUIET)
73-
if(NOT TARGET KDAB::KDBindings)
74-
fetchcontent_declare(
75-
KDBindings
76-
GIT_REPOSITORY https://github.com/KDAB/KDBindings.git
77-
GIT_TAG efb54c58c3c2fce280d7089617935ec265fe4e2d # v1.1.0
78-
USES_TERMINAL_DOWNLOAD YES USES_TERMINAL_UPDATE YES
79-
)
80-
fetchcontent_makeavailable(KDBindings)
18+
if(KDUTILS_BUILD_MQTT_SUPPORT)
19+
find_package(mosquitto REQUIRED)
8120
endif()
82-
83-
# whereami library
84-
find_package(Whereami QUIET)
85-
if(NOT TARGET whereami::whereami)
86-
fetchcontent_declare(
87-
whereami
88-
GIT_REPOSITORY https://github.com/gpakosz/whereami
89-
GIT_TAG e4b7ba1be0e9fd60728acbdd418bc7195cdd37e7 # master at 5/July/2021
90-
)
91-
fetchcontent_makeavailable(whereami)
92-
endif()
93-
94-
# mio header-only lib (provides memory mapping for files)
95-
find_package(mio QUIET)
96-
if(NOT TARGET mio::mio)
97-
fetchcontent_declare(
98-
mio
99-
GIT_REPOSITORY https://github.com/mandreyel/mio.git
100-
GIT_TAG 8b6b7d878c89e81614d05edca7936de41ccdd2da # March 3rd 2023
101-
)
102-
fetchcontent_makeavailable(mio)
103-
endif()
104-
105-
# mosquitto library
106-
find_package(Mosquitto QUIET)

src/KDMqtt/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ add_library(
2323

2424
target_link_libraries(
2525
KDMqtt
26-
PUBLIC KDUtils::KDFoundation Mosquitto::Mosquitto
26+
PUBLIC KDUtils::KDFoundation ${MOSQUITTO_LIBRARIES}
2727
)
2828

2929
target_include_directories(

src/KDUtils/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ add_library(
4747
target_link_libraries(
4848
KDUtils
4949
PUBLIC spdlog::spdlog
50-
PRIVATE mio::mio
50+
PRIVATE mio::mio whereami::whereami
5151
)
5252

5353
if(ANDROID)
@@ -59,13 +59,6 @@ target_include_directories(
5959
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../> $<INSTALL_INTERFACE:include/>
6060
)
6161

62-
if(NOT TARGET whereami::whereami)
63-
target_include_directories(KDUtils PRIVATE ${whereami_SOURCE_DIR}/src)
64-
target_sources(KDUtils PRIVATE ${whereami_SOURCE_DIR}/src/whereami.c)
65-
else()
66-
target_link_libraries(KDUtils PRIVATE whereami::whereami)
67-
endif()
68-
6962
set_target_properties(
7063
KDUtils
7164
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"

tests/CMakeLists.txt

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,14 @@
99
#
1010

1111
# doctest library
12-
find_package(doctest QUIET)
13-
if(TARGET doctest::doctest)
14-
# Apply https://github.com/doctest/doctest/pull/812
15-
# to be able to #include <doctest.h> instead of #include <doctest/doctest.h>
16-
get_target_property(DOCTEST_INTERFACE_INCLUDE_DIRECTORIES doctest::doctest INTERFACE_INCLUDE_DIRECTORIES)
17-
target_include_directories(
18-
doctest::doctest SYSTEM
19-
INTERFACE "${DOCTEST_INTERFACE_INCLUDE_DIRECTORIES};${DOCTEST_INTERFACE_INCLUDE_DIRECTORIES}/doctest"
20-
)
21-
else()
22-
fetchcontent_declare(
23-
doctest
24-
GIT_REPOSITORY https://github.com/doctest/doctest.git
25-
GIT_TAG 3a01ec37828affe4c9650004edb5b304fb9d5b75 # dev branch commit with CMake compatibility fix
26-
)
27-
fetchcontent_makeavailable(doctest)
28-
29-
list(APPEND CMAKE_MODULE_PATH ${doctest_SOURCE_DIR}/scripts/cmake)
30-
31-
target_include_directories(
32-
doctest SYSTEM INTERFACE $<BUILD_INTERFACE:${doctest_SOURCE_DIR}/doctest>
33-
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/KDUtils/doctest>
34-
)
35-
36-
# Copy all include directories to SYSTEM property so we don't get warnings from doctest
37-
#TODO(cmake >=3.25): remove these two lines and add SYSTEM to doctest's FetchContent_Declare
38-
get_target_property(DOCTEST_IID doctest INTERFACE_INCLUDE_DIRECTORIES)
39-
set_target_properties(doctest PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${DOCTEST_IID}")
40-
41-
if(APPLE)
42-
target_compile_options(doctest INTERFACE -Wno-deprecated-declarations)
43-
endif()
44-
45-
install(DIRECTORY ${doctest_SOURCE_DIR}/doctest/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/KDUtils/doctest)
46-
endif()
12+
find_package(doctest CONFIG REQUIRED)
13+
# Apply https://github.com/doctest/doctest/pull/812
14+
# to be able to #include <doctest.h> instead of #include <doctest/doctest.h>
15+
get_target_property(DOCTEST_INTERFACE_INCLUDE_DIRECTORIES doctest::doctest INTERFACE_INCLUDE_DIRECTORIES)
16+
target_include_directories(
17+
doctest::doctest SYSTEM
18+
INTERFACE "${DOCTEST_INTERFACE_INCLUDE_DIRECTORIES};${DOCTEST_INTERFACE_INCLUDE_DIRECTORIES}/doctest"
19+
)
4720

4821
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
4922
add_compile_definitions(PLATFORM_ANDROID)

vcpkg-configuration.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"default-registry": {
3+
"kind": "git",
4+
"baseline": "bed11935ca76d1e93906dbf742230a768882b98f",
5+
"repository": "https://github.com/microsoft/vcpkg"
6+
},
7+
"registries": [
8+
{
9+
"kind": "git",
10+
"repository": "https://github.com/KDAB/vcpkg-registry.git",
11+
"reference": "main",
12+
"baseline": "018a7217b3b4049e74499bc5a590280946d57b46",
13+
"packages": [
14+
"whereami"
15+
]
16+
}
17+
]
18+
}

vcpkg.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "kdutils",
3+
"version": "0.1.12",
4+
"description": "KD Utilities Library - Core utilities and helper functions",
5+
"homepage": "https://github.com/KDAB/kdutils",
6+
"license": "MIT",
7+
"supports": "!(uwp | arm)",
8+
"dependencies": [
9+
{
10+
"name": "spdlog",
11+
"version>=": "1.15.3"
12+
},
13+
{
14+
"name": "kdbindings",
15+
"version>=": "1.1.0"
16+
},
17+
{
18+
"name": "whereami",
19+
"version>=": "0.0.1"
20+
},
21+
{
22+
"name": "mio",
23+
"version>=": "2023-03-03"
24+
}
25+
],
26+
"features": {
27+
"testing": {
28+
"description": "Enable testing support",
29+
"dependencies": [
30+
{
31+
"name": "doctest",
32+
"version>=": "2.4.12"
33+
}
34+
]
35+
},
36+
"mqtt": {
37+
"description": "Enable mqtt support",
38+
"dependencies": [
39+
{
40+
"name": "mosquitto",
41+
"version>=": "2.0.20"
42+
}
43+
]
44+
}
45+
},
46+
"builtin-baseline": "d56a38a1f935f36e3033b6506123f96fc72979e7"
47+
}

vcpkg/vcpkg

Submodule vcpkg added at d56a38a

0 commit comments

Comments
 (0)