cmake函数,参数和返回 [英] cmake function, parameter and return

查看:544
本文介绍了cmake函数,参数和返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个cmake函数作为:

  function(test src_list dst_list)
#do something
endfunction()

用法:

  test($ {my_list} chg_list)

意味着,my_list是一个包含多个字段的列表,chg_list将接收在测试函数内部修改的列表。



但是它不工作,我如何在cmake在CMake中,函数有自己的作用域,默认情况下,所有的变量修改都是局部的,除非您可以将 CACHE PARENT_SCOPE 作为参数传递给 set 。在函数内部,如果要修改调用者范围内的变量,应该使用:

  set dst_list}< something> PARENT_SCOPE)

查看文档


函数打开新范围:请参阅 set(var PARENT_SCOPE)详情。



I would like to create a cmake function as:

function(test src_list dst_list)
# do something
endfunction()

usage:

test(${my_list} chg_list)

It means, my_list is a list with several fields, and chg_list will receive a list modified inside test function.

But it is not working, how can I create a function in cmake to do that?

解决方案

In CMake, functions have their own scope, and by default, all modification of variables are local, unless you pass CACHE or PARENT_SCOPE as parameter to set. Inside a function, if you want to modify a variable in the scope of the caller, you should use:

set(${dst_list} <something> PARENT_SCOPE)

See documentation:

A function opens a new scope: see set(var PARENT_SCOPE) for details.

这篇关于cmake函数,参数和返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆