CMake Error when importing ClangConfig.cmake

Asked by Moritz Sichert

I have a CMakeLists.txt with the following content:

cmake_minimum_required(VERSION 3.7)
project(myproject)

find_package(LLVM 5.0 REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

find_package(
    Clang REQUIRED CONFIG
    HINTS "/usr/share/llvm-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}"
)
message(STATUS "Using ClangConfig.cmake in: ${Clang_DIR}")

When I run cmake, I get the following output:

-- Found LLVM 5.0.0
-- Using LLVMConfig.cmake in: /usr/lib/llvm-5.0/cmake
CMake Error at /usr/share/llvm-5.0/cmake/ClangConfig.cmake:18 (include):
  include could not find load file:

    /usr/lib/cmake/clang/ClangTargets.cmake
Call Stack (most recent call first):
  CMakeLists.txt:11 (find_package)

-- Using ClangConfig.cmake in: /usr/share/llvm-5.0/cmake
-- Configuring incomplete, errors occurred!

Unfortunately, in ClangConfig.cmake the path to ClangTargets.cmake is hard-coded. Is there a way to make this work, or is this a bug?

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu llvm-toolchain-5.0 Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Ashutosh Gupta (agupta-s) said :
#1

I am facing the same problem. I think these files are at the wrong place.

We need a patch to make it work. I am working on it. I will let you know as soon as I have it.

I am only a user. I may not be able to create the patch.

Revision history for this message
Ashutosh Gupta (agupta-s) said :
#2

I have managed to make it work.

CMake files for clang are at wrong location. Give the following command to link them to the right location. Furthermore, a reference to clang binary is misplaced. For that we need one more link.

Give the following two commands (creating two links)

sudo ln -s /usr/share/llvm-5.0/cmake/ /usr/lib/llvm-5.0/lib/cmake/clang
sudo ln -s /usr/share/llvm-5.0/bin/clang /usr/lib/llvm-5.0/bin/clang-5.0

After the above changes, you may still be missing some clang utilities. Please install them.

You will need to call find_package as follows

 find_package(Clang REQUIRED CONFIG HINTS "/usr/lib/llvm-5.0/lib/cmake/clang")

Can you help with this problem?

Provide an answer of your own, or ask Moritz Sichert for more information if necessary.

To post a message you must log in.