From e7f89ae5299fe84c4af85383826c44eb426c8cd4 Mon Sep 17 00:00:00 2001 From: Matthew Albrecht Date: Mon, 20 Sep 2021 20:15:37 -0500 Subject: [PATCH] Only find OpenSSL, MbedTLS, zlib if they have not already been found, make CMake install optional. (#307) Co-authored-by: Benjamin Sergeant --- CMakeLists.txt | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d0cd6f3..87e83aed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,18 +180,23 @@ if (USE_TLS) # set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /opt/local/include/openssl-1.0) endif() - # Use OPENSSL_ROOT_DIR CMake variable if you need to use your own openssl - find_package(OpenSSL REQUIRED) + # This OPENSSL_FOUND check is to help find a cmake manually configured OpenSSL + if (NOT OPENSSL_FOUND) + find_package(OpenSSL REQUIRED) + endif() message(STATUS "OpenSSL: " ${OPENSSL_VERSION}) add_definitions(${OPENSSL_DEFINITIONS}) - target_include_directories(ixwebsocket PUBLIC ${OPENSSL_INCLUDE_DIR}) + target_include_directories(ixwebsocket PUBLIC $) target_link_libraries(ixwebsocket ${OPENSSL_LIBRARIES}) elseif (USE_MBED_TLS) message(STATUS "TLS configured to use mbedtls") - find_package(MbedTLS REQUIRED) - target_include_directories(ixwebsocket PUBLIC ${MBEDTLS_INCLUDE_DIRS}) + # This MBEDTLS_FOUND check is to help find a cmake manually configured MbedTLS + if (NOT MBEDTLS_FOUND) + find_package(MbedTLS REQUIRED) + endif() + target_include_directories(ixwebsocket PUBLIC $) target_link_libraries(ixwebsocket ${MBEDTLS_LIBRARIES}) elseif (USE_SECURE_TRANSPORT) message(STATUS "TLS configured to use secure transport") @@ -202,9 +207,11 @@ endif() option(USE_ZLIB "Enable zlib support" TRUE) if (USE_ZLIB) - # Use ZLIB_ROOT CMake variable if you need to use your own zlib - find_package(ZLIB REQUIRED) - include_directories(${ZLIB_INCLUDE_DIRS}) + # This ZLIB_FOUND check is to help find a cmake manually configured zlib + if (NOT ZLIB_FOUND) + find_package(ZLIB REQUIRED) + endif() + target_include_directories(ixwebsocket PUBLIC $) target_link_libraries(ixwebsocket ${ZLIB_LIBRARIES}) target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_USE_ZLIB) @@ -251,16 +258,20 @@ target_include_directories(ixwebsocket PUBLIC set_target_properties(ixwebsocket PROPERTIES PUBLIC_HEADER "${IXWEBSOCKET_HEADERS}") -install(TARGETS ixwebsocket - EXPORT ixwebsocket - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ixwebsocket/ -) +option(IXWEBSOCKET_INSTALL "Install IXWebSocket" TRUE) -install(EXPORT ixwebsocket - FILE ixwebsocket-config.cmake - NAMESPACE ixwebsocket:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ixwebsocket) +if (IXWEBSOCKET_INSTALL) + install(TARGETS ixwebsocket + EXPORT ixwebsocket + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ixwebsocket/ + ) + + install(EXPORT ixwebsocket + FILE ixwebsocket-config.cmake + NAMESPACE ixwebsocket:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ixwebsocket) +endif() if (USE_WS OR USE_TEST) include(FetchContent)