
On Thu, Apr 27, 2023 at 12:00:59PM +0200, Andrea Bolognani wrote:
On Thu, Apr 27, 2023 at 11:50:05AM +0200, Michal Prívozník wrote:
On 4/27/23 11:41, Andrea Bolognani wrote:
+# headers for which we need to check actual usability. in most +# cases, checking for presence is enough (and it's way faster) +check_headers = [ + 'linux/kvm.h', +] + +foreach name : check_headers + if cc.check_header(name) + conf.set('WITH_@0@'.format(name.underscorify().to_upper()), 1) + endif +endforeach
One could argue, that the semantics of has_header() is broken then. What good is there to check if the host has a header file when compiler rejects it subsequently?
But leaving meson aside, shouldn't we just use check_header() for every header file then? I mean, this fixes this particular instance of the problem, but can't we hit it again with say ifaddrs.h or any other header file on the list?
We could. The Meson documentation recommends not doing this, as check_header() is (understandably) slower than has_header().
I haven't tried to see how much slower we're actually talking... Maybe for the 20-ish headers that we care about, it wouldn't make a measurable difference? Especially since the results of the check are cached between Meson runs.
I tried testing: diff --git a/meson.build b/meson.build index c15003ce02..3ae02ce4df 100644 --- a/meson.build +++ b/meson.build @@ -633,14 +633,14 @@ if host_machine.system() == 'freebsd' endif foreach name : headers - if cc.has_header(name) + if cc.check_header(name) conf.set('WITH_@0@'.format(name.underscorify().to_upper()), 1) endif endforeach # check for kernel header required by src/util/virnetdevbridge.c if host_machine.system() == 'linux' - if not cc.has_header('linux/sockios.h') + if not cc.check_header('linux/sockios.h') error('You must install kernel-headers in order to compile libvirt with QEMU or LXC support') endif endif and could not measure any deterministic change in execution time before/after With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|