CMake的发电机前pression,区分C / C ++ code [英] CMake generator expression, differentiate C / C++ code
问题描述
我想补充 -std = C ++ 11
我的
add_compile_options("-std=c++11")
然而,这也增加了他们的的 C 的文件汇编,不仅的 C ++ 的。我知道我可以添加取决于所使用的配置条件编译标志:
However, this also adds them to compilation of C files, not only C++. I know I can add conditional compile flags depending on the configuration used:
add_compile_options("$<$<CONFIG:DEBUG>:-addMeInDebugOnly>")
我如何我的标志只添加到c ++文件?我在寻找类似:
How can I add my flag only to c++ files? I'm looking for something like:
add_compile_options("$<$<??:??>:-std=c++11>")
不过,我需要做什么用问号来填补?
But what do I need to fill in with the question marks?
推荐答案
您可以使用的 LINKER_LANGUAGE 目标属性添加标志只为C ++对象*:
You can use LINKER_LANGUAGE target property to add flag only to C++ targets*:
add_compile_options(
"$<$<STREQUAL:$<TARGET_PROPERTY:LINKER_LANGUAGE>,CXX>:-std=c++11>"
)
<子> *请注意,这将不会与混合的C / C ++源代码的目标工作
CMAKE_CXX_FLAGS 应该很好地工作过:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
也许你需要将它们添加到缓存,如果它设置项目
命令之前(例如,在工具链):
Probably you need to add them to cache if it set before project
command (e.g. in toolchain):
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" CACHE STRING "" FORCE)
这篇关于CMake的发电机前pression,区分C / C ++ code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!