Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(cmake): use installed cpp-httplib if available #1648

Merged
merged 1 commit into from
Aug 31, 2024
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
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://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": [
{
"name": "cpp-httplib",
"default-features": false
},
{
"name": "libarchive",
"default-features": false
Expand Down