From 7ad8b5f221ed23ff9ca60349f76e91f79ecd211d Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 12 May 2020 10:06:41 -0700 Subject: docs: Add a Howto about the null dependency [skip ci] --- docs/markdown/howtox.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/markdown/howtox.md b/docs/markdown/howtox.md index 8231d3d..abf7519 100644 --- a/docs/markdown/howtox.md +++ b/docs/markdown/howtox.md @@ -260,3 +260,26 @@ The `cmake_module_path` property is only needed for custom CMake scripts. System wide CMake scripts are found automatically. More information can be found [here](Dependencies.md#cmake) + +## Get a default not-found dependency? + +```meson +null_dep = dependency('', required : false) +``` + +This can be used in cases where you want a default value, but might override it +later. + +```meson +my_dep = dependency('', required : false) +if host_machine.system() in ['freebsd', 'netbsd', 'openbsd', 'dragonfly'] + my_dep = dependency('some dep', required : false) +elif host_machine.system() == 'linux' + my_dep = dependency('some other dep', required : false) +endif + +# Last ditch effort! +if no my_dep.found() + my_dep = meson.get_compiler('c').find_library('dep') +endif +``` -- cgit v1.1