[vlc-devel] [PATCH] configure: check the C compiler needs -latomic to support atomics

Steve Lhomme robux4 at ycbcr.xyz
Fri Mar 20 15:25:00 CET 2020


At least gcc 8 for the Raspberry Pi needs it.
---
 configure.ac    | 24 ++++++++++++++++++++++++
 src/Makefile.am |  4 ++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index bc1874cb97c..8351cb696c9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,6 +70,30 @@ AC_C_INLINE
 AC_C_RESTRICT
 AX_CXX_COMPILE_STDCXX_14([noext], [mandatory])
 
+dnl Check the compiler supports atomics in C
+AC_MSG_CHECKING([C atomics])
+VLC_SAVE_FLAGS
+ATOMIC_LIB=""
+AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdatomic.h>],[
+ atomic_uintmax_t test;
+ atomic_init(&test, 0);
+ atomic_fetch_add_explicit(&test, 2u, memory_order_relaxed);
+])], [AC_MSG_RESULT([built-in])], [
+  LDFLAGS="$LDFLAGS -latomic"
+  AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdatomic.h>],[
+atomic_uintmax_t test;
+atomic_init(&test, 0);
+atomic_fetch_add_explicit(&test, 2u, memory_order_relaxed);
+])],[
+    AC_MSG_RESULT([using -latomic])
+    ATOMIC_LIB="-latomic"
+  ],[
+  AC_MSG_ERROR([VLC requires atomics support])
+  ])
+])
+VLC_RESTORE_FLAGS
+AC_SUBST([ATOMIC_LIB])
+
 dnl Extend the --help string at the current spot.
 AC_DEFUN([EXTEND_HELP_STRING], [m4_divert_once([HELP_ENABLE], [$1])])
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 2b4dfcb7dd8..8b30afcf5bc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -393,7 +393,7 @@ libvlccore_la_SOURCES = \
 libvlccore_la_LIBADD = $(LIBS_libvlccore) \
 	../compat/libcompat.la \
 	$(LTLIBINTL) $(LTLIBICONV) \
-	$(IDN_LIBS) $(SOCKET_LIBS) $(LIBRT) $(LIBDL) $(LIBM)
+	$(IDN_LIBS) $(SOCKET_LIBS) $(ATOMIC_LIB) $(LIBRT) $(LIBDL) $(LIBM)
 
 if HAVE_WIN32
 libvlccore_la_SOURCES += \
@@ -611,7 +611,7 @@ test_mrl_helpers_SOURCES = test/mrl_helpers.c
 test_arrays_SOURCES = test/arrays.c
 test_vector_SOURCES = test/vector.c
 test_shared_data_ptr_SOURCES = test/shared_data_ptr.cpp
-test_extensions_SOURCES = test/extensions.c 
+test_extensions_SOURCES = test/extensions.c
 test_playlist_SOURCES = playlist/test.c \
 	playlist/content.c \
 	playlist/control.c \
-- 
2.17.1



More information about the vlc-devel mailing list