Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building LLVM example

Tags:

llvm

cmake

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

like image 469
Artem Pelenitsyn Avatar asked Aug 13 '12 11:08

Artem Pelenitsyn


People also ask

How long does it take to build LLVM?

For smaller changes, building LLVM from ccache and compiling the benchmarks takes about 20 minutes. This is too slow to test every single commit, but we don't really need to do that, as long as we automatically bisect any ranges with significant changes.

Why is LLVM so big?

A full build of LLVM and Clang will need around 15-20 GB of disk space. The exact space requirements will vary by system. (It is so large because of all the debugging information and the fact that the libraries are statically linked into multiple tools).


2 Answers

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)
like image 177
Artem Pelenitsyn Avatar answered Oct 05 '22 09:10

Artem Pelenitsyn


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)
like image 42
JaeIL Ryu Avatar answered Oct 05 '22 11:10

JaeIL Ryu