From 78d8bcfbe57396da8122a6c34af1f3c724790462 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 27 Jan 2026 13:36:45 +0100 Subject: [PATCH v2 2/3] meson: Allow disabling static libraries --- .cirrus.tasks.yml | 1 + meson.build | 14 ++++++++++++++ src/common/meson.build | 1 + src/fe_utils/meson.build | 4 +++- src/interfaces/ecpg/compatlib/meson.build | 12 ++++++++---- src/interfaces/ecpg/ecpglib/meson.build | 12 ++++++++---- src/interfaces/ecpg/pgtypeslib/meson.build | 12 ++++++++---- src/interfaces/libpq-oauth/meson.build | 11 ++++++++--- src/interfaces/libpq/meson.build | 12 ++++++++---- src/port/meson.build | 1 + 10 files changed, 60 insertions(+), 20 deletions(-) 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/meson.build b/meson.build index 824cebbade4..78918301d53 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,19 @@ not_found_dep = dependency('', required: false) thread_dep = dependency('threads') auto_features = get_option('auto_features') +# Declare dependencies 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. +default_library_opt = get_option('default_library') +dep_shared_lib = declare_dependency() +dep_static_lib = declare_dependency() +if default_library_opt == 'shared' + dep_static_lib = disabler() +elif default_library_opt == 'static' + dep_shared_lib = disabler() +endif + ############################################################### diff --git a/src/common/meson.build b/src/common/meson.build index b757618a9c9..1417ac3bbb7 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': dep_static_lib.found(), } ) pgcommon += {name: lib} diff --git a/src/fe_utils/meson.build b/src/fe_utils/meson.build index a2420ea2d5c..9c9e0bcc0da 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': dep_static_lib.found(), + }, ) diff --git a/src/interfaces/ecpg/compatlib/meson.build b/src/interfaces/ecpg/compatlib/meson.build index 6cb1be73407..861cb67205e 100644 --- a/src/interfaces/ecpg/compatlib/meson.build +++ b/src/interfaces/ecpg/compatlib/meson.build @@ -20,17 +20,19 @@ ecpg_compat_st = static_library('libecpg_compat', ecpg_compat_sources, include_directories: ecpg_compat_inc, c_args: ecpg_compat_c_args, - dependencies: [frontend_stlib_code, thread_dep], + dependencies: [dep_static_lib, frontend_stlib_code, thread_dep], link_with: [ecpglib_st, ecpg_pgtypes_st], kwargs: default_lib_args, ) -ecpg_targets += ecpg_compat_st +if dep_static_lib.found() + ecpg_targets += ecpg_compat_st +endif ecpg_compat_so = shared_library('libecpg_compat', ecpg_compat_sources + ecpg_compat_so_sources, include_directories: ecpg_compat_inc, c_args: ecpg_compat_c_args, - dependencies: [frontend_shlib_code, thread_dep], + dependencies: [dep_shared_lib, frontend_shlib_code, thread_dep], link_with: [ecpglib_so, ecpg_pgtypes_so], soversion: host_system != 'windows' ? '3' : '', darwin_versions: ['3', '3.' + pg_version_major.to_string()], @@ -39,7 +41,9 @@ ecpg_compat_so = shared_library('libecpg_compat', link_depends: export_file, kwargs: default_lib_args, ) -ecpg_targets += ecpg_compat_so +if dep_shared_lib.found() + 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..d0841e99a19 100644 --- a/src/interfaces/ecpg/ecpglib/meson.build +++ b/src/interfaces/ecpg/ecpglib/meson.build @@ -30,18 +30,20 @@ ecpglib_st = static_library('libecpg', include_directories: ecpglib_inc, c_args: ecpglib_c_args, c_pch: pch_postgres_fe_h, - dependencies: [frontend_stlib_code, thread_dep, libpq], + dependencies: [dep_static_lib, frontend_stlib_code, thread_dep, libpq], link_with: [ecpg_pgtypes_st], kwargs: default_lib_args, ) -ecpg_targets += ecpglib_st +if dep_static_lib.found() + ecpg_targets += ecpglib_st +endif ecpglib_so = shared_library('libecpg', ecpglib_sources + ecpglib_so_sources, include_directories: ecpglib_inc, c_args: ecpglib_c_args, c_pch: pch_postgres_fe_h, - dependencies: [frontend_shlib_code, libpq, thread_dep], + dependencies: [dep_shared_lib, frontend_shlib_code, libpq, thread_dep], link_with: ecpg_pgtypes_so, soversion: host_system != 'windows' ? '6' : '', darwin_versions: ['6', '6.' + pg_version_major.to_string()], @@ -50,7 +52,9 @@ ecpglib_so = shared_library('libecpg', link_depends: export_file, kwargs: default_lib_args, ) -ecpg_targets += ecpglib_so +if dep_shared_lib.found() + 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..7b79da2368b 100644 --- a/src/interfaces/ecpg/pgtypeslib/meson.build +++ b/src/interfaces/ecpg/pgtypeslib/meson.build @@ -26,17 +26,19 @@ ecpg_pgtypes_st = static_library('libpgtypes', include_directories: ecpg_pgtypes_inc, c_args: ecpg_pgtypes_c_args, c_pch: pch_postgres_fe_h, - dependencies: frontend_stlib_code, + dependencies: [dep_static_lib, frontend_stlib_code], kwargs: default_lib_args, ) -ecpg_targets += ecpg_pgtypes_st +if dep_static_lib.found() + ecpg_targets += ecpg_pgtypes_st +endif ecpg_pgtypes_so = shared_library('libpgtypes', ecpg_pgtypes_sources + ecpg_pgtypes_so_sources, include_directories: ecpg_pgtypes_inc, c_args: ecpg_pgtypes_c_args, c_pch: pch_postgres_fe_h, - dependencies: frontend_shlib_code, + dependencies: [dep_shared_lib, frontend_shlib_code], version: '3.' + pg_version_major.to_string(), soversion: host_system != 'windows' ? '3' : '', darwin_versions: ['3', '3.' + pg_version_major.to_string()], @@ -44,7 +46,9 @@ ecpg_pgtypes_so = shared_library('libpgtypes', link_depends: export_file, kwargs: default_lib_args, ) -ecpg_targets += ecpg_pgtypes_so +if dep_shared_lib.found() + 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..9c8cb90d989 100644 --- a/src/interfaces/libpq-oauth/meson.build +++ b/src/interfaces/libpq-oauth/meson.build @@ -26,13 +26,16 @@ libpq_oauth_st = static_library('libpq-oauth', include_directories: [libpq_oauth_inc, postgres_inc], c_pch: pch_postgres_fe_h, dependencies: [ + dep_static_lib, frontend_stlib_code, libpq_oauth_deps, ssl, # libpq-int.h includes OpenSSL headers ], kwargs: default_lib_args, ) -libpq_targets += libpq_oauth_st +if dep_static_lib.found() + 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. @@ -43,12 +46,14 @@ libpq_oauth_so = shared_module(libpq_oauth_name, include_directories: [libpq_oauth_inc, postgres_inc], c_args: libpq_oauth_so_c_args, c_pch: pch_postgres_fe_h, - dependencies: [frontend_shlib_code, libpq, libpq_oauth_deps], + dependencies: [dep_shared_lib, frontend_shlib_code, libpq, libpq_oauth_deps], link_depends: export_file, link_args: export_fmt.format(export_file.full_path()), kwargs: default_lib_args, ) -libpq_targets += libpq_oauth_so +if dep_shared_lib.found() + 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..647d7e2ae7c 100644 --- a/src/interfaces/libpq/meson.build +++ b/src/interfaces/libpq/meson.build @@ -62,10 +62,12 @@ libpq_st = static_library('libpq', include_directories: [libpq_inc], c_args: libpq_c_args, c_pch: pch_postgres_fe_h, - dependencies: [frontend_stlib_code, libpq_deps], + dependencies: [dep_static_lib, frontend_stlib_code, libpq_deps], kwargs: default_lib_args, ) -libpq_targets += libpq_st +if dep_static_lib.found() + libpq_targets += libpq_st +endif libpq_so = shared_library('libpq', libpq_sources + libpq_so_sources, @@ -75,12 +77,14 @@ libpq_so = shared_library('libpq', version: '5.' + pg_version_major.to_string(), soversion: host_system != 'windows' ? '5' : '', darwin_versions: ['5', '5.' + pg_version_major.to_string()], - dependencies: [frontend_shlib_code, libpq_deps], + dependencies: [dep_shared_lib, frontend_shlib_code, libpq_deps], link_depends: export_file, link_args: export_fmt.format(export_file.full_path()), kwargs: default_lib_args, ) -libpq_targets += libpq_so +if dep_shared_lib.found() + 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 d7d4e705b89..a8d92937581 100644 --- a/src/port/meson.build +++ b/src/port/meson.build @@ -192,6 +192,7 @@ foreach name, opts : pgport_variants c_pch: pch_c_h, kwargs: opts + { 'dependencies': opts['dependencies'] + [ssl], + 'install': dep_static_lib.found(), } ) pgport += {name: lib} -- 2.52.0