summaryrefslogtreecommitdiff
path: root/src
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 /src
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.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/gen_dispatch.py41
-rw-r--r--src/meson.build107
2 files changed, 101 insertions, 47 deletions
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)