Skip to content

Commit

Permalink
Only link against DL in the case that it is needed (#380)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll authored Aug 25, 2023
1 parent ac97ec5 commit f47d611
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmake/GzRelocatableBinaries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ macro(gz_add_get_install_prefix_impl)

# Write cpp for shared or module library type
option(GZ_ENABLE_RELOCATABLE_INSTALL "If ON, enable the feature of providing a relocatable install prefix in shared library." OFF)

if ((target_type STREQUAL "MODULE_LIBRARY" OR target_type STREQUAL "SHARED_LIBRARY") AND GZ_ENABLE_RELOCATABLE_INSTALL)
# We can't query the LOCATION property of the target due to https://cmake.org/cmake/help/v3.25/policy/CMP0026.html
# We can only access the directory of the library at generation time via $<TARGET_FILE_DIR:tgt>
Expand Down Expand Up @@ -208,7 +209,10 @@ endif()
# Add cpp to library
target_sources(${PROJECT_LIBRARY_TARGET_NAME} PRIVATE ${gz_add_get_install_prefix_impl_GENERATED_CPP})

# Only link DL in the case that it is needed.
if ((target_type STREQUAL "MODULE_LIBRARY" OR target_type STREQUAL "SHARED_LIBRARY") AND GZ_ENABLE_RELOCATABLE_INSTALL)
# Link DL_TARGET that provides dladdr
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME} PRIVATE ${DL_TARGET})
endif()

endmacro()

0 comments on commit f47d611

Please sign in to comment.