cmake: include directories don't have SYSTEM property which can cause warnings
envgap__abseil__abseil-cpp-964
01 / FAILURE SIGNATURE
As reported upstream
/home/matled/src/demo/abseil-cpp/absl/strings/str_cat.h:171:19: error: conversion from ‘int’ to ‘uint8_t’ {aka ‘unsigned char’} may change value [-Werror=conversion]Not a benchmark task.
- The project already builds and runs before the fix, so there is nothing to repair.
02 / ENVIRONMENT RECIPE
- Base commit
697acabc5b7e28c51f7ab8d2f43d4ef4fed77f8d- Manifest
CMakeLists.txt- Reproduce
Awaiting issue-specific recipe- Run under trace
Awaiting a meaningful runtime command
03 / ORIGINAL ISSUE TEXT
abseil/abseil-cpp #964 · read the original issue
**Summary**
When integrating the abseil-cpp library into a cmake project, the include directories are not marked as SYSTEM. This enables the project-specific diagnostics to be applied to absl headers.
Is there an good way to mark include directories of libraries as `SYSTEM`? I couldn't find one from researching a bit.
Otherwise, I think it would be useful if abseil had an option to apply `SYSTEM` property to the `target_include_directories`.
**Details**
Here is a minimal cmake project to demonstrate the issue (this should reproduce with most common systems/compilers, I was using Ubuntu 20.04, cmake 3.20, gcc 9.3.0/clang 10.0):
```
matled@fg:~/src/demo% tail -n 10 CMakeLists.txt demo.cc
==> CMakeLists.txt <==
cmake_minimum_required(VERSION 3.5)
project(demo)
add_subdirectory(abseil-cpp)
add_executable(demo demo.cc)
target_link_libraries(demo absl::strings)
target_compile_options(demo PRIVATE -Wconversion -Werror)
==> demo.cc <==
#include <absl/strings/str_cat.h>
int main() {
printf("%s\n", absl::StrCat("foo", "bar").c_str());
return 0;
}
matled@fg:~/src/demo% rm -rf build && cmake -S . -B build && cmake --build build --target demo --verbose
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
[...]
/usr/bin/c++ -I/home/matled/src/demo/abseil-cpp -Wconversion -Werror [...]
In file included from /home/matled/src/demo/demo.cc:1:
/home/matled/src/demo/abseil-cpp/absl/strings/str_cat.h: In constructor ‘absl::Hex::Hex(absl::PadSpec, uint64_t)’:
/home/matled/src/demo/abseil-cpp/absl/strings/str_cat.h:171:19: error: conversion from ‘int’ to ‘uint8_t’ {aka ‘unsigned char’} may change value [-Werror=conversion]
[...]
cc1plus: all warnings being treated as errors
make[3]: *** [CMakeFiles/demo.dir/build.make:76: CMakeFiles/demo.dir/demo.cc.o] Error 1
make[3]: Leaving directory '/mnt/c/Users/matled/source/demo/build'
make[2]: *** [CMakeFiles/Makefile2:551: CMakeFiles/demo.dir/all] Error 2
make[2]: Leaving directory '/mnt/c/Users/matled/source/demo/build'
make[1]: *** [CMakeFiles/Makefile2:558: CMakeFiles/demo.dir/rule] Error 2
make[1]: Leaving directory '/mnt/c/Users/matled/source/demo/build'
make: *** [Makefile:124: demo] Error 2
```
When include directories use the `-isystem` flag instead of `-I`, warnings are suppressed. cmake sets this option based on the `SYSTEM` property being specified on `target_include_directories`. I could not find an easy way to set this option outside of the abseil cmake files.
I've verified manually that adding the `SYSTEM` property to the two uses of `target_include_directories` in `function(absl_cc_library)` solves the issue.
An option in the abseil-cpp cmake file to mark the include directories as `SYSTEM` would be one solution for this.04 / LABELS
Labels from the report text only; not yet run
No supported category has been assigned.
Label rules and the text that matched
[]