Let's say we have CMake projet like following:
proj_main
├── proj_sub_0
├── ...
└── proj_sub_n
Each sub-project may have zero or more than one targets. Number of sub-projects may change in situations.
For some reasons, we have to get a list of sub project targets for future use. It's reasonable to setup a list in proj_main and let let each sub-project to append targets into it.
Then here comes the question:
- Is it to declare an empty list in CMake?
- How?
UPDATE
As in comments heros mentioned that set(name)
could define an empty list, previous questions got resolved.
But, here comes more.
Let's say we defined a list foo
and a fucntion func
in proj_main/CMakeLists.txt:
...
set(foo_list)
function(func var)
list(APPEND foo_list var)
endfunction()
...
In proj_sub_i/CMakeLists.txt (where i may be anyone from 0 to n):
...
func(bari)
...
My expectation is that foo_list
could be updated by func
called in proj_sub_i. But the trueth is foo_list
will stays unchanged. And more, even I call foo_list
in proj_main, I could not change foo_list
at all.
The func
calling in proj_sub_i could not effect the foo_list
. Why? What's the correct way to update the foo
here?