From: Peter Eisentraut Date: Mon, 23 Feb 2026 15:25:54 +0000 (+0100) Subject: meson: allow disabling building/installation of static libraries. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=78727dcba32ed374eb2e92df976649bff56e2056;p=thirdparty%2Fpostgresql.git meson: allow disabling building/installation of static libraries. 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 Reviewed-by: Andres Freund Reviewed-by: Tom Lane Discussion: https://postgr.es/m/e8aa97db-872b-4087-b073-f296baae948d@eisentraut.org --- diff --git a/.cirrus.tasks.yml b/.cirrus.tasks.yml index 2a821593ce5..4841a204248 100644 --- a/.cirrus.tasks.yml +++ b/.cirrus.tasks.yml @@ -133,6 +133,7 @@ task: meson setup \ --buildtype=debug \ --auto-features=disabled \ + -Ddefault_library=shared \ -Dtap_tests=enabled \ build EOF diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml index c903ccff988..2937c4a8fd0 100644 --- a/doc/src/sgml/installation.sgml +++ b/doc/src/sgml/installation.sgml @@ -2807,6 +2807,17 @@ ninja install + + + + + 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.) + + + + diff --git a/meson.build b/meson.build index 83d1f06b528..47b7eb02275 100644 --- a/meson.build +++ b/meson.build @@ -20,6 +20,7 @@ project('postgresql', '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) @@ -50,6 +51,32 @@ not_found_dep = dependency('', required: false) 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 + ############################################################### diff --git a/src/common/meson.build b/src/common/meson.build index b757618a9c9..4f9b8b8263d 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -192,6 +192,7 @@ foreach name, opts : pgcommon_variants opts.get('include_directories', []), ], 'dependencies': opts['dependencies'] + [ssl], + 'install': install_internal_static_lib and name != '_srv', } ) pgcommon += {name: lib} diff --git a/src/fe_utils/meson.build b/src/fe_utils/meson.build index a2420ea2d5c..86befca192e 100644 --- a/src/fe_utils/meson.build +++ b/src/fe_utils/meson.build @@ -35,5 +35,7 @@ fe_utils = static_library('libpgfeutils', 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, + }, ) diff --git a/src/interfaces/ecpg/compatlib/meson.build b/src/interfaces/ecpg/compatlib/meson.build index 6cb1be73407..d578faefe1c 100644 --- a/src/interfaces/ecpg/compatlib/meson.build +++ b/src/interfaces/ecpg/compatlib/meson.build @@ -16,6 +16,7 @@ if host_system == 'windows' 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, @@ -25,7 +26,9 @@ ecpg_compat_st = static_library('libecpg_compat', 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, @@ -40,6 +43,7 @@ ecpg_compat_so = shared_library('libecpg_compat', kwargs: default_lib_args, ) ecpg_targets += ecpg_compat_so +endif pkgconfig.generate( name: 'libecpg_compat', diff --git a/src/interfaces/ecpg/ecpglib/meson.build b/src/interfaces/ecpg/ecpglib/meson.build index 889bd9efd65..81e92151945 100644 --- a/src/interfaces/ecpg/ecpglib/meson.build +++ b/src/interfaces/ecpg/ecpglib/meson.build @@ -25,6 +25,7 @@ if host_system == 'windows' endif # see src/interfaces/libpq/meson.build +if build_static_lib ecpglib_st = static_library('libecpg', ecpglib_sources, include_directories: ecpglib_inc, @@ -35,7 +36,9 @@ ecpglib_st = static_library('libecpg', 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, @@ -51,6 +54,7 @@ ecpglib_so = shared_library('libecpg', kwargs: default_lib_args, ) ecpg_targets += ecpglib_so +endif pkgconfig.generate( name: 'libecpg', diff --git a/src/interfaces/ecpg/pgtypeslib/meson.build b/src/interfaces/ecpg/pgtypeslib/meson.build index 6b78f529e53..de564c63a5b 100644 --- a/src/interfaces/ecpg/pgtypeslib/meson.build +++ b/src/interfaces/ecpg/pgtypeslib/meson.build @@ -21,6 +21,7 @@ if host_system == 'windows' 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, @@ -30,7 +31,9 @@ ecpg_pgtypes_st = static_library('libpgtypes', 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, @@ -45,6 +48,7 @@ ecpg_pgtypes_so = shared_library('libpgtypes', kwargs: default_lib_args, ) ecpg_targets += ecpg_pgtypes_so +endif pkgconfig.generate( name: 'libpgtypes', diff --git a/src/interfaces/libpq-oauth/meson.build b/src/interfaces/libpq-oauth/meson.build index e573d36f20e..27aca2bc324 100644 --- a/src/interfaces/libpq-oauth/meson.build +++ b/src/interfaces/libpq-oauth/meson.build @@ -21,6 +21,7 @@ export_file = custom_target('libpq-oauth.exports', # 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], @@ -33,11 +34,13 @@ libpq_oauth_st = static_library('libpq-oauth', 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], @@ -49,6 +52,7 @@ libpq_oauth_so = shared_module(libpq_oauth_name, kwargs: default_lib_args, ) libpq_targets += libpq_oauth_so +endif libpq_oauth_test_deps = [] diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build index 0b8dd3e1f5e..2b95098187e 100644 --- a/src/interfaces/libpq/meson.build +++ b/src/interfaces/libpq/meson.build @@ -57,6 +57,7 @@ libpq_so_c_args = ['-DUSE_DYNAMIC_OAUTH'] # 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], @@ -66,7 +67,9 @@ libpq_st = static_library('libpq', 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], @@ -81,6 +84,7 @@ libpq_so = shared_library('libpq', kwargs: default_lib_args, ) libpq_targets += libpq_so +endif libpq = declare_dependency( link_with: [libpq_so], diff --git a/src/port/meson.build b/src/port/meson.build index edb2e5632bd..7296f8e3c03 100644 --- a/src/port/meson.build +++ b/src/port/meson.build @@ -191,6 +191,7 @@ foreach name, opts : pgport_variants c_pch: pch_c_h, kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], + 'install': install_internal_static_lib and name != '_srv', } ) pgport += {name: lib}