设置诊断:插入符号来自 CMakeLists.txt
set diagnostics:caret from CMakeLists.txt
我想使用Visual Studio 2017中的新的(更好的(诊断信息。
要立即为我的所有项目启用它,我想从我的 CMakeList 声明此标志.txt
我试过了
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /diagnostics:caret")
但是在编译时出现一个错误,指出/diagnostics:classic(这是默认值(与/diagnostics:caret 不兼容
有没有办法使用 cmake 覆盖默认值?
你只需要知道 CMake 尚未正式支持的 VS 编译器选项最终将位于:
Properties
/C/C++
/Command Line
/Additional Options
这就是为什么你会得到
cl : Command line error D8016: '/diagnostics:classic' and '/diagnostics:caret'
command-line options are incompatible
但是,您可以使用新的VS_USER_PROPS
目标属性(版本>= 3.8(全局提供cl
选项。
这是一个工作示例:
CMakeList.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"
)
参考
- 使用 CMake 添加视觉对象C++属性表
相关文章:
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- CMakeLists.txt中的命名空间表示法
- 将生成文件转换为 CMakeLists.txt等效项
- CMake 错误"源似乎不包含 CMakeLists.txt",路径/库连接问题
- 直接传递编译选项(绕过 CMakeLists.txt)
- 如何在 CMakeLists.txt Qt Creator 中包含头文件?
- 了解编写 CMakeLists.txt
- 如何制作 cmakelists.txt编译使用在其他地方声明和实现的函数和类的 CPP
- 将目录添加到没有 CMakeLists.txt 的 CMake 项目
- 如何在 CMakeLists.txt for Visual Studio 2019 中启用 clang-tidy?
- CMakeLists.txt structure
- CMakeLists.txt:(add_executable):没有给目标提供来源:教程
- 如何将opencv包添加到CMakelists.txt
- 如何在不更改CMakeLists.txt的情况下(可能通过CLI)将CFLAGS和CXXFLAGS传递给cmake
- 如何在CMakeLists.txt中正确设置CMake标志
- 如何为 UnitTest++ 项目编写 CMakeLists.txt 文件
- 设置诊断:插入符号来自 CMakeLists.txt
- cmake find_package CMakeLists.txt 子文件夹中的相对路径
- 在cmakelists.txt中链接GSL
- CMakelists.txt用于C 项目中的第三方C文件