目录属性和子目录 [英] Directory properties and subdirectories
问题描述
CMake手册,用于 set_directory_properties
声明:
设置当前目录和子目录的属性。
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
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
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})
此打印:
Property for a read from a:
Property for root directory root read from a: zort
Property read from root: zort
因此该属性只能是从设置它的目录而不是子目录中检索。使用 set_directory_properties
/ get_directory_properties
处理属性时,也是如此。
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.
我是否误解了 set_directory_properties
手册中的相应部分?还是仅仅是过时/错误?
Did I misinterpret the respective section in the set_directory_properties
manual? Or is it simply outdated/wrong?
推荐答案
将我的评论变成答案
如果我看一下CMake的源代码,这取决于 cmPropertyDefinition $ c $的
链式
成员c>是真的。
If I look at CMake's source code this depends on the chained
member of cmPropertyDefinition
to be true.
因此,您可以通过将 INHERITED
关键字与一起使用来为自己的目录属性实现此目标define_property()
:
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"
)
即使 INHERITED
文档仅说:
Even if the INHERITED
documentation says only:
如果
继承
选项,那么当在给定命令的作用域中未设置请求的属性时,get_property()
命令将链接到下一个更高的作用域。目录
作用域链到GLOBAL
。目标
,源
和TEST
链接到目录
。
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
.
这篇关于目录属性和子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!