Only find OpenSSL, MbedTLS, zlib if they have not already been found, make CMake install optional. (#307)

Co-authored-by: Benjamin Sergeant <bsergean@gmail.com>
This commit is contained in:
Matthew Albrecht 2021-09-20 20:15:37 -05:00 committed by GitHub
parent cdeaf8e2be
commit e7f89ae529
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -180,18 +180,23 @@ if (USE_TLS)
# set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /opt/local/include/openssl-1.0) # set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /opt/local/include/openssl-1.0)
endif() endif()
# Use OPENSSL_ROOT_DIR CMake variable if you need to use your own openssl # This OPENSSL_FOUND check is to help find a cmake manually configured OpenSSL
find_package(OpenSSL REQUIRED) if (NOT OPENSSL_FOUND)
find_package(OpenSSL REQUIRED)
endif()
message(STATUS "OpenSSL: " ${OPENSSL_VERSION}) message(STATUS "OpenSSL: " ${OPENSSL_VERSION})
add_definitions(${OPENSSL_DEFINITIONS}) add_definitions(${OPENSSL_DEFINITIONS})
target_include_directories(ixwebsocket PUBLIC ${OPENSSL_INCLUDE_DIR}) target_include_directories(ixwebsocket PUBLIC $<BUILD_INTERFACE:${OPENSSL_INCLUDE_DIR}>)
target_link_libraries(ixwebsocket ${OPENSSL_LIBRARIES}) target_link_libraries(ixwebsocket ${OPENSSL_LIBRARIES})
elseif (USE_MBED_TLS) elseif (USE_MBED_TLS)
message(STATUS "TLS configured to use mbedtls") message(STATUS "TLS configured to use mbedtls")
find_package(MbedTLS REQUIRED) # This MBEDTLS_FOUND check is to help find a cmake manually configured MbedTLS
target_include_directories(ixwebsocket PUBLIC ${MBEDTLS_INCLUDE_DIRS}) if (NOT MBEDTLS_FOUND)
find_package(MbedTLS REQUIRED)
endif()
target_include_directories(ixwebsocket PUBLIC $<BUILD_INTERFACE:${MBEDTLS_INCLUDE_DIRS}>)
target_link_libraries(ixwebsocket ${MBEDTLS_LIBRARIES}) target_link_libraries(ixwebsocket ${MBEDTLS_LIBRARIES})
elseif (USE_SECURE_TRANSPORT) elseif (USE_SECURE_TRANSPORT)
message(STATUS "TLS configured to use secure transport") message(STATUS "TLS configured to use secure transport")
@ -202,9 +207,11 @@ endif()
option(USE_ZLIB "Enable zlib support" TRUE) option(USE_ZLIB "Enable zlib support" TRUE)
if (USE_ZLIB) if (USE_ZLIB)
# Use ZLIB_ROOT CMake variable if you need to use your own zlib # This ZLIB_FOUND check is to help find a cmake manually configured zlib
find_package(ZLIB REQUIRED) if (NOT ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIRS}) find_package(ZLIB REQUIRED)
endif()
target_include_directories(ixwebsocket PUBLIC $<BUILD_INTERFACE:${ZLIB_INCLUDE_DIRS}>)
target_link_libraries(ixwebsocket ${ZLIB_LIBRARIES}) target_link_libraries(ixwebsocket ${ZLIB_LIBRARIES})
target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_USE_ZLIB) 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}") set_target_properties(ixwebsocket PROPERTIES PUBLIC_HEADER "${IXWEBSOCKET_HEADERS}")
install(TARGETS ixwebsocket option(IXWEBSOCKET_INSTALL "Install IXWebSocket" TRUE)
EXPORT ixwebsocket
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ixwebsocket/
)
install(EXPORT ixwebsocket if (IXWEBSOCKET_INSTALL)
FILE ixwebsocket-config.cmake install(TARGETS ixwebsocket
NAMESPACE ixwebsocket:: EXPORT ixwebsocket
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/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) if (USE_WS OR USE_TEST)
include(FetchContent) include(FetchContent)