build: Fix clock_gettime check with XCode 8

With XCode 8, clock_gettime will be incorrectly detected as being
available regardless of what OS X version we're targetting because the
symbol is available in the .tbd library as a weak symbol.
See: https://github.com/Homebrew/homebrew-core/issues/3727#issue-170086273

It's only starting from macOS 10.12 that clock_gettime is actually
available, so we can unconditionally disable it when targetting older
versions. We cannot simply do AC_CHECK_FUNCS with -Wl,-no_weak_imports
because the autoconf check does its own prototype declaration that
doesn't trigger that compiler flag.

https://bugzilla.gnome.org/show_bug.cgi?id=772451
This commit is contained in:
Nirbheek Chauhan 2016-10-03 20:22:53 +05:30
parent 0ab950f501
commit 6c1bc80d27
3 changed files with 60 additions and 6 deletions

View file

@ -671,18 +671,50 @@ AC_CHECK_FUNCS([posix_memalign])
AC_CHECK_FUNCS([getpagesize]) AC_CHECK_FUNCS([getpagesize])
dnl Check for POSIX timers dnl Check for POSIX timers
AC_CHECK_FUNCS(clock_gettime, [], [ CLOCK_GETTIME_FOUND="no"
AC_CHECK_FUNC(clock_gettime, [CLOCK_GETTIME_FOUND="yes"], [
AC_CHECK_LIB(rt, clock_gettime, [ AC_CHECK_LIB(rt, clock_gettime, [
AC_DEFINE(HAVE_CLOCK_GETTIME, 1) CLOCK_GETTIME_FOUND="yes"
LIBS="$LIBS -lrt" LIBS="$LIBS -lrt"
], [ ], [
AC_CHECK_LIB(pthread, clock_gettime, [ AC_CHECK_LIB(pthread, clock_gettime, [
AC_DEFINE(HAVE_CLOCK_GETTIME, 1) CLOCK_GETTIME_FOUND="yes"
LIBS="$LIBS -lpthread" LIBS="$LIBS -lpthread"
]) ])
]) ])
]) ])
# With XCode 8, clock_gettime will be incorrectly detected as being available
# regardless of what version of OS X you target because the symbol is available
# in the .tbd file as a weak symbol.
# See: https://bugzilla.gnome.org/show_bug.cgi?id=772451
#
# We cannot simply do AC_CHECK_FUNCS with -Wl,-no_weak_imports because the
# autoconf check does its own prototype declaration that doesn't trigger that
# compiler flag.
#
# It's only starting from macOS 10.12, that clock_gettime is actually available,
# so we can unconditionally disable it when targetting older versions.
case "$host_os" in
darwin*)
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
#error "Not compiling for OS X 10.12 or later"
#endif
]])], [], [
if test "$CLOCK_GETTIME_FOUND" = "yes"; then
AC_MSG_NOTICE([Disabling incorrectly detected clock_gettime on OS X])
fi
CLOCK_GETTIME_FOUND="no"
])
;;
esac
if test "$CLOCK_GETTIME_FOUND" = "yes"; then
AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Have clock_gettime])
fi
AC_CACHE_CHECK(for posix timers, gst_cv_posix_timers, AC_CACHE_CHECK(for posix timers, gst_cv_posix_timers,
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <time.h> #include <time.h>

View file

@ -95,7 +95,7 @@ AC_CHECK_LIB([rt], [timer_create, timer_settime, timer_delete])
AM_CONDITIONAL(HAVE_TIMER_CREATE_SETTIME_DELETE, test "x$ac_cv_lib_rt_timer_create__timer_settime__timer_delete" = "xyes") AM_CONDITIONAL(HAVE_TIMER_CREATE_SETTIME_DELETE, test "x$ac_cv_lib_rt_timer_create__timer_settime__timer_delete" = "xyes")
dnl Allow for checking HAVE_CLOCK_GETTIME in automake files dnl Allow for checking HAVE_CLOCK_GETTIME in automake files
AM_CONDITIONAL(HAVE_CLOCK_GETTIME, test "x$ac_cv_func_clock_gettime" = "xyes") AM_CONDITIONAL(HAVE_CLOCK_GETTIME, test "x$HAVE_CLOCK_GETTIME" = "xyes")
dnl Create _stdint.h in the top-level directory dnl Create _stdint.h in the top-level directory
AX_CREATE_STDINT_H AX_CREATE_STDINT_H

View file

@ -2,7 +2,7 @@ project('gstreamer', 'c', 'cpp',
version : '1.9.90', version : '1.9.90',
meson_version : '>= 0.33.0', meson_version : '>= 0.33.0',
default_options : [ 'warning_level=1', default_options : [ 'warning_level=1',
'c_std=gnu99', 'c_std=c99',
'buildtype=debugoptimized' ]) 'buildtype=debugoptimized' ])
gst_version = meson.project_version() gst_version = meson.project_version()
@ -185,8 +185,30 @@ endif
if cc.has_function('getpagesize', prefix : '#include<unistd.h>') if cc.has_function('getpagesize', prefix : '#include<unistd.h>')
cdata.set('HAVE_GETPAGESIZE', 1) cdata.set('HAVE_GETPAGESIZE', 1)
endif endif
# With OS X 10.11.6 and XCode 8, clock_gettime will be incorrectly detected as
# being available because the symbol is available in the .tbd file as a weak
# symbol. See: https://github.com/Homebrew/homebrew-core/issues/3727#issue-170086273
#
# We cannot simply do cc.has_function with -Wl,-no_weak_imports because the
# check does its own prototype decl that doesn't trigger that compiler flag.
#
# It's only starting from macOS 10.12, that clock_gettime is actually available,
# so we can unconditionally disable it for older versions.
for_osx_10_12_src = '''#include <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
#error "Not compiling for OS X 10.12 or later"
#endif
'''
if cc.has_function('clock_gettime', prefix : '#include <time.h>') if cc.has_function('clock_gettime', prefix : '#include <time.h>')
cdata.set('HAVE_CLOCK_GETTIME', 1) if host_machine.system() == 'darwin'
if cc.compiles(for_osx_10_12_src, name : 'minimum OS X version required >= 10.12')
cdata.set('HAVE_CLOCK_GETTIME', 1)
endif
else
cdata.set('HAVE_CLOCK_GETTIME', 1)
endif
endif endif
# We only want to use the __declspec(dllexport/import) dance in GST_EXPORT when # We only want to use the __declspec(dllexport/import) dance in GST_EXPORT when