The CMake manual for set_directory_properties
claims:
Set a property for the current directory and subdirectories.
To me this suggests that properties set in a parent directory should also be inherited to all subdirectories. But this does not seem to be the case. Consider:
CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(foo CXX)
set_property(DIRECTORY . PROPERTY narf "zort")
add_subdirectory(a)
get_property(res DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY narf)
message("Property read from root: " ${res})
a/CMakeLists.txt
get_property(res DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY narf)
message("Property for a read from a: " ${res})
get_property(res DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY narf)
message("Property for root directory root read from a: " ${res})
This prints:
Property for a read from a:
Property for root directory root read from a: zort
Property read from root: zort
So the property can only be retrieved from the directory on which it was set, not the subdirectories. The same is true when using the set_directory_properties
/get_directory_properties
to deal with the properties.
Did I misinterpret the respective section in the set_directory_properties
manual? Or is it simply outdated/wrong?
Turning my comment into an answer
If I look at CMake's source code this depends on the
chained
member ofcmPropertyDefinition
to be true.So you can achieve this for your own directory property by using the
INHERITED
keyword withdefine_property()
:Even if the
INHERITED
documentation says only: