CMake: Access variables across sub directories -
i have 2 sub directories root on 1 has line:
set(${libname}_publicheaders localizeresource.h )
i want able access variable other subdirectory. how can this?
@joakimgebart's answer more common way go this. however, can use get_directory_property
directly within second subdir achieve you're after.
i see in comment, you've used ${lib_name}_publicheaders
, in question have ${libname}_publicheaders
. cause of problems, since command should work this:
get_directory_property(myvar directory ${cmake_source_dir}/abc definition ${libname}_publicheaders)
however, there couple of provisos:
- this has called after setting variable in subdir. i.e. you'd have ensure
add_subdirectory(abc)
called beforeadd_subdirectory
1 used. - if
libname
set
inside same subdir (abc), you'll need retrieve value first.
so, while less common solution, has advantage doesn't "pollute" global namespace subdir-specific variables - works subdir referring subdir.
Comments
Post a Comment