[英]CMake 3.0 add_library of type INTERFACE breaks get_target_property
I want to add a header only directory to a cmake project which I am using in Windows 7 with Visual Studio 2013 Update 2. I did some research and came up with this Cmakelists.txt file:我想将一个 header 目录添加到一个 cmake 项目中,我在 Windows 7 中使用 Visual Studio 2013 Update 2。我做了一些研究并提出了这个 Cmakelists.txt 文件:
add_library(AAA_lib INTERFACE)
target_include_directories(AAA_lib
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
)
This appears to work however in some of our internal cmake code we call get_target_property:这似乎有效,但是在我们调用 get_target_property 的一些内部 cmake 代码中:
get_target_property(target_libraries ${target} LINK_LIBRARIES)
This generates a CMake error:这会生成 CMake 错误:
CMake Error at x_common_libs/xml/xsdmap.cmake:41 (get_target_property):
INTERFACE_LIBRARY targets may only have whitelisted properties. The
property "LINK_LIBRARIES" is not allowed.
It seems like an odd error since a get should only return targets with the appropriate property.这似乎是一个奇怪的错误,因为 get 应该只返回具有适当属性的目标。 Is this a bug in CMake?
这是 CMake 中的错误吗? Or is there some other way that this should be implemented?
或者还有其他方法可以实现吗?
Why do we need to call get_target_property?为什么我们需要调用 get_target_property? We have a cmake helper function which recursively goes through all of dependencies of a project building up a list of all dependent projects that require some custom post processing.
我们有一个 cmake 助手 function,它递归地遍历项目的所有依赖项,构建需要一些自定义后处理的所有依赖项目的列表。 So if project X uses project B and C and C uses D, then we get a list of X, B, C, D and then check to see which directories match a requirement and then call a custom_command.
因此,如果项目 X 使用项目 B,C 和 C 使用 D,那么我们将获得 X、B、C、D 的列表,然后检查哪些目录符合要求,然后调用 custom_command。
Thanks, Jason谢谢,杰森
Seems that it is CMake bug. 似乎是CMake错误。 There is new target type in CMake 3.0 called INTERFACE_LIBRARY.
CMake 3.0中有一个新的目标类型,称为INTERFACE_LIBRARY。 You are supposed to use only some of properties for this type.
您应该只对这种类型使用某些属性。 However, I don't think it was expected to raise an error in case of reading other properties.
但是,我不认为在读取其他属性的情况下会引发错误。
I came out with the following workaround: 我提出了以下解决方法:
get_target_property(_TARGET_TYPE ${target} TYPE)
if(_TARGET_TYPE STREQUAL "INTERFACE_LIBRARY")
unset(target_libraries)
else()
get_target_property(target_libraries ${target} LINK_LIBRARIES)
endif()
This is a restriction that was lifted in CMake 3.19.这是在 CMake 3.19 中解除的限制。
See https://gitlab.kitware.com/cmake/cmake/-/issues/19145 for details.详情见https://gitlab.kitware.com/cmake/cmake/-/issues/19145 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.