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 of cmPropertyDefinition
to be true.
So you can achieve this for your own directory property by using the INHERITED
keyword with define_property()
:
define_property(
DIRECTORY
PROPERTY narf
INHERITED
BRIEF_DOCS "Brief Doc"
FULL_DOCS "Full Doc"
)
Even if the INHERITED
documentation says only:
If the
INHERITED
option then theget_property()
command will chain up to the next higher scope when the requested property is not set in the scope given to the command.DIRECTORY
scope chains toGLOBAL
.TARGET
,SOURCE
, andTEST
chain toDIRECTORY
.
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