How to set compiler options with CMake in Visual Studio 2017

后端 未结 3 1687
时光取名叫无心
时光取名叫无心 2020-12-28 15:13

Visual Studio 2017 comes with full CMake integration. To learn about this combination, I was starting with this basic sample:

# CMakeLists.txt
cmake_minimum_         


        
3条回答
  •  囚心锁ツ
    2020-12-28 16:08

    In CMake 3.15, CMake introduced a fix for this MSVC-specific warning:

    cl : Command line warning D9025: overriding '/W3' with '/W4'
    

    and the compiler warning flags (like /W3) are no longer automatically added. So by upgrading to CMake 3.15 or greater, this warning should no longer appear. From the docs:

    When using MSVC-like compilers in CMake 3.14 and below, warning flags like /W3 are added to CMAKE__FLAGS by default. This is problematic for projects that want to choose a different warning level programmatically. In particular, it requires string editing of the CMAKE__FLAGS variables with knowledge of the CMake builtin defaults so they can be replaced.

    CMake 3.15 and above prefer to leave out warning flags from the value of CMAKE__FLAGS by default.

    Along with this fix, CMake introduced policy CMP0092, which allows you to switch back to the OLD behavior (adding the warning flags by default) if necessary.

提交回复
热议问题