本文介绍了cmake是否具有诸如target_link_options之类的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以在接口库( foo
上设置COMPILE_OPTIONS,并且
foo 的用户也将使用这些COMPILE_OPTIONS。

You can set the COMPILE_OPTIONS on an INTERFACE library (foo)and those COMPILE_OPTIONS will also be used by the users offoo.

add_library(foo INTERFACE)
target_link_libraries(foo INTERFACE foo_1)
target_compile_options(foo INTERFACE "-DSOME_DEFINE")
add_executable(exe exe.cpp)
target_link_libraries(exe foo)

是否可以对LINK_FLAGS做类似的事情?

Is it possible to do something similar for LINK_FLAGS ?

推荐答案

根据中没有 INTERFACE_LINK_OPTIONS 之类的东西。可能是因为 INTERFACE _ * 属性用于描述如何使用目标(例如避免违反ODR规则或未定义的引用)以及诸如之类的选项-允许-多重定义与特定库的使用无关(恕我直言,这是错误的征兆)。

According to the documentation there is no such property as INTERFACE_LINK_OPTIONS or something. Probably because INTERFACE_* properties used to describe how to use target (like avoiding violation of ODR rule or undefined references) and such options like --allow-multiple-definitions is not related to usage of a specific library (IMHO it's an indication of an error).

无论如何,对于 gcc ,您也可以使用 target_link_libraries 添加链接器标志:

Anyway, for compiler like gcc you can use target_link_libraries to add linker flags too:

target_link_libraries(foo INTERFACE "-Wl,--allow-multiple-definition")

但是我不知道如何为Visual Studio做类似的事情。

But I don't know how to do something like that for visual studio.

这篇关于cmake是否具有诸如target_link_options之类的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 20:58
查看更多