From 009dc0c2b8c3c7f68d2bdde74abd592d2f8bd0e6 Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Mon, 5 Aug 2024 21:56:06 -0400 Subject: [PATCH] build(cmake): use installed cpp-httplib if available --- .../core => contrib/cpp-httplib}/httplib.h | 0 src/libs/core/CMakeLists.txt | 18 ++++++++++++------ src/libs/core/httpserver.cpp | 3 ++- vcpkg.json | 4 ++++ 4 files changed, 18 insertions(+), 7 deletions(-) rename src/{libs/core => contrib/cpp-httplib}/httplib.h (100%) diff --git a/src/libs/core/httplib.h b/src/contrib/cpp-httplib/httplib.h similarity index 100% rename from src/libs/core/httplib.h rename to src/contrib/cpp-httplib/httplib.h diff --git a/src/libs/core/CMakeLists.txt b/src/libs/core/CMakeLists.txt index 22d0f773..45a351f6 100644 --- a/src/libs/core/CMakeLists.txt +++ b/src/libs/core/CMakeLists.txt @@ -6,14 +6,8 @@ add_library(Core STATIC httpserver.cpp networkaccessmanager.cpp settings.cpp - - # Show headers without .cpp in Qt Creator. - httplib.h ) -# Configure cpp-httplib. -add_definitions(-DCPPHTTPLIB_USE_POLL) - target_link_libraries(Core Registry Ui) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Network WebEngineCore Widgets REQUIRED) @@ -48,6 +42,18 @@ else() target_link_libraries(Core ${LibArchive_LIBRARIES}) endif() +# Configure cpp-httplib. +add_definitions(-DCPPHTTPLIB_USE_POLL) + +find_package(httplib CONFIG QUIET) +if(httplib_FOUND) + target_link_libraries(Core httplib::httplib) +else() + # Use bundled version of cpp-httplib if not found. + # TODO: Replace with QHttpServer once Qt 5 is dropped. + include_directories("${CMAKE_SOURCE_DIR}/src/contrib/cpp-httplib") +endif() + # Required by cpp-httplib. if(NOT WIN32) set(THREADS_PREFER_PTHREAD_FLAG ON) diff --git a/src/libs/core/httpserver.cpp b/src/libs/core/httpserver.cpp index 2351f090..bd86d952 100644 --- a/src/libs/core/httpserver.cpp +++ b/src/libs/core/httpserver.cpp @@ -23,7 +23,8 @@ #include "httpserver.h" #include "application.h" -#include "httplib.h" + +#include #include #include diff --git a/vcpkg.json b/vcpkg.json index c31f3bda..8b1441c0 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,10 @@ { "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "dependencies": [ + { + "name": "cpp-httplib", + "default-features": false + }, { "name": "libarchive", "default-features": false