I have a function which takes a list of arguments that I want to pass to a function in a target. Only when I try to use that multivalueargs, it places the second and further arguments on the following line instead of all on one line separated by spaces.
Here is my minimal version of my function. Save that in a file named CMakeLists.txt.
cmake_minimum_required(VERSION 3.22.1)
function(MyFunc)
set(options VERBOSE)
set(oneValueArgs PROJECT_NAME)
set(multiValueArgs PROJECT_ARGS)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
project(${ARG_PROJECT_NAME})
add_custom_command(
OUTPUT sample
COMMAND echo "starting..."
COMMAND echo "ARG_PROJECT_ARGS = [${ARG_PROJECT_ARGS}]"
COMMAND echo "done..."
)
add_custom_target(${PROJECT_NAME} DEPENDS sample)
endfunction()
MyFunc(
PROJECT_NAME testing
PROJECT_ARGS
--some additional
--parameters here
--to-test)
To generate, use:
cmake .
To run the result, use:
make testing
That outputs the correct first argument, but the following ones are on the next line and interpreted as commands instead of being just parameters in the echo ... string.
[100%] Generating sample
starting...
ARG_PROJECT_ARGS = [--some
/bin/sh: 1: additional: not found
/bin/sh: 1: --parameters: not found
/bin/sh: 1: here: not found
/bin/sh: 1: --to-test]: not found
make[3]: *** [CMakeFiles/testing.dir/build.make:74: sample] Error 127
make[2]: *** [CMakeFiles/Makefile2:83: CMakeFiles/testing.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/testing.dir/rule] Error 2
make: *** [Makefile:124: testing] Error 2
What do I have to do to use the list as a string which does not end up on multiple lines like in the above?