From 7d7826d7a58b7543078095a05821af23ccb87130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Mon, 10 Jan 2022 22:45:52 +0100 Subject: [PATCH 1/7] Set static build properly on non-Windows vcpkg targets --- CMakeLists.txt | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da97bc03d..8df5d4378 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,26 +32,26 @@ include(CPack) include(CMakeDependentOption) # Basic build options -if(WIN32) - if(VCPKG_TOOLCHAIN) - # For vcpkg builds we have to respect the linking method used by the - # specified triplet. - set(NO_STATIC_OPTION ON) - if(VCPKG_TARGET_TRIPLET MATCHES "-windows-static$") - # `-static` triplet, use static linking - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - set(STATIC_BUILD ON) - elseif(VCPKG_TARGET_TRIPLET MATCHES "-windows-static-md$") - # `-static-md` triplet, use static linking with dynamic CRT - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") - set(STATIC_BUILD ON) - elseif() - # Regular triplet, use dynamic linking - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") - set(STATIC_BUILD OFF) - endif() +if(VCPKG_TOOLCHAIN) + # For vcpkg builds we have to respect the linking method used by the + # specified triplet. + set(NO_STATIC_OPTION ON) + if(VCPKG_TARGET_TRIPLET MATCHES "-static$") + # `-static` triplet, use static linking + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + set(STATIC_BUILD ON) + elseif(VCPKG_TARGET_TRIPLET MATCHES "-static-md$") + # `-static-md` triplet, use static linking with dynamic CRT + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + set(STATIC_BUILD ON) + elseif() + # Regular triplet, use dynamic linking + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + set(STATIC_BUILD OFF) endif() +endif() +if(WIN32) # Prefer static builds on Windows set(PREFER_STATIC ON) From 3305063f55263d7915e2193493ce5fc36ee47fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Thu, 13 Jan 2022 03:01:15 +0100 Subject: [PATCH 2/7] Add options to discover munt and slirp locally --- src/network/CMakeLists.txt | 13 +++++++++++-- src/sound/CMakeLists.txt | 13 +++++++++++-- src/win/CMakeLists.txt | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index 434daa407..5cfa87d91 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -16,5 +16,14 @@ add_library(net OBJECT network.c net_pcap.c net_slirp.c net_dp8390.c net_3c503.c net_ne2000.c net_pcnet.c net_wd8003.c net_plip.c) -add_subdirectory(slirp) -target_link_libraries(86Box slirp) \ No newline at end of file +option(SLIRP_EXTERNAL "Link against the system-provided libslirp library" OFF) +mark_as_advanced(SLIRP_EXTERNAL) + +if(SLIRP_EXTERNAL) + find_package(PkgConfig REQUIRED) + pkg_check_modules(SLIRP REQUIRED IMPORTED_TARGET slirp) + target_link_libraries(86Box PkgConfig::SLIRP) +else() + add_subdirectory(slirp) + target_link_libraries(86Box slirp) +endif() \ No newline at end of file diff --git a/src/sound/CMakeLists.txt b/src/sound/CMakeLists.txt index 464e5c45a..e815d7329 100644 --- a/src/sound/CMakeLists.txt +++ b/src/sound/CMakeLists.txt @@ -33,8 +33,17 @@ if(MUNT) target_compile_definitions(snd PRIVATE USE_MUNT) target_sources(snd PRIVATE midi_mt32.c) - add_subdirectory(munt) - target_link_libraries(86Box mt32emu) + option(MUNT_EXTERNAL "Link against the system-provided MUNT library" OFF) + mark_as_advanced(MUNT_EXTERNAL) + + if(MUNT_EXTERNAL) + find_package(PkgConfig REQUIRED) + pkg_check_modules(MT32EMU REQUIRED IMPORTED_TARGET mt32emu) + target_link_libraries(86Box PkgConfig::MT32EMU) + else() + add_subdirectory(munt) + target_link_libraries(86Box mt32emu) + endif() endif() if(PAS16) diff --git a/src/win/CMakeLists.txt b/src/win/CMakeLists.txt index 0e8300946..b12d8523b 100644 --- a/src/win/CMakeLists.txt +++ b/src/win/CMakeLists.txt @@ -54,4 +54,4 @@ else() endif() target_link_libraries(86Box advapi32 comctl32 comdlg32 gdi32 shell32 iphlpapi - dxguid imm32 hid setupapi uxtheme version winmm psapi) + dxguid imm32 hid setupapi uxtheme version winmm psapi ws2_32) From 7d758ea9cd7b05f3a54c131053a5efc4f0f456b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Thu, 13 Jan 2022 04:16:05 +0100 Subject: [PATCH 3/7] Prefer config mode for finding OpenAL --- CMakeLists.txt | 1 + src/CMakeLists.txt | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8df5d4378..a29e0bdd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,7 @@ if(WIN32) endif() set(CMAKE_CXX_STANDARD 11) +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON) # Optional features # diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 00719e301..17920c07a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -89,8 +89,12 @@ endif() if(OPENAL) find_package(OpenAL REQUIRED) - include_directories(${OPENAL_INCLUDE_DIR}) - target_link_libraries(86Box ${OPENAL_LIBRARY}) + if(TARGET OpenAL::OpenAL) + target_link_libraries(86Box OpenAL::OpenAL) + else() + include_directories(${OPENAL_INCLUDE_DIR}) + target_link_libraries(86Box ${OPENAL_LIBRARY}) + endif() endif() find_package(SDL2 REQUIRED) From d87962855358e313dca1738f0cb8b98b60fd2626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Thu, 13 Jan 2022 04:17:30 +0100 Subject: [PATCH 4/7] Use `fixup_bundle` on Windows as well --- src/CMakeLists.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 17920c07a..c4e62ff8d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -179,7 +179,7 @@ endmacro() # Install our dependencies to the macOS bundle if(APPLE) - if (QT) + if(QT) set(prefix "86Box.app/Contents") set(INSTALL_RUNTIME_DIR "${prefix}/MacOS") set(INSTALL_CMAKE_DIR "${prefix}/Resources") @@ -229,6 +229,7 @@ if(APPLE) get_filename_component(CMAKE_INSTALL_PREFIX_ABSOLUTE \${CMAKE_INSTALL_PREFIX} ABSOLUTE) fixup_bundle(\"\${CMAKE_INSTALL_PREFIX_ABSOLUTE}/86Box.app\" \"\" \"\")" COMPONENT Runtime) + endif() endif() @@ -237,6 +238,17 @@ if(VCPKG_TOOLCHAIN) x_vcpkg_install_local_dependencies(TARGETS 86Box DESTINATION ".") endif() + +# Install other dependencies +if(WIN32) + install(CODE " + include(BundleUtilities) + get_filename_component(CMAKE_INSTALL_PREFIX_ABSOLUTE \${CMAKE_INSTALL_PREFIX} ABSOLUTE) + fixup_bundle(\"\${CMAKE_INSTALL_PREFIX_ABSOLUTE}/$\" \"\" \"\")" + COMPONENT Runtime) +endif() + + # Install the PDB file on Windows builds if(MSVC) # CMake fully supports PDB files on MSVC-compatible compilers From 5061d6c2751ec5561b0397ca4f97a7572a2561bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Mon, 7 Feb 2022 20:37:10 +0100 Subject: [PATCH 5/7] Futureproof the QT static path --- src/qt/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/CMakeLists.txt b/src/qt/CMakeLists.txt index 8aeb91a6b..9cedb83a2 100644 --- a/src/qt/CMakeLists.txt +++ b/src/qt/CMakeLists.txt @@ -16,7 +16,7 @@ endif() set(QT_STATIC ${STATIC_BUILD}) if(QT_STATIC AND MINGW) - set(CMAKE_PREFIX_PATH "$ENV{MSYSTEM_PREFIX}/qt5-static") + set(CMAKE_PREFIX_PATH "$ENV{MSYSTEM_PREFIX}/qt${QT_MAJOR}-static") endif() find_package(Threads REQUIRED) From b21d5b5a43a0104e829501084d494c9ac92d3f49 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Tue, 8 Feb 2022 01:52:02 +0600 Subject: [PATCH 6/7] Add MT-32 LCD message display support in the status bar --- src/include/86box/ui.h | 1 + src/qt/qt_ui.cpp | 10 ++++++++-- src/sound/midi_mt32.c | 16 +++++++++++++++- src/win/win_stbar.c | 6 ++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/include/86box/ui.h b/src/include/86box/ui.h index 256ae6002..61e251eeb 100644 --- a/src/include/86box/ui.h +++ b/src/include/86box/ui.h @@ -74,6 +74,7 @@ extern void ui_sb_update_icon_state(int tag, int active); extern void ui_sb_set_text_w(wchar_t *wstr); extern void ui_sb_set_text(char *str); extern void ui_sb_bugui(char *str); +extern void ui_sb_mt32lcd(char *str); #ifdef __cplusplus } diff --git a/src/qt/qt_ui.cpp b/src/qt/qt_ui.cpp index 3e71d13d9..c9f5c5451 100644 --- a/src/qt/qt_ui.cpp +++ b/src/qt/qt_ui.cpp @@ -28,7 +28,7 @@ MainWindow* main_window = nullptr; -static QString sb_text, sb_buguitext; +static QString sb_text, sb_buguitext, sb_mt32lcdtext; extern "C" { @@ -99,7 +99,13 @@ int ui_msgbox(int flags, void *message) { } void ui_sb_update_text() { - emit main_window->statusBarMessage(sb_text.isEmpty() ? sb_buguitext : sb_text); + emit main_window->statusBarMessage( !sb_mt32lcdtext.isEmpty() ? sb_mt32lcdtext : sb_text.isEmpty() ? sb_buguitext : sb_text); +} + +void ui_sb_mt32lcd(char* str) +{ + sb_mt32lcdtext = QString(str); + ui_sb_update_text(); } void ui_sb_set_text_w(wchar_t *wstr) { diff --git a/src/sound/midi_mt32.c b/src/sound/midi_mt32.c index 595023d52..6b59cf87f 100644 --- a/src/sound/midi_mt32.c +++ b/src/sound/midi_mt32.c @@ -9,6 +9,7 @@ #include <86box/mem.h> #include <86box/rom.h> #include <86box/plat.h> +#include <86box/ui.h> #include <86box/sound.h> #include <86box/midi.h> @@ -18,6 +19,19 @@ extern void givealbuffer_midi(void *buf, uint32_t size); extern void al_set_midi(int freq, int buf_size); #endif +static void display_mt32_message(void *instance_data, const char *message) +{ + int sz = 0; + char* ui_msg = NULL; + + sz = snprintf(NULL, 0, "MT-32: %s", message); + ui_msg = calloc(sz + 1, 1); + if (ui_msg) + { + snprintf(ui_msg, sz, "MT-32: %s", message); + ui_sb_mt32lcd(ui_msg); + } +} static const mt32emu_report_handler_i_v0 handler_v0 = { /** Returns the actual interface version ID */ NULL, //mt32emu_report_handler_version (*getVersionID)(mt32emu_report_handler_i i); @@ -28,7 +42,7 @@ static const mt32emu_report_handler_i_v0 handler_v0 = { NULL, //void (*onErrorControlROM)(void *instance_data); NULL, //void (*onErrorPCMROM)(void *instance_data); /** Callback for reporting about displaying a new custom message on LCD */ - NULL, //void (*showLCDMessage)(void *instance_data, const char *message); + display_mt32_message, //void (*showLCDMessage)(void *instance_data, const char *message); /** Callback for reporting actual processing of a MIDI message */ NULL, //void (*onMIDIMessagePlayed)(void *instance_data); /** diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index 29985aaf3..bf2830456 100644 --- a/src/win/win_stbar.c +++ b/src/win/win_stbar.c @@ -1073,3 +1073,9 @@ ui_sb_bugui(char *str) memset(sb_bugtext, 0x00, sizeof(sb_bugtext)); ui_sb_update_text(); } + +/* API */ +void +ui_sb_mt32lcd(char* str) +{ +} 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 7/7] 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)