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)
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
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?
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")
This results in
> 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)
Changing
to
makes it behave as you expect.