Include CMake project dependency include directories with -isystem

Viewed 779

A project I'm working on links to Google test (gtest) as a dependency. The google test headers are included in the project though CMake's interface dependencies, using the CMakeLists included in the google test project.

target_link_libraries (our_project gtest gmock)

Some of the warning flags that we have used for our project are printing tons of warnings in google test- for instance, GCC's -Wsuggest-override. Ideally these warnings would not be printed since they originate in a library, and I think including the library headers with -isystem is the correct way to do this. However, I'm not sure how to configure CMake to use -isystem for a specified library.

Is there a way we can specify a library dependency as a system library without modifying gtest, and ignore the warnings from it?

2 Answers

CMake's issue 21211 has a few interesting points, and provides this "fix": Use

get_property(_foo_include_dirs TARGET foo PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
set_property(TARGET foo PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_foo_include_dirs}")

to make the include directories of target foo appear as system includes in your project, even though they were not defined as SYSTEM includes in your dependency.

Related