Skip to content
Permalink
Browse files

attempt to fix more feature-test-macro portability issues

  • Loading branch information
Akaricchi committed Dec 14, 2019
1 parent 6834796 commit b8c2755ce1f342ae2e77e21cbcfedf118ee00cc2
Showing with 28 additions and 16 deletions.
  1. +28 −5 meson.build
  2. +0 −11 src/util/compat.h
@@ -3,7 +3,9 @@ project('taisei', 'c',
version : 'v1.4-dev',
meson_version : '>=0.48.0',
default_options : [
'c_std=c11',
# Should really be c11, but gnu11 is a safer default because everything is terrible.
'c_std=gnu11',

'default_library=static',

'libzip:enable_crypto=false',
@@ -212,10 +214,33 @@ endif

config.set('TAISEI_BUILDCONF_USE_ZIP', taisei_deps.contains(dep_zip))

have_posix = cc.has_header_symbol('unistd.h', '_POSIX_VERSION')
have_posix = cc.has_header_symbol('unistd.h', '_POSIX_VERSION')

# Feature test macros _SUCK_!
# On some platforms (FreeBSD, macOS, ...), defining _POSIX_C_SOURCE disables C11
# symbols, EVEN WHEN COMPILING IN C11 MODE! On macOS you can get around this
# with _DARWIN_C_SOURCE; on BSD you're screwed apparently. Some libCs require
# _POSIX_C_SOURCE for posix functionality (musl, glibc with __STRICT_ANSI__),
# others include everything by default, it's an inconsistent trash fire. So far
# the safest option seems to be to compile without strict conformance and only
# define _POSIX_C_SOURCE if we have to.
if have_posix
if not cc.has_header_symbol('stdio.h', 'fileno')
# No POSIX stuff by default? Then request it, and assume the libc isn't
# braindead enough to hide the standard C11 APIs.
# If it is then your system sucks.
config.set('_POSIX_C_SOURCE', '200809L')
endif

# For good measure
if host_machine.system() == 'darwin'
config.set('_DARWIN_C_SOURCE', true)
endif
endif

have_vla = not cc.has_header_symbol('stdlib.h', '__STDC_NO_VLA__')
have_complex = not cc.has_header_symbol('stdlib.h', '__STDC_NO_COMPLEX__')
have_timespec = cc.has_header_symbol('time.h', 'timespec_get')
have_timespec = cc.has_function('timespec_get')

assert(have_vla and have_complex, 'Your C implementation needs to support complex numbers and variable-length arrays.')

@@ -310,8 +335,6 @@ config.set('TAISEI_BUILDCONF_LOG_FATAL_MSGBOX', (
host_machine.system() == 'darwin' or
not is_developer_build
))
# fixes some build issues on macOS, see PR #183
config.set('TAISEI_BUILDCONF_DARWIN_SOURCE', (host_machine.system() == 'darwin'))
config.set('TAISEI_BUILDCONF_DEBUG_OPENGL', get_option('debug_opengl'))

install_docs = get_option('docs') and host_machine.system() != 'emscripten'
@@ -11,17 +11,6 @@

#include "taisei.h"

#ifdef TAISEI_BUILDCONF_HAVE_POSIX
#define _POSIX_C_SOURCE 200809L
#endif

// When compiling for Apple devices, the _POSIX_C_SOURCE option above messes with what header functions
// are available to the compiler, and it'll complain that things like timespec_get, etc don't exist
// even if Meson can detect them initially. Defining this fixes it.
#ifdef TAISEI_BUILDCONF_DARWIN_SOURCE
#define _DARWIN_C_SOURCE
#endif

// Common standard library headers
#include <complex.h>
#include <ctype.h>

0 comments on commit b8c2755

Please sign in to comment.
You can’t perform that action at this time.