From bb25829dbc371bda73e3b49a5d3b62d575f22e21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Mon, 7 Feb 2022 20:25:31 +0100 Subject: [PATCH] Try to build a static build on MSYS2 --- src/CMakeLists.txt | 115 +++++++++++++++++------------------------- src/qt/CMakeLists.txt | 17 +++++++ 2 files changed, 62 insertions(+), 70 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0a9fc03a1..00719e301 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -79,25 +79,6 @@ if(APPLE) endif() endif() -if(QT) - set(CMAKE_CXX_STANDARD 17) - set(CMAKE_CXX_STANDARD_REQUIRED ON) - set(CMAKE_CXX_EXTENSIONS OFF) - if (USE_QT6) - set(QT_MAJOR 6) - else() - set(QT_MAJOR 5) - endif() - - # if we want to use qt5-static to eliminate need for bundling qt dlls (windows) - #set(QT_STATIC ON) - # needed to build with qt5-static if both qt5 and qt5-static are installed - #set(CMAKE_PREFIX_PATH "path/to/qt5-static") - - find_package(Qt${QT_MAJOR} COMPONENTS Core Widgets OpenGL REQUIRED) - find_package(Qt${QT_MAJOR}LinguistTools REQUIRED) -endif() - find_package(Freetype REQUIRED) include_directories(${FREETYPE_INCLUDE_DIRS}) if(APPLE) @@ -174,13 +155,6 @@ 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) @@ -201,55 +175,56 @@ endmacro() # Install our dependencies to the macOS bundle if(APPLE) - if (NOT QT) + 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() - - 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}) - 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}\")") - endif() endif() diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 020a60cbe..8aeb91a6b 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -3,8 +3,25 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +if (USE_QT6) + set(QT_MAJOR 6) +else() + set(QT_MAJOR 5) +endif() + +set(QT_STATIC ${STATIC_BUILD}) + +if(QT_STATIC AND MINGW) + set(CMAKE_PREFIX_PATH "$ENV{MSYSTEM_PREFIX}/qt5-static") +endif() find_package(Threads REQUIRED) +find_package(Qt${QT_MAJOR} COMPONENTS Core Widgets OpenGL REQUIRED) +find_package(Qt${QT_MAJOR}LinguistTools REQUIRED) add_library(plat STATIC qt.c