From 4f566c9247439b2496d98823d81b7c95ab75e60a Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Mon, 4 Mar 2024 15:57:51 +0100 Subject: [PATCH] openssl_support: OBJECT or INTERFACE library? Signed-off-by: Erik Boasson --- src/security/openssl/CMakeLists.txt | 70 ++++++++++++++++++----------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/src/security/openssl/CMakeLists.txt b/src/security/openssl/CMakeLists.txt index 7004a16900..4969b903fb 100644 --- a/src/security/openssl/CMakeLists.txt +++ b/src/security/openssl/CMakeLists.txt @@ -10,30 +10,48 @@ # SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause # -add_library(security_openssl OBJECT) - -target_sources(security_openssl PRIVATE - "${CMAKE_CURRENT_SOURCE_DIR}/src/openssl_support.c" - "${CMAKE_CURRENT_SOURCE_DIR}/include/dds/security/openssl_support.h") - -target_include_directories( - security_openssl PUBLIC - "$" - "$" - "$" - "$" - "$" - "$" - "$" - "$" - "$") - -target_link_libraries(security_openssl PUBLIC OpenSSL::SSL) +# Ubuntu 22.04 shared library builds with ASAN fail with: +# +# /usr/bin/ld: ../../openssl/CMakeFiles/security_openssl.dir/src/openssl_support.c.o: \ +# warning: relocation against `__asan_option_detect_stack_use_after_return' in \ +# read-only section `.text' +# /usr/bin/ld: ../../openssl/CMakeFiles/security_openssl.dir/src/openssl_support.c.o: \ +# relocation R_X86_64_PC32 against symbol `__asan_option_detect_stack_use_after_return' \ +# can not be used when making a shared object; recompile with -fPIC +# +# Nowhere does it use this for something other than a shared library, so it seems to me +# that CMake is using incorrect build flags. Unfortunately, grokking CMake is beyond my +# abilities, so an ugly workaround will have to do for now. -install( - TARGETS security_openssl - EXPORT "${PROJECT_NAME}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT lib - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib -) +if(BUILD_SHARED_LIBS) + add_library(security_openssl INTERFACE) + target_sources(security_openssl INTERFACE + "${CMAKE_CURRENT_SOURCE_DIR}/src/openssl_support.c" + "${CMAKE_CURRENT_SOURCE_DIR}/include/dds/security/openssl_support.h") + target_include_directories( + security_openssl INTERFACE + "$") +else() + add_library(security_openssl OBJECT) + target_sources(security_openssl PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/src/openssl_support.c" + "${CMAKE_CURRENT_SOURCE_DIR}/include/dds/security/openssl_support.h") + target_include_directories( + security_openssl PUBLIC + "$" + "$" + "$" + "$" + "$" + "$" + "$" + "$" + "$") + target_link_libraries(security_openssl PUBLIC OpenSSL::SSL) + install( + TARGETS security_openssl + EXPORT "${PROJECT_NAME}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT lib + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib) +endif()