Marking headers as SYSTEM does not suppress warnings on Windows.

Hi :slight_smile: I need to compile unit tests for simple project with some warnings turned on. But I want to suppress this warnings from being arisen in an external INTERFACE library(actually this is my fork from Boost.Leaf with added SYSTEM option) and to achieve this I have added SYSTEM option in target_include_directories:

# Generated by `boostdep --cmake leaf`
# Copyright 2020 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt

cmake_minimum_required(VERSION 3.5...3.16)

project(boost_leaf VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)

add_library(boost_leaf INTERFACE)
add_library(Boost::leaf ALIAS boost_leaf)

target_include_directories(boost_leaf SYSTEM INTERFACE include)

if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")

  add_subdirectory(test)

endif()

This works fine on Linux and MacOS but unfortunately not for Windows because warnings keeps being arisen in the external library(here you can see errors arisen in boost/leaf/handle_errors.hpp which in theory must be suppressed)

If this can be useful the project that I try to compile can be found on github

Any idea what Iā€™m doing wrong and how to suppress those warnings?

Ignoring warnings from system headers is only supported with MSVC with the Ninja generators as of CMake 3.22 and the Visual Studio generators as of CMake 3.24. Of course, an MSVC of at least (compiler) version 19.29.30036.3 is required (the 14.29 toolchain in the Visual Studio installer).

2 Likes