CMake也将所有gcc标志也传递给nvcc [英] CMake passes all gcc flags to nvcc as well

查看:253
本文介绍了CMake也将所有gcc标志也传递给nvcc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目将cuda内核用于一个小模块,并且需要nvcc进行编译.在编译期间,cmake还将用于gcc的相同链接器和编译器标志传递给nvcc.在我的情况下,出现以下错误.

My project uses cuda kernel for a small module and needs nvcc for compiling. During compilation, cmake pass the same linker and compiler flags intended for gcc to nvcc as well. In my particular case, I get the following error.

nvcc fatal   : Unknown option 'Wl,--no-as-needed'

中接受的答案之后>线程,如下所示,我设法删除了需要nvcc的目标的编译器标志.

Following the accepted answer in this thread, I managed to remove the compiler flags for the target that needs nvcc as follows.

get_target_property(_target_cxx_flags target_that_needs_nvcc COMPILE_OPTIONS)
list(REMOVE_ITEM _target_cxx_flags "-fcolor-diagnostics")

使用此方法,我避免了由于错误的编译器标志而导致的错误,如下所示:

Using this, I avoided the errors due to wrong compiler flags like this:

nvcc fatal   : Unknown option 'fdiagnostics-color'

但是我不能使用相同的过程来删除链接器标志,因为get_target_property仅获取编译器标志,而不获取链接器标志.

But I cannot use the same procedure to remove linker flags because get_target_property fetches only compiler flags and not linker flags.

我正在寻找一种仅针对一个目标编译禁用链接器标志的解决方案.

I am looking for a solution to disable the linker flags for just one target compilation.

预期的cmake最低版本为VERSION 3.0

The cmake minimum version expected is VERSION 3.0

推荐答案

删除不需要的标志的一种方法是从不添加标志.您可以使用生成器表达式来特定于语言.例如:

An alternative to removing flags you don't want is to never add them in the first place. You can be language-specific using generator expressions. eg:

add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:${my_cxx_flags}>")
add_compile_options("$<$<COMPILE_LANGUAGE:CUDA>:${my_cuda_flags}>")

我知道您在问的是链接器标志而不是编译器标志,但是希望这可能使您朝着一个有用的方向迈进.

I realise you're asking about linker flags not compiler flags, but hopefully this might set you off in a useful direction.

这篇关于CMake也将所有gcc标志也传递给nvcc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆