1
1
#[[
2
2
Build options:
3
+ * BUILD_SHARED_LIBS (default off) builds as a static library (if HTTPLIB_COMPILE is ON)
3
4
* HTTPLIB_USE_OPENSSL_IF_AVAILABLE (default on)
4
5
* HTTPLIB_USE_ZLIB_IF_AVAILABLE (default on)
5
6
* HTTPLIB_REQUIRE_OPENSSL (default off)
6
7
* HTTPLIB_REQUIRE_ZLIB (default off)
8
+ * HTTPLIB_USE_BROTLI_IF_AVAILABLE (default on)
9
+ * HTTPLIB_REQUIRE_BROTLI (default off)
7
10
* 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).
8
13
9
14
-------------------------------------------------------------------------------
10
15
36
41
* HTTPLIB_HEADER_PATH - this is the full path to the installed header (e.g. /usr/include/httplib.h).
37
42
* HTTPLIB_IS_USING_OPENSSL - a bool for if OpenSSL support is enabled.
38
43
* 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.
39
45
* HTTPLIB_IS_COMPILED - a bool for if the library is compiled, or otherwise header-only.
40
46
* HTTPLIB_INCLUDE_DIR - the root path to httplib's header (e.g. /usr/include).
41
47
* 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.
43
49
* HTTPLIB_FOUND - a bool for if the target was found.
44
50
45
51
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.
86
92
# Allow for a build to casually enable OpenSSL/ZLIB support, but silenty continue if not found.
87
93
# Make these options so their automatic use can be specifically disabled (as needed)
88
94
option (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 )
90
96
# Lets you compile the program as a regular library instead of header-only
91
97
option (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 )
92
105
# Defaults to static library
93
106
option (BUILD_SHARED_LIBS "Build the library as a shared library instead of static. Has no effect if using header-only." OFF )
94
107
if (BUILD_SHARED_LIBS AND WIN32 AND HTTPLIB_COMPILE)
@@ -105,11 +118,33 @@ if(HTTPLIB_REQUIRE_OPENSSL)
105
118
elseif (HTTPLIB_USE_OPENSSL_IF_AVAILABLE)
106
119
find_package (OpenSSL ${_HTTPLIB_OPENSSL_MIN_VER} COMPONENTS Crypto SSL QUIET )
107
120
endif ()
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
+
108
126
if (HTTPLIB_REQUIRE_ZLIB)
109
127
find_package (ZLIB REQUIRED)
110
128
elseif (HTTPLIB_USE_ZLIB_IF_AVAILABLE)
111
129
find_package (ZLIB QUIET )
112
130
endif ()
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 ()
113
148
114
149
# Used for default, common dirs that the end-user can change (if needed)
115
150
# like CMAKE_INSTALL_INCLUDEDIR or CMAKE_INSTALL_DATADIR
@@ -185,33 +220,21 @@ target_link_libraries(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
185
220
$<$<PLATFORM_ID:Windows>:ws2_32>
186
221
$<$<PLATFORM_ID:Windows>:crypt32>
187
222
$<$<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>
188
230
)
189
231
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
+ )
215
238
216
239
# Cmake's find_package search path is different based on the system
217
240
# 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
266
289
install (FILES
267
290
"${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} Config.cmake"
268
291
"${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"
269
295
DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
270
296
)
271
297
0 commit comments