在cmake中传递空字符串?

时间:2018-09-24 13:41:43

标签: cmake

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

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,该命令会打印

> 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没有得到空字符串,并且我的重新定义函数停止工作。有什么线索可以传递所有参数,包括空字符串吗?

实际用例正在尝试重新定义file来更改安装。您似乎无法解决这个问题:

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)

1 个答案:

答案 0 :(得分:1)

更改

y(${ARGN})

y("${ARGN}")

使其表现出预期的效果。