]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
meson: allow disabling building/installation of static libraries.
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 23 Feb 2026 15:25:54 +0000 (16:25 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Mon, 23 Feb 2026 15:45:40 +0000 (16:45 +0100)
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

.cirrus.tasks.yml
doc/src/sgml/installation.sgml
meson.build
src/common/meson.build
src/fe_utils/meson.build
src/interfaces/ecpg/compatlib/meson.build
src/interfaces/ecpg/ecpglib/meson.build
src/interfaces/ecpg/pgtypeslib/meson.build
src/interfaces/libpq-oauth/meson.build
src/interfaces/libpq/meson.build
src/port/meson.build

index 2a821593ce50f5da2c2a5a74c242063616f2a1e6..4841a2042486ab2d959bc15d10b2f0cceae95e9c 100644 (file)
@@ -133,6 +133,7 @@ task:
       meson setup \
         --buildtype=debug \
         --auto-features=disabled \
+        -Ddefault_library=shared \
         -Dtap_tests=enabled \
         build
     EOF
index c903ccff9888e8d31f7397e005e6d8e06d86c76b..2937c4a8fd0b4f1304efd1225981b8734fc36363 100644 (file)
@@ -2807,6 +2807,17 @@ ninja install
       </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>
index 83d1f06b528679facde66b523aed3bff22a19790..47b7eb02275e086eda874391592b22eddac661e7 100644 (file)
@@ -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
+
 
 
 ###############################################################
index b757618a9c9e9fb2c174cd5e6849482fd2dfa04e..4f9b8b8263d55d866e35732eb5a2af5f2ffceed1 100644 (file)
@@ -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}
index a2420ea2d5cae32958e48830efa553e2b4624d7c..86befca192e66a27729e47554ae83702961fd711 100644 (file)
@@ -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,
+          },
 )
index 6cb1be73407f687d40d833989d93a7e9188efdbf..d578faefe1c875db8e9458af4dc0f11df0d16587 100644 (file)
@@ -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',
index 889bd9efd65819f47e94d5ff4560e58febc60f78..81e921519452f2ce4f0154e152be1fc80617544b 100644 (file)
@@ -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',
index 6b78f529e5352c02cc253baf59ae0398cd8115f4..de564c63a5b1cabac846667577c26ab5d4f49521 100644 (file)
@@ -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',
index e573d36f20e067661578ee19da58f7ca9641f853..27aca2bc3247b95420e73f4117bb595d16327072 100644 (file)
@@ -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 = []
 
index 0b8dd3e1f5e6e9b80c035f028f6688bd9ec0c88c..2b95098187e927f812e943ee5cc27637828e66ba 100644 (file)
@@ -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],
index edb2e5632bdfd3891e782949d8f0c6b9e91b0c0f..7296f8e3c037f3996139221d792a20ae2b716a76 100644 (file)
@@ -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}