Ensure that symlinks such as /usr/lib/cmake/clang-X.Y (pointing to
/usr/lib/llvm-X.Y/lib/cmake/llvm) are resolved. This ensures that
CLANG_INSTALL_PREFIX ends up to be /usr/lib/llvm-X.Y instead of /usr.
Partially addresses PR37128
Lekensteyn on May 7 2018, 6:00 AM.Authored by
Hi, this patch was required to make find_package(Clang CONFIG) work when /usr/lib/llvm/clang-X.Y was a symlink and is integrated in the Debian packaging. Please have a look, thanks!
One unfortunate limitation (that existed before) is that find_package(Clang 5.0) does not work because CLANG_VERSION_* is not defined. So
The reason for me to use different Clang versions is for CI purposes. As such, I am currently using CMAKE_PREFIX_PATH=/usr/lib/llvm-6.0 which will find the correct version without explicitly having to specify it in find_package.
Per discussion in D46521, resolving symlinks might introduce issues that are are worse than the issue that was solved here. It seems better to carry this patch downstream (in Debian) since the problem only exists there due to its use of symlinks (which is apparently not fully supported/recommended in LLVM upstream).
I'm interested in this, I've tried for a while to fix the Debian packaging but I'm completely new to the packaging toolchain, so I'm making slow headway.
Some of the problems are recorded in: https://bugs.debian.org/cgi-bin/bugreport.cgi?att=1;bug=862328
My (possibly naive) take is that since the LLVM/Clang build/install tree works as-is with find_package, the bug must be in packaging. That is, if you have a local build tree in /build/, this configures without a hitch: cmake -DCMAKE_PREFIX_PATH=/build/ -G Ninja . with a simple CMakeLists.txt doing find_package for both LLVM and Clang.
The Debian clang-5.0 1:5.0.2-2 package already includes this patch. I tried to upstream it, but there were some concerns about the real path not always being the desired value.
On Debian, cmake -DCMAKE_PREFIX_PATH=/usr/lib/llvm-5.0 would work as well, the problem was that the FindClang.cmake file was installed into an unexpected location (packaging issue).
Secondary to that, some additional symlinks were installed to ensure that users do not have to set CMAKE_PREFIX_PATH in order to find some LLVM/Clang version. That scenario was being addressed with this patch (and D46521).
It works! Having to specify CMAKE_PREFIX_PATH is at least documentable, so I don't see that as a major drawback, especially if it makes docs for tools using Clang more portable.
Thank you for moving this along, now I can vastly simplify our CMake build.