构建LLVM示例

时间:2012-08-13 11:33:55

标签: cmake llvm

我正在尝试从标准分发中构建一个示例,即BrainF并没有成功。

我制作了我的示例副本/ BrainF并试图从这个目录运行cmake。最初CMakeLists.txt看起来像这样:

set(LLVM_LINK_COMPONENTS jit bitwriter nativecodegen interpreter)

add_llvm_example(BrainF
  BrainF.cpp
  BrainFDriver.cpp
  )

cmake抱怨add_ *。我通读http://llvm.org/docs/CMake.html#embedding并决定在CMakeLists.txt中添加一些前奏:

find_package(LLVM)

# Define add_llvm_* macro's.
include(AddLLVM)

add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})

然后cmake抱怨它无法执行find_package(LLVM)并建议寻找LLVMConfig.cmake或llvm-config.cmake。我发现最接近/usr/src/llvm/cmake/modules/LLVM-Config.cmake的东西,所以我设置CMAKE_PREFIX_PATH=/usr/src/llvm/cmake/modules/并将软链接LLVMConfig.cmake设为LLVM-Config.cmake。

然后cmake以这种方式抱怨:“include无法找到加载文件:AddLLVM”。如果我将整个路径硬编码为包含AddLLVM.cmake,那么问题就在于包含AddLLVM.cmake中存在的内容,因此它似乎不是完成任务的正确方法。

我的环境是Xubuntu 12.04和llvm + clang 3.1(来自某些ppa的deb包,来自Debian的后端)。

2 个答案:

答案 0 :(得分:4)

这个帖子帮助我获得了AddLLVM:For the cmake "include" command, what is the difference between a file and a module?

此外,现在手动设置后我有问题:“llvm库列表中找不到”库`jit'“。错误全文:

$ cmake .
CMake Error at /usr/src/llvm/cmake/modules/LLVM-Config.cmake:141 (message):
  Library `jit' not found in list of llvm libraries.
Call Stack (most recent call first):
  /usr/src/llvm/cmake/modules/LLVM-Config.cmake:54 (explicit_map_components_to_libraries)
  /usr/src/llvm/cmake/modules/LLVM-Config.cmake:47 (explicit_llvm_config)
  /usr/src/llvm/cmake/modules/AddLLVM.cmake:86 (llvm_config)
  /usr/src/llvm/cmake/modules/AddLLVM.cmake:112 (add_llvm_executable)
  CMakeLists.txt:17 (add_llvm_example)

答案 1 :(得分:1)

在llvm 11.0上。

我尝试过,并且可以。

可能必须使用add_llvm_executable命令与LLVM_LINK_COMPONENTS链接

cmake_minimum_required(VERSION 3.4.3)

find_package(LLVM REQUIRED CONFIG)
project(BrainF)

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

include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(AddLLVM)

set(LLVM_LINK_COMPONENTS
  BitWriter
  Core
  ExecutionEngine
  MC
  MCJIT
  Support
  nativecodegen
  )

add_llvm_executable(BrainF
  BrainF.cpp
  BrainFDriver.cpp
  )

p.s。更新。 2020.11.1。

more info

cmake_minimum_required(VERSION 3.4.3)
project(BrainF)

find_package(LLVM 11 REQUIRED CONFIG)
add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})

message(STATUS "LLVM VERSION : ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

add_executable(BrainF
  BrainF.cpp
  BrainFDriver.cpp
)

llvm_map_components_to_libnames(llvm_libs support core irreader)

target_link_libraries(BrainF llvm_libs)