To suppress compiler warnings that originate from libraries I use in my application, I manually include their directories with target_include_directories(myapp SYSTEM ...)
as system libraries before adding them with target_link_libraries
like so:
add_executable(myapp myapp.cpp)
target_include_directories(myapp SYSTEM
PRIVATE "extern/lib/include"
)
target_link_libraries(myapp lib::lib)
However, that kind of feels hacky and will also break if the developers of lib
decide to change the include path. This wouldn't be a problem if using only target_link_library
but then, of course, they are included via -I
and again I would get compiler warnings coming from this include.
Is there any more elegant and fail-safe way of doing this? It would be great if target_link_libraries
had a SYSTEM
option to tell cmake to include it as a system library.