From 47adc7d3dec1e1d2454750612d48353944fcf836 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 13 Jul 2022 15:51:25 -0400 Subject: Simplify linking against static libraries This adds -DSERD_STATIC to the Cflags in the pkg-config file if serd is built as a static library, to simplify linking against a static serd library with pkg-config. Note that this only works for default_library=static. For linking against libraries built with default_library=both, dependant projects must still specify SERD_STATIC for static builds. Resolving that requires meson adding support for writing Cflags.local, and the world migrating to pkgconf (or improving pkg-config) so it is supported. --- meson.build | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/meson.build b/meson.build index 2b9c1d3a..217d1772 100644 --- a/meson.build +++ b/meson.build @@ -60,16 +60,17 @@ sources = files( ) # Set appropriate arguments for building against the library type +extra_c_args = [] subdir('meson/library') if get_option('default_library') == 'static' - add_project_arguments(['-DSERD_STATIC'], language: ['c']) + extra_c_args = ['-DSERD_STATIC'] endif # Build shared and/or static library libserd = library( meson.project_name() + library_suffix, sources, - c_args: c_suppressions + [ + c_args: c_suppressions + extra_c_args + [ '-DSERD_INTERNAL', '-DSERD_VERSION="@0@"'.format(meson.project_version()), ], @@ -77,10 +78,12 @@ libserd = library( gnu_symbol_visibility: 'hidden', include_directories: include_dirs, install: true, - version: meson.project_version()) + version: meson.project_version(), +) # Declare dependency for internal meson dependants serd_dep = declare_dependency( + compile_args: extra_c_args, include_directories: include_dirs, link_with: libserd, ) @@ -89,6 +92,7 @@ serd_dep = declare_dependency( pkg.generate( libserd, description: 'A lightweight library for working with RDF', + extra_cflags: extra_c_args, filebase: versioned_name, name: get_option('title'), subdirs: [versioned_name], -- cgit v1.2.1