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

    <tr>
        <th>Summary</th>
        <td>
            [libc] consider using runtimes/CMakeLists.txt as base (rather than llvm/CMakeLists.txt)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            cmake,
            libc
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          nickdesaulniers
      </td>
    </tr>
</table>

<pre>
    we've observed issues in the past where flags set in llvm's cmake files end up polluting toolchain command line options for libc.

Via discussions with @ldionne on discord and https://github.com/llvm/llvm-project/pull/77810#issuecomment-1890061319

> Yes, I've run into such pollution many times
> This was one of the many motivating reasons for switching from LLVM_ENABLE_PROJECTS to LLVM_ENABLE_RUNTIMES, and using runtimes/CMakeLists.txt instead of llvm/CMakeLists.txt as a CMake root
> It didn't solve everything, but at least it insulated the runtimes from arbitrary flags being added in other LLVM projects
> We still have this issue due to e.g. HandleLLVMOptions.cmake
> I think eventually the solution would be to ban global flags entirely. Modern CMake doesn't need that, it can define targets with flags and have them propagate to dependencies. It's a lot cleaner and safer
> For most projects under the LLVM umbrella, being polluted by flags is an annoyance. For the runtimes, this can be actually dangerous cause you need to control exactly what flags you use for building.

> I think this makes sense, however I'll note that other things can be polluted by the "rest" of LLVM as well:
> Link flags
> CMake variables like CMAKE_POSITION_INDEPENDENT_CODE
> Other compiler flags that are not -D options
> This is better than nothing, but I think the full fix is to gradually refactor the CMake files used by runtimes to avoid setting anything global.

We would have to update documentation, too.  cc @petrhosek 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU1vIzcM_TXjC7EDe2xn7IMP2dhG3eZjsZvuoqeAI9EeNRrJkCh7_e8LaiYfGxQoeklgjUi99_hIYozm4IhWxfxzMV-PMHHrw8oZ9awpYrLOUIijxuvL6kxFVZ8IfBMpnEiDiTFRB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