Hi,

On 2025-11-04 18:30:51 +1300, Thomas Munro wrote:
> First two patches as before, except for a couple of unnecessary hunks
> I deleted based on an off-list review from Bilal.

I think there may be a less verbose way to do this:

The problem is caused by us adding extra_include_dirs to postgres_inc_d, which
does not include the private include dir for e.g. libpq. As it is added to
frontend_code etc as a flat list, there's no way for meson to know that
src/interfaces/libpq should be added earlier in the commandline.

The position we add extra_include_dirs right now also seems wrong on windows,
leaving libpq aside, as it's added *before* src/include/port/win32 etc.


The easiest way to fix that seems to be to simply not extra_include_dirs to
postgres_inc_d, but instead either add it to cppflags (the meson variable, not
the environment) or add it to the project C flags.

It seems that with autoconf we add the --with-includes to the pg_config
--cppflags, but we don't today with meson. Adding it to the cppflags variable
would take care of that too.

A quick prototype of that is attached.

Thoughts?

Greetings,

Andres Freund
diff --git i/meson.build w/meson.build
index 0f61ff6a700..31ef82a52a4 100644
--- i/meson.build
+++ w/meson.build
@@ -84,7 +84,6 @@ endif
 ###############################################################
 
 postgres_inc_d = ['src/include']
-postgres_inc_d += get_option('extra_include_dirs')
 
 postgres_lib_d = get_option('extra_lib_dirs')
 
@@ -327,6 +326,23 @@ else
   error('unknown host system: @0@'.format(host_system))
 endif
 
+# While the most obvious way to implement extra_include_dirs would be to add
+# extra_include_dirs to postgres_inc_d, that turns out to not work well: For
+# some parts of the buildtree (e.g. src/interfaces/libpq or tools linking
+# against libpq) we need to add additional directories to be included, and
+# those directories need to take precedence over extra_include_dirs.  The
+# easiest way to achieve that is to gin up the compiler arguments ourselves
+# (which luckily is the same across all supported compilers) and add it to
+# cppflags. That works as meson always adds explicit include_directories
+# before generic compiler arguments.
+#
+# An additional advantage is that this way the extra include directories are
+# included in pg_config --cppflags output, keeping the behavior consistent
+# with autoconf builds.
+foreach extra_dir : get_option('extra_include_dirs')
+  cppflags += '-I@0@'.format(extra_dir)
+endforeach
+
 
 
 ###############################################################

Reply via email to