From a68201b181fb883bc1aa6dfd3e70ffffe5900cc8 Mon Sep 17 00:00:00 2001 From: autoantwort <41973254+autoantwort@users.noreply.github.com> Date: Sat, 27 Jul 2024 10:13:32 +0200 Subject: [PATCH] [vcpkg-scripts] z_vcpkg_fixup_macho_rpath_in_dir: Call install_name_tool only once (#39995) --- scripts/cmake/z_vcpkg_fixup_rpath_macho.cmake | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/cmake/z_vcpkg_fixup_rpath_macho.cmake b/scripts/cmake/z_vcpkg_fixup_rpath_macho.cmake index cd2bd785370898..f0986f0208f498 100644 --- a/scripts/cmake/z_vcpkg_fixup_rpath_macho.cmake +++ b/scripts/cmake/z_vcpkg_fixup_rpath_macho.cmake @@ -110,14 +110,14 @@ function(z_vcpkg_fixup_macho_rpath_in_dir) OUTPUT_QUIET ERROR_VARIABLE set_id_error ) - message(STATUS "Set install name id of '${macho_file}' (To '@rpath/${macho_file_name}')") + message(STATUS "Set install name id of '${macho_file}' to '@rpath/${macho_file_name}'") if(NOT "${set_id_error}" STREQUAL "") message(WARNING "Couldn't adjust install name of '${macho_file}': ${set_id_error}") continue() endif() endif() - # Clear all existing rpaths + # List all existing rpaths execute_process( COMMAND "${otool_cmd}" -l "${macho_file}" OUTPUT_VARIABLE get_rpath_ov @@ -132,18 +132,23 @@ function(z_vcpkg_fixup_macho_rpath_in_dir) string(REGEX MATCHALL "rpath [^\n]+" get_rpath_ov "${get_rpath_ov}") string(REGEX REPLACE "rpath " "" rpath_list "${get_rpath_ov}") + list(FIND rpath_list "${new_rpath}" has_new_rpath) + if(NOT has_new_rpath EQUAL -1) + list(REMOVE_AT rpath_list ${has_new_rpath}) + set(rpath_args) + else() + set(rpath_args -add_rpath "${new_rpath}") + endif() foreach(rpath IN LISTS rpath_list) - execute_process( - COMMAND "${install_name_tool_cmd}" -delete_rpath "${rpath}" "${macho_file}" - OUTPUT_QUIET - ERROR_VARIABLE delete_rpath_error - ) - message(STATUS "Remove RPATH from '${macho_file}' ('${rpath}')") + list(APPEND rpath_args "-delete_rpath" "${rpath}") endforeach() + if(rpath_args STREQUAL "") + continue() + endif() # Set the new rpath execute_process( - COMMAND "${install_name_tool_cmd}" -add_rpath "${new_rpath}" "${macho_file}" + COMMAND "${install_name_tool_cmd}" ${rpath_args} "${macho_file}" OUTPUT_QUIET ERROR_VARIABLE set_rpath_error ) @@ -153,7 +158,7 @@ function(z_vcpkg_fixup_macho_rpath_in_dir) continue() endif() - message(STATUS "Adjusted RPATH of '${macho_file}' (To '${new_rpath}')") + message(STATUS "Adjusted RPATH of '${macho_file}' to '${new_rpath}'") endforeach() endforeach() endfunction()