fix_extra_include_prototype.diff.txt

text/plain

Filename: fix_extra_include_prototype.diff.txt
Type: text/plain
Part: 0
Message: Re: meson's in-tree libpq header search order vs -Dextra_include_dirs
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
+
 
 
 ###############################################################