I want to execute a CMake command in a subdirectory with execute_process
, and also pass some cache variables as -D
options.
If the variable is of type string, it works. However, if the variable is a list, the typical method of passing a list in command line does not seem to work.
I tried all of the combinations listed in that answer. I even tried to join mylist
with "\\;"
or "\\\\;"
. However, the execute_process
seems to always unpack the '-DVal2=a\\;b\\;c\\;'
or '-DVal2=a;b;c'
to -Dval2=a b c
.
How can I prevent this? Only -DVal2=a\\;b\\;c
works, but it's very annoying.
set(
mylist
a
b
c
)
set(
cmake_args
"-DVal1=abc"
"'-DVal2=${mylist}'" #does not work, the execute_process will unpack it into seperated args
)
execute_process(
COMMAND ${CMAKE_COMMAND} ${cmake_args} ${CMAKE_SOURCE_DIR}/subproject
OUTPUT_FILE ${CMAKE_BINARY_DIR}/config.log
ERROR_FILE ${CMAKE_BINARY_DIR}/config.log
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/subproject
RESULT_VARIABLE config_result
)