gpt4 book ai didi

cmake - 目录属性和子目录

转载 作者:行者123 更新时间:2023-12-04 19:29:54 25 4
gpt4 key购买 nike

CMake manual for set_directory_properties claim :

Set a property for the current directory and subdirectories.



对我来说,这表明在父目录中设置的属性也应该继承到所有子目录。但情况似乎并非如此。考虑:

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

这打印:
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来处理属性。

我是否误解了 set_directory_properties 中的相应部分手动的?或者它只是过时/错误?

最佳答案

把我的评论变成答案

如果我查看 CMake 的源代码,这取决于 chained cmPropertyDefinition成员(member)是真实的。

因此,您可以使用 INHERITED 为您自己的目录属性实现此目的。关键字与 define_property() :

define_property(
DIRECTORY
PROPERTY narf
INHERITED
BRIEF_DOCS "Brief Doc"
FULL_DOCS "Full Doc"
)

即使 INHERITED documentation只说:

If the INHERITED option then the get_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 to GLOBAL. TARGET, SOURCE, and TEST chain to DIRECTORY.

关于cmake - 目录属性和子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44885943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com