summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2016-12-14 15:35:44 +0000
committerEmmanuele Bassi <ebassi@gnome.org>2017-01-25 12:36:20 +0000
commit59318edf6419afb850b7875ffee4d97522449a5a (patch)
treea0164f71d36748fb6059d81809b4eeddbd657109
parent08cc4d021dc523c4243a23b2b4ba432af760716b (diff)
downloadlibepoxy-59318edf6419afb850b7875ffee4d97522449a5a.tar.gz
build: Rework the build rules for generated files in Meson
Instead of using a generator and having to deal with tweaking the inclusion paths, we can use a custom target rule, which will do the right thing and put the generate files where we expect them to be. Due to how Meson and Ninja work we need to be a bit more careful as to how we deal with dependencies and generated files, especially since Epoxy is built on the assumption that the only inclusion path for the headers lies under the 'include' sub-directory. First of all, we need to split the dispatch table generation into two separate steps, one for the headers and one for the source files. Additionally, we need to munge the paths of the non-generated headers so that we reference them by their correct path. These changes are necessary to ensure that Epoxy can be built on a system without Epoxy installed already; the previous Meson-based build system relied on the headers being installed in a system directory.
-rw-r--r--include/epoxy/meson.build80
-rw-r--r--meson.build25
-rwxr-xr-xsrc/gen_dispatch.py41
-rw-r--r--src/meson.build107
-rw-r--r--test/meson.build3
5 files changed, 205 insertions, 51 deletions
diff --git a/include/epoxy/meson.build b/include/epoxy/meson.build
new file mode 100644
index 0000000..38fe4ad
--- /dev/null
+++ b/include/epoxy/meson.build
@@ -0,0 +1,80 @@
+gl_generated = custom_target('gl_generated.h',
+ input: gl_registry,
+ output: [
+ 'gl_generated.h',
+ ],
+ command: [
+ python,
+ gen_dispatch_py,
+ '--header',
+ '--no-source',
+ '--outputdir=' + meson.current_build_dir(),
+ '@INPUT@'
+ ],
+ install: true,
+ install_dir: join_paths(epoxy_includedir, 'epoxy'))
+
+gen_headers = [ gl_generated ]
+headers = [ 'gl.h', ]
+
+if build_egl
+ egl_generated = custom_target('egl_generated.h',
+ input: egl_registry,
+ output: [
+ 'egl_generated.h',
+ ],
+ command: [
+ python,
+ gen_dispatch_py,
+ '--header',
+ '--no-source',
+ '--outputdir=' + meson.current_build_dir(),
+ '@INPUT@'
+ ],
+ install: true,
+ install_dir: join_paths(epoxy_includedir, 'epoxy'))
+ gen_headers += [ egl_generated ]
+ headers += [ 'egl.h' ]
+endif
+
+if build_glx
+ glx_generated = custom_target('glx_generated.h',
+ input: glx_registry,
+ output: [
+ 'glx_generated.h',
+ ],
+ command: [
+ python,
+ gen_dispatch_py,
+ '--header',
+ '--no-source',
+ '--outputdir=' + meson.current_build_dir(),
+ '@INPUT@'
+ ],
+ install: true,
+ install_dir: join_paths(epoxy_includedir, 'epoxy'))
+ gen_headers += [ glx_generated ]
+ headers += [ 'glx.h' ]
+endif
+
+if build_wgl
+ wgl_generated = custom_target('wgl_generated.h',
+ input: wgl_registry,
+ output: [
+ 'wgl_generated.h',
+ ],
+ command: [
+ python,
+ gen_dispatch_py,
+ '--header',
+ '--no-source',
+ '--outputdir=' + meson.current_build_dir(),
+ '@INPUT@'
+ ],
+ install: true,
+ install_dir: join_paths(epoxy_includedir, 'epoxy'))
+ gen_headers += [ wgl_generated ]
+ headers += [ 'wgl.h' ]
+endif
+
+install_headers(headers, subdir: 'epoxy')
diff --git a/meson.build b/meson.build
index 101788c..a0c9554 100644
--- a/meson.build
+++ b/meson.build
@@ -1,6 +1,6 @@
-project('libepoxy', 'c', version: '1.3.1',
+project('libepoxy', 'c', version: '1.3.2',
default_options: [
- 'buildtype=debug',
+ 'buildtype=debugoptimized',
'c_std=gnu99',
'warning_level=1',
],
@@ -102,8 +102,6 @@ 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)
@@ -121,5 +119,24 @@ configure_file(input: 'epoxy.pc.in',
install: true,
install_dir: join_paths(epoxy_libdir, 'pkgconfig'))
+# Find Python for gen_dispatch
+# XXX: With Meson 0.37 we should use
+# python = import('python3').find_python()
+python = find_program('python3')
+
+# Generates the dispatch tables
+gen_dispatch_py = find_program('src/gen_dispatch.py')
+
+gl_registry = join_paths(meson.source_root(), 'registry/gl.xml')
+egl_registry = join_paths(meson.source_root(), 'registry/egl.xml')
+glx_registry = join_paths(meson.source_root(), 'registry/glx.xml')
+wgl_registry = join_paths(meson.source_root(), 'registry/wgl.xml')
+
+libepoxy_inc = [
+ include_directories('include'),
+ include_directories('src'),
+]
+
+subdir('include/epoxy')
subdir('src')
subdir('test')
diff --git a/src/gen_dispatch.py b/src/gen_dispatch.py
index 283d965..71c3bc1 100755
--- a/src/gen_dispatch.py
+++ b/src/gen_dispatch.py
@@ -836,23 +836,36 @@ class Generator(object):
argparser = argparse.ArgumentParser(description='Generate GL dispatch wrappers.')
argparser.add_argument('files', metavar='file.xml', nargs='+', help='GL API XML files to be parsed')
-argparser.add_argument('--srcdir', metavar='srcdir', required=False, help='Destination directory for source files')
-argparser.add_argument('--includedir', metavar='incdir', required=False, help='Destination director for header files')
-argparser.add_argument('--dir', metavar='dir', required=False, help='Destination directory')
+argparser.add_argument('--outputdir', metavar='dir', required=False, help='Destination directory for files (default to current dir)')
+argparser.add_argument('--includedir', metavar='dir', required=False, help='Destination directory for headers')
+argparser.add_argument('--srcdir', metavar='dir', required=False, help='Destination directory for source')
+argparser.add_argument('--source', dest='source', action='store_true', required=False, help='Generate the source file')
+argparser.add_argument('--no-source', dest='source', action='store_false', required=False, help='Do not generate the source file')
+argparser.add_argument('--header', dest='header', action='store_true', required=False, help='Generate the header file')
+argparser.add_argument('--no-header', dest='header', action='store_false', required=False, help='Do not generate the header file')
args = argparser.parse_args()
-if args.dir:
- srcdir = args.dir
- incdir = args.dir
+if args.outputdir:
+ outputdir = args.outputdir
else:
+ outputdir = os.getcwd()
+
+if args.includedir:
+ includedir = args.includedir
+else:
+ includedir = outputdir
+
+if args.srcdir:
srcdir = args.srcdir
- incdir = args.includedir
+else:
+ srcdir = outputdir
-if not srcdir:
- srcdir = os.getcwd()
+build_source = args.source
+build_header = args.header
-if not incdir:
- incdir = os.getcwd()
+if not build_source and not build_header:
+ build_source = True
+ build_header = True
for file in args.files:
name = os.path.basename(file).split('.xml')[0]
@@ -881,5 +894,7 @@ for file in args.files:
generator.prepare_provider_enum()
- generator.write_header(os.path.join(incdir, name + '_generated.h'))
- generator.write_source(os.path.join(srcdir, name + '_generated_dispatch.c'))
+ if build_header:
+ generator.write_header(os.path.join(includedir, name + '_generated.h'))
+ if build_source:
+ generator.write_source(os.path.join(srcdir, name + '_generated_dispatch.c'))
diff --git a/src/meson.build b/src/meson.build
index 1ca4117..c47a674 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -6,45 +6,87 @@ common_sources = [
# Configuration file
configure_file(output: 'config.h', configuration: conf)
-# Generate the dispatch tables
-gen_dispatch_py = find_program('gen_dispatch.py')
+gl_generated = custom_target('gl_generated_dispatch.c',
+ input: gl_registry,
+ output: [
+ 'gl_generated_dispatch.c',
+ ],
+ command: [
+ python,
+ gen_dispatch_py,
+ '--source',
+ '--no-header',
+ '--outputdir=' + meson.current_build_dir(),
+ '@INPUT@',
+ ])
-gen_dispatch = generator(gen_dispatch_py,
- output: [ '@BASENAME@_generated.h', '@BASENAME@_generated_dispatch.c', ],
- arguments: [ '--dir=@BUILD_DIR@', '@INPUT@' ])
+gen_sources = [ gl_generated ]
+sources = common_sources
-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', ]
+ egl_generated = custom_target('egl_generated_dispatch.c',
+ input: egl_registry,
+ output: [
+ 'egl_generated_dispatch.c',
+ ],
+ command: [
+ python,
+ gen_dispatch_py,
+ '--source',
+ '--no-header',
+ '--outputdir=' + meson.current_build_dir(),
+ '@INPUT@',
+ ])
+ gen_sources += [ egl_generated ]
+ sources += [ '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', ]
+ glx_generated = custom_target('glx_generated_dispatch.c',
+ input: glx_registry,
+ output: [
+ 'glx_generated_dispatch.c',
+ ],
+ command: [
+ python,
+ gen_dispatch_py,
+ '--source',
+ '--no-header',
+ '--outputdir=' + meson.current_build_dir(),
+ '@INPUT@',
+ ])
+ gen_sources += [ glx_generated ]
+ sources += [ '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', ]
+ wgl_generated = custom_target('wgl_generated_dispatch.c',
+ input: wgl_registry,
+ output: [
+ 'wgl_generated_dispatch.c',
+ ],
+ command: [
+ python,
+ gen_dispatch_py,
+ '--source',
+ '--no-header',
+ '--outputdir=' + meson.current_build_dir(),
+ '@INPUT@',
+ ])
+ gen_sources += [ wgl_generated ]
+ sources += [ 'dispatch_wgl.c' ]
endif
-if cc.get_id() == 'msvc'
- common_ldflags = []
-else
+epoxy_sources = common_sources + sources + gen_sources
+epoxy_headers = gen_headers
+foreach h: headers
+ epoxy_headers += join_paths(meson.source_root(), 'include/epoxy/@0@'.format(h))
+endforeach
+
+if cc.get_id() == 'gcc'
common_ldflags = [ '-Wl,-Bsymbolic', ]
+else
+ common_ldflags = []
endif
epoxy_deps = [ dl_dep, ]
@@ -53,14 +95,12 @@ if host_system == 'windows'
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 ],
+ sources: epoxy_sources + epoxy_headers,
install: true,
dependencies: epoxy_deps,
include_directories: libepoxy_inc,
@@ -71,7 +111,7 @@ endif
if libtype != 'static'
libepoxy_shared = shared_library('epoxy',
- sources: common_sources + [ gl_sources, egl_sources, glx_sources, wgl_sources ],
+ sources: epoxy_sources + epoxy_headers,
version: '0.0.0',
install: true,
dependencies: epoxy_deps,
@@ -83,6 +123,5 @@ 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')
+ dependencies: epoxy_deps,
+ sources: epoxy_headers)
diff --git a/test/meson.build b/test/meson.build
index eaf3952..857a980 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -11,10 +11,12 @@ test_cflags = common_cflags + [
test('header_guards',
executable('header guards', 'headerguards.c',
c_args: common_cflags,
+ dependencies: libepoxy_dep,
include_directories: libepoxy_inc))
test('misc_defines',
executable('misc defines', 'miscdefines.c',
c_args: common_cflags,
+ dependencies: libepoxy_dep,
include_directories: libepoxy_inc))
test('khronos_typedefs',
executable('khronos typedefs', [
@@ -23,6 +25,7 @@ test('khronos_typedefs',
'khronos_typedefs_nonepoxy.c',
],
c_args: common_cflags,
+ dependencies: libepoxy_dep,
include_directories: libepoxy_inc))
if build_egl and build_x11_tests