Re: meson: Allow disabling static libraries
Peter Eisentraut <peter@eisentraut.org>
From: Peter Eisentraut <peter@eisentraut.org>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>,
Tristan Partin <tristan@partin.io>
Date: 2026-01-27T14:03:03Z
Lists: pgsql-hackers
Attachments
- v2-0001-meson-Refactor-libpq-targets-variables.patch (text/plain) patch v2-0001
- v2-0002-meson-Allow-disabling-static-libraries.patch (text/plain) patch v2-0002
- v2-0003-meson-Allow-disabling-static-libraries-variant-2.patch (text/plain) patch v2-0003
On 20.01.26 18:03, Andres Freund wrote: >> ############################################################### >> @@ -3499,18 +3513,20 @@ endif >> installed_targets = [ >> backend_targets, >> bin_targets, >> - libpq_st, >> pl_targets, >> contrib_targets, >> nls_mo_targets, >> ecpg_targets, >> ] >> +if dep_static_lib.found() >> + installed_targets += [libpq_st] >> +endif > > Wonder if we ought to define installed_targets = [] earlier and allow > different meson.build files to add themselves, instead of putting knowledge > like this into a central spot. Right. See attached patch 0001. This introduces a variable libpq_targets and populates it in the subdirectories. This moves the knowledge away from the top-level meson.build. > Separately, perhaps it'd be mildly nicer to have a boolean for static libs > instead of using .found() everywhere. Yeah, after playing with this a bit more, I'm not sure sure this disabler trick is really that good. The idea would have been that you just need to add the disabler to the dependencies and everything else will magically work. But the reason that you need stuff like +if dep_static_lib.found() + installed_targets += [libpq_st] +endif is that the disabler sneaks up into other variables and dependencies and has weird effects. For example, if you remove "if" around this and similar lines, then "meson test" breaks in highly confusing ways (probably because tmp_install depends on installed_targets). So I think, since we have to have these conditionals, we might as well put them around the whole static_library() call. And then we can use a straightforward Boolean variable, like you suggest. See attached patch 0003 (which is on top of 0002, so it would make more sense to view the diff 0001..0003). This is also more robust because you get explicit errors for example if you use libpq_st or libpq_so when they are disabled, instead of sometimes silently doing nothing.
Commits
-
meson: allow disabling building/installation of static libraries.
- 78727dcba32e 19 (unreleased) landed
-
meson: Refactor libpq targets variables
- 4bfbbeb679c0 19 (unreleased) landed