From 9a2ee310596d229e334b40c4cc37a253009cabf3 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 10 Sep 2020 17:45:45 +0200 Subject: [PATCH] CMake: Fix rpaths set for Qt internal apps like Designer qt_apply_rpaths takes into account properties like MACOSX_BUNDLE. This property might not yet be set when qt_internal_add_app is called, but later. To handle that, move the call of qt_apply_rpaths to qt_internal_finalize_app. As a result, the installed apps will have 2 rpaths, the $ORIGIN style relocatable one, and an absolute path one pointing to the Qt prefix/lib. The last one might be unnecessary. Fixes: QTBUG-86514 Change-Id: I25e0d695c78c8b5703e94c99cc2457f772721456 Reviewed-by: Joerg Bornemann --- cmake/QtAppHelpers.cmake | 8 ++++---- cmake/QtBuild.cmake | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cmake/QtAppHelpers.cmake b/cmake/QtAppHelpers.cmake index 845645a75e9..20edc41b0a1 100644 --- a/cmake/QtAppHelpers.cmake +++ b/cmake/QtAppHelpers.cmake @@ -40,10 +40,6 @@ function(qt_internal_add_app target) qt_internal_add_target_aliases("${target}") _qt_internal_apply_strict_cpp("${target}") - if(NOT arg_NO_INSTALL) - qt_apply_rpaths(TARGET "${target}" INSTALL_PATH "${INSTALL_BINDIR}" RELATIVE_RPATH) - endif() - # To mimic the default behaviors of qt_app.prf, we by default enable GUI Windows applications, # but don't enable macOS bundles. # Bundles are enabled in a separate set_target_properties call if an Info.plist file @@ -99,4 +95,8 @@ function(qt_internal_finalize_app target) if(WIN32) qt6_generate_win32_rc_file("${target}") endif() + + # Rpaths need to be applied in the finalizer, because the MACOSX_BUNDLE property might be + # set after a qt_internal_add_app call. + qt_apply_rpaths(TARGET "${target}" INSTALL_PATH "${INSTALL_BINDIR}" RELATIVE_RPATH) endfunction() diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 27fe8d4226d..92b4e7e4002 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -247,6 +247,15 @@ set(CMAKE_INSTALL_RPATH "" CACHE STRING "RPATH for installed binaries") # add the automatically determined parts of the RPATH # which point to directories outside the build tree to the install RPATH +# +# TODO: Do we really want to use this option for official packages? Perhaps make it configurable +# or remove it? This causes final installed binaries to contain an absolute path RPATH pointing +# to ${CMAKE_INSTALL_PREFIX}/lib, which on the CI would be something like +# /Users/qt/work/install/lib. +# It doesn't seem necessary to me, given that qt_apply_rpaths already applies $ORIGIN-style +# relocatable paths, but maybe i'm missing something, because the original commit that added the +# option mentions it's needed in some cross-compilation scenario for program binaries that +# link against QtCore. set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) function(qt_setup_tool_path_command)