Skip to content

Commit 92faa65

Browse files
authored
build(cmake): use installed cpp-httplib if available (#1648)
1 parent 821ae66 commit 92faa65

4 files changed

Lines changed: 18 additions & 7 deletions

File tree

src/libs/core/CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,8 @@ add_library(Core STATIC
66
httpserver.cpp
77
networkaccessmanager.cpp
88
settings.cpp
9-
10-
# Show headers without .cpp in Qt Creator.
11-
httplib.h
129
)
1310

14-
# Configure cpp-httplib.
15-
add_definitions(-DCPPHTTPLIB_USE_POLL)
16-
1711
target_link_libraries(Core Registry Ui)
1812

1913
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Network WebEngineCore Widgets REQUIRED)
@@ -48,6 +42,18 @@ else()
4842
target_link_libraries(Core ${LibArchive_LIBRARIES})
4943
endif()
5044

45+
# Configure cpp-httplib.
46+
add_definitions(-DCPPHTTPLIB_USE_POLL)
47+
48+
find_package(httplib CONFIG QUIET)
49+
if(httplib_FOUND)
50+
target_link_libraries(Core httplib::httplib)
51+
else()
52+
# Use bundled version of cpp-httplib if not found.
53+
# TODO: Replace with QHttpServer once Qt 5 is dropped.
54+
include_directories("${CMAKE_SOURCE_DIR}/src/contrib/cpp-httplib")
55+
endif()
56+
5157
# Required by cpp-httplib.
5258
if(NOT WIN32)
5359
set(THREADS_PREFER_PTHREAD_FLAG ON)

src/libs/core/httpserver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
#include "httpserver.h"
2424

2525
#include "application.h"
26-
#include "httplib.h"
26+
27+
#include <httplib.h>
2728

2829
#include <QLoggingCategory>
2930
#include <QRegularExpression>

vcpkg.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
33
"dependencies": [
4+
{
5+
"name": "cpp-httplib",
6+
"default-features": false
7+
},
48
{
59
"name": "libarchive",
610
"default-features": false

0 commit comments

Comments
 (0)