Google Test System Includes

Google test is using system interface includes. This does not work for my project/build, so I am trying to not have those interface includes be -isystem. I did the following…

set(CMAKE_NO_SYSTEM_FROM_IMPORTED ON)
add_subdirectory(googletest)

Instead I’ve had to resort to just wiping out the system directories.

set_target_properties(gmock gtest PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "")

Unfortunately even clearing the target properties explicitly, system includes are still showing up…

Note this set and add_subdirectory is before adding my other targets as well. However, the INTERFACE includes of google test are still being used as -isystem. Any idea why?

After using

set_target_properties(gmock gtest gtest_main gmock_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "")

My issue seems to be resolved. But I still wonder why CMAKE_NO_SYSTEM_FROM_IMPORTED wasn’t working?

The variable governs the treatment of include directories of imported targets. Imported targets are usually created behind the scenes of find_package() and you use such imported targets by means of target_link_libraries(). In your case, you used add_subdirectory() which, essentially, does what googletest/CMakeLists.txt does and that does not involve imported targets.

See https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#imported-targets to learn more about imported targets.