Skip to content

Commit

Permalink
Use only one aligned alloc function
Browse files Browse the repository at this point in the history
Closes: ebassi#76

This commit makes the existing flat set of macro tests into a big if-else
block, and selects only one aligned alloc function. If no such function is
available, meson now terminates with an error and the build will fail.

This is as recommended by @nirbheek, who suggests that meson should only
search for a single aligned memory allocation function during configuration
of graphene.

Ref: ebassi#86 (comment)

On MSYS2, a buggy mismatch between the native mingw-w64 builtins and the
standard headers causes meson < 0.37.0 to report that the function exists
because the underlying builtin exists. Cascading the tests like this works
around breaking configuration on the MSYS2 platform for meson<0.37 by
excluding certain POSIX-only cases on Windows.

Ref: mesonbuild/meson#1083
  • Loading branch information
achadwick committed Jan 3, 2017
1 parent a3a959b commit df7e479
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions meson.build
Expand Up @@ -129,10 +129,21 @@ conf.set('HAVE_STDBOOL_H', cc.has_header('stdbool.h'))
conf.set('HAVE_MEMORY_H', cc.has_header('memory.h'))

# Functions
conf.set('HAVE_ALIGNED_ALLOC', cc.has_function('aligned_alloc', prefix: '#include <stdlib.h>'))
conf.set('HAVE__ALIGNED_MALLOC', cc.has_function('_aligned_malloc', prefix: '#include <malloc.h>'))
conf.set('HAVE_MEMALIGN', cc.has_function('memalign', prefix: '#include <stdlib.h>\n#include <malloc.h>'))
conf.set('HAVE_POSIX_MEMALIGN', cc.has_function('posix_memalign', prefix: '#include <stdlib.h>'))
if cc.has_function('memalign', prefix: '#include <stdlib.h>\n#include <malloc.h>')
conf.set('HAVE_MEMALIGN', 1)
elif cc.has_function('_aligned_malloc', prefix: '#include <malloc.h>')
conf.set('HAVE__ALIGNED_MALLOC', 1)
# Don't probe the ones below on Windows because when building with
# MinGW-w64 on MSYS2, Meson<0.37.0 incorrectly detects those below as
# being available even though they're not.
elif cc.has_function('aligned_alloc', prefix: '#include <stdlib.h>') and not (host_system == 'windows')
conf.set('HAVE_ALIGNED_ALLOC', 1)
elif cc.has_function('posix_memalign', prefix: '#include <stdlib.h>') and not (host_system == 'windows')
conf.set('HAVE_POSIX_MEMALIGN', 1)
else
error('No aligned malloc function could be found.')
endif

conf.set('HAVE_SINCOSF', cc.has_function('sincosf', prefix: '#define _GNU_SOURCE\n#include <math.h>'))

# Debugging
Expand Down

0 comments on commit df7e479

Please sign in to comment.