I\'m writing a CMakeLists.txt to generate files and compile the generated files. I create a function to add some file path strings to a global list variable.
My CMak
Building upon Maxim Suslov's answer, the following code worked for a similar problem I faced:
set_property(GLOBAL PROPERTY source_list)
function(add_source)
get_property(tmp GLOBAL PROPERTY source_list)
foreach(arg ${ARGV})
set(tmp "${tmp} ${arg}")
endforeach()
set_property(GLOBAL PROPERTY source_list "${tmp}")
endfunction(add_source)
add_source(a_file)
add_source(b_file c_file)
get_property(local_prop GLOBAL PROPERTY source_list)
message("list: ${local_prop}")
Function add_source can be called from inside any sub-directory.