11#[[
22 Build options:
3+ * BUILD_SHARED_LIBS (default off) builds as a static library (if HTTPLIB_COMPILE is ON)
34 * HTTPLIB_USE_OPENSSL_IF_AVAILABLE (default on)
45 * HTTPLIB_USE_ZLIB_IF_AVAILABLE (default on)
56 * HTTPLIB_REQUIRE_OPENSSL (default off)
67 * HTTPLIB_REQUIRE_ZLIB (default off)
8+ * HTTPLIB_USE_BROTLI_IF_AVAILABLE (default on)
9+ * HTTPLIB_REQUIRE_BROTLI (default off)
710 * HTTPLIB_COMPILE (default off)
11+ * BROTLI_USE_STATIC_LIBS - tells Cmake to use the static Brotli libs (only works if you have them installed).
12+ * OPENSSL_USE_STATIC_LIBS - tells Cmake to use the static OpenSSL libs (only works if you have them installed).
813
914 -------------------------------------------------------------------------------
1015
3641 * HTTPLIB_HEADER_PATH - this is the full path to the installed header (e.g. /usr/include/httplib.h).
3742 * HTTPLIB_IS_USING_OPENSSL - a bool for if OpenSSL support is enabled.
3843 * HTTPLIB_IS_USING_ZLIB - a bool for if ZLIB support is enabled.
44+ * HTTPLIB_IS_USING_BROTLI - a bool for if Brotli support is enabled.
3945 * HTTPLIB_IS_COMPILED - a bool for if the library is compiled, or otherwise header-only.
4046 * HTTPLIB_INCLUDE_DIR - the root path to httplib's header (e.g. /usr/include).
4147 * HTTPLIB_LIBRARY - the full path to the library if compiled (e.g. /usr/lib/libhttplib.so).
42- * HTTPLIB_VERSION - the project's version string.
48+ * httplib_VERSION or HTTPLIB_VERSION - the project's version string.
4349 * HTTPLIB_FOUND - a bool for if the target was found.
4450
4551 Want to use precompiled headers (Cmake feature since v3.16)?
@@ -86,9 +92,16 @@ option(HTTPLIB_REQUIRE_ZLIB "Requires ZLIB to be found & linked, or fails build.
8692# Allow for a build to casually enable OpenSSL/ZLIB support, but silenty continue if not found.
8793# Make these options so their automatic use can be specifically disabled (as needed)
8894option (HTTPLIB_USE_OPENSSL_IF_AVAILABLE "Uses OpenSSL (if available) to enable HTTPS support." ON )
89- option (HTTPLIB_USE_ZLIB_IF_AVAILABLE "Uses ZLIB (if available) to enable compression support." ON )
95+ option (HTTPLIB_USE_ZLIB_IF_AVAILABLE "Uses ZLIB (if available) to enable Zlib compression support." ON )
9096# Lets you compile the program as a regular library instead of header-only
9197option (HTTPLIB_COMPILE "If ON, uses a Python script to split the header into a compilable header & source file (requires Python v3)." OFF )
98+ # Just setting this variable here for people building in-tree
99+ if (HTTPLIB_COMPILE)
100+ set (HTTPLIB_IS_COMPILED TRUE )
101+ endif ()
102+
103+ option (HTTPLIB_REQUIRE_BROTLI "Requires Brotli to be found & linked, or fails build." OFF )
104+ option (HTTPLIB_USE_BROTLI_IF_AVAILABLE "Uses Brotli (if available) to enable Brotli compression support." ON )
92105# Defaults to static library
93106option (BUILD_SHARED_LIBS "Build the library as a shared library instead of static. Has no effect if using header-only." OFF )
94107if (BUILD_SHARED_LIBS AND WIN32 AND HTTPLIB_COMPILE)
@@ -105,11 +118,33 @@ if(HTTPLIB_REQUIRE_OPENSSL)
105118elseif (HTTPLIB_USE_OPENSSL_IF_AVAILABLE)
106119 find_package (OpenSSL ${_HTTPLIB_OPENSSL_MIN_VER} COMPONENTS Crypto SSL QUIET )
107120endif ()
121+ # Just setting this variable here for people building in-tree
122+ if (OPENSSL_FOUND)
123+ set (HTTPLIB_IS_USING_OPENSSL TRUE )
124+ endif ()
125+
108126if (HTTPLIB_REQUIRE_ZLIB)
109127 find_package (ZLIB REQUIRED)
110128elseif (HTTPLIB_USE_ZLIB_IF_AVAILABLE)
111129 find_package (ZLIB QUIET )
112130endif ()
131+ # Just setting this variable here for people building in-tree
132+ # FindZLIB doesn't have a ZLIB_FOUND variable, so check the target.
133+ if (TARGET ZLIB::ZLIB)
134+ set (HTTPLIB_IS_USING_ZLIB TRUE )
135+ endif ()
136+
137+ # Adds our cmake folder to the search path for find_package
138+ list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
139+ if (HTTPLIB_REQUIRE_BROTLI)
140+ find_package (Brotli COMPONENTS encoder decoder common REQUIRED)
141+ elseif (HTTPLIB_USE_BROTLI_IF_AVAILABLE)
142+ find_package (Brotli COMPONENTS encoder decoder common QUIET )
143+ endif ()
144+ # Just setting this variable here for people building in-tree
145+ if (Brotli_FOUND)
146+ set (HTTPLIB_IS_USING_BROTLI TRUE )
147+ endif ()
113148
114149# Used for default, common dirs that the end-user can change (if needed)
115150# like CMAKE_INSTALL_INCLUDEDIR or CMAKE_INSTALL_DATADIR
@@ -185,33 +220,21 @@ target_link_libraries(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
185220 $<$<PLATFORM_ID:Windows>:ws2_32>
186221 $<$<PLATFORM_ID:Windows>:crypt32>
187222 $<$<PLATFORM_ID:Windows>:cryptui>
223+ # Can't put multiple targets in a single generator expression or it bugs out.
224+ $<$<BOOL :${HTTPLIB_IS_USING_BROTLI} >:Brotli::common>
225+ $<$<BOOL :${HTTPLIB_IS_USING_BROTLI} >:Brotli::encoder>
226+ $<$<BOOL :${HTTPLIB_IS_USING_BROTLI} >:Brotli::decoder>
227+ $<$<BOOL :${HTTPLIB_IS_USING_ZLIB} >:ZLIB::ZLIB>
228+ $<$<BOOL :${HTTPLIB_IS_USING_OPENSSL} >:OpenSSL::SSL>
229+ $<$<BOOL :${HTTPLIB_IS_USING_OPENSSL} >:OpenSSL::Crypto>
188230)
189231
190- # We check for the target when using IF_AVAILABLE since it's possible we didn't find it.
191- if (HTTPLIB_USE_OPENSSL_IF_AVAILABLE AND TARGET OpenSSL::SSL AND TARGET OpenSSL::Crypto OR HTTPLIB_REQUIRE_OPENSSL)
192- target_link_libraries (${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
193- OpenSSL::SSL OpenSSL::Crypto
194- )
195- target_compile_definitions (${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
196- CPPHTTPLIB_OPENSSL_SUPPORT
197- )
198- set (HTTPLIB_IS_USING_OPENSSL TRUE )
199- else ()
200- set (HTTPLIB_IS_USING_OPENSSL FALSE )
201- endif ()
202-
203- # We check for the target when using IF_AVAILABLE since it's possible we didn't find it.
204- if (HTTPLIB_USE_ZLIB_IF_AVAILABLE AND TARGET ZLIB::ZLIB OR HTTPLIB_REQUIRE_ZLIB)
205- target_link_libraries (${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
206- ZLIB::ZLIB
207- )
208- target_compile_definitions (${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
209- CPPHTTPLIB_ZLIB_SUPPORT
210- )
211- set (HTTPLIB_IS_USING_ZLIB TRUE )
212- else ()
213- set (HTTPLIB_IS_USING_ZLIB FALSE )
214- endif ()
232+ # Set the definitions to enable optional features
233+ target_compile_definitions (${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
234+ $<$<BOOL :${HTTPLIB_IS_USING_BROTLI} >:"CPPHTTPLIB_BROTLI_SUPPORT" >
235+ $<$<BOOL :${HTTPLIB_IS_USING_ZLIB} >:"CPPHTTPLIB_ZLIB_SUPPORT" >
236+ $<$<BOOL :${HTTPLIB_IS_USING_OPENSSL} >:"CPPHTTPLIB_OPENSSL_SUPPORT" >
237+ )
215238
216239# Cmake's find_package search path is different based on the system
217240# See https://cmake.org/cmake/help/latest/command/find_package.html for the list
@@ -266,6 +289,9 @@ install(FILES "${_httplib_build_includedir}/httplib.h" DESTINATION ${CMAKE_INSTA
266289install (FILES
267290 "${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} Config.cmake"
268291 "${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} ConfigVersion.cmake"
292+ # Install it so it can be used later by the httplibConfig.cmake file.
293+ # Put it in the same dir as our config file instead of a global path so we don't potentially stomp on other packages.
294+ "${CMAKE_CURRENT_SOURCE_DIR} /cmake/FindBrotli.cmake"
269295 DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
270296)
271297
0 commit comments