Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 016838f

Browse files
authored
cmake: support components (yhirose#1504)
1 parent 75053bf commit 016838f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
1515
-------------------------------------------------------------------------------
1616
17-
After installation with Cmake, a find_package(httplib) is available.
18-
This creates a httplib::httplib target (if found).
17+
After installation with Cmake, a find_package(httplib COMPONENTS OpenSSL ZLIB Brotli) is available.
18+
This creates a httplib::httplib target (if found and if listed components are supported).
1919
It can be linked like so:
2020
2121
target_link_libraries(your_exe httplib::httplib)
@@ -235,8 +235,6 @@ configure_package_config_file("${PROJECT_NAME}Config.cmake.in"
235235
INSTALL_DESTINATION "${_TARGET_INSTALL_CMAKEDIR}"
236236
# Passes the includedir install path
237237
PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR
238-
# There aren't any components, so don't use the macro
239-
NO_CHECK_REQUIRED_COMPONENTS_MACRO
240238
)
241239

242240
if(HTTPLIB_COMPILE)

httplibConfig.cmake.in

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,17 @@ set_and_check(HTTPLIB_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@")
4242
# This is helpful if you're using Cmake's pre-compiled header feature
4343
set_and_check(HTTPLIB_HEADER_PATH "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@/httplib.h")
4444

45-
# Brings in the target library
46-
include("${CMAKE_CURRENT_LIST_DIR}/httplibTargets.cmake")
45+
# Consider each library support as a "component"
46+
set(httplib_OpenSSL_FOUND @HTTPLIB_IS_USING_OPENSSL@)
47+
set(httplib_ZLIB_FOUND @HTTPLIB_IS_USING_ZLIB@)
48+
set(httplib_Brotli_FOUND @HTTPLIB_IS_USING_BROTLI@)
49+
50+
check_required_components(httplib)
51+
52+
# Brings in the target library, but only if all required components are found
53+
if(NOT DEFINED httplib_FOUND OR httplib_FOUND)
54+
include("${CMAKE_CURRENT_LIST_DIR}/httplibTargets.cmake")
55+
endif()
4756

4857
# Ouputs a "found httplib /usr/include/httplib.h" message when using find_package(httplib)
4958
include(FindPackageMessage)

0 commit comments

Comments
 (0)