We now support the common meson option -Ddefault_library, with values
'both' (the default), 'shared' (install only shared libraries), and
'static' (install only static libraries). The 'static' choice doesn't
actually work, since psql and other programs insist on linking to the
shared version of libpq, but it's there pro-forma. It could be built
out if we really wanted, but since we have never supported the
equivalent in the autoconf build system, there doesn't appear to be an
urgent need.
With an eye to re-supporting AIX, the internal implementation
distinguishes whether to install libpgport.a and other static-only
libraries from whether to build/install the static variant of
libraries that we can build both ways. This detail isn't exposed as a
meson option, though it could be if there's demand.
The Cirrus CI task SanityCheck now uses -Ddefault_library=shared to
save a little bit of build time (and to test this option).
Author: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/
e8aa97db-872b-4087-b073-
f296baae948d@eisentraut.org
meson setup \
--buildtype=debug \
--auto-features=disabled \
+ -Ddefault_library=shared \
-Dtap_tests=enabled \
build
EOF
</listitem>
</varlistentry>
+ <varlistentry id="configure-default-library-meson">
+ <term><option>-Ddefault_library={ both | shared }</option></term>
+ <listitem>
+ <para>
+ This option selects whether both shared and static libraries are built
+ (the default), or only shared libraries. (The third variant of only
+ building static libraries is currently not supported.)
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="configure-extra-include-dirs-meson">
<term><option>-Dextra_include_dirs=<replaceable>DIRECTORIES</replaceable></option></term>
<listitem>
'warning_level=1', #-Wall equivalent
'b_pch=false',
'buildtype=debugoptimized', # -O2 + debug
+ 'default_library=both',
# For compatibility with the autoconf build, set a default prefix. This
# works even on windows, where it's a drive-relative path (i.e. when on
# d:/somepath it'll install to d:/usr/local/pgsql)
thread_dep = dependency('threads')
auto_features = get_option('auto_features')
+# Declare variables to disable static or shared libraries. This
+# makes the 'default_library' option work even though we don't use the
+# library() function but instead shared_library() and static_library()
+# separately.
+#
+# build_shared_lib/build_static_lib control building/installing the two
+# versions of libraries that we can build both versions of (e.g., libpq).
+# There are also libraries that we only build a static version of (e.g.,
+# libpgport). These are always built, since we need them while building,
+# but they are installed only if install_internal_static_lib is true.
+#
+# Note: at present, -Ddefault_library=static doesn't actually work, because
+# psql and other programs insist on linking to the shared version of libpq.
+# This could be fixed if there was interest, but so far there is not.
+default_library_opt = get_option('default_library')
+build_shared_lib = true
+build_static_lib = true
+install_internal_static_lib = true
+if default_library_opt == 'shared'
+ build_static_lib = false
+ install_internal_static_lib = false
+elif default_library_opt == 'static'
+ build_shared_lib = false
+ error('-Ddefault_library=static is not yet supported')
+endif
+
###############################################################
opts.get('include_directories', []),
],
'dependencies': opts['dependencies'] + [ssl],
+ 'install': install_internal_static_lib and name != '_srv',
}
)
pgcommon += {name: lib}
include_directories: [postgres_inc, libpq_inc],
c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [],
dependencies: frontend_common_code,
- kwargs: default_lib_args,
+ kwargs: default_lib_args + {
+ 'install': install_internal_static_lib,
+ },
)
endif
# see src/interfaces/libpq/meson.build
+if build_static_lib
ecpg_compat_st = static_library('libecpg_compat',
ecpg_compat_sources,
include_directories: ecpg_compat_inc,
kwargs: default_lib_args,
)
ecpg_targets += ecpg_compat_st
+endif
+if build_shared_lib
ecpg_compat_so = shared_library('libecpg_compat',
ecpg_compat_sources + ecpg_compat_so_sources,
include_directories: ecpg_compat_inc,
kwargs: default_lib_args,
)
ecpg_targets += ecpg_compat_so
+endif
pkgconfig.generate(
name: 'libecpg_compat',
endif
# see src/interfaces/libpq/meson.build
+if build_static_lib
ecpglib_st = static_library('libecpg',
ecpglib_sources,
include_directories: ecpglib_inc,
kwargs: default_lib_args,
)
ecpg_targets += ecpglib_st
+endif
+if build_shared_lib
ecpglib_so = shared_library('libecpg',
ecpglib_sources + ecpglib_so_sources,
include_directories: ecpglib_inc,
kwargs: default_lib_args,
)
ecpg_targets += ecpglib_so
+endif
pkgconfig.generate(
name: 'libecpg',
endif
# see src/interfaces/libpq/meson.build
+if build_static_lib
ecpg_pgtypes_st = static_library('libpgtypes',
ecpg_pgtypes_sources,
include_directories: ecpg_pgtypes_inc,
kwargs: default_lib_args,
)
ecpg_targets += ecpg_pgtypes_st
+endif
+if build_shared_lib
ecpg_pgtypes_so = shared_library('libpgtypes',
ecpg_pgtypes_sources + ecpg_pgtypes_so_sources,
include_directories: ecpg_pgtypes_inc,
kwargs: default_lib_args,
)
ecpg_targets += ecpg_pgtypes_so
+endif
pkgconfig.generate(
name: 'libpgtypes',
# port needs to be in include path due to pthread-win32.h
libpq_oauth_inc = include_directories('.', '../libpq', '../../port')
+if build_static_lib
libpq_oauth_st = static_library('libpq-oauth',
libpq_oauth_sources,
include_directories: [libpq_oauth_inc, postgres_inc],
kwargs: default_lib_args,
)
libpq_targets += libpq_oauth_st
+endif
# This is an internal module; we don't want an SONAME and therefore do not set
# SO_MAJOR_VERSION.
libpq_oauth_name = 'libpq-oauth-@0@'.format(pg_version_major)
+if build_shared_lib
libpq_oauth_so = shared_module(libpq_oauth_name,
libpq_oauth_sources + libpq_oauth_so_sources,
include_directories: [libpq_oauth_inc, postgres_inc],
kwargs: default_lib_args,
)
libpq_targets += libpq_oauth_so
+endif
libpq_oauth_test_deps = []
# We could try to avoid building the source files twice, but it probably adds
# more complexity than its worth (reusing object files requires also linking
# to the library on windows or breaks precompiled headers).
+if build_static_lib
libpq_st = static_library('libpq',
libpq_sources,
include_directories: [libpq_inc],
kwargs: default_lib_args,
)
libpq_targets += libpq_st
+endif
+if build_shared_lib
libpq_so = shared_library('libpq',
libpq_sources + libpq_so_sources,
include_directories: [libpq_inc, postgres_inc],
kwargs: default_lib_args,
)
libpq_targets += libpq_so
+endif
libpq = declare_dependency(
link_with: [libpq_so],
c_pch: pch_c_h,
kwargs: opts + {
'dependencies': opts['dependencies'] + [ssl],
+ 'install': install_internal_static_lib and name != '_srv',
}
)
pgport += {name: lib}