I want to do do something like this
execute_process(
COMMAND bash -c "git --git-dir ${CMAKE_SOURCE_DIR}/.git ls-files"
OUTPUT_VARIABLE TRACKED_FILES)
add_custom_target(all_file_project SOURCES ${TRACKED_FILES})
And the command itself seems to work as expected but the generated variable "TRACKED_FILES" contains only one logical entry (one multi line string) rather than a list of files.
Can I somehow turn a string containing multiple lines separated by a newline ("\n") into a list in CMake?
One option (as the title of my question suggests) is to actively split the string manually rather than interpreting a variable as list in the first place:
string(REPLACE "\n" ";" ADDITIONAL_PROJECT_FILES_LIST ${ADDITIONAL_PROJECT_FILES})
This works for me but it would be very nice to have something more abstract and less platform specific (e.g. I don't know whether this works on all OSes including Windows)
Something like execute_process(COMMAND find -type f OUTPUT_LIST_VARIABLE MY_LIST)
Or at least set(MY_LIST FROM_MULTILINE MY_MULTILINE_STRING)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With