From 7fdeff18519ff6c4e3295d1c1f9a676b99716efa Mon Sep 17 00:00:00 2001 From: ts-korhonen Date: Fri, 21 Jan 2022 19:08:58 +0200 Subject: [PATCH] qt: macos patches from dob205 --- cmake/llvm-macos-aarch64.cmake | 22 +++++++++ src/CMakeLists.txt | 86 +++++++++++++++++++++++++++------- src/mac/CMakeLists.txt | 5 +- 3 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 cmake/llvm-macos-aarch64.cmake diff --git a/cmake/llvm-macos-aarch64.cmake b/cmake/llvm-macos-aarch64.cmake new file mode 100644 index 000000000..da9ccb449 --- /dev/null +++ b/cmake/llvm-macos-aarch64.cmake @@ -0,0 +1,22 @@ +# +# 86Box A hypervisor and IBM PC system emulator that specializes in +# running old operating systems and software designed for IBM +# PC systems and compatibles from 1981 through fairly recent +# system designs based on the PCI bus. +# +# This file is part of the 86Box distribution. +# +# CMake toolchain file defining Clang compiler flags +# for AArch64 (ARM64)-based Apple Silicon targets. +# +# Authors: David Hrdlička, +# dob205 +# +# Copyright 2021 David Hrdlička. +# Copyright 2022 dob205. +# + +string(APPEND CMAKE_C_FLAGS_INIT " -march=armv8.5-a+simd") +string(APPEND CMAKE_CXX_FLAGS_INIT " -march=armv8.5-a+simd") + +include(${CMAKE_CURRENT_LIST_DIR}/flags-gcc.cmake) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f8e55fcaa..9bed3bccc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -176,28 +176,78 @@ else() install(TARGETS 86Box) endif() +# prepare everything for Qt5 bundle creation +if (APPLE AND QT) + set(prefix "86Box.app/Contents") + set(INSTALL_RUNTIME_DIR "${prefix}/MacOS") + set(INSTALL_CMAKE_DIR "${prefix}/Resources") +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) - 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) + if (NOT QT) + 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() + + if(QT) + # 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}) + 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}") - if (QT) - # needed for Qt packaging - # get the macdeployqt path - get_target_property(_qmake_executable Qt${QT_MAJOR}::qmake IMPORTED_LOCATION) - get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY) - find_program(MACDEPLOYQT_EXECUTABLE macdeployqt HINTS "${_qt_bin_dir}") + # Note Mac specific extension .app + set(APPS "\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/86Box.app") - # excecute macdeployqt - add_custom_command(TARGET 86Box POST_BUILD - COMMAND "${MACDEPLOYQT_EXECUTABLE}" - "$/../.." - -always-overwrite - COMMENT "Running macdeployqt..." - ) + # 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() endif() diff --git a/src/mac/CMakeLists.txt b/src/mac/CMakeLists.txt index 91759690f..6682d5bcd 100644 --- a/src/mac/CMakeLists.txt +++ b/src/mac/CMakeLists.txt @@ -48,6 +48,7 @@ configure_file(Info.plist.in Info.plist @ONLY) set_target_properties(86Box PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/Info.plist) -#set(XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "YES") -#set(XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "-") +set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "-o linker-signed") +set(XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "YES") +set(XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "-") #set(XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS ${CMAKE_CURRENT_SOURCE_DIR}/mac/codesign/dev/app.entitlements) \ No newline at end of file