cmake: only validate component when the required library is found (#2112)

This commit is contained in:
Alexandre Bouvier 2025-03-17 01:05:55 +00:00 committed by GitHub
parent 87a5ae64a4
commit 0be0526085
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,9 +22,11 @@ if(@HTTPLIB_IS_USING_OPENSSL@)
# 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@)
@ -33,10 +35,12 @@ if(@HTTPLIB_IS_USING_BROTLI@)
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@)
find_dependency(zstd)
set(httplib_zstd_FOUND ${zstd_FOUND})
endif()
# Mildly useful for end-users
@ -46,12 +50,6 @@ set_and_check(HTTPLIB_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@")
# 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")
# Consider each library support as a "component"
set(httplib_OpenSSL_FOUND @HTTPLIB_IS_USING_OPENSSL@)
set(httplib_ZLIB_FOUND @HTTPLIB_IS_USING_ZLIB@)
set(httplib_Brotli_FOUND @HTTPLIB_IS_USING_BROTLI@)
set(httplib_zstd_FOUND @HTTPLIB_IS_USING_ZSTD@)
check_required_components(httplib)
# Brings in the target library, but only if all required components are found