I took another look and got it working, after something else I'm using insisted on installing libpq. It's mostly no-brainer hunks like this:
- dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], For the new src/test/modules/test_oat_hooks/meson.build, I copied what I'd seen in contrib modules that use libpq: - kwargs: pg_test_mod_args, + kwargs: pg_test_mod_args + { + 'dependencies': [libpq] + pg_test_mod_args['dependencies'], + } (I'm still green enough with Meson that I had to look that syntax up: it's how you replace the values of common keys with the values from the right hand dict[1], which ain't Pythonesque AFAIK.) For ecpg and pg_regress, where I got stuck last time, I am still a bit confused about whether it should go here: -ecpg_inc = include_directories('.') +ecpg_inc = [libpq_inc, include_directories('.')] ... or perhaps in intermediate ecpgXXX_inc variables or the final include_directories directives. In this version I just did that easy thing and it works for me. But is it the right place? Likewise for pg_regress_inc, also used by ECPG and isolation tests: -pg_regress_inc = include_directories('.') +pg_regress_inc = [libpq_inc, include_directories('.')] [1] https://mesonbuild.com/Reference-manual_elementary_dict.html
From 0ba525115e6c6b7b9cadd73b3db9e26c77b8c1a2 Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.mu...@gmail.com> Date: Mon, 14 Jul 2025 11:54:00 +1200 Subject: [PATCH] meson: Fix libpq header include order. On systems using -Dextra_include_dir that happen to have a copy of libpq installed there, it's important to put the libpq header search path ahead of -Dextra_include_dir. Reorder the dependencies to achieve that. This matches the order used by configure. Back-patch to 16, where meson arrived. Reviewed-by: Discussion: https://postgr.es/m/CA+hUKGKispvxLyrBn3=3mp0bb1n+rbyr5ee2gucoksnweoo...@mail.gmail.com --- contrib/dblink/meson.build | 2 +- contrib/oid2name/meson.build | 2 +- contrib/postgres_fdw/meson.build | 2 +- contrib/vacuumlo/meson.build | 2 +- src/backend/replication/libpqwalreceiver/meson.build | 2 +- src/bin/initdb/meson.build | 2 +- src/bin/pg_amcheck/meson.build | 2 +- src/bin/pg_basebackup/meson.build | 4 ++-- src/bin/pg_combinebackup/meson.build | 2 +- src/bin/pg_dump/meson.build | 8 ++++---- src/bin/pg_rewind/meson.build | 2 +- src/bin/pg_upgrade/meson.build | 2 +- src/bin/pgbench/meson.build | 2 +- src/bin/psql/meson.build | 2 +- src/bin/scripts/meson.build | 4 ++-- src/fe_utils/meson.build | 2 +- src/interfaces/ecpg/ecpglib/meson.build | 6 +++--- src/interfaces/ecpg/include/meson.build | 2 +- src/interfaces/libpq/test/meson.build | 4 ++-- src/test/isolation/meson.build | 4 ++-- src/test/modules/libpq_pipeline/meson.build | 2 +- src/test/modules/oauth_validator/meson.build | 2 +- src/test/modules/test_escape/meson.build | 2 +- src/test/modules/test_oat_hooks/meson.build | 4 +++- src/test/regress/meson.build | 4 ++-- 25 files changed, 37 insertions(+), 35 deletions(-) diff --git a/contrib/dblink/meson.build b/contrib/dblink/meson.build index a19ce6cf4b9..28da26d3d45 100644 --- a/contrib/dblink/meson.build +++ b/contrib/dblink/meson.build @@ -13,7 +13,7 @@ endif dblink = shared_module('dblink', dblink_sources, kwargs: contrib_mod_args + { - 'dependencies': contrib_mod_args['dependencies'] + [libpq], + 'dependencies': [libpq] + contrib_mod_args['dependencies'], }, ) contrib_targets += dblink diff --git a/contrib/oid2name/meson.build b/contrib/oid2name/meson.build index 074f16acd72..dd958f00bdf 100644 --- a/contrib/oid2name/meson.build +++ b/contrib/oid2name/meson.build @@ -12,7 +12,7 @@ endif oid2name = executable('oid2name', oid2name_sources, - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: default_bin_args, ) contrib_targets += oid2name diff --git a/contrib/postgres_fdw/meson.build b/contrib/postgres_fdw/meson.build index 5c11bc6496f..49012db1ba0 100644 --- a/contrib/postgres_fdw/meson.build +++ b/contrib/postgres_fdw/meson.build @@ -17,7 +17,7 @@ endif postgres_fdw = shared_module('postgres_fdw', postgres_fdw_sources, kwargs: contrib_mod_args + { - 'dependencies': contrib_mod_args['dependencies'] + [libpq], + 'dependencies': [libpq] + contrib_mod_args['dependencies'], }, ) contrib_targets += postgres_fdw diff --git a/contrib/vacuumlo/meson.build b/contrib/vacuumlo/meson.build index deee1d2832d..51e8fe9a325 100644 --- a/contrib/vacuumlo/meson.build +++ b/contrib/vacuumlo/meson.build @@ -12,7 +12,7 @@ endif vacuumlo = executable('vacuumlo', vacuumlo_sources, - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: default_bin_args, ) contrib_targets += vacuumlo diff --git a/src/backend/replication/libpqwalreceiver/meson.build b/src/backend/replication/libpqwalreceiver/meson.build index 2150f31cfa3..5318a76e29d 100644 --- a/src/backend/replication/libpqwalreceiver/meson.build +++ b/src/backend/replication/libpqwalreceiver/meson.build @@ -14,7 +14,7 @@ libpqwalreceiver = shared_module('pqwalreceiver', libpqwalreceiver_sources, kwargs: pg_mod_args + { 'name_prefix': 'lib', - 'dependencies': pg_mod_args['dependencies'] + [libpq], + 'dependencies': [libpq] + pg_mod_args['dependencies'], } ) diff --git a/src/bin/initdb/meson.build b/src/bin/initdb/meson.build index 06958e370f3..b8584fe56de 100644 --- a/src/bin/initdb/meson.build +++ b/src/bin/initdb/meson.build @@ -21,7 +21,7 @@ initdb = executable('initdb', # shared library from a different PG version. Define # USE_PRIVATE_ENCODING_FUNCS to ensure that that happens. c_args: ['-DUSE_PRIVATE_ENCODING_FUNCS'], - dependencies: [frontend_code, libpq, icu, icu_i18n], + dependencies: [libpq, frontend_code, icu, icu_i18n], kwargs: default_bin_args, ) bin_targets += initdb diff --git a/src/bin/pg_amcheck/meson.build b/src/bin/pg_amcheck/meson.build index 316ea0d40b8..c8f792ff971 100644 --- a/src/bin/pg_amcheck/meson.build +++ b/src/bin/pg_amcheck/meson.build @@ -12,7 +12,7 @@ endif pg_amcheck = executable('pg_amcheck', pg_amcheck_sources, - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: default_bin_args, ) bin_targets += pg_amcheck diff --git a/src/bin/pg_basebackup/meson.build b/src/bin/pg_basebackup/meson.build index 3a7fc10eab0..b85ba465d47 100644 --- a/src/bin/pg_basebackup/meson.build +++ b/src/bin/pg_basebackup/meson.build @@ -7,7 +7,7 @@ common_sources = files( 'walmethods.c', ) -pg_basebackup_deps = [frontend_code, libpq, lz4, zlib, zstd] +pg_basebackup_deps = [libpq, frontend_code, lz4, zlib, zstd] pg_basebackup_common = static_library('libpg_basebackup_common', common_sources, dependencies: pg_basebackup_deps, @@ -45,7 +45,7 @@ endif pg_createsubscriber = executable('pg_createsubscriber', pg_createsubscriber_sources, - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: default_bin_args, ) bin_targets += pg_createsubscriber diff --git a/src/bin/pg_combinebackup/meson.build b/src/bin/pg_combinebackup/meson.build index e80a4756a7f..04e09162d9b 100644 --- a/src/bin/pg_combinebackup/meson.build +++ b/src/bin/pg_combinebackup/meson.build @@ -17,7 +17,7 @@ endif pg_combinebackup = executable('pg_combinebackup', pg_combinebackup_sources, - dependencies: [frontend_code], + dependencies: [libpq, frontend_code], kwargs: default_bin_args, ) bin_targets += pg_combinebackup diff --git a/src/bin/pg_dump/meson.build b/src/bin/pg_dump/meson.build index 4a4ebbd8ec9..a079b6dfa92 100644 --- a/src/bin/pg_dump/meson.build +++ b/src/bin/pg_dump/meson.build @@ -22,7 +22,7 @@ pg_dump_common_sources = files( pg_dump_common = static_library('libpgdump_common', pg_dump_common_sources, c_pch: pch_postgres_fe_h, - dependencies: [frontend_code, libpq, lz4, zlib, zstd], + dependencies: [libpq, frontend_code, lz4, zlib, zstd], kwargs: internal_lib_args, ) @@ -42,7 +42,7 @@ endif pg_dump = executable('pg_dump', pg_dump_sources, link_with: [pg_dump_common], - dependencies: [frontend_code, libpq, zlib], + dependencies: [libpq, frontend_code, zlib], kwargs: default_bin_args, ) bin_targets += pg_dump @@ -61,7 +61,7 @@ endif pg_dumpall = executable('pg_dumpall', pg_dumpall_sources, link_with: [pg_dump_common], - dependencies: [frontend_code, libpq, zlib], + dependencies: [libpq, frontend_code, zlib], kwargs: default_bin_args, ) bin_targets += pg_dumpall @@ -80,7 +80,7 @@ endif pg_restore = executable('pg_restore', pg_restore_sources, link_with: [pg_dump_common], - dependencies: [frontend_code, libpq, zlib], + dependencies: [libpq, frontend_code, zlib], kwargs: default_bin_args, ) bin_targets += pg_restore diff --git a/src/bin/pg_rewind/meson.build b/src/bin/pg_rewind/meson.build index 36171600cca..f2790246b23 100644 --- a/src/bin/pg_rewind/meson.build +++ b/src/bin/pg_rewind/meson.build @@ -21,7 +21,7 @@ endif pg_rewind = executable('pg_rewind', pg_rewind_sources, - dependencies: [frontend_code, libpq, lz4, zstd], + dependencies: [libpq, frontend_code, lz4, zstd], c_args: ['-DFRONTEND'], # needed for xlogreader et al kwargs: default_bin_args, ) diff --git a/src/bin/pg_upgrade/meson.build b/src/bin/pg_upgrade/meson.build index ac992f0d14b..8aefaeea91f 100644 --- a/src/bin/pg_upgrade/meson.build +++ b/src/bin/pg_upgrade/meson.build @@ -28,7 +28,7 @@ endif pg_upgrade = executable('pg_upgrade', pg_upgrade_sources, c_pch: pch_postgres_fe_h, - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: default_bin_args, ) bin_targets += pg_upgrade diff --git a/src/bin/pgbench/meson.build b/src/bin/pgbench/meson.build index a2a909a8442..de013cc9827 100644 --- a/src/bin/pgbench/meson.build +++ b/src/bin/pgbench/meson.build @@ -27,7 +27,7 @@ endif pgbench = executable('pgbench', pgbench_sources, - dependencies: [frontend_code, libpq, thread_dep], + dependencies: [libpq, frontend_code, thread_dep], include_directories: include_directories('.'), c_pch: pch_postgres_fe_h, c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [], diff --git a/src/bin/psql/meson.build b/src/bin/psql/meson.build index f795ff28271..4fe711177af 100644 --- a/src/bin/psql/meson.build +++ b/src/bin/psql/meson.build @@ -58,7 +58,7 @@ psql = executable('psql', psql_sources, c_pch: pch_postgres_fe_h, include_directories: include_directories('.'), - dependencies: [frontend_code, libpq, readline], + dependencies: [libpq, frontend_code, readline], kwargs: default_bin_args, ) bin_targets += psql diff --git a/src/bin/scripts/meson.build b/src/bin/scripts/meson.build index 80df7c33257..90517dd9a10 100644 --- a/src/bin/scripts/meson.build +++ b/src/bin/scripts/meson.build @@ -2,7 +2,7 @@ scripts_common = static_library('libscripts_common', files('common.c'), - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: internal_lib_args, ) @@ -29,7 +29,7 @@ foreach binary : binaries binary = executable(binary, binary_sources, link_with: [scripts_common], - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: default_bin_args, ) bin_targets += binary diff --git a/src/fe_utils/meson.build b/src/fe_utils/meson.build index a18cbc939e4..7487869f1cf 100644 --- a/src/fe_utils/meson.build +++ b/src/fe_utils/meson.build @@ -31,7 +31,7 @@ fe_utils_sources += psqlscan fe_utils = static_library('libpgfeutils', fe_utils_sources + generated_headers, c_pch: pch_postgres_fe_h, - include_directories: [postgres_inc, libpq_inc], + include_directories: [libpq_inc, postgres_inc], c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [], dependencies: frontend_common_code, kwargs: default_lib_args, diff --git a/src/interfaces/ecpg/ecpglib/meson.build b/src/interfaces/ecpg/ecpglib/meson.build index 8f478c6a73e..fb7d33d2a0e 100644 --- a/src/interfaces/ecpg/ecpglib/meson.build +++ b/src/interfaces/ecpg/ecpglib/meson.build @@ -30,7 +30,7 @@ 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: [libpq, frontend_stlib_code, thread_dep], link_with: [ecpg_pgtypes_st], kwargs: default_lib_args, ) @@ -41,7 +41,7 @@ ecpglib_so = shared_library('libecpg', include_directories: ecpglib_inc, c_args: ecpglib_c_args, c_pch: pch_postgres_fe_h, - dependencies: [frontend_shlib_code, libpq, thread_dep], + dependencies: [libpq, frontend_shlib_code, thread_dep], link_with: ecpg_pgtypes_so, soversion: host_system != 'windows' ? '6' : '', darwin_versions: ['6', '6.' + pg_version_major.to_string()], @@ -58,7 +58,7 @@ pkgconfig.generate( url: pg_url, libraries: ecpglib_so, libraries_private: [frontend_stlib_code, thread_dep], - requires_private: ['libpgtypes', 'libpq'], + requires_private: ['libpq', 'libpgtypes'], ) subdir('po', if_found: libintl) diff --git a/src/interfaces/ecpg/include/meson.build b/src/interfaces/ecpg/include/meson.build index a6541e1a686..133ebe2f11f 100644 --- a/src/interfaces/ecpg/include/meson.build +++ b/src/interfaces/ecpg/include/meson.build @@ -1,6 +1,6 @@ # Copyright (c) 2022-2025, PostgreSQL Global Development Group -ecpg_inc = include_directories('.') +ecpg_inc = [libpq_inc, include_directories('.')] ecpg_conf_keys = [ 'SIZEOF_LONG', diff --git a/src/interfaces/libpq/test/meson.build b/src/interfaces/libpq/test/meson.build index 07a5facc321..75d2012ba17 100644 --- a/src/interfaces/libpq/test/meson.build +++ b/src/interfaces/libpq/test/meson.build @@ -14,7 +14,7 @@ endif libpq_test_deps += executable('libpq_uri_regress', libpq_uri_regress_sources, - dependencies: [frontend_no_fe_utils_code, libpq], + dependencies: [libpq, frontend_no_fe_utils_code], kwargs: default_bin_args + { 'install': false, } @@ -33,7 +33,7 @@ endif libpq_test_deps += executable('libpq_testclient', libpq_testclient_sources, - dependencies: [frontend_no_fe_utils_code, libpq], + dependencies: [libpq, frontend_no_fe_utils_code], kwargs: default_bin_args + { 'install': false, } diff --git a/src/test/isolation/meson.build b/src/test/isolation/meson.build index a180e4e2741..660b11eff8b 100644 --- a/src/test/isolation/meson.build +++ b/src/test/isolation/meson.build @@ -35,7 +35,7 @@ pg_isolation_regress = executable('pg_isolation_regress', isolation_sources, c_args: pg_regress_cflags, include_directories: pg_regress_inc, - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: default_bin_args + { 'install_dir': dir_pgxs / 'src/test/isolation', }, @@ -52,7 +52,7 @@ endif isolationtester = executable('isolationtester', isolationtester_sources, include_directories: include_directories('.'), - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: default_bin_args + { 'install_dir': dir_pgxs / 'src/test/isolation', }, diff --git a/src/test/modules/libpq_pipeline/meson.build b/src/test/modules/libpq_pipeline/meson.build index 3fd70a04a38..83201111ca3 100644 --- a/src/test/modules/libpq_pipeline/meson.build +++ b/src/test/modules/libpq_pipeline/meson.build @@ -12,7 +12,7 @@ endif libpq_pipeline = executable('libpq_pipeline', libpq_pipeline_sources, - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: default_bin_args + { 'install': false, }, diff --git a/src/test/modules/oauth_validator/meson.build b/src/test/modules/oauth_validator/meson.build index a6f937fd7d7..2cd5c4cd537 100644 --- a/src/test/modules/oauth_validator/meson.build +++ b/src/test/modules/oauth_validator/meson.build @@ -60,7 +60,7 @@ endif oauth_hook_client = executable('oauth_hook_client', oauth_hook_client_sources, - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: default_bin_args + { 'install': false, }, diff --git a/src/test/modules/test_escape/meson.build b/src/test/modules/test_escape/meson.build index a21341d5067..04fd0be0889 100644 --- a/src/test/modules/test_escape/meson.build +++ b/src/test/modules/test_escape/meson.build @@ -10,7 +10,7 @@ endif test_escape = executable('test_escape', test_escape_sources, - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: default_bin_args + { 'install': false, } diff --git a/src/test/modules/test_oat_hooks/meson.build b/src/test/modules/test_oat_hooks/meson.build index 1e600b0f4c7..6f0c4afd433 100644 --- a/src/test/modules/test_oat_hooks/meson.build +++ b/src/test/modules/test_oat_hooks/meson.build @@ -12,7 +12,9 @@ endif test_oat_hooks = shared_module('test_oat_hooks', test_oat_hooks_sources, - kwargs: pg_test_mod_args, + kwargs: pg_test_mod_args + { + 'dependencies': [libpq] + pg_test_mod_args['dependencies'], + } ) test_install_libs += test_oat_hooks diff --git a/src/test/regress/meson.build b/src/test/regress/meson.build index 1da9e9462a9..99f402f49a8 100644 --- a/src/test/regress/meson.build +++ b/src/test/regress/meson.build @@ -2,7 +2,7 @@ # also used by isolationtester and ecpg tests pg_regress_c = files('pg_regress.c') -pg_regress_inc = include_directories('.') +pg_regress_inc = [libpq_inc, include_directories('.')] regress_sources = pg_regress_c + files( 'pg_regress_main.c' @@ -30,7 +30,7 @@ endif pg_regress = executable('pg_regress', regress_sources, c_args: pg_regress_cflags, - dependencies: [frontend_code, libpq], + dependencies: [libpq, frontend_code], kwargs: default_bin_args + { 'install_dir': dir_pgxs / 'src/test/regress', }, -- 2.50.1