mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.55k stars 1.61k forks source link

RFC: Add a generic variable getter method for dependencies #4957

Closed dcbaker closed 5 years ago

dcbaker commented 5 years ago

We now have 4 different kinds of dependencies, cmake, pkg-config, config-tool, and declare_dependency. pkg-config and config-tool have a method that allow getting arbitrary variables, cmake might but I haven't looked closely. Some dependencies can be found multiple ways (cmake or config-tool for example). Because of that it would be nice to have a generic getter method, such as

dep = dependency('dep')
use_thing = dep.get_variable(cmake : 'CMakeVariable', pkg-config : 'pkg-config-variable', config-tool : 'config-tool-argument')

Which would be implemented such that each kind of dependency would respect the proper keyword.

@jpakkane, opinions?

mensinda commented 5 years ago

CMake also has a method for getting arbitrary variables, however, they might not be 100% accurate. The main question I have with your proposal is what happens when you forget to specify a method in dep.get_variable.

For instance, what happens when you call dep.get_variable(cmake : 'vcm', pkg-config : 'vpkg') but dep is internally a config-tool dependency?

dcbaker commented 5 years ago

then you'd get an error, the same as calling one of the specific methods on the wrong dependency type.

jpakkane commented 5 years ago

Should it also have a default or something similar for a variable name to try if the dependency type is not one of the listed ones?

dcbaker commented 5 years ago

That might be a good idea it could have behavior such that if default is provided it returns that, otherwise error.