configure/cmake: Hook up Emscripten threads (disabled by default). Fixes #3795.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4fef447..6804107 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -153,7 +153,14 @@ else()
set(UNIX_OR_MAC_SYS OFF)
endif()
-if (UNIX_OR_MAC_SYS AND NOT EMSCRIPTEN) # JavaScript does not yet have threading support, so disable pthreads when building for Emscripten.
+# Emscripten pthreads work, but you need to have a non-pthread fallback build
+# for systems without support. It's not currently enough to not use
+# pthread functions in a pthread-build; it won't start up on unsupported
+# browsers. As such, you have to explicitly enable it on Emscripten builds
+# for the time being. This default with change to ON once this becomes
+# commonly supported in browsers or the Emscripten teams makes a single
+# binary work everywhere.
+if (UNIX_OR_MAC_SYS AND NOT EMSCRIPTEN)
set(SDL_PTHREADS_ENABLED_BY_DEFAULT ON)
else()
set(SDL_PTHREADS_ENABLED_BY_DEFAULT OFF)
@@ -289,11 +296,14 @@ set(OPT_DEF_ASM TRUE)
if(EMSCRIPTEN)
# Set up default values for the currently supported set of subsystems:
# Emscripten/Javascript does not have assembly support, a dynamic library
- # loading architecture, low-level CPU inspection or multithreading.
+ # loading architecture, or low-level CPU inspection.
+
+ # SDL_THREADS_ENABLED_BY_DEFAULT now defaults to ON, but pthread support might be disabled by default.
+ # !!! FIXME: most of these subsystems should default to ON if there are dummy implementations to be used.
+
set(OPT_DEF_ASM FALSE)
set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
set(SDL_ATOMIC_ENABLED_BY_DEFAULT OFF)
- set(SDL_THREADS_ENABLED_BY_DEFAULT OFF)
set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
set(SDL_DLOPEN_ENABLED_BY_DEFAULT OFF)
@@ -1154,6 +1164,8 @@ elseif(EMSCRIPTEN)
endif()
endif()
+ CheckPTHREAD()
+
elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS)
if(SDL_AUDIO)
if(SYSV5 OR SOLARIS OR HPUX)
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index 64089c6..9e05497 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -919,6 +919,9 @@ macro(CheckPTHREAD)
elseif(HAIKU)
set(PTHREAD_CFLAGS "-D_REENTRANT")
set(PTHREAD_LDFLAGS "")
+ elseif(EMSCRIPTEN)
+ set(PTHREAD_CFLAGS "-D_REENTRANT -pthread")
+ set(PTHREAD_LDFLAGS "-pthread")
else()
set(PTHREAD_CFLAGS "-D_REENTRANT")
set(PTHREAD_LDFLAGS "-lpthread")
diff --git a/configure b/configure
index b1a6c24..0daa8a1 100755
--- a/configure
+++ b/configure
@@ -771,6 +771,7 @@ infodir
docdir
oldincludedir
includedir
+runstatedir
localstatedir
sharedstatedir
sysconfdir
@@ -986,6 +987,7 @@ datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE}'
@@ -1238,6 +1240,15 @@ do
| -silent | --silent | --silen | --sile | --sil)
silent=yes ;;
+ -runstatedir | --runstatedir | --runstatedi | --runstated \
+ | --runstate | --runstat | --runsta | --runst | --runs \
+ | --run | --ru | --r)
+ ac_prev=runstatedir ;;
+ -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
+ | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
+ | --run=* | --ru=* | --r=*)
+ runstatedir=$ac_optarg ;;
+
-sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
ac_prev=sbindir ;;
-sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1375,7 +1386,7 @@ fi
for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \
datadir sysconfdir sharedstatedir localstatedir includedir \
oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
- libdir localedir mandir
+ libdir localedir mandir runstatedir
do
eval ac_val=\$$ac_var
# Remove trailing slashes.
@@ -1528,6 +1539,7 @@ Fine tuning of the installation directories:
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
+ --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
@@ -1682,8 +1694,9 @@ Optional Features:
--enable-ibus enable IBus support [default=yes]
--enable-fcitx enable fcitx support [default=yes]
--enable-joystick-mfi include macOS MFI joystick support [default=yes]
- --enable-pthreads use POSIX threads for multi-threading [default=yes]
- --enable-pthread-sem use pthread semaphores [default=yes]
+ --enable-pthreads use POSIX threads for multi-threading
+ [default=maybe]
+ --enable-pthread-sem use pthread semaphores [default=maybe]
--enable-directx use DirectX for Windows audio/video [default=yes]
--enable-xinput use Xinput for Windows [default=yes]
--enable-wasapi use the Windows WASAPI audio driver [default=yes]
@@ -20257,34 +20270,8 @@ else
$as_echo_n "(cached) " >&6
else
# One or both of the vars are not set, and there is no cached value.
-ac_x_includes=no
-ac_x_libraries=no
-# Do we need to do anything special at all?
-ac_save_LIBS=$LIBS
-LIBS="-lX11 $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-#include <X11/Xlib.h>
-int
-main ()
-{
-XrmInitialize ()
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
- # We can compile and link X programs with no special options.
- ac_x_includes=
- ac_x_libraries=
-fi
-rm -f core conftest.err conftest.$ac_objext \
- conftest$ac_exeext conftest.$ac_ext
-LIBS="$ac_save_LIBS"
-# If that didn't work, only try xmkmf and filesystem searches
-# for native compilation.
-if test x"$ac_x_includes" = xno && test "$cross_compiling" = no; then :
- rm -f -r conftest.dir
+ac_x_includes=no ac_x_libraries=no
+rm -f -r conftest.dir
if mkdir conftest.dir; then
cd conftest.dir
cat >Imakefile <<'_ACEOF'
@@ -20323,7 +20310,7 @@ _ACEOF
rm -f -r conftest.dir
fi
- # Standard set of common directories for X headers.
+# Standard set of common directories for X headers.
# Check X11 before X11Rn because it is often a symlink to the current release.
ac_x_header_dirs='
/usr/X11/include
@@ -20350,8 +20337,6 @@ ac_x_header_dirs='
/usr/local/include/X11R5
/usr/local/include/X11R4
-/opt/X11/include
-
/usr/X386/include
/usr/x386/include
/usr/XFree86/include/X11
@@ -20425,17 +20410,15 @@ rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
fi # $ac_x_libraries = no
-fi
-# Record the results.
case $ac_x_includes,$ac_x_libraries in #(
- no,* | *,no | *\'*) :
+ no,* | *,no | *\'*)
# Didn't find X, or a directory has "'" in its name.
- ac_cv_have_x="have_x=no" ;; #(
- *) :
+ ac_cv_have_x="have_x=no";; #(
+ *)
# Record where we found X for the cache.
ac_cv_have_x="have_x=yes\
ac_x_includes='$ac_x_includes'\
- ac_x_libraries='$ac_x_libraries'" ;;
+ ac_x_libraries='$ac_x_libraries'"
esac
fi
;; #(
@@ -23541,20 +23524,39 @@ $as_echo "#define SDL_JOYSTICK_MFI 1" >>confdefs.h
CheckPTHREAD()
{
- # Check whether --enable-pthreads was given.
+
+
+ case "$host" in
+ *-*-emscripten*)
+ enable_pthreads_default=no
+ ;;
+ *)
+ enable_pthreads_default=yes
+ ;;
+ esac
+
+ # Check whether --enable-pthreads was given.
if test "${enable_pthreads+set}" = set; then :
enableval=$enable_pthreads;
else
- enable_pthreads=yes
+ enable_pthreads=maybe
fi
# Check whether --enable-pthread-sem was given.
if test "${enable_pthread_sem+set}" = set; then :
enableval=$enable_pthread_sem;
else
- enable_pthread_sem=yes
+ enable_pthread_sem=maybe
fi
+
+ if test x$enable_pthreads = xmaybe; then
+ enable_pthreads=$enable_pthreads_default
+ fi
+ if test x$enable_pthread_sem = xmaybe; then
+ enable_pthread_sem=$enable_pthreads
+ fi
+
case "$host" in
*-*-android*)
pthread_cflags="-D_REENTRANT -D_THREAD_SAFE"
@@ -23620,6 +23622,10 @@ fi
pthread_cflags="-D_REENTRANT"
pthread_lib=""
;;
+ *-*-emscripten*)
+ pthread_cflags="-D_REENTRANT -pthread"
+ pthread_lib="-pthread"
+ ;;
*)
pthread_cflags="-D_REENTRANT"
pthread_lib="-lpthread"
@@ -25868,6 +25874,7 @@ $as_echo "#define SDL_AUDIO_DRIVER_EMSCRIPTEN 1" >>confdefs.h
CheckDummyVideo
CheckDiskAudio
CheckDummyAudio
+ CheckPTHREAD
CheckDLOPEN
CheckClockGettime
CheckEmscriptenGLES
diff --git a/configure.ac b/configure.ac
index e289966..5e583e0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2941,13 +2941,39 @@ dnl See what type of thread model to use on Linux and Solaris
CheckPTHREAD()
{
dnl Check for pthread support
+
+ dnl Emscripten pthreads work, but you need to have a non-pthread fallback build
+ dnl for systems without support. It's not currently enough to not use
+ dnl pthread functions in a pthread-build; it won't start up on unsupported
+ dnl browsers. As such, you have to explicitly enable it on Emscripten builds
+ dnl for the time being. This default with change to ON once this becomes
+ dnl commonly supported in browsers or the Emscripten teams makes a single
+ dnl binary work everywhere.
+
+ case "$host" in
+ *-*-emscripten*)
+ enable_pthreads_default=no
+ ;;
+ *)
+ enable_pthreads_default=yes
+ ;;
+ esac
+
AC_ARG_ENABLE(pthreads,
-[AS_HELP_STRING([--enable-pthreads], [use POSIX threads for multi-threading [default=yes]])],
- , enable_pthreads=yes)
+[AS_HELP_STRING([--enable-pthreads], [use POSIX threads for multi-threading [default=maybe]])],
+ , enable_pthreads=maybe)
dnl This is used on Linux for glibc binary compatibility (Doh!)
AC_ARG_ENABLE(pthread-sem,
-[AS_HELP_STRING([--enable-pthread-sem], [use pthread semaphores [default=yes]])],
- , enable_pthread_sem=yes)
+[AS_HELP_STRING([--enable-pthread-sem], [use pthread semaphores [default=maybe]])],
+ , enable_pthread_sem=maybe)
+
+ if test x$enable_pthreads = xmaybe; then
+ enable_pthreads=$enable_pthreads_default
+ fi
+ if test x$enable_pthread_sem = xmaybe; then
+ enable_pthread_sem=$enable_pthreads
+ fi
+
case "$host" in
*-*-android*)
pthread_cflags="-D_REENTRANT -D_THREAD_SAFE"
@@ -3013,6 +3039,10 @@ CheckPTHREAD()
pthread_cflags="-D_REENTRANT"
pthread_lib=""
;;
+ *-*-emscripten*)
+ pthread_cflags="-D_REENTRANT -pthread"
+ pthread_lib="-pthread"
+ ;;
*)
pthread_cflags="-D_REENTRANT"
pthread_lib="-lpthread"
@@ -4302,6 +4332,7 @@ case "$host" in
CheckDummyVideo
CheckDiskAudio
CheckDummyAudio
+ CheckPTHREAD
CheckDLOPEN
CheckClockGettime
CheckEmscriptenGLES