From ee998a71a49a0290a316c08ee0956205e19666b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Mon, 7 Feb 2022 21:08:28 +0100 Subject: [PATCH] Fix Qt on Mac bundle generation --- src/CMakeLists.txt | 75 +------------------------------------------ src/qt/CMakeLists.txt | 65 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 74 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c4e62ff8d..c5728721b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -159,79 +159,6 @@ else() install(TARGETS 86Box) endif() -# loads a macro to install Qt5 plugins on macOS -# based on https://stackoverflow.com/questions/35612687/cmake-macos-x-bundle-with-bundleutiliies-for-qt-application -macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var _prefix) - get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION) - if(EXISTS "${_qt_plugin_path}") - get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME) - get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH) - get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME) - set(_qt_plugin_dest "${_prefix}/PlugIns/${_qt_plugin_type}") - install(FILES "${_qt_plugin_path}" - DESTINATION "${_qt_plugin_dest}") - set(${_qt_plugins_var} - "${${_qt_plugins_var}};\$ENV{DEST_DIR}\${CMAKE_INSTALL_PREFIX}/${_qt_plugin_dest}/${_qt_plugin_file}") - else() - message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found") - endif() -endmacro() - -# Install our dependencies to the macOS bundle -if(APPLE) - if(QT) - set(prefix "86Box.app/Contents") - set(INSTALL_RUNTIME_DIR "${prefix}/MacOS") - set(INSTALL_CMAKE_DIR "${prefix}/Resources") - - # using the install_qt5_plugin to add Qt plugins into the macOS app bundle - if (USE_QT6) - install_qt5_plugin("Qt6::QCocoaIntegrationPlugin" QT_PLUGINS ${prefix}) - else() - install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS ${prefix}) - install_qt5_plugin("Qt5::QMacStylePlugin" QT_PLUGINS ${prefix}) - install_qt5_plugin("Qt5::QICOPlugin" QT_PLUGINS ${prefix}) - install_qt5_plugin("Qt5::QICNSPlugin" QT_PLUGINS ${prefix}) - endif() - - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" - "[Paths]\nPlugins = ${_qt_plugin_dir}\n") - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" - DESTINATION "${INSTALL_CMAKE_DIR}") - - # Note Mac specific extension .app - set(APPS "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/86Box.app") - - # Directories to look for dependencies - set(DIRS "${CMAKE_BINARY_DIR}") - - # Path used for searching by FIND_XXX(), with appropriate suffixes added - if(CMAKE_PREFIX_PATH) - foreach(dir ${CMAKE_PREFIX_PATH}) - list(APPEND DIRS "${dir}/bin" "${dir}/lib") - endforeach() - endif() - - # Append Qt's lib folder which is two levels above Qt5Widgets_DIR - list(APPEND DIRS "${Qt5Widgets_DIR}/../..") - - include(InstallRequiredSystemLibraries) - - message(STATUS "APPS: ${APPS}") - message(STATUS "QT_PLUGINS: ${QT_PLUGINS}") - message(STATUS "DIRS: ${DIRS}") - - install(CODE "include(BundleUtilities) - fixup_bundle(\"${APPS}\" \"${QT_PLUGINS}\" \"${DIRS}\")") - else() - install(CODE " - include(BundleUtilities) - get_filename_component(CMAKE_INSTALL_PREFIX_ABSOLUTE \${CMAKE_INSTALL_PREFIX} ABSOLUTE) - fixup_bundle(\"\${CMAKE_INSTALL_PREFIX_ABSOLUTE}/86Box.app\" \"\" \"\")" - COMPONENT Runtime) - endif() -endif() - # Install our dependencies if using vcpkg if(VCPKG_TOOLCHAIN) @@ -240,7 +167,7 @@ endif() # Install other dependencies -if(WIN32) +if(WIN32 OR (APPLE AND NOT QT)) install(CODE " include(BundleUtilities) get_filename_component(CMAKE_INSTALL_PREFIX_ABSOLUTE \${CMAKE_INSTALL_PREFIX} ABSOLUTE) diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 9cedb83a2..643e7ece7 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -189,6 +189,71 @@ if (WIN32) qt_import_plugins(plat INCLUDE Qt${QT_MAJOR}::QWindowsIntegrationPlugin Qt${QT_MAJOR}::QICOPlugin QWindowsVistaStylePlugin) endif() +# loads a macro to install Qt5 plugins on macOS +# based on https://stackoverflow.com/questions/35612687/cmake-macos-x-bundle-with-bundleutiliies-for-qt-application +macro(install_qt5_plugin _qt_plugin_name _qt_plugins_var _prefix) + get_target_property(_qt_plugin_path "${_qt_plugin_name}" LOCATION) + if(EXISTS "${_qt_plugin_path}") + get_filename_component(_qt_plugin_file "${_qt_plugin_path}" NAME) + get_filename_component(_qt_plugin_type "${_qt_plugin_path}" PATH) + get_filename_component(_qt_plugin_type "${_qt_plugin_type}" NAME) + set(_qt_plugin_dest "${_prefix}/PlugIns/${_qt_plugin_type}") + install(FILES "${_qt_plugin_path}" + DESTINATION "${_qt_plugin_dest}") + set(${_qt_plugins_var} + "${${_qt_plugins_var}};\$ENV{DEST_DIR}\${CMAKE_INSTALL_PREFIX}/${_qt_plugin_dest}/${_qt_plugin_file}") + else() + message(FATAL_ERROR "QT plugin ${_qt_plugin_name} not found") + endif() +endmacro() + +if (APPLE AND CMAKE_MACOSX_BUNDLE) + set(prefix "$/Contents") + set(INSTALL_RUNTIME_DIR "${prefix}/MacOS") + set(INSTALL_CMAKE_DIR "${prefix}/Resources") + + # using the install_qt5_plugin to add Qt plugins into the macOS app bundle + if (USE_QT6) + install_qt5_plugin("Qt6::QCocoaIntegrationPlugin" QT_PLUGINS ${prefix}) + else() + install_qt5_plugin("Qt5::QCocoaIntegrationPlugin" QT_PLUGINS ${prefix}) + install_qt5_plugin("Qt5::QMacStylePlugin" QT_PLUGINS ${prefix}) + install_qt5_plugin("Qt5::QICOPlugin" QT_PLUGINS ${prefix}) + install_qt5_plugin("Qt5::QICNSPlugin" QT_PLUGINS ${prefix}) + endif() + + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" + "[Paths]\nPlugins = ${_qt_plugin_dir}\n") + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/qt.conf" + DESTINATION "${INSTALL_CMAKE_DIR}") + + # Note Mac specific extension .app + set(APPS "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/$") + + # Directories to look for dependencies + set(DIRS "${CMAKE_BINARY_DIR}") + + # Path used for searching by FIND_XXX(), with appropriate suffixes added + if(CMAKE_PREFIX_PATH) + foreach(dir ${CMAKE_PREFIX_PATH}) + list(APPEND DIRS "${dir}/bin" "${dir}/lib") + endforeach() + endif() + + # Append Qt's lib folder which is two levels above Qt5Widgets_DIR + list(APPEND DIRS "${Qt5Widgets_DIR}/../..") + + include(InstallRequiredSystemLibraries) + + message(STATUS "APPS: ${APPS}") + message(STATUS "QT_PLUGINS: ${QT_PLUGINS}") + message(STATUS "DIRS: ${DIRS}") + + install(CODE " + include(BundleUtilities) + fixup_bundle(\"${APPS}\" \"${QT_PLUGINS}\" \"${DIRS}\")") +endif() + if (UNIX AND NOT APPLE) find_package(X11 REQUIRED) target_link_libraries(ui PRIVATE X11::X11)