I am looking for an explanation of the following function in CMake:
function(file_grab src arg)
file(GLOB_RECURSE ${arg} CONFIGURE_DEPENDS
${src}/*.cc
${src}/*.hpp
)
set(${arg} ${${arg}} PARENT_SCOPE)
endfunction(file_grab)
As far as I understand, we use filesystem
and recursively grab all the files with *.cc
and *.hpp
extension and set it to arg
variable.
What I don't understand is
set(${arg} ${${arg}} PARENT_SCOPE)
I understand the first argument is to set whatever ${${arg}}
is to the arg
variable in PARENT_SCOPE
. What does the nested ${${arg}}
?
${${arg}}
is a nested variable reference, see variable references.
As explained in the documentation, it is evaluated from the inside out. In your case, the value of ${arg}
is used as a variable name and itself evaluated.
set(foo "42")
set(arg "foo")
message(STATUS "${${arg}}")
will print 42
.
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