From b60b7b4fcbecdc02a670c7d00e4e4828ba2ade35 Mon Sep 17 00:00:00 2001 From: Jonny Date: Wed, 21 Aug 2024 23:22:52 +0100 Subject: [PATCH 1/6] Use imported target for openal to simplify copying dll's --- cmake/Modules/FindOpenAL.cmake | 134 +++++++++++++++++++++++++++++++++ src/SFML/Audio/CMakeLists.txt | 4 +- 2 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 cmake/Modules/FindOpenAL.cmake diff --git a/cmake/Modules/FindOpenAL.cmake b/cmake/Modules/FindOpenAL.cmake new file mode 100644 index 000000000..7d1ccd522 --- /dev/null +++ b/cmake/Modules/FindOpenAL.cmake @@ -0,0 +1,134 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindOpenAL +---------- + +Finds Open Audio Library (OpenAL). + +Projects using this module should use ``#include "al.h"`` to include the OpenAL +header file, **not** ``#include ``. The reason for this is that the +latter is not entirely portable. Windows/Creative Labs does not by default put +their headers in ``AL/`` and macOS uses the convention ````. + +Hints +^^^^^ + +Environment variable ``$OPENALDIR`` can be used to set the prefix of OpenAL +installation to be found. + +By default on macOS, system framework is search first. In other words, +OpenAL is searched in the following order: + +1. System framework: ``/System/Library/Frameworks``, whose priority can be + changed via setting the :variable:`CMAKE_FIND_FRAMEWORK` variable. +2. Environment variable ``$OPENALDIR``. +3. System paths. +4. User-compiled framework: ``~/Library/Frameworks``. +5. Manually compiled framework: ``/Library/Frameworks``. +6. Add-on package: ``/opt``. + +IMPORTED Targets +^^^^^^^^^^^^^^^^ + +.. versionadded:: 3.25 + +This module defines the :prop_tgt:`IMPORTED` target: + +``OpenAL::OpenAL`` + The OpenAL library, if found. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module defines the following variables: + +``OPENAL_FOUND`` + If false, do not try to link to OpenAL +``OPENAL_INCLUDE_DIR`` + OpenAL include directory +``OPENAL_LIBRARY`` + Path to the OpenAL library +``OPENAL_VERSION_STRING`` + Human-readable string containing the version of OpenAL +#]=======================================================================] + +# For Windows, Creative Labs seems to have added a registry key for their +# OpenAL 1.1 installer. I have added that key to the list of search paths, +# however, the key looks like it could be a little fragile depending on +# if they decide to change the 1.00.0000 number for bug fix releases. +# Also, they seem to have laid down groundwork for multiple library platforms +# which puts the library in an extra subdirectory. Currently there is only +# Win32 and I have hardcoded that here. This may need to be adjusted as +# platforms are introduced. +# The OpenAL 1.0 installer doesn't seem to have a useful key I can use. +# I do not know if the Nvidia OpenAL SDK has a registry key. + +find_path(OPENAL_INCLUDE_DIR al.h + HINTS + ENV OPENALDIR + PATHS + ~/Library/Frameworks + /Library/Frameworks + /opt + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir] + PATH_SUFFIXES include/AL include/OpenAL include AL OpenAL + ) + +find_library(OPENAL_LIBRARY + NAMES OpenAL al openal OpenAL32 + HINTS + ENV OPENALDIR + PATHS + ~/Library/Frameworks + /Library/Frameworks + /opt + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Creative\ Labs\\OpenAL\ 1.1\ Software\ Development\ Kit\\1.00.0000;InstallDir] + PATH_SUFFIXES libx32 lib64 lib libs64 libs + ) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + OpenAL + REQUIRED_VARS OPENAL_LIBRARY OPENAL_INCLUDE_DIR + VERSION_VAR OPENAL_VERSION_STRING + ) + +mark_as_advanced(OPENAL_LIBRARY OPENAL_INCLUDE_DIR) + +if(OPENAL_INCLUDE_DIR AND OPENAL_LIBRARY) + if(NOT TARGET OpenAL::OpenAL) + if(EXISTS "${OPENAL_LIBRARY}") + if(WIN32) + get_filename_component(OPENAL_PATH ${OPENAL_LIBRARY} DIRECTORY) + add_library(OpenAL::OpenAL SHARED IMPORTED) + if (ARCH_x86) + set(DLL_PATH "${OPENAL_PATH}/../../bin/x86/openal32.dll") + elseif(ARCH_X64) + set(DLL_PATH "${OPENAL_PATH}/../../bin/x64/openal32.dll") + else() + set(DLL_PATH "${OPENAL_PATH}/../../bin/ARM64/openal32.dll") + endif() + set_target_properties(OpenAL::OpenAL PROPERTIES + IMPORTED_LOCATION "${DLL_PATH}" + IMPORTED_IMPLIB "${OPENAL_LIBRARY}") + elseif(APPLE) + find_file(OPENAL_FULL_PATH OpenAL OpenAL.tbd PATHS ${OPENAL_LIBRARY} REQUIRED) + add_library(OpenAL::OpenAL SHARED IMPORTED) + set_target_properties(OpenAL::OpenAL PROPERTIES + IMPORTED_LOCATION "${OPENAL_FULL_PATH}") + else() + add_library(OpenAL::OpenAL UNKNOWN IMPORTED) + set_target_properties(OpenAL::OpenAL PROPERTIES + IMPORTED_LOCATION "${OPENAL_LIBRARY}") + endif() + else() + add_library(OpenAL::OpenAL INTERFACE IMPORTED) + set_target_properties(OpenAL::OpenAL PROPERTIES + IMPORTED_LIBNAME "${OPENAL_LIBRARY}") + endif() + set_target_properties(OpenAL::OpenAL PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${OPENAL_INCLUDE_DIR}") + endif() +endif() \ No newline at end of file diff --git a/src/SFML/Audio/CMakeLists.txt b/src/SFML/Audio/CMakeLists.txt index d27dc6d54..8158365f6 100644 --- a/src/SFML/Audio/CMakeLists.txt +++ b/src/SFML/Audio/CMakeLists.txt @@ -68,7 +68,7 @@ elseif(SFML_OS_ANDROID) endif() # find external libraries -sfml_find_package(OpenAL INCLUDE "OPENAL_INCLUDE_DIR" LINK "OPENAL_LIBRARY") +find_package(OpenAL REQUIRED) sfml_find_package(VORBIS INCLUDE "VORBIS_INCLUDE_DIRS" LINK "VORBIS_LIBRARIES") sfml_find_package(FLAC INCLUDE "FLAC_INCLUDE_DIR" LINK "FLAC_LIBRARY") @@ -81,7 +81,7 @@ sfml_add_library(sfml-audio SOURCES ${SRC} ${CODECS_SRC}) # setup dependencies -target_link_libraries(sfml-audio PRIVATE OpenAL) +target_link_libraries(sfml-audio PRIVATE OpenAL::OpenAL) # minimp3 sources target_include_directories(sfml-audio SYSTEM PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/minimp3") From e16f895057d8c32e8f8a36a9f9f9296cf4f23f50 Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Mon, 2 Sep 2024 06:13:14 +0200 Subject: [PATCH 2/6] Add missing openal name --- cmake/Modules/FindOpenAL.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindOpenAL.cmake b/cmake/Modules/FindOpenAL.cmake index 7d1ccd522..aee19aade 100644 --- a/cmake/Modules/FindOpenAL.cmake +++ b/cmake/Modules/FindOpenAL.cmake @@ -77,7 +77,7 @@ find_path(OPENAL_INCLUDE_DIR al.h ) find_library(OPENAL_LIBRARY - NAMES OpenAL al openal OpenAL32 + NAMES OpenAL al openal OpenAL32 openal32 HINTS ENV OPENALDIR PATHS From 54c7edb2a0f4be537d5e476a4d548b6d26fe0070 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Tue, 10 Sep 2024 09:15:35 -0600 Subject: [PATCH 3/6] Update v2.6.2 changelog --- changelog.md | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 365e5aecd..22c11eb20 100644 --- a/changelog.md +++ b/changelog.md @@ -1,13 +1,34 @@ # Changelog -## Unreleased +## Unreleased SFML 2.6.2 ### General - Ensure GNUInstallDirs cache vars are included before first used (#2778, #2779) - [macOS] Fix incorrect variable expansion (#2780) -- Issue warning when trying to use UCRT MinGW with precompiled MSVCRT depenencies (#2821) -- Fix Nix pkg-config support +- Replace deprecated CMake command `exec_program` (#2888) +- Fix Doxygen Generation (#2986, #2812, #2813) +- [iOS] Use built-in iOS support for CMake (#3113) +- [Windows] Fix `SFML_USE_STATIC_STD_LIBS` behavior (#3131) +- [Windows] Add support for UCRT MinGW (#2289, #2821, #3054, #3115) +- [Windows] Add support for Windows ARM64 (#3111, #3176) +- Fix Nix pkg-config support (#2835) + +### Window + +**Bugfixes** + +- Fix joystickButton being used for Joystick(Dis)Connected event (#2957) +- [Windows] Close the clipboard if we fail to empty it (#3043) +- [Android] Remove use of deprecated `ALooper_pollAll` (#3181, #3189) +- [macOS] Fix how macOS fullscreen video modes are detected (#2300, #3151) + +### Graphics + +**Bugfixes** + +- [Windows] Fix MSVC warning about uninitialized `sf::Glyph` members (#2929) +- Prevent crash when setting empty uniform array (#3185, #3186) ### Audio From 5545df7290250cbe767a2705c8401d8f3c4f23a0 Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Mon, 16 Sep 2024 22:50:53 +0200 Subject: [PATCH 4/6] Use lazy loading for keyboard scancodes on macos (backport) --- changelog.md | 1 + src/SFML/Window/OSX/HIDInputManager.hpp | 1 + src/SFML/Window/OSX/HIDInputManager.mm | 23 +++++++++++++++++------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 22c11eb20..0e59b0e23 100644 --- a/changelog.md +++ b/changelog.md @@ -22,6 +22,7 @@ - [Windows] Close the clipboard if we fail to empty it (#3043) - [Android] Remove use of deprecated `ALooper_pollAll` (#3181, #3189) - [macOS] Fix how macOS fullscreen video modes are detected (#2300, #3151) +- [macOS] Prevent unnecessary macOS input monitoring permission prompts (#2843, #3235) ### Graphics diff --git a/src/SFML/Window/OSX/HIDInputManager.hpp b/src/SFML/Window/OSX/HIDInputManager.hpp index b17d566b5..75376b335 100644 --- a/src/SFML/Window/OSX/HIDInputManager.hpp +++ b/src/SFML/Window/OSX/HIDInputManager.hpp @@ -281,6 +281,7 @@ private: // Member data //////////////////////////////////////////////////////////// IOHIDManagerRef m_manager; ///< Underlying HID Manager + bool m_keysInitialized; ///< Has initializeKeyboard been called at least once? IOHIDElements m_keys[Keyboard::Scan::ScancodeCount]; ///< All the keys on any connected keyboard Keyboard::Scancode m_keyToScancodeMapping[Keyboard::KeyCount]; ///< Mapping from Key to Scancode Keyboard::Key m_scancodeToKeyMapping[Keyboard::Scan::ScancodeCount]; ///< Mapping from Scancode to Key diff --git a/src/SFML/Window/OSX/HIDInputManager.mm b/src/SFML/Window/OSX/HIDInputManager.mm index 6d31ae6b7..f3f7b3ab2 100644 --- a/src/SFML/Window/OSX/HIDInputManager.mm +++ b/src/SFML/Window/OSX/HIDInputManager.mm @@ -555,6 +555,13 @@ bool HIDInputManager::isKeyPressed(Keyboard::Key key) //////////////////////////////////////////////////////////// bool HIDInputManager::isKeyPressed(Keyboard::Scancode code) { + // Lazy load m_keys to prevent unnecessary macOS input monitoring permission requests + if (!m_keysInitialized) + { + initializeKeyboard(); + m_keysInitialized = true; + } + return (code != Keyboard::Scan::Unknown) && isPressed(m_keys[code]); } @@ -694,7 +701,8 @@ String HIDInputManager::getDescription(Keyboard::Scancode code) //////////////////////////////////////////////////////////// HIDInputManager::HIDInputManager() : -m_manager(0) +m_manager(0), +m_keysInitialized(false) { // Create an HID Manager reference m_manager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); @@ -708,7 +716,6 @@ m_manager(0) } // Build up our knownledge of the hardware - initializeKeyboard(); buildMappings(); // Register for notification on keyboard layout changes @@ -908,13 +915,17 @@ void HIDInputManager::freeUp() CFRelease(m_manager); m_manager = 0; - for (unsigned int i = 0; i < Keyboard::KeyCount; ++i) + if (m_keysInitialized) { - for (IOHIDElements::iterator it = m_keys[i].begin(); it != m_keys[i].end(); ++it) - CFRelease(*it); + for (unsigned int i = 0; i < Keyboard::KeyCount; ++i) + { + for (IOHIDElements::iterator it = m_keys[i].begin(); it != m_keys[i].end(); ++it) + CFRelease(*it); - m_keys[i].clear(); + m_keys[i].clear(); + } } + m_keysInitialized = false; } From 02fe28f35b8e23edcb8012462d41caecfc41ce52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20D=C3=BCrrenberger?= Date: Thu, 19 Sep 2024 19:49:09 +0200 Subject: [PATCH 5/6] Fix regex for SFML_USE_STATIC_STD_LIBS --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dce546274..cbc9c8fae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,7 +217,7 @@ if(SFML_OS_WINDOWS) foreach(flag CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) - string(REGEX REPLACE "/MD|/MDd|/MT|/MTd" "" ${flag} "${${flag}}") + string(REGEX REPLACE "/MDd|/MD|/MTd|/MT" "" ${flag} "${${flag}}") endforeach() add_compile_options(/MT$<$:d>) endif() From 40fc524b8d08ebfb190786c8321e89ee09de069d Mon Sep 17 00:00:00 2001 From: Zombieschannel <54750550+Zombieschannel@users.noreply.github.com> Date: Thu, 26 Sep 2024 00:50:37 +0200 Subject: [PATCH 6/6] `InputImpl.hpp` now has `Android` implementation --- src/SFML/Window/Android/InputImpl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SFML/Window/Android/InputImpl.hpp b/src/SFML/Window/Android/InputImpl.hpp index ae6ee5a0d..a3f9fbd7b 100644 --- a/src/SFML/Window/Android/InputImpl.hpp +++ b/src/SFML/Window/Android/InputImpl.hpp @@ -37,7 +37,7 @@ namespace sf namespace priv { //////////////////////////////////////////////////////////// -/// \brief iOS implementation of inputs (keyboard + mouse) +/// \brief Android implementation of inputs (keyboard + mouse) /// //////////////////////////////////////////////////////////// class InputImpl