diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index d14715ae7f..44dc16f977 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -436,9 +436,9 @@ if(wxUSE_GUI) wx_option_force_value(wxUSE_GRAPHICS_DIRECT2D OFF) endif() endif() - if(MSVC) # match setup.h + if(MSVC) # match setup.h wx_option_force_value(wxUSE_GRAPHICS_DIRECT2D ${wxUSE_GRAPHICS_CONTEXT}) - endif() + endif() # WXQT checks if(WXQT) @@ -691,12 +691,17 @@ if(wxUSE_GUI) endif() if(wxUSE_SOUND AND wxUSE_LIBSDL AND UNIX AND NOT APPLE) - find_package(SDL2) - if(NOT SDL2_FOUND) - find_package(SDL) - mark_as_advanced(SDL_INCLUDE_DIR SDLMAIN_LIBRARY) + find_package(SDL3) + if(SDL3_FOUND) + set(wxUSE_LIBSDL3 ON) + else() + find_package(SDL2) + if(NOT SDL2_FOUND) + find_package(SDL) + mark_as_advanced(SDL_INCLUDE_DIR SDLMAIN_LIBRARY) + endif() endif() - if(NOT SDL2_FOUND AND NOT SDL_FOUND) + if(NOT SDL3_FOUND AND NOT SDL2_FOUND AND NOT SDL_FOUND) message(WARNING "SDL not found, SDL Audio back-end won't be available") wx_option_force_value(wxUSE_LIBSDL OFF) endif() diff --git a/build/cmake/lib/core/CMakeLists.txt b/build/cmake/lib/core/CMakeLists.txt index 68f139b4d2..deb80e79f4 100644 --- a/build/cmake/lib/core/CMakeLists.txt +++ b/build/cmake/lib/core/CMakeLists.txt @@ -99,7 +99,17 @@ if(WXGTK AND wxUSE_PRIVATE_FONTS) wx_lib_link_libraries(wxcore PUBLIC ${FONTCONFIG_LIBRARIES} ${PANGOFT2_LIBRARIES}) endif() if(wxUSE_LIBSDL) - if(SDL2_FOUND) + if(SDL3_FOUND) + # Upstream SDL3 ships an imported target; prefer it over raw vars. + if(TARGET SDL3::SDL3) + wx_lib_link_libraries(wxcore PUBLIC SDL3::SDL3) + elseif(TARGET SDL3::SDL3-shared) + wx_lib_link_libraries(wxcore PUBLIC SDL3::SDL3-shared) + else() + wx_lib_include_directories(wxcore ${SDL3_INCLUDE_DIRS}) + wx_lib_link_libraries(wxcore PUBLIC ${SDL3_LIBRARIES}) + endif() + elseif(SDL2_FOUND) wx_lib_include_directories(wxcore ${SDL2_INCLUDE_DIR}) wx_lib_link_libraries(wxcore PUBLIC ${SDL2_LIBRARY}) elseif(SDL_FOUND) diff --git a/build/cmake/setup.h.in b/build/cmake/setup.h.in index 2697fc29e1..08169ee065 100644 --- a/build/cmake/setup.h.in +++ b/build/cmake/setup.h.in @@ -626,9 +626,9 @@ This is needed by any Wayland-specific code in wxGTK implementation. - Recommended setting: 1, only set to 0 if wayland-client is not available. + Define if wayland-client is available. */ -#cmakedefine01 wxHAVE_WAYLAND_CLIENT +#cmakedefine wxHAVE_WAYLAND_CLIENT 1 /* Use XTest extension to implement wxUIActionSimulator? @@ -735,6 +735,11 @@ */ #cmakedefine01 wxUSE_LIBSDL +/* + * Use SDL 3.x (rather than SDL 2.x or 1.x) for the SDL audio backend + */ +#cmakedefine01 wxUSE_LIBSDL3 + /* * Compile sound backends as plugins */ diff --git a/build/cmake/wxWidgetsConfig.cmake.in b/build/cmake/wxWidgetsConfig.cmake.in index 7b19e746c1..f0fb7bae8a 100644 --- a/build/cmake/wxWidgetsConfig.cmake.in +++ b/build/cmake/wxWidgetsConfig.cmake.in @@ -190,6 +190,12 @@ if(TARGET wx::wxgl AND NOT (APPLE AND IOS)) find_dependency(OpenGL) endif() +if(@wxUSE_LIBSDL3@) + # make sure SDL3 targets are available: + # The link interface of target "wx::wxcore" contains: SDL3::SDL3(-shared) + find_dependency(SDL3) +endif() + # make sure Threads targets are available find_dependency(Threads) diff --git a/configure b/configure index 9abf7e6137..e78dd273d8 100755 --- a/configure +++ b/configure @@ -36544,6 +36544,68 @@ if test "$wxUSE_SOUND" = "yes"; then if test "$USE_UNIX" = 1 -a "$USE_MAC" != 1 ; then if test "$wxUSE_LIBSDL" != "no"; then +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sdl3 >= 3.0.0" >&5 +$as_echo_n "checking for sdl3 >= 3.0.0... " >&6; } + +if test -n "$SDL_CFLAGS"; then + pkg_cv_SDL_CFLAGS="$SDL_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"sdl3 >= 3.0.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "sdl3 >= 3.0.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_SDL_CFLAGS=`$PKG_CONFIG --cflags "sdl3 >= 3.0.0" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$SDL_LIBS"; then + pkg_cv_SDL_LIBS="$SDL_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"sdl3 >= 3.0.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "sdl3 >= 3.0.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_SDL_LIBS=`$PKG_CONFIG --libs "sdl3 >= 3.0.0" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + SDL_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "sdl3 >= 3.0.0" 2>&1` + else + SDL_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "sdl3 >= 3.0.0" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$SDL_PKG_ERRORS" >&5 + + + { $as_echo "$as_me:${as_lineno-$LINENO}: SDL 3.0 not available. Falling back to SDL 2.0." >&5 +$as_echo "$as_me: SDL 3.0 not available. Falling back to SDL 2.0." >&6;} + pkg_failed=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sdl2 >= 2.0.0" >&5 $as_echo_n "checking for sdl2 >= 2.0.0... " >&6; } @@ -36603,7 +36665,7 @@ fi echo "$SDL_PKG_ERRORS" >&5 - { $as_echo "$as_me:${as_lineno-$LINENO}: SDL 2.0 not available. Falling back to 1.2." >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: SDL 2.0 not available. Falling back to 1.2." >&5 $as_echo "$as_me: SDL 2.0 not available. Falling back to 1.2." >&6;} # Check whether --with-sdl-prefix was given. @@ -36792,10 +36854,10 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } - EXTRALIBS_SDL="$SDL_LIBS" - CFLAGS="$SDL_CFLAGS $CFLAGS" - CXXFLAGS="$SDL_CFLAGS $CXXFLAGS" - $as_echo "#define wxUSE_LIBSDL 1" >>confdefs.h + EXTRALIBS_SDL="$SDL_LIBS" + CFLAGS="$SDL_CFLAGS $CFLAGS" + CXXFLAGS="$SDL_CFLAGS $CXXFLAGS" + $as_echo "#define wxUSE_LIBSDL 1" >>confdefs.h else @@ -36869,7 +36931,7 @@ elif test $pkg_failed = untried; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: SDL 2.0 not available. Falling back to 1.2." >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: SDL 2.0 not available. Falling back to 1.2." >&5 $as_echo "$as_me: SDL 2.0 not available. Falling back to 1.2." >&6;} # Check whether --with-sdl-prefix was given. @@ -37058,10 +37120,10 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } - EXTRALIBS_SDL="$SDL_LIBS" - CFLAGS="$SDL_CFLAGS $CFLAGS" - CXXFLAGS="$SDL_CFLAGS $CXXFLAGS" - $as_echo "#define wxUSE_LIBSDL 1" >>confdefs.h + EXTRALIBS_SDL="$SDL_LIBS" + CFLAGS="$SDL_CFLAGS $CFLAGS" + CXXFLAGS="$SDL_CFLAGS $CXXFLAGS" + $as_echo "#define wxUSE_LIBSDL 1" >>confdefs.h else @@ -37131,6 +37193,628 @@ rm -f core conftest.err conftest.$ac_objext \ rm -f conf.sdltest +else + SDL_CFLAGS=$pkg_cv_SDL_CFLAGS + SDL_LIBS=$pkg_cv_SDL_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + + EXTRALIBS_SDL="$SDL_LIBS" + CFLAGS="$SDL_CFLAGS $CFLAGS" + CXXFLAGS="$SDL_CFLAGS $CXXFLAGS" + $as_echo "#define wxUSE_LIBSDL 1" >>confdefs.h + + +fi + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: SDL 3.0 not available. Falling back to SDL 2.0." >&5 +$as_echo "$as_me: SDL 3.0 not available. Falling back to SDL 2.0." >&6;} + +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sdl2 >= 2.0.0" >&5 +$as_echo_n "checking for sdl2 >= 2.0.0... " >&6; } + +if test -n "$SDL_CFLAGS"; then + pkg_cv_SDL_CFLAGS="$SDL_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"sdl2 >= 2.0.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "sdl2 >= 2.0.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_SDL_CFLAGS=`$PKG_CONFIG --cflags "sdl2 >= 2.0.0" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$SDL_LIBS"; then + pkg_cv_SDL_LIBS="$SDL_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"sdl2 >= 2.0.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "sdl2 >= 2.0.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_SDL_LIBS=`$PKG_CONFIG --libs "sdl2 >= 2.0.0" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + SDL_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "sdl2 >= 2.0.0" 2>&1` + else + SDL_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "sdl2 >= 2.0.0" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$SDL_PKG_ERRORS" >&5 + + + { $as_echo "$as_me:${as_lineno-$LINENO}: SDL 2.0 not available. Falling back to 1.2." >&5 +$as_echo "$as_me: SDL 2.0 not available. Falling back to 1.2." >&6;} + +# Check whether --with-sdl-prefix was given. +if test "${with_sdl_prefix+set}" = set; then : + withval=$with_sdl_prefix; sdl_prefix="$withval" +else + sdl_prefix="" +fi + + +# Check whether --with-sdl-exec-prefix was given. +if test "${with_sdl_exec_prefix+set}" = set; then : + withval=$with_sdl_exec_prefix; sdl_exec_prefix="$withval" +else + sdl_exec_prefix="" +fi + +# Check whether --enable-sdltest was given. +if test "${enable_sdltest+set}" = set; then : + enableval=$enable_sdltest; +else + enable_sdltest=yes +fi + + + if test x$sdl_exec_prefix != x ; then + sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix" + if test x${SDL_CONFIG+set} != xset ; then + SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config + fi + fi + if test x$sdl_prefix != x ; then + sdl_args="$sdl_args --prefix=$sdl_prefix" + if test x${SDL_CONFIG+set} != xset ; then + SDL_CONFIG=$sdl_prefix/bin/sdl-config + fi + fi + + if test "x$prefix" != xNONE; then + PATH="$prefix/bin:$prefix/usr/bin:$PATH" + fi + # Extract the first word of "sdl-config", so it can be a program name with args. +set dummy sdl-config; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_SDL_CONFIG+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $SDL_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_SDL_CONFIG="$SDL_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_SDL_CONFIG="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_path_SDL_CONFIG" && ac_cv_path_SDL_CONFIG="no" + ;; +esac +fi +SDL_CONFIG=$ac_cv_path_SDL_CONFIG +if test -n "$SDL_CONFIG"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SDL_CONFIG" >&5 +$as_echo "$SDL_CONFIG" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + min_sdl_version=1.2.0 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SDL - version >= $min_sdl_version" >&5 +$as_echo_n "checking for SDL - version >= $min_sdl_version... " >&6; } + no_sdl="" + if test "$SDL_CONFIG" = "no" ; then + no_sdl=yes + else + SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags` + SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs` + + sdl_major_version=`$SDL_CONFIG $sdl_args --version | \ + sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1/'` + sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \ + sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\2/'` + sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \ + sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\3/'` + if test "x$enable_sdltest" = "xyes" ; then + ac_save_CFLAGS="$CFLAGS" + ac_save_CXXFLAGS="$CXXFLAGS" + ac_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $SDL_CFLAGS" + CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" + LIBS="$LIBS $SDL_LIBS" + rm -f conf.sdltest + if test "$cross_compiling" = yes; then : + echo $ac_n "cross compiling; assumed OK... $ac_c" +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include +#include +#include "SDL.h" + +char* +my_strdup (char *str) +{ + char *new_str; + + if (str) + { + new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char)); + strcpy (new_str, str); + } + else + new_str = NULL; + + return new_str; +} + +int main (int argc, char *argv[]) +{ + int major, minor, micro; + char *tmp_version; + + /* This hangs on some systems (?) + system ("touch conf.sdltest"); + */ + { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); } + + /* HP/UX 9 (%@#!) writes to sscanf strings */ + tmp_version = my_strdup("$min_sdl_version"); + if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { + printf("%s, bad version string\n", "$min_sdl_version"); + exit(1); + } + + if (($sdl_major_version > major) || + (($sdl_major_version == major) && ($sdl_minor_version > minor)) || + (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro))) + { + return 0; + } + else + { + printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); + printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro); + printf("*** best to upgrade to the required version.\n"); + printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n"); + printf("*** to point to the correct copy of sdl-config, and remove the file\n"); + printf("*** config.cache before re-running configure\n"); + return 1; + } +} + + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + no_sdl=yes +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + CFLAGS="$ac_save_CFLAGS" + CXXFLAGS="$ac_save_CXXFLAGS" + LIBS="$ac_save_LIBS" + fi + fi + if test "x$no_sdl" = x ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + + EXTRALIBS_SDL="$SDL_LIBS" + CFLAGS="$SDL_CFLAGS $CFLAGS" + CXXFLAGS="$SDL_CFLAGS $CXXFLAGS" + $as_echo "#define wxUSE_LIBSDL 1" >>confdefs.h + + + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + if test "$SDL_CONFIG" = "no" ; then + echo "*** The sdl-config script installed by SDL could not be found" + echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" + echo "*** your path, or set the SDL_CONFIG environment variable to the" + echo "*** full path to sdl-config." + else + if test -f conf.sdltest ; then + : + else + echo "*** Could not run SDL test program, checking why..." + CFLAGS="$CFLAGS $SDL_CFLAGS" + CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" + LIBS="$LIBS $SDL_LIBS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +}[ +#include +#include "SDL.h" + +int main(int argc, char *argv[]) +{ return 0; } +#undef main +#define main K_and_R_C_main +], return 0; ) +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + echo "*** The test program compiled, but did not run. This usually means" + echo "*** that the run-time linker is not finding SDL or finding the wrong" + echo "*** version of SDL. If it is not finding SDL, you'll need to set your" + echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" + echo "*** to the installed location Also, make sure you have run ldconfig if that" + echo "*** is required on your system" + echo "***" + echo "*** If you have an old version installed, it is best to remove it, although" + echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" +else + echo "*** The test program failed to compile or link. See the file config.log for the" + echo "*** exact error that occurred. This usually means SDL was incorrectly installed" + echo "*** or that you have moved SDL since it was installed. In the latter case, you" + echo "*** may want to edit the sdl-config script: $SDL_CONFIG" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + CFLAGS="$ac_save_CFLAGS" + CXXFLAGS="$ac_save_CXXFLAGS" + LIBS="$ac_save_LIBS" + fi + fi + SDL_CFLAGS="" + SDL_LIBS="" + wxUSE_LIBSDL="no" + fi + + + rm -f conf.sdltest + + +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: SDL 2.0 not available. Falling back to 1.2." >&5 +$as_echo "$as_me: SDL 2.0 not available. Falling back to 1.2." >&6;} + +# Check whether --with-sdl-prefix was given. +if test "${with_sdl_prefix+set}" = set; then : + withval=$with_sdl_prefix; sdl_prefix="$withval" +else + sdl_prefix="" +fi + + +# Check whether --with-sdl-exec-prefix was given. +if test "${with_sdl_exec_prefix+set}" = set; then : + withval=$with_sdl_exec_prefix; sdl_exec_prefix="$withval" +else + sdl_exec_prefix="" +fi + +# Check whether --enable-sdltest was given. +if test "${enable_sdltest+set}" = set; then : + enableval=$enable_sdltest; +else + enable_sdltest=yes +fi + + + if test x$sdl_exec_prefix != x ; then + sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix" + if test x${SDL_CONFIG+set} != xset ; then + SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config + fi + fi + if test x$sdl_prefix != x ; then + sdl_args="$sdl_args --prefix=$sdl_prefix" + if test x${SDL_CONFIG+set} != xset ; then + SDL_CONFIG=$sdl_prefix/bin/sdl-config + fi + fi + + if test "x$prefix" != xNONE; then + PATH="$prefix/bin:$prefix/usr/bin:$PATH" + fi + # Extract the first word of "sdl-config", so it can be a program name with args. +set dummy sdl-config; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_path_SDL_CONFIG+:} false; then : + $as_echo_n "(cached) " >&6 +else + case $SDL_CONFIG in + [\\/]* | ?:[\\/]*) + ac_cv_path_SDL_CONFIG="$SDL_CONFIG" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_path_SDL_CONFIG="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_path_SDL_CONFIG" && ac_cv_path_SDL_CONFIG="no" + ;; +esac +fi +SDL_CONFIG=$ac_cv_path_SDL_CONFIG +if test -n "$SDL_CONFIG"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SDL_CONFIG" >&5 +$as_echo "$SDL_CONFIG" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + min_sdl_version=1.2.0 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for SDL - version >= $min_sdl_version" >&5 +$as_echo_n "checking for SDL - version >= $min_sdl_version... " >&6; } + no_sdl="" + if test "$SDL_CONFIG" = "no" ; then + no_sdl=yes + else + SDL_CFLAGS=`$SDL_CONFIG $sdlconf_args --cflags` + SDL_LIBS=`$SDL_CONFIG $sdlconf_args --libs` + + sdl_major_version=`$SDL_CONFIG $sdl_args --version | \ + sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\1/'` + sdl_minor_version=`$SDL_CONFIG $sdl_args --version | \ + sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\2/'` + sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \ + sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\)/\3/'` + if test "x$enable_sdltest" = "xyes" ; then + ac_save_CFLAGS="$CFLAGS" + ac_save_CXXFLAGS="$CXXFLAGS" + ac_save_LIBS="$LIBS" + CFLAGS="$CFLAGS $SDL_CFLAGS" + CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" + LIBS="$LIBS $SDL_LIBS" + rm -f conf.sdltest + if test "$cross_compiling" = yes; then : + echo $ac_n "cross compiling; assumed OK... $ac_c" +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include +#include +#include "SDL.h" + +char* +my_strdup (char *str) +{ + char *new_str; + + if (str) + { + new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char)); + strcpy (new_str, str); + } + else + new_str = NULL; + + return new_str; +} + +int main (int argc, char *argv[]) +{ + int major, minor, micro; + char *tmp_version; + + /* This hangs on some systems (?) + system ("touch conf.sdltest"); + */ + { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); } + + /* HP/UX 9 (%@#!) writes to sscanf strings */ + tmp_version = my_strdup("$min_sdl_version"); + if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) { + printf("%s, bad version string\n", "$min_sdl_version"); + exit(1); + } + + if (($sdl_major_version > major) || + (($sdl_major_version == major) && ($sdl_minor_version > minor)) || + (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro))) + { + return 0; + } + else + { + printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version); + printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro); + printf("*** best to upgrade to the required version.\n"); + printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n"); + printf("*** to point to the correct copy of sdl-config, and remove the file\n"); + printf("*** config.cache before re-running configure\n"); + return 1; + } +} + + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + +else + no_sdl=yes +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + CFLAGS="$ac_save_CFLAGS" + CXXFLAGS="$ac_save_CXXFLAGS" + LIBS="$ac_save_LIBS" + fi + fi + if test "x$no_sdl" = x ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + + EXTRALIBS_SDL="$SDL_LIBS" + CFLAGS="$SDL_CFLAGS $CFLAGS" + CXXFLAGS="$SDL_CFLAGS $CXXFLAGS" + $as_echo "#define wxUSE_LIBSDL 1" >>confdefs.h + + + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + if test "$SDL_CONFIG" = "no" ; then + echo "*** The sdl-config script installed by SDL could not be found" + echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in" + echo "*** your path, or set the SDL_CONFIG environment variable to the" + echo "*** full path to sdl-config." + else + if test -f conf.sdltest ; then + : + else + echo "*** Could not run SDL test program, checking why..." + CFLAGS="$CFLAGS $SDL_CFLAGS" + CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" + LIBS="$LIBS $SDL_LIBS" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +}[ +#include +#include "SDL.h" + +int main(int argc, char *argv[]) +{ return 0; } +#undef main +#define main K_and_R_C_main +], return 0; ) +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + echo "*** The test program compiled, but did not run. This usually means" + echo "*** that the run-time linker is not finding SDL or finding the wrong" + echo "*** version of SDL. If it is not finding SDL, you'll need to set your" + echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" + echo "*** to the installed location Also, make sure you have run ldconfig if that" + echo "*** is required on your system" + echo "***" + echo "*** If you have an old version installed, it is best to remove it, although" + echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" +else + echo "*** The test program failed to compile or link. See the file config.log for the" + echo "*** exact error that occurred. This usually means SDL was incorrectly installed" + echo "*** or that you have moved SDL since it was installed. In the latter case, you" + echo "*** may want to edit the sdl-config script: $SDL_CONFIG" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + CFLAGS="$ac_save_CFLAGS" + CXXFLAGS="$ac_save_CXXFLAGS" + LIBS="$ac_save_LIBS" + fi + fi + SDL_CFLAGS="" + SDL_LIBS="" + wxUSE_LIBSDL="no" + fi + + + rm -f conf.sdltest + + +else + SDL_CFLAGS=$pkg_cv_SDL_CFLAGS + SDL_LIBS=$pkg_cv_SDL_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + + EXTRALIBS_SDL="$SDL_LIBS" + CFLAGS="$SDL_CFLAGS $CFLAGS" + CXXFLAGS="$SDL_CFLAGS $CXXFLAGS" + $as_echo "#define wxUSE_LIBSDL 1" >>confdefs.h + + +fi + else SDL_CFLAGS=$pkg_cv_SDL_CFLAGS SDL_LIBS=$pkg_cv_SDL_LIBS @@ -37142,6 +37826,8 @@ $as_echo "yes" >&6; } CXXFLAGS="$SDL_CFLAGS $CXXFLAGS" $as_echo "#define wxUSE_LIBSDL 1" >>confdefs.h + $as_echo "#define wxUSE_LIBSDL3 1" >>confdefs.h + fi if test "$wxUSE_LIBSDL" = "yes" -a "$wxUSE_PLUGINS" = "yes" ; then @@ -45927,3 +46613,4 @@ else fi echo "" + diff --git a/configure.ac b/configure.ac index 8e18ba12b1..ab556bc032 100644 --- a/configure.ac +++ b/configure.ac @@ -5320,23 +5320,34 @@ WITH_PLUGIN_SDL=0 if test "$wxUSE_SOUND" = "yes"; then if test "$USE_UNIX" = 1 -a "$USE_MAC" != 1 ; then if test "$wxUSE_LIBSDL" != "no"; then - PKG_CHECK_MODULES([SDL], [sdl2 >= 2.0.0], + PKG_CHECK_MODULES([SDL], [sdl3 >= 3.0.0], [ EXTRALIBS_SDL="$SDL_LIBS" CFLAGS="$SDL_CFLAGS $CFLAGS" CXXFLAGS="$SDL_CFLAGS $CXXFLAGS" AC_DEFINE(wxUSE_LIBSDL) + AC_DEFINE(wxUSE_LIBSDL3) ], [ - AC_MSG_NOTICE([SDL 2.0 not available. Falling back to 1.2.]) - AM_PATH_SDL([1.2.0], + AC_MSG_NOTICE([SDL 3.0 not available. Falling back to SDL 2.0.]) + PKG_CHECK_MODULES([SDL], [sdl2 >= 2.0.0], [ EXTRALIBS_SDL="$SDL_LIBS" CFLAGS="$SDL_CFLAGS $CFLAGS" CXXFLAGS="$SDL_CFLAGS $CXXFLAGS" AC_DEFINE(wxUSE_LIBSDL) ], - [wxUSE_LIBSDL="no"]) + [ + AC_MSG_NOTICE([SDL 2.0 not available. Falling back to 1.2.]) + AM_PATH_SDL([1.2.0], + [ + EXTRALIBS_SDL="$SDL_LIBS" + CFLAGS="$SDL_CFLAGS $CFLAGS" + CXXFLAGS="$SDL_CFLAGS $CXXFLAGS" + AC_DEFINE(wxUSE_LIBSDL) + ], + [wxUSE_LIBSDL="no"]) + ]) ]) if test "$wxUSE_LIBSDL" = "yes" -a "$wxUSE_PLUGINS" = "yes" ; then WITH_PLUGIN_SDL=1 diff --git a/setup.h.in b/setup.h.in index 0f1a1fdbd8..4bec4eb6e4 100644 --- a/setup.h.in +++ b/setup.h.in @@ -625,7 +625,7 @@ This is needed by any Wayland-specific code in wxGTK implementation. - Recommended setting: 1, only set to 0 if wayland-client is not available. + Define if wayland-client is available. */ #undef wxHAVE_WAYLAND_CLIENT @@ -734,6 +734,11 @@ */ #define wxUSE_LIBSDL 0 +/* + * Use SDL 3.x (rather than SDL 2.x or 1.x) for the SDL audio backend + */ +#define wxUSE_LIBSDL3 0 + /* * Compile sound backends as plugins */ diff --git a/setup.h_vms b/setup.h_vms index df5b5fef8f..3aaf2a0578 100644 --- a/setup.h_vms +++ b/setup.h_vms @@ -88,7 +88,7 @@ typedef pid_t GPid; #endif #endif -#if defined( VMS_GTK2 ) || defined( __WXX11__ ) +#if defined( VMS_GTK2 ) || defined( __WXX11__ ) #define wxUSE_CAIRO 1 #else #define wxUSE_CAIRO 0 @@ -764,6 +764,12 @@ typedef pid_t GPid; * Use SDL for audio (Unix) */ #define wxUSE_LIBSDL 0 + +/* + * Use SDL 3.x (rather than SDL 2.x or 1.x) for the SDL audio backend + */ +#define wxUSE_LIBSDL3 0 + /* * Use GTK print for printing under GTK+ 2.10+ */ diff --git a/src/unix/sound_sdl.cpp b/src/unix/sound_sdl.cpp index 4ef5b7af16..8cac39a1e2 100644 --- a/src/unix/sound_sdl.cpp +++ b/src/unix/sound_sdl.cpp @@ -13,7 +13,24 @@ #if wxUSE_SOUND && wxUSE_LIBSDL -#include +#if wxUSE_LIBSDL3 + #include +#else + #include +#endif + +// Compatibility helpers so the rest of this file can be written once. +#if SDL_MAJOR_VERSION >= 3 + typedef SDL_AudioFormat wxSDL_AudioFormat; + #define wxSDL_AUDIO_U8 SDL_AUDIO_U8 + #define wxSDL_AUDIO_S16LSB SDL_AUDIO_S16LE + #define WX_SDL_USE_STREAM_API 1 +#else + typedef int wxSDL_AudioFormat; + #define wxSDL_AUDIO_U8 AUDIO_U8 + #define wxSDL_AUDIO_S16LSB AUDIO_S16LSB + #define WX_SDL_USE_STREAM_API 0 +#endif #ifndef WX_PRECOMP #include "wx/event.h" @@ -65,7 +82,11 @@ class wxSoundBackendSDL : public wxSoundBackend public: wxSoundBackendSDL() : m_initialized(false), m_playing(false), m_audioOpen(false), - m_data(nullptr), m_evtHandler(nullptr) {} + m_data(nullptr), +#if WX_SDL_USE_STREAM_API + m_stream(nullptr), m_silence(0), +#endif + m_evtHandler(nullptr) {} virtual ~wxSoundBackendSDL(); wxString GetName() const override { return wxT("Simple DirectMedia Layer"); } @@ -93,6 +114,13 @@ private: SDL_AudioSpec m_spec; bool m_loop; +#if WX_SDL_USE_STREAM_API + // SDL3 owns the device through the audio stream; silence sample is no + // longer part of SDL_AudioSpec, so we keep our own copy. + SDL_AudioStream *m_stream; + Uint8 m_silence; +#endif + wxSoundBackendSDLEvtHandler *m_evtHandler; }; @@ -128,22 +156,45 @@ bool wxSoundBackendSDL::IsAvailable() const { if (m_initialized) return true; - if (SDL_WasInit(SDL_INIT_AUDIO) != SDL_INIT_AUDIO) + if ((SDL_WasInit(SDL_INIT_AUDIO) & SDL_INIT_AUDIO) != SDL_INIT_AUDIO) { SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1"); +#if SDL_MAJOR_VERSION >= 3 + // SDL3: SDL_Init returns bool, and SDL_INIT_NOPARACHUTE is gone. + if (!SDL_Init(SDL_INIT_AUDIO)) + return false; +#else if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE) == -1) return false; +#endif } wxConstCast(this, wxSoundBackendSDL)->m_initialized = true; wxLogTrace(wxT("sound"), wxT("initialized SDL audio subsystem")); return true; } +#if WX_SDL_USE_STREAM_API +extern "C" void SDLCALL +wx_sdl_audio_callback(void *userdata, SDL_AudioStream *stream, + int additional_amount, int /*total_amount*/) +{ + if (additional_amount <= 0) + return; + wxSoundBackendSDL *bk = static_cast(userdata); + Uint8 *buf = static_cast(SDL_malloc(additional_amount)); + if (!buf) + return; + bk->FillAudioBuffer(buf, additional_amount); + SDL_PutAudioStreamData(stream, buf, additional_amount); + SDL_free(buf); +} +#else extern "C" void wx_sdl_audio_callback(void *userdata, Uint8 *stream, int len) { wxSoundBackendSDL *bk = (wxSoundBackendSDL*)userdata; bk->FillAudioBuffer(stream, len); } +#endif void wxSoundBackendSDL::FillAudioBuffer(Uint8 *stream, int len) { @@ -180,7 +231,11 @@ void wxSoundBackendSDL::FillAudioBuffer(Uint8 *stream, int len) } else { +#if WX_SDL_USE_STREAM_API + memset(stream, m_silence, len); +#else memset(stream, m_spec.silence, len); +#endif } } } @@ -198,6 +253,33 @@ bool wxSoundBackendSDL::OpenAudio() if (!m_evtHandler) m_evtHandler = new wxSoundBackendSDLEvtHandler(this); +#if WX_SDL_USE_STREAM_API + // SDL3: silence and buffering are handled by the stream itself, and + // SDL_AudioSpec only carries format/channels/freq. + m_silence = (m_spec.format == wxSDL_AUDIO_U8) ? 128 : 0; + + wxLogTrace(wxT("sound"), wxT("opening SDL audio...")); + m_stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, + &m_spec, + wx_sdl_audio_callback, + this); + if (m_stream) + { +#if wxUSE_LOG_DEBUG + const char *drv = SDL_GetCurrentAudioDriver(); + wxLogTrace(wxT("sound"), wxT("opened audio, driver '%s'"), + wxString(drv ? drv : "", wxConvLocal)); +#endif + m_audioOpen = true; + return true; + } + else + { + wxString err(SDL_GetError(), wxConvLocal); + wxLogError(_("Couldn't open audio: %s"), err); + return false; + } +#else m_spec.silence = 0; m_spec.samples = 4096; m_spec.size = 0; @@ -226,6 +308,7 @@ bool wxSoundBackendSDL::OpenAudio() wxLogError(_("Couldn't open audio: %s"), err); return false; } +#endif } return true; } @@ -234,7 +317,12 @@ void wxSoundBackendSDL::CloseAudio() { if (m_audioOpen) { +#if WX_SDL_USE_STREAM_API + SDL_DestroyAudioStream(m_stream); + m_stream = nullptr; +#else SDL_CloseAudio(); +#endif wxLogTrace(wxT("sound"), wxT("closed audio")); m_audioOpen = false; } @@ -245,11 +333,11 @@ bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags, { Stop(); - int format; + wxSDL_AudioFormat format; if (data->m_bitsPerSample == 8) - format = AUDIO_U8; + format = wxSDL_AUDIO_U8; else if (data->m_bitsPerSample == 16) - format = AUDIO_S16LSB; + format = wxSDL_AUDIO_S16LSB; else return false; @@ -258,7 +346,7 @@ bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags, { if (format == m_spec.format && m_spec.freq == (int)data->m_samplingRate && - m_spec.channels == data->m_channels) + (unsigned)m_spec.channels == data->m_channels) { needsOpen = false; } @@ -277,16 +365,24 @@ bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags, return false; } +#if WX_SDL_USE_STREAM_API + SDL_LockAudioStream(m_stream); +#else SDL_LockAudio(); +#endif wxLogTrace(wxT("sound"), wxT("playing new sound")); m_playing = true; m_pos = 0; m_loop = (flags & wxSOUND_LOOP); m_data = data; data->IncRef(); +#if WX_SDL_USE_STREAM_API + SDL_UnlockAudioStream(m_stream); + SDL_ResumeAudioStreamDevice(m_stream); +#else SDL_UnlockAudio(); - SDL_PauseAudio(0); +#endif // wait until playback finishes if called in sync mode: if (!(flags & wxSOUND_ASYNC)) @@ -314,6 +410,21 @@ bool wxSoundBackendSDL::Play(wxSoundData *data, unsigned flags, void wxSoundBackendSDL::Stop() { +#if WX_SDL_USE_STREAM_API + if (m_stream) + { + SDL_LockAudioStream(m_stream); + SDL_PauseAudioStreamDevice(m_stream); + } + m_playing = false; + if (m_data) + { + m_data->DecRef(); + m_data = nullptr; + } + if (m_stream) + SDL_UnlockAudioStream(m_stream); +#else SDL_LockAudio(); SDL_PauseAudio(1); m_playing = false; @@ -323,6 +434,7 @@ void wxSoundBackendSDL::Stop() m_data = nullptr; } SDL_UnlockAudio(); +#endif } extern "C" wxSoundBackend *wxCreateSoundBackendSDL()