qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] meson.build: Don't look for libudev for static builds


From: Paolo Bonzini
Subject: Re: [PATCH] meson.build: Don't look for libudev for static builds
Date: Fri, 2 Oct 2020 17:14:39 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0

On 02/10/20 16:18, Peter Maydell wrote:
>> No, there's no functions at all.  You can of course put the detection and
>> test in a single loop:
>>
>>   dependencies = {}
>>   ...
>>   if targetos == 'linux' and (have_system or have_tools)
>>     dependencies += {'libudev': 'mpath'}
>>   endif
>>   ...
>>   skeleton = 'int main(void) { return 0; }'
>>   foreach var, option: dependencies
>>     dep = dependency(var,
>>                      required: get_option(option).enabled(),
>>                      static: enable_static)
>>     if dep.found() and enable_static and not cc.links(skeleton, 
>> dependencies: get_variable(var))
>>       if get_option(option).enabled()
>>           error('Cannot link with @0@'.format(var))
>>         else
>>           warning('Cannot link with @0@, disabling'.format(skeleton))
>>           set_variable(var, not_found)
>>         endif
>>       endif
>>     endif
>>   endforeach
> That is a lot uglier.

The code above is ugly but it is also botched; it should be more like:

  dependencies = {}
  ...
  if targetos == 'linux' and (have_system or have_tools)
    dependencies += {'libudev': get_option('mpath')}
  else
    libudev = not_found
  endif
  ...

  skeleton = 'int main(void) { return 0; }'
  foreach var, opt: dependencies
    dep = dependency(var,
                     required: opt.enabled(),
                     static: enable_static)
    if dep.found() and enable_static and not cc.links(skeleton, dependencies: 
dep)
      # Meson should have already warned about the lack of a static library
      if opt.enabled()
        error('Cannot link with @0@'.format(var))
      else
      dep = not_found
    endif
    set_variable(var, dep)
  endforeach

which both shorter and more readable.

Or is it loops vs. functions that you find ugly?

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]