在cmake中传递空字符串? [英] Pass empty strings in cmake?

查看:338
本文介绍了在cmake中传递空字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在cmake中重新定义一个函数。但是,此功能只有一些签名。如果我不识别签名,我只想用所有原始参数调用原始签名。除非函数os以空字符串( )作为参数调用,否则此方法工作正常。这个问题可以这样说明:

I'm trying to redefine a function in cmake. But, only some signatures for this function. If I do not recognise the signature I simply want to call the original with all original arguments. This works fine, unless the function os called with empty strings ("") as arguments. The problem can be illustrated like this:

function(y)
  list(LENGTH ARGN len)
  message("y got ${len} elements: ${ARGN}")
endfunction()

function(x)
  list(LENGTH ARGN len)
  message("x got ${len} elements: ${ARGN}")
  y(${ARGN})
endfunction()

x(a b "")
x(a "" c)

将以上内容保存到 x.cmake 并运行 cmake -P x.cmake ,它会打印

Save the above to x.cmake and run cmake -P x.cmake, which prints

> cmake -P x.cmake
x got 3 elements: a;b;
y got 2 elements: a;b
x got 3 elements: a;;c
y got 2 elements: a;c

即, y 没有得到空字符串,并且我重新定义的函数停止工作。任何线索如何传递所有参数(包括空字符串)?

I.e., y doesn't get the empty string and my redefined function stops working. Any clue how to pass all arguments, including empty strings?

实际用例正在尝试重新定义 file 更改安装。您可能无法解决此问题:

Real use case is trying to redefine file to change the installation. You're alternative doesn't seem to work for that:

function(file)
  message("Calling file(${ARGN})")
  _file("${ARGN}")
endfunction()

include("cmake_install.cmake")

这将导致

> cmake -P cmake_ln_install.cmake
-- Install configuration: "RelWithDebInfo"
Calling file(RPATH_CHECK;FILE;/home/janw/cmake/linux/lib/swipl/bin/x86_64-linux/swipl;RPATH;/home/janw/cmake/linux/lib/swipl/lib/x86_64-linux)
CMake Error at cmake_ln_install.cmake:3 (_file):
  _file must be called with at least two arguments.
Call Stack (most recent call first):
  src/cmake_install.cmake:43 (file)
  cmake_install.cmake:42 (include)
  cmake_ln_install.cmake:6 (include)


推荐答案

更改

y(${ARGN})

y("${ARGN}")

使其表现出预期效果。

这篇关于在cmake中传递空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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