Skip to content

Commit c54c71a

Browse files
rotolofNiccolò Iardellajimmy-park
authored
Add HTTPLIB_INSTALL CMake option (#1575)
* Add HTTPLIB_INSTALL CMake option * Proper formatting of HTTPLIB_INSTALL block Co-authored-by: Jiwoo Park <[email protected]> --------- Co-authored-by: Niccolò Iardella <[email protected]> Co-authored-by: Jiwoo Park <[email protected]>
1 parent 3409c00 commit c54c71a

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

CMakeLists.txt

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* HTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN (default on)
1010
* HTTPLIB_REQUIRE_BROTLI (default off)
1111
* HTTPLIB_COMPILE (default off)
12+
* HTTPLIB_INSTALL (default on)
1213
* HTTPLIB_TEST (default off)
1314
* BROTLI_USE_STATIC_LIBS - tells Cmake to use the static Brotli libs (only works if you have them installed).
1415
* OPENSSL_USE_STATIC_LIBS - tells Cmake to use the static OpenSSL libs (only works if you have them installed).
@@ -87,6 +88,8 @@ option(HTTPLIB_USE_OPENSSL_IF_AVAILABLE "Uses OpenSSL (if available) to enable H
8788
option(HTTPLIB_USE_ZLIB_IF_AVAILABLE "Uses ZLIB (if available) to enable Zlib compression support." ON)
8889
# Lets you compile the program as a regular library instead of header-only
8990
option(HTTPLIB_COMPILE "If ON, uses a Python script to split the header into a compilable header & source file (requires Python v3)." OFF)
91+
# Lets you disable the installation (useful when fetched from another CMake project)
92+
option(HTTPLIB_INSTALL "Enables the installation target" ON)
9093
# Just setting this variable here for people building in-tree
9194
if(HTTPLIB_COMPILE)
9295
set(HTTPLIB_IS_COMPILED TRUE)
@@ -262,31 +265,33 @@ else()
262265
)
263266
endif()
264267

265-
# Creates the export httplibTargets.cmake
266-
# This is strictly what holds compilation requirements
267-
# and linkage information (doesn't find deps though).
268-
install(TARGETS ${PROJECT_NAME}
269-
EXPORT httplibTargets
270-
)
268+
if(HTTPLIB_INSTALL)
269+
# Creates the export httplibTargets.cmake
270+
# This is strictly what holds compilation requirements
271+
# and linkage information (doesn't find deps though).
272+
install(TARGETS ${PROJECT_NAME}
273+
EXPORT httplibTargets
274+
)
271275

272-
install(FILES "${_httplib_build_includedir}/httplib.h" TYPE INCLUDE)
276+
install(FILES "${_httplib_build_includedir}/httplib.h" TYPE INCLUDE)
273277

274-
install(FILES
278+
install(FILES
275279
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
276280
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
277281
# Install it so it can be used later by the httplibConfig.cmake file.
278282
# Put it in the same dir as our config file instead of a global path so we don't potentially stomp on other packages.
279283
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindBrotli.cmake"
280-
DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
281-
)
284+
DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
285+
)
282286

283-
# NOTE: This path changes depending on if it's on Windows or Linux
284-
install(EXPORT httplibTargets
285-
# Puts the targets into the httplib namespace
286-
# So this makes httplib::httplib linkable after doing find_package(httplib)
287-
NAMESPACE ${PROJECT_NAME}::
288-
DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
289-
)
287+
# NOTE: This path changes depending on if it's on Windows or Linux
288+
install(EXPORT httplibTargets
289+
# Puts the targets into the httplib namespace
290+
# So this makes httplib::httplib linkable after doing find_package(httplib)
291+
NAMESPACE ${PROJECT_NAME}::
292+
DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
293+
)
294+
endif()
290295

291296
if(HTTPLIB_TEST)
292297
include(CTest)

0 commit comments

Comments
 (0)