build: Add Meson build files

Meson is a Python-based build system that generates build rules of
Ninja, Visual Studio, and XCode. It's designed to be fast, and have a
small, non-Turing complete language to describe the build process,
tests, and dependencies. It's simpler than CMake, and faster than
autotools.

As a direct comparison in terms of speed, three build and check runs for
libepoxy from a clean Git repository clone yield these results on my
Kabylake Core i7 7500U (nproc=4):

- Autotools (make)
Run #1 (cold)   real: 22.384s, user: 20.011s, sys: 3.689s
Run #2 (warm)   real: 22.429s, user: 20.220s, sys: 3.708s
Run #3 (warm)   real: 22.068s, user: 19.743s, sys: 3.594s

- Meson (ninja)
Run #1 (cold)   real: 5.932s, user:  9.371s, sys: 1.625s
Run #2 (warm)   real: 6.273s, user: 10.066,  sys: 1.740s
Run #3 (warm)   real: 5.796s, user:  9.233s, sys: 1.607s

Which means that Meson and ninja are approximately 4x faster than
autotools.

In terms of simplicity, the autotools build takes six files and a total
of 645 lines; Meson requires 3 files, and 361 lines to achieve the same
result. Additionally, Meson automatically builds in a separate build
directory and does not leave files inside the source directory; and Meson
does not use libtool.

Since Meson is quite new and still actively developed, we're going to
leave the autotools build in place for a while, with the intention of
switching to Meson in the future.
macos/v1.5.9
Emmanuele Bassi 8 years ago
parent e2e2fedbdb
commit 08cc4d021d
  1. 125
      meson.build
  2. 88
      src/meson.build
  3. 174
      test/meson.build

@ -0,0 +1,125 @@
project('libepoxy', 'c', version: '1.3.1',
default_options: [
'buildtype=debug',
'c_std=gnu99',
'warning_level=1',
],
license: 'MIT',
meson_version: '>= 0.36.0')
epoxy_version = meson.project_version().split('.')
epoxy_major_version = epoxy_version[0].to_int()
epoxy_minor_version = epoxy_version[1].to_int()
epoxy_micro_version = epoxy_version[2].to_int()
epoxy_prefix = get_option('prefix')
epoxy_libdir = join_paths(epoxy_prefix, get_option('libdir'))
epoxy_datadir = join_paths(epoxy_prefix, get_option('datadir'))
epoxy_includedir = join_paths(epoxy_prefix, get_option('includedir'))
cc = meson.get_compiler('c')
host_system = host_machine.system()
conf = configuration_data()
conf.set_quoted('PACKAGE_NAME', meson.project_name())
conf.set_quoted('PACKAGE_VERSION', meson.project_version())
conf.set_quoted('PACKAGE_STRING', '@0@-@1@'.format(meson.project_name(), meson.project_version()))
conf.set_quoted('PACKAGE_DATADIR', join_paths(get_option('prefix'), get_option('datadir')))
conf.set_quoted('PACKAGE_LIBDIR', join_paths(get_option('prefix'), get_option('libdir')))
conf.set_quoted('PACKAGE_LOCALEDIR', join_paths(get_option('prefix'), get_option('datadir'), 'locale'))
conf.set_quoted('PACKAGE_LIBEXECDIR', join_paths(get_option('prefix'), get_option('libexecdir')))
conf.set('HAVE_KHRPLATFORM_H', cc.has_header('KHR/khrplatform.h', required: false))
if host_system == 'windows'
build_glx = false
build_egl = false
build_apple = false
build_wgl = true
has_znow = true
elif host_system == 'darwin'
build_glx = false
build_egl = false
build_apple = true
build_wgl = false
has_znow = false
else
build_glx = true
build_egl = true
build_apple = false
build_wgl = false
has_znow = true
endif
# Compiler flags, taken from the Xorg macros
test_cflags = [
'-Wall',
'-Wpointer-arith',
'-Wmissing-declarations',
'-Wformat=2',
'-Wstrict-prototypes',
'-Wmissing-prototypes',
'-Wnested-externs',
'-Wbad-function-cast',
'-Wold-style-definition',
'-Wdeclaration-after-statement',
'-Wunused',
'-Wuninitialized',
'-Wshadow',
'-Wmissing-noreturn',
'-Wmissing-format-attribute',
'-Wredundant-decls',
'-Wlogical-op',
'-Werror=implicit',
'-Werror=nonnull',
'-Werror=init-self',
'-Werror=main',
'-Werror=missing-braces',
'-Werror=sequence-point',
'-Werror=return-type',
'-Werror=trigraphs',
'-Werror=array-bounds',
'-Werror=write-strings',
'-Werror=address',
'-Werror=int-to-pointer-cast',
'-Werror=pointer-to-int-cast',
'-fno-strict-aliasing',
'-Wno-int-conversion',
]
common_cflags = []
foreach cflag: test_cflags
if cc.has_argument(cflag)
common_cflags += [ cflag ]
endif
endforeach
# Dependencies
dl_dep = cc.find_library('dl', required: false)
gl_dep = dependency('gl', required: false)
egl_dep = dependency('egl', required: false)
# Optional dependencies for tests
x11_dep = dependency('x11', required: false)
gles1_dep = cc.find_library('libGLESv1_CM', required: false)
gles2_dep = cc.find_library('libGLESv2', required: false)
epoxy_include = include_directories('include')
# PkgConfig file
pkgconf = configuration_data()
pkgconf.set('prefix', epoxy_prefix)
pkgconf.set('exec_prefix', epoxy_prefix)
pkgconf.set('libdir', epoxy_libdir)
pkgconf.set('includedir', epoxy_includedir)
pkgconf.set('PACKAGE_VERSION', meson.project_version())
if dl_dep.found()
pkgconf.set('DLOPEN_LIBS', '-ldl')
endif
configure_file(input: 'epoxy.pc.in',
output: 'epoxy.pc',
configuration: pkgconf,
install: true,
install_dir: join_paths(epoxy_libdir, 'pkgconfig'))
subdir('src')
subdir('test')

@ -0,0 +1,88 @@
common_sources = [
'dispatch_common.c',
'dispatch_common.h',
]
# Configuration file
configure_file(output: 'config.h', configuration: conf)
# Generate the dispatch tables
gen_dispatch_py = find_program('gen_dispatch.py')
gen_dispatch = generator(gen_dispatch_py,
output: [ '@BASENAME@_generated.h', '@BASENAME@_generated_dispatch.c', ],
arguments: [ '--dir=@BUILD_DIR@', '@INPUT@' ])
gl_generated = gen_dispatch.process(join_paths(meson.source_root(), 'registry/gl.xml'))
gl_headers = [ join_paths(meson.source_root(), 'include/epoxy/gl.h'), 'gl_generated.h', ]
gl_sources = gl_generated
egl_headers = []
egl_sources = []
if build_egl
egl_generated = gen_dispatch.process(join_paths(meson.source_root(), 'registry/egl.xml'))
egl_headers += [ join_paths(meson.source_root(), 'include/epoxy/egl.h'), 'egl_generated.h', ]
egl_sources += [ egl_generated, 'dispatch_egl.c', ]
endif
glx_headers = []
glx_sources = []
if build_glx
glx_generated = gen_dispatch.process(join_paths(meson.source_root(), 'registry/glx.xml'))
glx_headers += [ join_paths(meson.source_root(), 'include/epoxy/glx.h'), 'glx_generated.h', ]
glx_sources += [ glx_generated, 'dispatch_glx.c', ]
endif
wgl_headers = []
wgl_sources = []
if build_wgl
wgl_generated = gen_dispatch.process(join_paths(meson.source_root(), 'registry/wgl.xml'))
wgl_headers += [ join_paths(meson.source_root(), 'include/epoxy/wgl.h'), 'wgl_generated.h', ]
wgl_sources += [ wgl_generated, 'dispatch_wgl.c', ]
endif
if cc.get_id() == 'msvc'
common_ldflags = []
else
common_ldflags = [ '-Wl,-Bsymbolic', ]
endif
epoxy_deps = [ dl_dep, ]
if host_system == 'windows'
ogl_dep = cc.find_library('opengl32', required: true)
epoxy_deps += [ ogl_dep, ]
endif
libepoxy_inc = [ epoxy_include, include_directories('.'), ]
# Allow building a static version of epoxy
libtype = get_option('default_library')
if libtype != 'shared'
libepoxy_static = static_library('epoxy',
common_sources + [ gl_sources, egl_sources, glx_sources, wgl_sources ],
install: true,
dependencies: epoxy_deps,
include_directories: libepoxy_inc,
c_args: common_cflags,
link_args: common_ldflags)
libepoxy = libepoxy_static
endif
if libtype != 'static'
libepoxy_shared = shared_library('epoxy',
sources: common_sources + [ gl_sources, egl_sources, glx_sources, wgl_sources ],
version: '0.0.0',
install: true,
dependencies: epoxy_deps,
include_directories: libepoxy_inc,
c_args: common_cflags,
link_args: common_ldflags)
libepoxy = libepoxy_shared
endif
libepoxy_dep = declare_dependency(link_with: libepoxy,
include_directories: libepoxy_inc,
dependencies: dl_dep)
install_headers(gl_headers + glx_headers + egl_headers + wgl_headers, subdir: 'epoxy')

@ -0,0 +1,174 @@
has_gles1 = gles1_dep.found()
has_gles2 = gles2_dep.found()
build_x11_tests = x11_dep.found()
test_cflags = common_cflags + [
'-D_XOPEN_SOURCE',
'-D_POSIX_C_SOURCE=200809L',
]
# Unconditionally built tests
test('header_guards',
executable('header guards', 'headerguards.c',
c_args: common_cflags,
include_directories: libepoxy_inc))
test('misc_defines',
executable('misc defines', 'miscdefines.c',
c_args: common_cflags,
include_directories: libepoxy_inc))
test('khronos_typedefs',
executable('khronos typedefs', [
'khronos_typedefs.c',
'khronos_typedefs.h',
'khronos_typedefs_nonepoxy.c',
],
c_args: common_cflags,
include_directories: libepoxy_inc))
if build_egl and build_x11_tests
egl_common_sources = [ 'egl_common.h', 'egl_common.c', ]
egl_common_lib = static_library('egl_common',
sources: egl_common_sources,
dependencies: libepoxy_dep,
include_directories: libepoxy_inc,
c_args: common_cflags,
install: false)
egl_tests = [
[ 'egl_has_extension_nocontext', [], [ 'egl_has_extension_nocontext.c' ], true, ],
[ 'egl_gl', [], [ 'egl_gl.c' ], true, ],
[ 'egl_gles1_without_glx', [ '-DGLES_VERSION=1', ], [ 'egl_without_glx.c' ], has_gles1, ],
[ 'egl_gles2_without_glx', [ '-DGLES_VERSION=2', ], [ 'egl_without_glx.c' ], has_gles2, ],
]
foreach test: egl_tests
test_name = test[0]
test_source = test[2]
test_args = test[1]
test_run = test[3]
if test_run
test_bin = executable(test_name, test_source,
c_args: test_cflags + test_args,
include_directories: libepoxy_inc,
dependencies: [ libepoxy_dep, x11_dep, egl_dep, dl_dep ],
link_with: egl_common_lib,
link_args: '-rdynamic')
test(test_name, test_bin)
endif
endforeach
endif
if build_glx
glx_common_sources = [ 'glx_common.h', 'glx_common.c', ]
glx_common_lib = static_library('glx_common',
sources: glx_common_sources,
dependencies: libepoxy_dep,
include_directories: libepoxy_inc,
c_args: common_cflags,
install: false)
# glx_beginend links directly with the GL library, so we need to check it
# separately
test('glx_beginend', executable('glx_beginend', 'glx_beginend.c',
c_args: test_cflags,
include_directories: libepoxy_inc,
dependencies: [ libepoxy_dep, x11_dep, gl_dep, dl_dep ],
link_with: glx_common_lib))
glx_tests = [
[ 'glx_public_api', [ 'glx_public_api.c' ], [], [], true ],
[ 'glx_public_api_core', [ 'glx_public_api_core.c' ], [], [], true ],
[ 'glx_glxgetprocaddress_nocontext', [ 'glx_glxgetprocaddress_nocontext.c' ], [], [], true ],
[ 'glx_has_extension_nocontext', [ 'glx_has_extension_nocontext.c' ], [], [], true ],
[ 'glx_static', [ 'glx_static.c' ], [ '-DNEEDS_TO_BE_STATIC'], [ '-static' ], libtype == 'static' ],
[ 'glx_shared_znow', [ 'glx_static.c', ], [], [ '-Wl,-z,now' ], has_znow ],
[ 'glx_alias_prefer_same_name', [ 'glx_alias_prefer_same_name.c', 'dlwrap.c', 'dlwrap.h' ], [], [ '-rdynamic' ], not build_apple ],
[ 'glx_gles2', [ 'glx_gles2.c', 'dlwrap.c', 'dlwrap.h' ], [], [ '-rdynamic' ], not build_apple ],
]
foreach test: glx_tests
test_name = test[0]
test_source = test[1]
test_c_args = test[2]
test_link_args = test[3]
test_run = test[4]
if test_run
test_bin = executable(test_name, test_source,
c_args: test_cflags + test_c_args,
include_directories: libepoxy_inc,
dependencies: [ libepoxy_dep, x11_dep, dl_dep ],
link_with: glx_common_lib,
link_args: test_link_args)
test(test_name, test_bin)
endif
endforeach
if not build_apple
# GLX/EGL tests
if build_egl
glx_egl_sources = [
'egl_and_glx_different_pointers.c',
'dlwrap.c',
'dlwrap.h',
]
glx_egl_deps = [ libepoxy_dep, x11_dep, dl_dep ]
glx_egl_link_flags = [ '-rdynamic' ]
glx_egl_link_with = [ glx_common_lib, egl_common_lib ]
glx_egl_tests = [
[ 'egl_and_glx_different_pointers_glx', [ '-DUSE_GLX' ], false ],
[ 'egl_and_glx_different_pointers_egl', [ '-DUSE_EGL' ], false ],
[ 'egl_and_glx_different_pointers_egl_glx', [ '-DUSE_EGL', '-DUSE_GLX' ], true ],
]
foreach test: glx_egl_tests
test_name = test[0]
test_c_args = test[1]
test_should_fail = test[2]
test_bin = executable(test_name, glx_egl_sources,
c_args: common_cflags + test_c_args,
include_directories: libepoxy_inc,
dependencies: glx_egl_deps,
link_with: glx_egl_link_with,
link_args: glx_egl_link_flags)
test(test_name, test_bin, should_fail: test_should_fail)
endforeach
endif
endif
endif
# WGL
if build_wgl
wgl_common_sources = [ 'wgl_common.h', 'wgl_common.c', ]
wgl_common_lib = static_library('wgl_common',
sources: wgl_common_sources,
dependencies: libepoxy_dep,
include_directories: libepoxy_inc,
c_args: common_cflags,
install: false)
wgl_tests = [
[ 'wgl_core_and_exts', [ 'wgl_core_and_exts.c' ], [], ],
[ 'wgl_per_context_funcptrs', [ 'wgl_per_context_funcptrs.c' ], [], ],
[ 'wgl_usefontbitmaps', [ 'wgl_usefontbitmaps.c'], [], ],
[ 'wgl_usefontbitmaps_unicode', [ 'wgl_usefontbitmaps.c' ], [ '-DUNICODE' ], ],
]
foreach test: wgl_tests
test_name = test[0]
test_source = test[1]
test_c_args = test[2]
test_bin = executable(test_name, test_source,
c_args: test_cflags + test_c_args,
include_directories: libepoxy_inc,
dependencies: [ libepoxy_dep ],
link_with: wgl_common_lib)
test(test_name, test_bin)
endforeach
endif
Loading…
Cancel
Save