|
1 | 1 | #[[ |
2 | 2 | Build options: |
3 | | - * BUILD_SHARED_LIBS (default off) builds as a shared library (if HTTPLIB_COMPILE is ON) |
| 3 | + * Standard BUILD_SHARED_LIBS is supported and sets HTTPLIB_SHARED default value. |
4 | 4 | * HTTPLIB_USE_OPENSSL_IF_AVAILABLE (default on) |
5 | 5 | * HTTPLIB_USE_ZLIB_IF_AVAILABLE (default on) |
6 | 6 | * HTTPLIB_USE_BROTLI_IF_AVAILABLE (default on) |
|
13 | 13 | * HTTPLIB_USE_NON_BLOCKING_GETADDRINFO (default on) |
14 | 14 | * HTTPLIB_COMPILE (default off) |
15 | 15 | * HTTPLIB_INSTALL (default on) |
| 16 | + * HTTPLIB_SHARED (default off) builds as a shared library (if HTTPLIB_COMPILE is ON) |
16 | 17 | * HTTPLIB_TEST (default off) |
17 | 18 | * BROTLI_USE_STATIC_LIBS - tells Cmake to use the static Brotli libs (only works if you have them installed). |
18 | 19 | * OPENSSL_USE_STATIC_LIBS - tells Cmake to use the static OpenSSL libs (only works if you have them installed). |
@@ -109,12 +110,20 @@ option(HTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN "Enable feature to load system cer |
109 | 110 | option(HTTPLIB_USE_NON_BLOCKING_GETADDRINFO "Enables the non-blocking alternatives for getaddrinfo." ON) |
110 | 111 | option(HTTPLIB_REQUIRE_ZSTD "Requires ZSTD to be found & linked, or fails build." OFF) |
111 | 112 | option(HTTPLIB_USE_ZSTD_IF_AVAILABLE "Uses ZSTD (if available) to enable zstd support." ON) |
112 | | -# Defaults to static library |
113 | | -option(BUILD_SHARED_LIBS "Build the library as a shared library instead of static. Has no effect if using header-only." OFF) |
114 | | -if(BUILD_SHARED_LIBS AND WIN32 AND HTTPLIB_COMPILE) |
115 | | - # Necessary for Windows if building shared libs |
116 | | - # See https://stackoverflow.com/a/40743080 |
117 | | - set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) |
| 113 | +# Defaults to static library but respects standard BUILD_SHARED_LIBS if set |
| 114 | +include(CMakeDependentOption) |
| 115 | +cmake_dependent_option(HTTPLIB_SHARED "Build the library as a shared library instead of static. Has no effect if using header-only." |
| 116 | + "${BUILD_SHARED_LIBS}" HTTPLIB_COMPILE OFF |
| 117 | +) |
| 118 | +if(HTTPLIB_SHARED) |
| 119 | + set(HTTPLIB_LIB_TYPE SHARED) |
| 120 | + if(WIN32) |
| 121 | + # Necessary for Windows if building shared libs |
| 122 | + # See https://stackoverflow.com/a/40743080 |
| 123 | + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) |
| 124 | + endif() |
| 125 | +else() |
| 126 | + set(HTTPLIB_LIB_TYPE STATIC) |
118 | 127 | endif() |
119 | 128 |
|
120 | 129 | if(CMAKE_SYSTEM_NAME MATCHES "Windows") |
@@ -230,8 +239,7 @@ if(HTTPLIB_COMPILE) |
230 | 239 |
|
231 | 240 | # split.py puts output in "out" |
232 | 241 | set(_httplib_build_includedir "${CMAKE_CURRENT_BINARY_DIR}/out") |
233 | | - # This will automatically be either static or shared based on the value of BUILD_SHARED_LIBS |
234 | | - add_library(${PROJECT_NAME} "${_httplib_build_includedir}/httplib.cc") |
| 242 | + add_library(${PROJECT_NAME} ${HTTPLIB_LIB_TYPE} "${_httplib_build_includedir}/httplib.cc") |
235 | 243 | target_sources(${PROJECT_NAME} |
236 | 244 | PUBLIC |
237 | 245 | $<BUILD_INTERFACE:${_httplib_build_includedir}/httplib.h> |
|
0 commit comments