从CMakeLists.txt设置诊断:插入符号 [英] set diagnostics:caret from CMakeLists.txt
问题描述
我想使用Visual Studio 2017中的新的(更好的)诊断信息。
I would like to use the new (and better) diagnostic information from visual studio 2017.
要立即声明我所有项目的功能我的CMakeLists.txt中的此标志
To have it enabled to all my project at once I want to declare this flag from my CMakeLists.txt
我尝试
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /diagnostics:caret")
但是编译时出现错误,即/ diagnostics:classic(默认值)与/ diagnostics:caret
But when compiling there is an error saying that /diagnostics:classic (which is the default value) is not compatible with /diagnostics:caret
是否可以使用cmake覆盖默认值?
Is there a way to override the default value using cmake ?
推荐答案
您只需要知道CMake尚未正式支持的VS编译器选项将最终出现在以下位置:
You just have to know that VS compiler options that CMake does not yet officially support will end up under:
属性
/ C / C ++
/ 命令行
/ 其他选项
Properties
/C/C++
/Command Line
/Additional Options
这就是为什么你得到
cl : Command line error D8016: '/diagnostics:classic' and '/diagnostics:caret'
command-line options are incompatible
但是您可以给 cl
选项在全球范围内使用新的 VS_USER_PROPS
目标属性(版本> = 3.8)。
But you can give cl
options globally with the new VS_USER_PROPS
target property (version >= 3.8).
这是一个有效的示例:
CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(VSAnyFlag)
file(WRITE main.cpp "int main() { return 0; }")
add_executable(${PROJECT_NAME} main.cpp)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.Cpp.user.props" [=[
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<ClCompile>
<DiagnosticsFormat>Caret</DiagnosticsFormat>
</ClCompile>
</ItemDefinitionGroup>
</Project>
]=])
set_target_properties(
${PROJECT_NAME}
PROPERTIES
VS_USER_PROPS "${PROJECT_NAME}.Cpp.user.props"
)
参考
- Add Visual C++ property sheets using CMake
这篇关于从CMakeLists.txt设置诊断:插入符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!