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

    <tr>
        <th>Summary</th>
        <td>
            C_INCLUDE_DIRS feature is messed up
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            cmake,
            clang:driver
      </td>
    </tr>

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

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

<pre>
    When doing some driver work a little while ago, I bumped into code handling C_INCLUDE_DIRS, which appears to be replicated across many driver toolchain classes. My first thought was to refactor all those duplicates into a common utility function, but on closer inspection they aren't all the same.

First off, C_INCLUDE_DIRS is a CMake variable that is a PATH-like string that lets you specify system include directories; the driver handling typically skips adding $sysroot/include (and maybe others, varies with target) and use what's in the C_INCLUDE_DIRS string instead.  This appears to be legacy going back to the autoconf days, with references to `configure --with-c-include-dirs` popping up. I have no idea whether anyone actually uses this.

Even so, there are issues.

1. Some targets prepend the sysroot to absolute paths from C_INCLUDE_DIRS, and leave relative paths along. Other targets do it the other way around. (This inconsistency stopped me from doing the refactor. The code for all targets is otherwise identical, except for the name of the variable containing the sysroot to use.)
2. Not all targets support this. I removed PS4/PS5 support it because it makes no sense for us (and it existed in the first place only because I was cargo-culting other targets). I don't know what the story is for other targets.
3. The separator is hard-coded to be a colon, which totally fails on a Windows hosted cross compiler. (Windows _targets_ do not support C_INCLUDE_DIRS at all.) It should use `llvm::sys::EnvPathSeparator` instead. But, that means updating all the 8-10 places that do this bit of code, because factoring into a utility routine would change behavior (see item 1).

I know too little about how different environments and distros handle where they put things, so I have no opinion about what if anything should be done here. But item 1 in particular seems very weird. Personally I'd be inclined to rip it all out, but maybe it's useful to someone.

Tagging @MaskRay as the current Driver owner, and @echristo as the former Driver and autoconf-stuff owner.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVl1v20oO_TXyC2HDkex8PPihT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