From 17604f15a1a1fe4199449150675c2613874ae4a5 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Wed, 20 Jun 2018 15:59:41 -0700 Subject: [PATCH] CMake+macOS: Make sure we're using the right Qt tools. Qt5CoreConfigExtras.cmake sets Qt5::qmake. Use it to find the corresponding path to macdeployqt and use those in osx-app.sh. Change-Id: I2e67f0126e272fc95d40476b9bfc83ab38d73cee Reviewed-on: https://code.wireshark.org/review/28359 Reviewed-by: Gerald Combs Petri-Dish: Gerald Combs Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- CMakeLists.txt | 74 ++++++++++++++++++---------------- packaging/macosx/osx-app.sh.in | 4 +- 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6a59543fb..c636f271b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1211,6 +1211,30 @@ if (Qt5Widgets_FOUND) # Squelch moc verbose "nothing to do" output set(MOC_OPTIONS -nn) endif() + + # CMake uses qmake to find Qt4. It relies on Qt's CMake modules + # to find Qt5. This means that we can't assume that the qmake + # in our PATH is the correct one. We can fetch qmake's location + # from Qt5::qmake, which is is defined in Qt5CoreConfigExtras.cmake. + get_target_property(QT_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION) + get_filename_component(_qt_bin_path "${QT_QMAKE_EXECUTABLE}" DIRECTORY) + set(QT_BIN_PATH "${_qt_bin_path}" CACHE INTERNAL + "Path to qmake, macdeployqt, windeployqt, and other Qt utilities." + ) + # Use qmake to find windeployqt and macdeployqt. Ideally one of + # the modules in ${QTDIR}/lib/cmake would do this for us. + if(WIN32) + find_program(QT_WINDEPLOYQT_EXECUTABLE windeployqt + HINTS "${QT_BIN_PATH}" + DOC "Path to the windeployqt utility." + ) + elseif(APPLE) + find_program(QT_MACDEPLOYQT_EXECUTABLE macdeployqt + HINTS "${QT_BIN_PATH}" + DOC "Path to the macdeployqt utility." + ) + endif() + endif() if(ENABLE_CHECKHF_CONFLICT) @@ -2171,41 +2195,23 @@ if(BUILD_wireshark AND QT_FOUND) BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR} ) - if(WIN32 AND Qt5Core_FOUND) - # Use windeployqt to copy our required DLLs to the run path. - # Ideally one of the modules in ${QTDIR}/lib/cmake would expose - # the path to windeployqt. For that matter having a reliable - # path to qmake would be *amazingly convenient*. We don't have - # either of those so we try to discover the path via Qt5Core. - # http://stackoverflow.com/questions/24650936/qt5-with-cmake-how-to-find-qt-translations-dir - - get_target_property(_qmake_location Qt5::qmake IMPORTED_LOCATION) - get_filename_component(_qt_bin_path "${_qmake_location}" DIRECTORY) - find_program(QT_WINDEPLOYQT_EXECUTABLE windeployqt - HINTS "${_qmake_location}" - DOC "Path to the windeployqt utility." + if(QT_WINDEPLOYQT_EXECUTABLE) + add_custom_target(copy_qt_dlls ALL) + set_target_properties(copy_qt_dlls PROPERTIES FOLDER "Copy Tasks") + # Will we ever need to use --debug? Windeployqt seems to + # be smart enough to copy debug DLLs when needed. + add_custom_command(TARGET copy_qt_dlls + POST_BUILD + COMMAND set "PATH=${QT_BIN_PATH};%PATH%" + COMMAND "${QT_WINDEPLOYQT_EXECUTABLE}" + $<$:--debug> + $<$>:--release> + --no-compiler-runtime + --verbose 10 + "$" ) - if(QT_WINDEPLOYQT_EXECUTABLE) - set(QT_BIN_PATH "${_qt_bin_path}" CACHE INTERNAL - "Path to qmake, windeployqt, and other Qt utilities." - ) - add_custom_target(copy_qt_dlls ALL) - set_target_properties(copy_qt_dlls PROPERTIES FOLDER "Copy Tasks") - # Will we ever need to use --debug? Windeployqt seems to - # be smart enough to copy debug DLLs when needed. - add_custom_command(TARGET copy_qt_dlls - POST_BUILD - COMMAND set "PATH=${QT_BIN_PATH};%PATH%" - COMMAND "${QT_WINDEPLOYQT_EXECUTABLE}" - $<$:--debug> - $<$>:--release> - --no-compiler-runtime - --verbose 10 - "$" - ) - add_dependencies(copy_qt_dlls wireshark) - endif() - endif(WIN32 AND Qt5Core_FOUND) + add_dependencies(copy_qt_dlls wireshark) + endif(QT_WINDEPLOYQT_EXECUTABLE) endif() # Common properties for CLI executables diff --git a/packaging/macosx/osx-app.sh.in b/packaging/macosx/osx-app.sh.in index 1c92099eef..512036336b 100755 --- a/packaging/macosx/osx-app.sh.in +++ b/packaging/macosx/osx-app.sh.in @@ -106,7 +106,7 @@ if [ ! -d "$bundle" ] ; then exit 1 fi -qt_frameworks_dir=$( qmake -query QT_INSTALL_LIBS ) +qt_frameworks_dir=$( "@QT_QMAKE_EXECUTABLE@" -query QT_INSTALL_LIBS ) if [ ! -d "$qt_frameworks_dir" ] ; then echo "Can't find the Qt frameworks directory" >&2 exit 1 @@ -205,7 +205,7 @@ fi # This may not work on Qt 5.5.0 or 5.5.1: # https://bugreports.qt.io/browse/QTBUG-47868 # -macdeployqt "$bundle" -no-strip -verbose=2 || exit 1 +"@QT_MACDEPLOYQT_EXECUTABLE@" "$bundle" -no-strip -verbose=2 || exit 1 # # The build process added to the Wireshark binary an rpath entry