<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/129254>129254</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [CMake] `llvm_add_library` does not preserve `SYSTEM` property for headers in `OBJECT` mode
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ingomueller-net
      </td>
    </tr>
</table>

<pre>
    If a `LINK_LIB` dependency is passed to `llvm_add_library` together with the `OBJECT` keyword (or with, both, the `STATIC` and `SHARED` keywords), then the include directories from that library use their `SYSTEM` marker.

As a consequence, these directories will be linked to with `-I` instead of `-isystem`, such that warnings will be reported, making it impossible to use `-Werror` if there are any warnings. I, thus, think that the `SYSTEM` property should be preserved.

I believe that this is due to some manual construction of dependencies and/or include directories for the `obj.XXX` target that is created in that case, which doesn't seem to preserve the `SYSTEM` property. I have tried a few ways to set that or related properties but failed and exhausted my CMake knowledge.

https://github.com/ingomueller-net/llvm-project/tree/llvm-add-library-system-headers contains a reproducer that adds the `Protobuf` library to a new target `MLIREmitCDialect2`. If CMake is configure with XXX, we can see the following output (note the `-I` flag):

```
$ grep MLIREmitCDialect2 build/compile_commands.json | grep protobuf
  "command": "/usr/bin/clang++ ... -I/.../git/llvm-project/build-Debug/_deps/protobuf-src/src ... -o tools/mlir/lib/Dialect/EmitC/IR/CMakeFiles/obj.MLIREmitCDialect2.dir/EmitC.cpp.o -c .../git/llvm-project/mlir/lib/Dialect/EmitC/IR/EmitC.cpp"
```

If we remove the `OBJECT` keyword in the call to `llvm_add_library` as the comment indicates, then the library is included with `-isystem` instead of `-I`.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVd1u4zYTfRr6ZmBBoS07vvCF8yN8-rrbFrsBur0KKHIkcU2RKknF9dsXQ1lxd7NZFEggmBrOmTln5kiEoF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