Skip to content

Commit

Permalink
openssl_support: OBJECT or INTERFACE library?
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Boasson <[email protected]>
  • Loading branch information
eboasson committed Mar 4, 2024
1 parent e5d4bd8 commit 4f566c9
Showing 1 changed file with 44 additions and 26 deletions.
70 changes: 44 additions & 26 deletions src/security/openssl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../core/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../api/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../ddsrt/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../core/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../core/ddsc/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../core/ddsi/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../../ddsrt/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../../core/include>")

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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")
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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../core/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../api/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../ddsrt/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../core/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../core/ddsc/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../core/ddsi/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../../ddsrt/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../../core/include>")
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()

0 comments on commit 4f566c9

Please sign in to comment.