Adding LLVM to my Cmake project: Why do hardcodes exist in the LLmM Cmake file?

I am using LLVM / Clang in my C ++ project. I can create and run everything using the Makefile.

Now I am trying to switch to Cmake and I cannot get it to work. Let me explain what I did.

I follow this guide:

http://llvm.org/docs/CMake.html#embedding

Relevant snippet from this web page:

Starting with LLVM 3.5 and the CMake and autoconf / Makefile assemblies, systems export LLVM libraries as imported CMake targets.

Excellent! I will post the LLVM 3.5 download and I should be good to go. I went to the download page:

http://llvm.org/releases/download.html

and downloaded the pre-created binaries for Clang for Ubuntu 14.04 Linux.

Then I added the following to the CMakeLists.txt file:

 find_path (LLVM_DIR LLVM-Config.cmake /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake ) message(STATUS "LLVM_DIR = ${LLVM_DIR}") find_package(LLVM REQUIRED CONFIG) 

(This is the same as in the tutorial, except that I set LLVM_DIR since it is in a non-standard place.)

When I run cmake , I get the following error:

 [ dev@beauty :/path/to/project/build (develop)] $ cmake .. -- LLVM_DIR = /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake CMake Error at /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake/LLVMConfig.cmake:50 (include): include could not find load file: /home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/share/llvm/cmake/LLVMExports.cmake Call Stack (most recent call first): CMakeLists.txt:14 (find_package) CMake Error at /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake/LLVMConfig.cmake:53 (include): include could not find load file: /home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/share/llvm/cmake/LLVM-Config.cmake Call Stack (most recent call first): CMakeLists.txt:14 (find_package) 

So, Cmake seems to find the Cmake LLVM file, but Cmake complains about some path starting with /home/ben/ .

In fact, it looks like the LLVM LLVMConfig.cmake file has some absolute paths in it that are not relevant to my machine. For instance:

 [ dev@beauty :~/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu ] $ head ./share/llvm/cmake/LLVMConfig.cmake # This file provides information and services to the final user. set(LLVM_INSTALL_PREFIX "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install") set(LLVM_VERSION_MAJOR 3) set(LLVM_VERSION_MINOR 5) set(LLVM_VERSION_PATCH 0) set(LLVM_PACKAGE_VERSION 3.5.0) set(LLVM_COMMON_DEPENDS ) 

Who is ben and what is he doing in this file? He appears in several more places:

 [ dev@beauty :~/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu ] $ grep ben ./share/llvm/cmake/LLVMConfig.cmake set(LLVM_INSTALL_PREFIX "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install") set(LLVM_INCLUDE_DIRS "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/include") set(LLVM_LIBRARY_DIRS "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/lib") set(LLVM_CMAKE_DIR "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/share/llvm/cmake") set(LLVM_TOOLS_BINARY_DIR "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/bin") 

Needless to say, these paths do not exist on my machine. I'm confused why these files have these paths? Do I have to run a tool or something to change these paths for my machine? Or do I need to change them manually?

EDIT . Out of curiosity, I manually changed all these paths to point to the paths on my machine:

 [ dev@beauty :~/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake ] $ sed -i -e's/.home.ben.development.llvm.3.5.final.Phase3.Release.llvmCore-3.5.0-final.install/\/home\/dev\/Downloads\/clang+llvm-3.5.0-x86_64-linux-gnu/g' * 

After that, Cmake no longer complained, and my build continued.

I would still like to know why I need this.

+6
source share
1 answer

Sounds like an LLVM error. Remember to enter it: http://llvm.org/bugs

+2
source

Source: https://habr.com/ru/post/976116/


All Articles