2017-07-26 76 views
2

插入符號我想用從Visual Studio新的(更好)的診斷信息2017集診斷:從的CMakeLists.txt

把它啓用我所有的項目一次我想從申報這個標誌我的CMakeLists.txt

我試圖

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /diagnostics:caret") 

但是,編譯時有一個錯誤,指出/診斷:典型的(這是默認值)不與/診斷兼容:插入記號

有沒有辦法使用cmake覆蓋默認值?

回答

3

你必須要知道這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選項。

這裏是一個工作示例:

的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" 
)  

參考