meson中自定义变量的使用

在meson.build中增加定义变量和宏

定义变量

修改meson.build,定义use_drmbuffer:

drmbuffer_dep = dependency('drmbuffer ',  required:get_option('drmbuffer'))
use_drmbuffer = drmbuffer_dep.found()


if use_drmbuffer
    gstwaylandsink = library('gstwaylandsink',
        wl_sources + protocols_files,
        c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API'],
        c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API', '-DAML_BUFFER_POOL'],
        include_directories : [configinc],
        dependencies : [gst_dep, gstvideo_dep, gstwayland_dep, gstallocators_dep,
                        wl_client_dep, wl_protocol_dep, libdrm_dep, drmbuffer_dep],
        install : true,
        install_dir : plugins_install_dir,
    )
else
    gstwaylandsink = library('gstwaylandsink',
        wl_sources + protocols_files,
        c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API'],
        include_directories : [configinc],
        dependencies : [gst_dep, gstvideo_dep, gstwayland_dep, gstallocators_dep,
                        wl_client_dep, wl_protocol_dep, libdrm_dep],
        install : true,
        install_dir : plugins_install_dir,
    )
endif

定义option

在meson_options.txt文件中增加:

option('drmbuffer', type : 'boolean', value : 'true')

在meson configure中增加option drmbuffer为false就可以按false处理:

-Dgst-plugins-bad:drmbuffer=false

option定义参考如下,type有好多种类型,bool类型的可以在meson configure的时候传递false或true:

option('someoption', type : 'string', value : 'optval', description : 'An option')
option('other_one', type : 'boolean', value : false)
option('combo_opt', type : 'combo', choices : ['one', 'two', 'three'], value : 'three')
option('integer_opt', type : 'integer', min : 0, max : 5, value : 3) # Since 0.45.0
option('free_array_opt', type : 'array', value : ['one', 'two'])  # Since 0.44.0
option('array_opt', type : 'array', choices : ['one', 'two', 'three'], value : ['one', 'two'])
option('some_feature', type : 'feature', value : 'enabled')  # Since 0.47.0
option('long_desc', type : 'string', value : 'optval',
    description : 'An option with a very long description' +
                  'that does something in a specific context') # Since 0.55.0

可选的依赖(optional dependency)

不定义也是可以的,在dependency里面required配置为false:

meson.build文件

drmbuffer_dep = dependency('drmbuffer', required:false)

可选的依赖

如果依赖是可选的(optional),你可以告诉 Meson 如果没有找到依赖就不要出错(通过required : false就可以做到),然后做进一步的配置。无论是否找到实际依赖项,都可以将 opt_dep 变量传递给目标构造函数。 meson将忽略未找到的依赖项。

opt_dep = dependency('somedep', required : false)
if opt_dep.found()
  # Do something.
else
  # Do something else.
endif

meson中的if语句

if语句就像在其他语言中一样:

var1 = 1
var2 = 2
if var1 == var2 # Evaluates to false
  something_broke()
elif var3 == var2
  something_else_broke()
else
  everything_ok()
endif

opt = get_option('someoption')
if opt != 'foo'
  do_something()
endif
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值