tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: [PATCH] cmake/build.mk: Hide non-buildlink3 libraries from cmake



> Date: Sun, 12 Jan 2025 16:33:18 +0100
> From: Thomas Klausner <wiz%NetBSD.org@localhost>
> 
> With the patch, I see weird problems in some KDE packages like
> kguiaddons (but also others):
> 
> [...]
> /scratch/x11/kguiaddons/work/.buildlink/include/wayland-util.h:51:5: error: "__STDC_VERSION__" is not defined, evaluates to 0 [-Werror=undef]
>    51 | #if __STDC_VERSION__ >= 202311L
>       |     ^~~~~~~~~~~~~~~~
> [...]
> 
> __STDC_VERSION__ is only defined when compiling C code, but the header
> is included from a C++ source file and thus we get this warning.
> 
> But why don't we get it without the cmake changes?

After lots of digging off-list, we found why this is happening:

=> _Without_ the cmake change, some configure test in kguiaddons (and
   kwayland and whatever else) puts `-isystem /usr/pkg/include' in
   CPPFLAGS, in addition to the `-I/usr/pkg/include' already there.

   So any header file found via /usr/pkg/include, like wayland-util.h,
   is treated as a system header file, and warnings like -Werror=undef
   are suppressed under the default -Wno-system-headers.  If you
   enable -Wsystem-headers, it triggers this failure -- and a zillion
   others along with it.

=> _With_ the cmake change, it's just `-I/usr/pkg/include' -- there's
   no `-isystem /usr/pkg/include'.

   So any header file found via /usr/pkg/include, like wayland-util.h,
   is treated as a user header file, and warnings like -Werror=undef
   are kept and treated as errors.  In this case, __STDC_VERSION__ is
   (legitimately) not defined in GCC's C++ environment, so it trips
   -Werror=undef.

(Of course, ${PREFIX}/include=/usr/pkg/include is mapped by the
wrappers to ${BUILDLINK_DIR}/include=/scratch/.../.buildlink/include
in the above build output, but that difference is immaterial here.)


So, three obvious ways to resolve this:

1. Patch wayland to change

	-#if __STDC_VERSION__ >= 202311L
	+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L

   and submit that upstream.  This might be reasonable because
   wayland-util.h is a public header file that's obviously supposed to
   work in C++ too (it has `#ifdef __cplusplus extern "C" { ...').

2. Change devel/wayland/buildlink3.mk to forcibly add

	-isystem ${PREFIX}/include

   (or `-isystem ${BUILDLINK_DIR}/include') to CPPFLAGS for packages
   that link against wayland.  Kind of awkward for wayland to apply
   this (it will also affect all non-wayland header files too) but it
   should work and any fallout will be limited to wayland-related
   packages,

3. Change buildlink3/cwrappers to change

	-I${PREFIX}/include

   to

	-isystem ${PREFIX}/include

   in CPPFLAGS for all packages (or BUILDLINK_DIR instead of PREFIX).
   This is a heavy hammer and I'm a little reluctant to reach for it
   (especially given the comment in cwrappers.mk

	# TODO: Find and fix packages depending on the implicit include path.

   which suggests this is supposed to go away at some point) but maybe
   it's reasonable, I dunno.


Home | Main Index | Thread Index | Old Index