Skip to content

Commit

Permalink
Some minor cleanups
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Boasson <[email protected]>
  • Loading branch information
eboasson committed Feb 23, 2024
1 parent 2f18f5b commit e5d4bd8
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 60 deletions.
27 changes: 22 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ else()
set(not_crosscompiling ON)
endif()

# By default we do shared libraries (we really prefer shared libraries because of the
# plugins for IDLC, security, PSMX, ...)
#
# For static builds, we recommend doing a regular shared library build first, then
# building the static Cyclone library with CMAKE_CROSSCOMPILING set. This avoids the
# dynamic linking in IDLC of something involving the static library, and that in turn
# avoids a position-dependent/position-independent mess.
#
# Note that on Linux that mess can be partially resolved by defining
#
# CMAKE_POSITION_INDEPENDENT_CODE=1
#
# resulting in a PIC static library, but that is in turn incompatible with the
# system-provided static libraries for OpenSSL. So much easier to avoid it for the rare
# case where it is needed.
#
# It appears that on macOS, all code is position independent and it'll work regardless.
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
if(NOT BUILD_SHARED_LIBS AND NOT CMAKE_CROSSCOMPILING)
message(WARNING "It is probably best to build a static library as-if cross compiling (e.g., use -DCMAKE_CROSSCOMPILING=1 -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME})")
endif()

# By default don't treat warnings as errors, else anyone building it with a different compiler that
# just happens to generate a warning, as well as anyone adding or modifying something and making a
# small mistake would run into errors. CI builds can be configured differently.
Expand Down Expand Up @@ -327,11 +349,6 @@ set(generated_options_md "${CMAKE_CURRENT_SOURCE_DIR}/docs/manual/options.md
set(generated_options_rst "${CMAKE_CURRENT_SOURCE_DIR}/docs/manual/config/config_file_reference.rst")
set(generated_defconfig_src "${CMAKE_CURRENT_SOURCE_DIR}/src/core/ddsi/defconfig.c")

if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
else()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

add_subdirectory(compat)
add_subdirectory(src)
if(BUILD_EXAMPLES)
Expand Down
38 changes: 16 additions & 22 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
#
include (GenerateExportHeader)

if (BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
add_library(ddsc SHARED "")
else()
add_library(ddsc)
endif()
add_library(ddsc)

if(BUILD_TESTING)
set_property(TARGET ddsc PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
Expand Down Expand Up @@ -66,27 +62,25 @@ include(cdr/CMakeLists.txt)
include(ddsi/CMakeLists.txt)
include(ddsc/CMakeLists.txt)

## HACK
get_property(plugin_list GLOBAL PROPERTY cdds_plugin_list)
if(plugin_list)
list(JOIN plugin_list "," plugin_commasep)
target_compile_options(ddsc PRIVATE "-DPLUGINS=${plugin_commasep}")
target_link_libraries(ddsc PRIVATE ${plugin_list})
foreach(plugin ${plugin_list})
set(propname ${plugin}_symbols)
get_property(plugin_symbols GLOBAL PROPERTY ${propname})
list(JOIN plugin_symbols "," plugin_symbols_commasep)
target_compile_options(ddsc PRIVATE "-DPLUGIN_SYMBOLS_${plugin}=${plugin_symbols_commasep}")
endforeach()
endif()

if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
else()
# The not-so-elegant inclusion of all configured plug-ins for static builds. At least it
# keeps most of the dirty things in one place.
if(NOT BUILD_SHARED_LIBS)
get_property(plugin_list GLOBAL PROPERTY cdds_plugin_list)
if(plugin_list)
list(JOIN plugin_list "," plugin_commasep)
target_compile_options(ddsc PRIVATE "-DPLUGINS=${plugin_commasep}")
target_link_libraries(ddsc PRIVATE ${plugin_list})
foreach(plugin ${plugin_list})
set(propname ${plugin}_symbols)
get_property(plugin_symbols GLOBAL PROPERTY ${propname})
list(JOIN plugin_symbols "," plugin_symbols_commasep)
target_compile_options(ddsc PRIVATE "-DPLUGIN_SYMBOLS_${plugin}=${plugin_symbols_commasep}")
endforeach()
endif()
if(ENABLE_SSL)
target_link_libraries(ddsc PUBLIC security_openssl)
endif()
endif()
## HACK

add_coverage(ddsc)
target_link_libraries(ddsc PRIVATE "$<BUILD_INTERFACE:ddsrt>")
Expand Down
7 changes: 1 addition & 6 deletions src/core/cdr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ else()
include(Generate)
include(GenerateExportHeader)

if (BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
add_library(cdr SHARED "")
else()
add_library(cdr)
endif()

add_library(cdr)
add_library(${PROJECT_NAME}::cdr ALIAS cdr)

target_sources(cdr PRIVATE ${srcs_cdr} ${hdrs_private_cdr} ${CMAKE_CURRENT_LIST_DIR}/../../ddsrt/src/bswap.c)
Expand Down
4 changes: 2 additions & 2 deletions src/core/ddsc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ target_link_libraries(oneliner PRIVATE RoundTrip Space ddsc)
#
# Fortunately, The Iceoryx doesn't suffer from this, so all it needs is some trickery to
# still get the Iceoryx tests to run.
if (BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
if (BUILD_SHARED_LIBS)
idlc_generate(TARGET psmx_cdds_data FILES psmx_cdds_data.idl)
set(psmx_cdds_sources
"psmx_cdds_impl.c"
Expand Down Expand Up @@ -308,7 +308,7 @@ kill -0 `cat ctest_fixture_iox_roudi.pid`")
add_test(NAME ${fullname}_iox COMMAND cunit_ddsc -s ddsc_psmx -t ${shortname})
set_tests_properties(${fullname}_iox PROPERTIES FIXTURES_REQUIRED iox)
set_tests_properties(${fullname}_iox PROPERTIES RESOURCE_LOCK iox_lock)
if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
set_tests_properties(${fullname}_iox PROPERTIES ENVIRONMENT "CDDS_PSMX_NAME=iox;LD_LIBRARY_PATH=$<TARGET_FILE_DIR:psmx_iox>:$ENV{LD_LIBRARY_PATH}")
else()
set_tests_properties(${fullname}_iox PROPERTIES ENVIRONMENT "CDDS_PSMX_NAME=iox")
Expand Down
3 changes: 1 addition & 2 deletions src/ddsrt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ if(BUILD_TESTING)
set(DDS_ALLOW_NESTED_DOMAIN 1)
endif()

if (BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
else()
if (NOT BUILD_SHARED_LIBS)
set(DDS_IS_STATIC_LIBRARY 1)
endif()

Expand Down
4 changes: 2 additions & 2 deletions src/psmx_iox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ include(GenerateExportHeader)

message(STATUS "Building Iceoryx PSMX plugin")

if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
add_library(psmx_iox SHARED "src/psmx_iox_impl.cpp" "include/psmx_iox_impl.hpp")
else()
add_library(psmx_iox OBJECT "src/psmx_iox_impl.cpp" "include/psmx_iox_impl.hpp")
Expand All @@ -35,7 +35,7 @@ target_include_directories(psmx_iox PRIVATE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")

target_link_libraries(psmx_iox PRIVATE iceoryx_hoofs::iceoryx_hoofs iceoryx_posh::iceoryx_posh)
if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
target_link_libraries(psmx_iox PRIVATE ddsc)
endif()

Expand Down
4 changes: 2 additions & 2 deletions src/security/builtin_plugins/access_control/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ set(private_headers
src/access_control.h
../include/ac_tokens.h)

if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
add_library(dds_security_ac SHARED ${sources} ${private_headers})
else()
add_library(dds_security_ac OBJECT ${sources} ${private_headers})
Expand All @@ -38,7 +38,7 @@ generate_export_header(
)

target_link_libraries(dds_security_ac PRIVATE security_openssl)
if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
target_link_libraries(dds_security_ac PUBLIC ddsc)
endif()
target_link_libraries(dds_security_ac PUBLIC OpenSSL::SSL)
Expand Down
4 changes: 2 additions & 2 deletions src/security/builtin_plugins/authentication/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set(private_headers
src/authentication.h
src/auth_utils.h)

if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
add_library(dds_security_auth SHARED ${sources} ${private_headers})
else()
add_library(dds_security_auth OBJECT ${sources} ${private_headers})
Expand All @@ -36,7 +36,7 @@ generate_export_header(
)

target_link_libraries(dds_security_auth PRIVATE security_openssl)
if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
target_link_libraries(dds_security_auth PUBLIC ddsc)
endif()
target_link_libraries(dds_security_auth PUBLIC OpenSSL::SSL)
Expand Down
4 changes: 2 additions & 2 deletions src/security/builtin_plugins/cryptographic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set(private_headers
src/cryptography.h
../include/crypto_tokens.h)

if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
add_library(dds_security_crypto SHARED ${sources} ${private_headers})
else()
add_library(dds_security_crypto OBJECT ${sources} ${private_headers})
Expand All @@ -44,7 +44,7 @@ generate_export_header(
)

target_link_libraries(dds_security_crypto PRIVATE security_openssl)
if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
target_link_libraries(dds_security_crypto PUBLIC ddsc)
endif()
target_link_libraries(dds_security_crypto PUBLIC OpenSSL::SSL)
Expand Down
12 changes: 4 additions & 8 deletions src/security/core/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ function(add_wrapper libname linklibs)
set(srcs_wrapper
"${CMAKE_CURRENT_LIST_DIR}/common/${libname}_wrapper.c"
"${CMAKE_CURRENT_LIST_DIR}/common/plugin_wrapper_msg_q.c")
if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
add_library("dds_security_${libname}_wrapper" SHARED "")
else()
add_library("dds_security_${libname}_wrapper" STATIC "")
add_library("dds_security_${libname}_wrapper")
if(NOT BUILD_SHARED_LIBS)
set_property(GLOBAL APPEND PROPERTY cdds_plugin_list dds_security_${libname}_wrapper)
set_property(GLOBAL PROPERTY dds_security_${libname}_wrapper_symbols
init_test_${libname}_wrapped finalize_test_${libname}_wrapped
Expand Down Expand Up @@ -79,8 +77,7 @@ function(add_wrapper libname linklibs)

target_link_libraries("dds_security_${libname}_wrapper" PRIVATE CycloneDDS::ucunit)
target_include_directories("dds_security_${libname}_wrapper" PRIVATE "${CUNIT_DIR}/include")

if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
if(BUILD_SHARED_LIBS)
target_link_libraries("dds_security_${libname}_wrapper" PUBLIC ddsc ${linklibs})
endif()

Expand Down Expand Up @@ -164,8 +161,7 @@ if(ENABLE_SSL AND OPENSSL_FOUND)
endif()
target_include_directories(cunit_security_core PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")

if(BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
else()
if(NOT BUILD_SHARED_LIBS)
install(TARGETS dds_security_authentication_wrapper EXPORT "${PROJECT_NAME}")
install(TARGETS dds_security_cryptography_wrapper EXPORT "${PROJECT_NAME}")
install(TARGETS dds_security_access_control_wrapper EXPORT "${PROJECT_NAME}")
Expand Down
9 changes: 2 additions & 7 deletions src/ucunit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
#
include (GenerateExportHeader)

if (BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
add_library(ucunit SHARED "")
else()
add_library(ucunit)
endif()
add_library(ucunit)
add_library(${PROJECT_NAME}::ucunit ALIAS ucunit)

set(srcs_ucunit
Expand Down Expand Up @@ -44,8 +40,7 @@ target_link_libraries(test_ucunit CycloneDDS::ucunit)

add_test(NAME ucunit COMMAND $<TARGET_FILE_DIR:test_ucunit>/test_ucunit)

if (BUILD_SHARED_LIBS OR NOT DEFINED BUILD_SHARED_LIBS)
else()
if (NOT BUILD_SHARED_LIBS)
install(
TARGETS ucunit
EXPORT "${PROJECT_NAME}"
Expand Down

0 comments on commit e5d4bd8

Please sign in to comment.