From 0ce956ba000031c202a1ba296264d71009ce6934 Mon Sep 17 00:00:00 2001 From: Castor215 <132155746+Castor215@users.noreply.github.com> Date: Wed, 4 Oct 2023 14:41:13 +0100 Subject: [PATCH] externals: allow users to use system cpp-httplib (#7034) --- CMakeLists.txt | 1 + externals/CMakeLists.txt | 7 ++++- externals/cmake-modules/FindCppHttp.cmake | 35 +++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 externals/cmake-modules/FindCppHttp.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 23f2a1f40..1e27b1caf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,7 @@ option(USE_SYSTEM_OPENSSL "Use the system OpenSSL libs (instead of the bundled L option(USE_SYSTEM_LIBUSB "Use the system libusb (instead of the bundled libusb)" OFF) option(USE_SYSTEM_CPP_JWT "Use the system cpp-jwt (instead of the bundled one)" OFF) option(USE_SYSTEM_SOUNDTOUCH "Use the system SoundTouch (instead of the bundled one)" OFF) +option(USE_SYSTEM_CPP_HTTPLIB "Use the system cpp-httplib (instead of the bundled one)" OFF) if (CITRA_USE_PRECOMPILED_HEADERS) message(STATUS "Using Precompiled Headers.") diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt index b81b3fe9b..7e3a0e7d7 100644 --- a/externals/CMakeLists.txt +++ b/externals/CMakeLists.txt @@ -199,7 +199,12 @@ endif() # httplib add_library(httplib INTERFACE) -target_include_directories(httplib INTERFACE ./httplib) +if(USE_SYSTEM_CPP_HTTPLIB) + find_package(CppHttp REQUIRED) + target_link_libraries(httplib INTERFACE cpp-httplib::cpp-httplib) +else() + target_include_directories(httplib INTERFACE ./httplib) +endif() target_compile_options(httplib INTERFACE -DCPPHTTPLIB_OPENSSL_SUPPORT) target_link_libraries(httplib INTERFACE ${OPENSSL_LIBRARIES}) diff --git a/externals/cmake-modules/FindCppHttp.cmake b/externals/cmake-modules/FindCppHttp.cmake new file mode 100644 index 000000000..b91cc9f6e --- /dev/null +++ b/externals/cmake-modules/FindCppHttp.cmake @@ -0,0 +1,35 @@ +if(NOT CppHttp_FOUND) + pkg_check_modules(HTTP_TMP cpp-httplib) + + find_path(CPP-HTTP_INCLUDE_DIR NAMES httplib.h + PATHS + ${HTTP_TMP_INCLUDE_DIRS} + /usr/include + /usr/local/include + ) + + find_library(CPP-HTTP_LIBRARIES NAMES cpp-httplib + PATHS + ${HTTP_TMP_LIBRARY_DIRS} + /usr/lib + /usr/local/lib + ) + + if(CPP-HTTP_INCLUDE_DIR AND CPP-HTTP_LIBRARIES) + set(CppHttp_FOUND TRUE CACHE INTERNAL "cpp-httplib found") + message(STATUS "Found cpp-httplib: ${CPP-HTTP_INCLUDE_DIR}, ${CPP-HTTP_LIBRARIES}") + else() + set(CppHttp_FOUND FALSE CACHE INTERNAL "cpp-httplib found") + message(STATUS "Cpp-httplib not found.") + endif() + +endif() + +if(CppHttp_FOUND AND NOT TARGET cpp-httplib::cpp-httplib) + add_library(cpp-httplib::cpp-httplib INTERFACE IMPORTED) + set_target_properties(cpp-httplib::cpp-httplib PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CPP-HTTP_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${CPP-HTTP_LIBRARIES}" + IMPORTED_LOCATION "${CPP-HTTP_LIBRARIES}" + ) +endif()