CMake: Improvement for CMake/Rust openssl detection

We observed build failures on Ubuntu 20.04 ARM64 because the Rust code
saw extra OpenSSL dependencies in the OPENSSL_LIBS environment variable
and was confused.

This change switches from using OPENSSL_LIBRARIES, which may have extra
dependencies for libcrypto/libssl, to only use OPENSSL_CRYPTO_LIBRARY
and OPENSSL_SSL_LIBRARY.
pull/1491/head
Valerie Snyder 3 weeks ago
parent 41aa292e97
commit 8ac8f4ac8a
No known key found for this signature in database
GPG Key ID: DCBE519BFAF4C517
  1. 40
      libclamav_rust/CMakeLists.txt
  2. 42
      unit_tests/CMakeLists.txt

@ -8,29 +8,25 @@
get_filename_component(OPENSSL_DIR "${OPENSSL_INCLUDE_DIR}" DIRECTORY)
set(OPENSSL_LIBS "")
foreach(LIB IN LISTS OPENSSL_LIBRARIES)
# Skip any libraries starting with `-l` (e.g. -lpthread).
# These are system libraries and won't be found in the OPENSSL_LIB_DIR.
if (NOT LIB MATCHES "^-l")
# Remove path and extension
get_filename_component(LIBNAME "${LIB}" NAME_WLE)
# Remove "lib" prefix, if present
string(REGEX REPLACE "^lib" "" LIBNAME "${LIBNAME}")
if (NOT OPENSSL_LIBS)
# Add first openssl lib.
set(OPENSSL_LIBS "${LIBNAME}")
# While we're at it... get directory of the first library to use for the OPENSSL_LIB_DIR.
# Note: This assumes that all libs are in the same directory.
get_filename_component(OPENSSL_LIB_DIR "${LIB}" DIRECTORY)
else()
# Add additional openssl libs.
set(OPENSSL_LIBS "${OPENSSL_LIBS}:${LIBNAME}")
endif()
endif()
endforeach()
# Get the libcrypto library.
# Remove path and extension.
get_filename_component(LIBNAME "${OPENSSL_CRYPTO_LIBRARY}" NAME_WLE)
# Remove "lib" prefix, if present.
string(REGEX REPLACE "^lib" "" LIBNAME "${LIBNAME}")
# Add libcrypto.
set(OPENSSL_LIBS "${LIBNAME}")
# Get the libssl library.
# Remove path and extension.
get_filename_component(LIBNAME "${OPENSSL_SSL_LIBRARY}" NAME_WLE)
# Remove "lib" prefix, if present.
string(REGEX REPLACE "^lib" "" LIBNAME "${LIBNAME}")
# Add libssl.
set(OPENSSL_LIBS "${OPENSSL_LIBS}:${LIBNAME}")
# Get directory of the first library to use for the OPENSSL_LIB_DIR.
get_filename_component(OPENSSL_LIB_DIR "${OPENSSL_CRYPTO_LIBRARY}" DIRECTORY)
set(ENVIRONMENT "")
list(APPEND ENVIRONMENT "OPENSSL_DIR=${OPENSSL_DIR}")

@ -303,29 +303,25 @@ set(ENVIRONMENT
get_filename_component(OPENSSL_DIR "${OPENSSL_INCLUDE_DIR}" DIRECTORY)
set(OPENSSL_LIBS "")
foreach(LIB IN LISTS OPENSSL_LIBRARIES)
# Skip any libraries starting with `-l` (e.g. -lpthread).
# These are system libraries and won't be found in the OPENSSL_LIB_DIR.
if (NOT LIB MATCHES "^-l")
# Remove path and extension
get_filename_component(LIBNAME "${LIB}" NAME_WLE)
# Remove "lib" prefix, if present
string(REGEX REPLACE "^lib" "" LIBNAME "${LIBNAME}")
if (NOT OPENSSL_LIBS)
# Add first openssl lib.
set(OPENSSL_LIBS "${LIBNAME}")
# While we're at it... get directory of the first library to use for the OPENSSL_LIB_DIR.
# Note: This assumes that all libs are in the same directory.
get_filename_component(OPENSSL_LIB_DIR "${LIB}" DIRECTORY)
else()
# Add additional openssl libs.
set(OPENSSL_LIBS "${OPENSSL_LIBS}:${LIBNAME}")
endif()
endif()
endforeach()
# Get the libcrypto library.
# Remove path and extension.
get_filename_component(LIBNAME "${OPENSSL_CRYPTO_LIBRARY}" NAME_WLE)
# Remove "lib" prefix, if present.
string(REGEX REPLACE "^lib" "" LIBNAME "${LIBNAME}")
# Add libcrypto.
set(OPENSSL_LIBS "${LIBNAME}")
# Get the libssl library.
# Remove path and extension.
get_filename_component(LIBNAME "${OPENSSL_SSL_LIBRARY}" NAME_WLE)
# Remove "lib" prefix, if present.
string(REGEX REPLACE "^lib" "" LIBNAME "${LIBNAME}")
# Add libssl.
set(OPENSSL_LIBS "${OPENSSL_LIBS}:${LIBNAME}")
# Get directory of the first library to use for the OPENSSL_LIB_DIR.
get_filename_component(OPENSSL_LIB_DIR "${OPENSSL_CRYPTO_LIBRARY}" DIRECTORY)
list(APPEND ENVIRONMENT "OPENSSL_DIR=${OPENSSL_DIR}")
list(APPEND ENVIRONMENT "OPENSSL_INCLUDE_DIR=${OPENSSL_INCLUDE_DIR}")

Loading…
Cancel
Save