11

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

Artem Pelenitsyn
  • 2,508
  • 22
  • 38
  • `I made my copy of examples/BrainF and trying to run cmake from this dir.` Why did you do that? If you wish to set up project, that uses LLVM, see http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project – arrowd Aug 13 '12 at 17:46
  • “Why did you do that? If you wish to set up project” — I just try to build one of their example. And I don't want to do this inside system dirs (where I'll have to use sudo). The update discussed in my answer to the post below comes exactly from the page you pointed. I just didn't use explicitly llvm_map_components_to_libraries and left their set(LLVM_LINK_COMPONENTS …) and add_llvm_example(…) which (as error text suggests) use explicit_map_components_to_libraries which in turn do nearly the same, I guess. – Artem Pelenitsyn Aug 13 '12 at 20:25

2 Answers2

4

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)
Community
  • 1
  • 1
Artem Pelenitsyn
  • 2,508
  • 22
  • 38
2

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)
JaeIL Ryu
  • 159
  • 10