Skip to content

Commit

Permalink
Move DL fatal message
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Aug 25, 2023
1 parent ac97ec5 commit 6589a88
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cmake/GzRelocatableBinaries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,12 @@ macro(gz_add_get_install_prefix_impl)
"gz_add_get_install_prefix_impl: missing parameter OVERRIDE_INSTALL_PREFIX_ENV_VARIABLE")
endif()


if(NOT TARGET ${PROJECT_LIBRARY_TARGET_NAME})
message(FATAL_ERROR
"Target ${PROJECT_LIBRARY_TARGET_NAME} required by gz_add_get_install_prefix_impl\n"
"does not exist.")
endif()

if(NOT TARGET ${DL_TARGET})
message(FATAL_ERROR
"gz_add_get_install_prefix_impl called without DL_TARGET defined,\n"
"please add gz_find_package(DL) if you want to use gz_add_get_install_prefix_impl.")
endif()

get_target_property(target_type ${PROJECT_LIBRARY_TARGET_NAME} TYPE)
if(NOT (target_type STREQUAL "STATIC_LIBRARY" OR target_type STREQUAL "MODULE_LIBRARY" OR target_type STREQUAL "SHARED_LIBRARY"))
message(FATAL_ERROR "gz_add_get_install_prefix_impl: library ${_library} is of unsupported type ${target_type}")
Expand Down Expand Up @@ -208,7 +201,16 @@ 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)
if(NOT TARGET ${DL_TARGET})
message(FATAL_ERROR
"gz_add_get_install_prefix_impl called without DL_TARGET defined,\n"
"please add gz_find_package(DL) if you want to use gz_add_get_install_prefix_impl.")
endif()

# Link DL_TARGET that provides dladdr
target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME} PRIVATE ${DL_TARGET})
endif()

endmacro()

0 comments on commit 6589a88

Please sign in to comment.