Artem Pelenitsyn
Artem Pelenitsyn

Reputation: 2578

Building LLVM example

I'm trying to build one of examples from standard distribution, namely BrainF and haven't succeed.

I made my copy of examples/BrainF and trying to run cmake from this dir. Initially CMakeLists.txt looked like this:

set(LLVM_LINK_COMPONENTS jit bitwriter nativecodegen interpreter)

add_llvm_example(BrainF
  BrainF.cpp
  BrainFDriver.cpp
  )

cmake complained about add_*. I read through http://llvm.org/docs/CMake.html#embedding and decided to add some prelude to 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})

Then cmake complained about the fact that it could't perform find_package(LLVM) and suggested to look for LLVMConfig.cmake or llvm-config.cmake. The closest thing that I found laid under /usr/src/llvm/cmake/modules/LLVM-Config.cmake so I set CMAKE_PREFIX_PATH=/usr/src/llvm/cmake/modules/ and made soft link LLVMConfig.cmake to LLVM-Config.cmake.

Then cmake complained this way: “include could not find load file: AddLLVM”. If I hardcode the whole path to include AddLLVM.cmake the problem goes to includes which exist inside the AddLLVM.cmake so it doesn't seem like the right way to get things done.

My environment is Xubuntu 12.04 and llvm+clang 3.1 (got deb package from some ppa, backport from Debian).

Upvotes: 11

Views: 8953

Answers (2)

JaeIL Ryu
JaeIL Ryu

Reputation: 189

at llvm 11.0.

i tried to it, and it works.

maybe have to use add_llvm_executable command for linking with 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. update. 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)

Upvotes: 2

Artem Pelenitsyn
Artem Pelenitsyn

Reputation: 2578

This thread helped me to get AddLLVM: For the cmake "include" command, what is the difference between a file and a module?

Besides, now after manually setting I have problem: “Library `jit' not found in list of llvm libraries”. The full text of error:

$ 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)

Upvotes: 4

Related Questions