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