From aeee37490ac0be468b61dba3dbc456dfb4fa839f Mon Sep 17 00:00:00 2001 From: cold-brewed <47337035+cold-brewed@users.noreply.github.com> Date: Wed, 31 Aug 2022 14:59:29 -0400 Subject: [PATCH] macOS: Add Vulkan support via MoltenVK (#2650) * macOS: Add the ability to build with and bundle MoltenVK for Vulkan support * macOS: Add cmake variable for RPATH as needed by macports moltenvk lib * macOS: Change minimum macOS target for vulkan builds Co-authored-by: cold-brewed --- CMakeLists.txt | 3 +++ src/CMakeLists.txt | 12 ++++++++++-- src/qt/CMakeLists.txt | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89495234d..4e49ac784 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,6 +165,9 @@ cmake_dependent_option(XL24 "ATI VGA Wonder XL24 (ATI-28800-6)" # Ditto but for Qt if(QT) option(USE_QT6 "Use Qt6 instead of Qt5" OFF) + if(APPLE) + option(MOLTENVK "Use MoltenVK libraries for Vulkan support on macOS. Requires a Vulkan-enabled QT." OFF) + endif() endif() # Determine the build type diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 428d5b521..01de9a473 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,6 +14,9 @@ # Copyright 2020-2022 David Hrdlička. # Copyright 2021 dob205. # +if(APPLE) + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +endif() add_executable(86Box 86box.c config.c log.c random.c timer.c io.c acpi.c apm.c dma.c ddma.c discord.c nmi.c pic.c pit.c pit_fast.c port_6x.c port_92.c ppi.c pci.c @@ -83,11 +86,16 @@ if(APPLE) # Force using the newest library if it's installed by homebrew set(CMAKE_FIND_FRAMEWORK LAST) - # setting our compilation target to macOS 10.15 Catalina if targetting Qt6, macOS 10.13 High Sierra otherwise + # setting our compilation target to macOS 10.15 Catalina if targeting Qt6, + # macOS 10.14 Mojave for vulkan support, 10.13 High Sierra otherwise if (USE_QT6) set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15") else() - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13") + if(MOLTENVK) + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14") + else() + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13") + endif() endif() endif() diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 6a4b74bd0..0b7ac7092 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -209,6 +209,18 @@ endif() if (APPLE) target_sources(ui PRIVATE macos_event_filter.mm) + if(MOLTENVK) + find_path(MOLTENVK_INCLUDE "vulkan/vulkan.h" PATHS "/opt/homebrew/opt/molten-vk/libexec/include" "/usr/local/opt/molten-vk/libexec/include" ${MOLTENVK_INCLUDE_DIR}) + if (NOT MOLTENVK_INCLUDE) + message(FATAL_ERROR "Could not find vulkan/vulkan.h. If the headers are installed please use -DMOLTENVK_INCLUDE_DIR=/path/to/headers") + endif() + target_include_directories(ui PRIVATE ${MOLTENVK_INCLUDE}) + find_library(MOLTENVK_LIB MoltenVK) + if (NOT MOLTENVK_LIB) + message(FATAL_ERROR "Could not find MoltenVK library") + endif() + target_link_libraries(ui PRIVATE "${MOLTENVK_LIB}") + endif() endif() if (WIN32) @@ -285,6 +297,7 @@ if (APPLE AND CMAKE_MACOSX_BUNDLE) set(prefix "86Box.app/Contents") set(INSTALL_RUNTIME_DIR "${prefix}/MacOS") set(INSTALL_CMAKE_DIR "${prefix}/Resources") + set(INSTALL_LIB_DIR "${prefix}/Frameworks") # using the install_qt5_plugin to add Qt plugins into the macOS app bundle install_qt5_plugin("Qt${QT_MAJOR}::QCocoaIntegrationPlugin" QT_PLUGINS ${prefix}) @@ -317,6 +330,16 @@ if (APPLE AND CMAKE_MACOSX_BUNDLE) COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath \"@executable_path/../Frameworks/\" \"\${CMAKE_INSTALL_PREFIX_ABSOLUTE}/${INSTALL_RUNTIME_DIR}/86Box\") ") + if(MOLTENVK) + install(CODE " + execute_process( + COMMAND bash -c \"set -e + echo \\\"-- Creating vulkan dylib symlink for QT (libVulkan.dylib -> libMoltenVK.dylib)\\\" + cd \${CMAKE_INSTALL_PREFIX_ABSOLUTE}/${INSTALL_LIB_DIR} + ln -sf libMoltenVK.dylib libVulkan.dylib + \") + ") + endif() endif() if (UNIX AND NOT APPLE AND NOT HAIKU)