Skip to content

Commit

Permalink
build(cmake): use installed cpp-httplib if available (#1648)
Browse files Browse the repository at this point in the history
  • Loading branch information
trollixx authored Aug 31, 2024
1 parent 821ae66 commit 92faa65
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
File renamed without changes.
18 changes: 12 additions & 6 deletions src/libs/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/libs/core/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
#include "httpserver.h"

#include "application.h"
#include "httplib.h"

#include <httplib.h>

#include <QLoggingCategory>
#include <QRegularExpression>
Expand Down
4 changes: 4 additions & 0 deletions vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"$schema": "https://github.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": [
{
"name": "cpp-httplib",
"default-features": false
},
{
"name": "libarchive",
"default-features": false
Expand Down

0 comments on commit 92faa65

Please sign in to comment.