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

    <tr>
        <th>Summary</th>
        <td>
            FindLibEdit.cmake somehow ignores CMAKE_SYSROOT
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            bug,
            cmake,
            build-problem
      </td>
    </tr>

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

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

<pre>
    Fuchsia's Clang CI had a breakage due to `FindLibEdit.cmake` incorrectly finding libedit headers in `/usr/include`, despite the fact that our builders set `CMAKE_SYSROOT` explicitly.

This is incorrect because in our build we set `CMAKE_SYSROOT=/b/s/w/ir/x/w/cipd/linux` so CMake shouldn't be looking in paths like `/usr/include`, because at build time Clang will be invoked with `--sysroot=/b/s/w/ir/x/w/cipd/linux` and it won't consider include paths like `/usr/include`.

More details can be found in a short discussion in the change in https://reviews.llvm.org/D124673.

The initial breakage can be found here:  https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8814329895908917697/overview

We were able to work around this in our builders for now, but its concerning that the `CMAKE_SYSROOT` may be ignored. 

Looking at `FindLibEdit.cmake` hasn't highlighted anything obviously suspicious. It uses `find_path` and `find_library`, but the [CMake documentation](https://cmake.org/cmake/help/latest/variable/CMAKE_SYSROOT.html) says that the `find_*` set of utilities will prefix their searches with the path set in `CMAKE_SYSROOT`.

Comparing it to other `Find*` utilities (e.g., from kitware) hasn't highlighted anything immediately obvious either.

cc: @petrhosek @MaskRay @upsj Since you were all on the initial discussion.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVV1v2zgQ_DXyC2FBkq3YfvBDzmmA4hoUaAoc-lRQ1MpiTYkCP-z439-sLDdxrr3DAdEXTe7Ozs5sKluft49RtV7LpFh5sTOy34vdR9HKWkhROZIHuSdRRxLBiuQue9R9_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