summaryrefslogtreecommitdiff
path: root/libs/cpp-httplib/cmake
diff options
context:
space:
mode:
Diffstat (limited to 'libs/cpp-httplib/cmake')
-rw-r--r--libs/cpp-httplib/cmake/FindBrotli.cmake168
-rw-r--r--libs/cpp-httplib/cmake/httplibConfig.cmake.in106
2 files changed, 274 insertions, 0 deletions
diff --git a/libs/cpp-httplib/cmake/FindBrotli.cmake b/libs/cpp-httplib/cmake/FindBrotli.cmake
new file mode 100644
index 0000000..2048e55
--- /dev/null
+++ b/libs/cpp-httplib/cmake/FindBrotli.cmake
@@ -0,0 +1,168 @@
+# A simple FindBrotli package for Cmake's find_package function.
+# Note: This find package doesn't have version support, as the version file doesn't seem to be installed on most systems.
+#
+# If you want to find the static packages instead of shared (the default), define BROTLI_USE_STATIC_LIBS as TRUE.
+# The targets will have the same names, but it will use the static libs.
+#
+# Valid find_package COMPONENTS names: "decoder", "encoder", and "common"
+# Note that if you're requiring "decoder" or "encoder", then "common" will be automatically added as required.
+#
+# Defines the libraries (if found): Brotli::decoder, Brotli::encoder, Brotli::common
+# and the includes path variable: Brotli_INCLUDE_DIR
+#
+# If it's failing to find the libraries, try setting BROTLI_ROOT_DIR to the folder containing your library & include dir.
+
+# If they asked for a specific version, warn/fail since we don't support it.
+# TODO: if they start distributing the version somewhere, implement finding it.
+# See https://github.com/google/brotli/issues/773#issuecomment-579133187
+if(Brotli_FIND_VERSION)
+ set(_brotli_version_error_msg "FindBrotli.cmake doesn't have version support!")
+ # If the package is required, throw a fatal error
+ # Otherwise, if not running quietly, we throw a warning
+ if(Brotli_FIND_REQUIRED)
+ message(FATAL_ERROR "${_brotli_version_error_msg}")
+ elseif(NOT Brotli_FIND_QUIETLY)
+ message(WARNING "${_brotli_version_error_msg}")
+ endif()
+endif()
+
+# Since both decoder & encoder require the common lib, force its requirement..
+# if the user is requiring either of those other libs.
+if(Brotli_FIND_REQUIRED_decoder OR Brotli_FIND_REQUIRED_encoder)
+ set(Brotli_FIND_REQUIRED_common TRUE)
+endif()
+
+# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
+# Credit to FindOpenSSL.cmake for this
+if(BROTLI_USE_STATIC_LIBS)
+ set(_brotli_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ if(WIN32)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ else()
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
+ endif()
+endif()
+
+# Make PkgConfig optional, since some users (mainly Windows) don't have it.
+# But it's a lot more clean than manually using find_library.
+find_package(PkgConfig QUIET)
+
+# Only used if the PkgConfig libraries aren't used.
+find_path(Brotli_INCLUDE_DIR
+ NAMES
+ "brotli/decode.h"
+ "brotli/encode.h"
+ HINTS
+ ${BROTLI_ROOT_DIR}
+ PATH_SUFFIXES
+ "include"
+ "includes"
+ DOC "The path to Brotli's include directory."
+)
+# Hides this var from the GUI
+mark_as_advanced(Brotli_INCLUDE_DIR)
+
+# Just used for PkgConfig stuff in the loop below
+set(_brotli_stat_str "")
+if(BROTLI_USE_STATIC_LIBS)
+ set(_brotli_stat_str "_STATIC")
+endif()
+
+# Each string here is "ComponentName;LiteralName" (the semi-colon is a delimiter)
+foreach(_listvar "common;common" "decoder;dec" "encoder;enc")
+ # Split the component name and literal library name from the listvar
+ list(GET _listvar 0 _component_name)
+ list(GET _listvar 1 _libname)
+
+ # NOTE: We can't rely on PkgConf for static libs since the upstream static lib support is broken
+ # See https://github.com/google/brotli/issues/795
+ # TODO: whenever their issue is fixed upstream, remove this "AND NOT BROTLI_USE_STATIC_LIBS" check
+ if(PKG_CONFIG_FOUND AND NOT BROTLI_USE_STATIC_LIBS)
+ # These need to be GLOBAL for MinGW when making ALIAS libraries against them.
+ # Have to postfix _STATIC on the name to tell PkgConfig to find the static libs.
+ pkg_check_modules(Brotli_${_component_name}${_brotli_stat_str} QUIET GLOBAL IMPORTED_TARGET libbrotli${_libname})
+ endif()
+
+ # Check if the target was already found by Pkgconf
+ if(TARGET PkgConfig::Brotli_${_component_name}${_brotli_stat_str})
+ # ALIAS since we don't want the PkgConfig namespace on the Cmake library (for end-users)
+ add_library(Brotli::${_component_name} ALIAS PkgConfig::Brotli_${_component_name}${_brotli_stat_str})
+
+ # Tells HANDLE_COMPONENTS we found the component
+ set(Brotli_${_component_name}_FOUND TRUE)
+ if(Brotli_FIND_REQUIRED_${_component_name})
+ # If the lib is required, we can add its literal path as a required var for FindPackageHandleStandardArgs
+ # Since it won't accept the PkgConfig targets
+ if(BROTLI_USE_STATIC_LIBS)
+ list(APPEND _brotli_req_vars "Brotli_${_component_name}_STATIC_LIBRARIES")
+ else()
+ list(APPEND _brotli_req_vars "Brotli_${_component_name}_LINK_LIBRARIES")
+ endif()
+ endif()
+
+ # Skip searching for the libs with find_library since it was already found by Pkgconf
+ continue()
+ endif()
+
+ if(Brotli_FIND_REQUIRED_${_component_name})
+ # If it's required, we can set the name used in find_library as a required var for FindPackageHandleStandardArgs
+ list(APPEND _brotli_req_vars "Brotli_${_component_name}")
+ endif()
+
+ list(APPEND _brotli_lib_names
+ "brotli${_libname}"
+ "libbrotli${_libname}"
+ )
+ if(BROTLI_USE_STATIC_LIBS)
+ # Postfix "-static" to the libnames since we're looking for static libs
+ list(TRANSFORM _brotli_lib_names APPEND "-static")
+ endif()
+
+ find_library(Brotli_${_component_name}
+ NAMES ${_brotli_lib_names}
+ HINTS ${BROTLI_ROOT_DIR}
+ PATH_SUFFIXES
+ "lib"
+ "lib64"
+ "libs"
+ "libs64"
+ "lib/x86_64-linux-gnu"
+ )
+ # Hide the library variable from the Cmake GUI
+ mark_as_advanced(Brotli_${_component_name})
+
+ # Unset since otherwise it'll stick around for the next loop and break things
+ unset(_brotli_lib_names)
+
+ # Check if find_library found the library
+ if(Brotli_${_component_name})
+ # Tells HANDLE_COMPONENTS we found the component
+ set(Brotli_${_component_name}_FOUND TRUE)
+
+ add_library("Brotli::${_component_name}" UNKNOWN IMPORTED)
+ # Attach the literal library and include dir to the IMPORTED target for the end-user
+ set_target_properties("Brotli::${_component_name}" PROPERTIES
+ INTERFACE_INCLUDE_DIRECTORIES "${Brotli_INCLUDE_DIR}"
+ IMPORTED_LOCATION "${Brotli_${_component_name}}"
+ )
+ else()
+ # Tells HANDLE_COMPONENTS we found the component
+ set(Brotli_${_component_name}_FOUND FALSE)
+ endif()
+endforeach()
+
+include(FindPackageHandleStandardArgs)
+# Sets Brotli_FOUND, and fails the find_package(Brotli) call if it was REQUIRED but missing libs.
+find_package_handle_standard_args(Brotli
+ FOUND_VAR
+ Brotli_FOUND
+ REQUIRED_VARS
+ Brotli_INCLUDE_DIR
+ ${_brotli_req_vars}
+ HANDLE_COMPONENTS
+)
+
+# Restore the original find library ordering
+if(BROTLI_USE_STATIC_LIBS)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES ${_brotli_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
+endif()
diff --git a/libs/cpp-httplib/cmake/httplibConfig.cmake.in b/libs/cpp-httplib/cmake/httplibConfig.cmake.in
new file mode 100644
index 0000000..8ca8b99
--- /dev/null
+++ b/libs/cpp-httplib/cmake/httplibConfig.cmake.in
@@ -0,0 +1,106 @@
+# Generates a macro to auto-configure everything
+@PACKAGE_INIT@
+
+# Setting these here so they're accessible after install.
+# Might be useful for some users to check which settings were used.
+set(HTTPLIB_IS_USING_OPENSSL @HTTPLIB_IS_USING_OPENSSL@)
+set(HTTPLIB_IS_USING_ZLIB @HTTPLIB_IS_USING_ZLIB@)
+set(HTTPLIB_IS_COMPILED @HTTPLIB_COMPILE@)
+set(HTTPLIB_IS_USING_BROTLI @HTTPLIB_IS_USING_BROTLI@)
+set(HTTPLIB_IS_USING_NON_BLOCKING_GETADDRINFO @HTTPLIB_IS_USING_NON_BLOCKING_GETADDRINFO@)
+set(HTTPLIB_VERSION @PROJECT_VERSION@)
+
+include(CMakeFindDependencyMacro)
+
+# We add find_dependency calls here to not make the end-user have to call them.
+find_dependency(Threads)
+if(@HTTPLIB_IS_USING_OPENSSL@)
+ # OpenSSL COMPONENTS were added in Cmake v3.11
+ if(CMAKE_VERSION VERSION_LESS "3.11")
+ find_dependency(OpenSSL @_HTTPLIB_OPENSSL_MIN_VER@)
+ else()
+ # Once the COMPONENTS were added, they were made optional when not specified.
+ # Since we use both, we need to search for both.
+ find_dependency(OpenSSL @_HTTPLIB_OPENSSL_MIN_VER@ COMPONENTS Crypto SSL)
+ endif()
+ set(httplib_OpenSSL_FOUND ${OpenSSL_FOUND})
+endif()
+if(@HTTPLIB_IS_USING_ZLIB@)
+ find_dependency(ZLIB)
+ set(httplib_ZLIB_FOUND ${ZLIB_FOUND})
+endif()
+
+if(@HTTPLIB_IS_USING_BROTLI@)
+ # Needed so we can use our own FindBrotli.cmake in this file.
+ # Note that the FindBrotli.cmake file is installed in the same dir as this file.
+ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
+ set(BROTLI_USE_STATIC_LIBS @BROTLI_USE_STATIC_LIBS@)
+ find_dependency(Brotli COMPONENTS common encoder decoder)
+ set(httplib_Brotli_FOUND ${Brotli_FOUND})
+endif()
+
+if(@HTTPLIB_IS_USING_ZSTD@)
+ set(httplib_fd_zstd_quiet_arg)
+ if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
+ set(httplib_fd_zstd_quiet_arg QUIET)
+ endif()
+ set(httplib_fd_zstd_required_arg)
+ if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
+ set(httplib_fd_zstd_required_arg REQUIRED)
+ endif()
+ find_package(zstd QUIET)
+ if(NOT zstd_FOUND)
+ find_package(PkgConfig ${httplib_fd_zstd_quiet_arg} ${httplib_fd_zstd_required_arg})
+ if(PKG_CONFIG_FOUND)
+ pkg_check_modules(zstd ${httplib_fd_zstd_quiet_arg} ${httplib_fd_zstd_required_arg} IMPORTED_TARGET libzstd)
+
+ if(TARGET PkgConfig::zstd)
+ add_library(zstd::libzstd ALIAS PkgConfig::zstd)
+ endif()
+ endif()
+ endif()
+ set(httplib_zstd_FOUND ${zstd_FOUND})
+endif()
+
+# Mildly useful for end-users
+# Not really recommended to be used though
+set_and_check(HTTPLIB_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@")
+# Lets the end-user find the header path with the header appended
+# This is helpful if you're using Cmake's pre-compiled header feature
+set_and_check(HTTPLIB_HEADER_PATH "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@/httplib.h")
+
+check_required_components(httplib)
+
+# Brings in the target library, but only if all required components are found
+if(NOT DEFINED httplib_FOUND OR httplib_FOUND)
+ include("${CMAKE_CURRENT_LIST_DIR}/httplibTargets.cmake")
+endif()
+
+# Outputs a "found httplib /usr/include/httplib.h" message when using find_package(httplib)
+include(FindPackageMessage)
+if(TARGET httplib::httplib)
+ set(HTTPLIB_FOUND TRUE)
+
+ # Since the compiled version has a lib, show that in the message
+ if(@HTTPLIB_COMPILE@)
+ # The list of configurations is most likely just 1 unless they installed a debug & release
+ get_target_property(_httplib_configs httplib::httplib "IMPORTED_CONFIGURATIONS")
+ # Need to loop since the "IMPORTED_LOCATION" property isn't want we want.
+ # Instead, we need to find the IMPORTED_LOCATION_RELEASE or IMPORTED_LOCATION_DEBUG which has the lib path.
+ foreach(_httplib_conf "${_httplib_configs}")
+ # Grab the path to the lib and sets it to HTTPLIB_LIBRARY
+ get_target_property(HTTPLIB_LIBRARY httplib::httplib "IMPORTED_LOCATION_${_httplib_conf}")
+ # Check if we found it
+ if(HTTPLIB_LIBRARY)
+ break()
+ endif()
+ endforeach()
+
+ unset(_httplib_configs)
+ unset(_httplib_conf)
+
+ find_package_message(httplib "Found httplib: ${HTTPLIB_LIBRARY} (found version \"${HTTPLIB_VERSION}\")" "[${HTTPLIB_LIBRARY}][${HTTPLIB_HEADER_PATH}]")
+ else()
+ find_package_message(httplib "Found httplib: ${HTTPLIB_HEADER_PATH} (found version \"${HTTPLIB_VERSION}\")" "[${HTTPLIB_HEADER_PATH}]")
+ endif()
+endif()