Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of ${${arg}} in CMake?

Tags:

cmake

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}}?

like image 981
beepboop Avatar asked Sep 01 '25 20:09

beepboop


1 Answers

${${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.

Example

set(foo "42")
set(arg "foo")
message(STATUS "${${arg}}")

will print 42.

like image 169
havogt Avatar answered Sep 04 '25 22:09

havogt