我在我的C ++项目中使用LLVM / Clang。我可以使用Makefile构建并运行一切。
我现在正试图搬到Cmake而且我无法让事情发挥作用。让我解释一下我所做的事情。
我遵循本教程:
http://llvm.org/docs/CMake.html#embedding
该网页的相关摘录如下:
从LLVM 3.5开始,构建CMake和autoconf / Makefile 系统将LLVM库导出为可导入的CMake目标。
大!我将下载LLVM 3.5,我应该很高兴。我去了下载页面:
http://llvm.org/releases/download.html
并为Ubuntu 14.04 Linux下载了Clang的预构建二进制文件。
然后,我将以下内容添加到我的CMakeLists.txt
文件中:
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)
(这与教程相同,但我设置了LLVM_DIR
,因为它目前位于非标准位置。)
当我运行cmake
时,我收到以下错误:
[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)
所以Cmake似乎正在寻找LLVM的Cmake文件,但是Cmake抱怨从/home/ben/
开始的一些路径。
实际上,似乎LLVM的LLVMConfig.cmake
文件中有一些与我的机器无关的绝对路径。例如:
[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 )
他ben
以及他在这个文件中做了什么?他出现在几个地方:
[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")
毋庸置疑,我的机器上不存在这些路径。我很困惑为什么这些文件中包含这些路径?我应该运行一个工具或什么来改变我的机器的这些路径?或者我是否需要手动更改它们?
编辑:出于好奇,我手动将所有这些路径更改为指向我机器上的路径:
[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' *
在那之后,Cmake不再抱怨,我的构建继续进行。
我仍然想知道为什么我需要这样做。