From 6589a88b90a40f13f6572edc4849fbfbc475bc59 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Fri, 25 Aug 2023 15:20:50 +0000 Subject: [PATCH 1/2] Move DL fatal message Signed-off-by: Michael Carroll --- cmake/GzRelocatableBinaries.cmake | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cmake/GzRelocatableBinaries.cmake b/cmake/GzRelocatableBinaries.cmake index 36986b45..f4f64c6f 100644 --- a/cmake/GzRelocatableBinaries.cmake +++ b/cmake/GzRelocatableBinaries.cmake @@ -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}") @@ -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() From 89b29acfa02e6933fb306c7bfe48e8b96157d524 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Fri, 25 Aug 2023 15:32:30 +0000 Subject: [PATCH 2/2] Move error location Signed-off-by: Michael Carroll --- cmake/GzRelocatableBinaries.cmake | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmake/GzRelocatableBinaries.cmake b/cmake/GzRelocatableBinaries.cmake index df46239e..3b51fc55 100644 --- a/cmake/GzRelocatableBinaries.cmake +++ b/cmake/GzRelocatableBinaries.cmake @@ -93,6 +93,12 @@ macro(gz_add_get_install_prefix_impl) 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) + 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() + # 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 $ file(GENERATE OUTPUT "${gz_add_get_install_prefix_impl_GENERATED_CPP}" @@ -204,12 +210,6 @@ endif() # 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()