Skip to content

Commit

Permalink
PS-9151: Fix opensslpp build with WITH_SSL=openssl11
Browse files Browse the repository at this point in the history
https://perconadev.atlassian.net/browse/PS-9151

The opensslpp build fails with "Could NOT find OpenSSL" error in case
WITH_SSL=openssl11 is used.

To fix the issue:
- Remove find_package(OpenSSL REQUIRED) in opensslpp/CMakeLists.txt.
  All openssl related preparations are done inside ssl.cmake.
- Update ssl.cmake to always create OpenSSL::SSL and OpenSSL::Crypto
  imported libs. For all possible WITH_SSL values: system, openssl11,
  /path/to/openssl.
  • Loading branch information
oleksandr-kachan committed Mar 20, 2024
1 parent 6ec7af2 commit d24e6eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 22 additions & 20 deletions cmake/ssl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -221,26 +221,6 @@ MACRO(FIND_ALTERNATIVE_SYSTEM_SSL)
SET(OPENSSL_SSL_LIBRARY ${OPENSSL_LIBRARY})
SET(OPENSSL_CRYPTO_LIBRARY ${CRYPTO_LIBRARY})

# Add support for bundled curl.
ADD_LIBRARY(OpenSSL::SSL UNKNOWN IMPORTED)
SET_TARGET_PROPERTIES(OpenSSL::SSL PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
IF(EXISTS "${OPENSSL_SSL_LIBRARY}")
SET_TARGET_PROPERTIES(OpenSSL::SSL PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${OPENSSL_SSL_LIBRARY}")
ENDIF()

# Add support for bundled curl.
ADD_LIBRARY(OpenSSL::Crypto UNKNOWN IMPORTED)
SET_TARGET_PROPERTIES(OpenSSL::Crypto PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
IF(EXISTS "${OPENSSL_CRYPTO_LIBRARY}")
SET_TARGET_PROPERTIES(OpenSSL::Crypto PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${OPENSSL_CRYPTO_LIBRARY}")
ENDIF()

ENDMACRO(FIND_ALTERNATIVE_SYSTEM_SSL)

# MYSQL_CHECK_SSL
Expand Down Expand Up @@ -449,6 +429,28 @@ MACRO (MYSQL_CHECK_SSL)
SET(MY_OPENSSL_LIBRARY "${CMAKE_BINARY_DIR}/copied_openssl.lib")
ENDIF()

# Create OpenSSL::SSL and OpenSSL::Crypto imported libs for all possible
# WITH_SSL values (system, openssl11, /path/to/openssl). This will fix
# building modules which rely on OpenSSL::SSL and OpenSSL::Crypto only with
# different openssl variants.
ADD_LIBRARY(OpenSSL::SSL UNKNOWN IMPORTED)
SET_TARGET_PROPERTIES(OpenSSL::SSL PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
IF(EXISTS "${MY_OPENSSL_LIBRARY}")
SET_TARGET_PROPERTIES(OpenSSL::SSL PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${MY_OPENSSL_LIBRARY}")
ENDIF()

ADD_LIBRARY(OpenSSL::Crypto UNKNOWN IMPORTED)
SET_TARGET_PROPERTIES(OpenSSL::Crypto PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR}")
IF(EXISTS "${MY_CRYPTO_LIBRARY}")
SET_TARGET_PROPERTIES(OpenSSL::Crypto PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${MY_CRYPTO_LIBRARY}")
ENDIF()

MESSAGE(STATUS "OPENSSL_INCLUDE_DIR = ${OPENSSL_INCLUDE_DIR}")
MESSAGE(STATUS "OPENSSL_LIBRARY = ${OPENSSL_LIBRARY}")
MESSAGE(STATUS "CRYPTO_LIBRARY = ${CRYPTO_LIBRARY}")
Expand Down
2 changes: 0 additions & 2 deletions extra/opensslpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ set(
)
list_transform_prepend(SOURCE_LIST "${SRC_DIR_EX}/")

find_package(OpenSSL REQUIRED)

add_library(${PROJECT_NAME} STATIC ${SOURCE_LIST} ${PUBLIC_HEADER_LIST} ${PRIVATE_HEADER_LIST})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

Expand Down

0 comments on commit d24e6eb

Please sign in to comment.