Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use LLVM in a cmake build

Tags:

llvm

cmake

I'm trying to build my own project that use LLVM. I downloaded the source code and the precompiled package on the official web site (last version).

http://releases.llvm.org/download.html

I downloaded :

LLVM source code
Clang for Windows (64-bit)

FYI, I don't build LLVM... only want to use it !

I followed the instruction here : http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project

in the section : "Embedding LLVM in your project"

So, I added this code :

find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message("LLVM_INCLUDE_DIRS=${LLVM_INCLUDE_DIRS}")
message("LLVM_DEFINITIONS=${LLVM_DEFINITIONS}")

But I got several cmake error messages, here is my output :

-- Using LLVMConfig.cmake in: C:\\Luciad_src\\libs\\LLVM\\cmake\\modules
LLVM_INCLUDE_DIRS=
LLVM_DEFINITIONS=
CMake Error at C:/Luciad_src/libs/LLVM/cmake/modules/LLVM-Config.cmake:31 (list):
  list sub-command REMOVE_ITEM requires two or more arguments.
Call Stack (most recent call first):
  C:/Luciad_src/libs/LLVM/cmake/modules/LLVM-Config.cmake:256 (is_llvm_target_library)
  components/query/CMakeLists.txt:15 (llvm_map_components_to_libnames)

Is there a problem with my script, or the packages I use ? Any idea ?

Thanks for your help

like image 531
CDZ Avatar asked Feb 23 '18 12:02

CDZ


People also ask

Is LLVM better than GCC?

While LLVM and GCC both support a wide variety languages and libraries, they are licensed and developed differently. LLVM libraries are licensed more liberally and GCC has more restrictions for its reuse. When it comes to performance differences, GCC has been considered superior in the past.

Why is LLVM so big?

An LLVM-only build will need about 1-3 GB of space. 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).

Does Rust use LLVM?

Tradeoff #4: LLVM and poor LLVM IR generationrustc uses LLVM to generate code. LLVM can generate very fast code, but it comes at a cost. LLVM is a very big system. In fact, LLVM code makes up the majority of the Rust codebase.

Is LLVM made by Apple?

LLVM was released under the University of Illinois/NCSA Open Source License, a permissive free software licence. In 2005, Apple Inc. hired Lattner and formed a team to work on the LLVM system for various uses within Apple's development systems.


1 Answers

You can have the LLVM as binary or source package.

The binary package does not include CMake support. If you compare both installations (binary on the left, source after building and installing it on the right) you can see the difference:

LLVM-5.0.0-win64.exe <=> llvm-5.0.1.src.tar.xz (build and installed)

enter image description here enter image description here

So you need to build and install the source package first to get CMake support. On my Windows machine I needed a cmd shell with administrator rights, a Visual Studio installation, go to the downloaded and extracted sources and do:

> mkdir mybuilddir
> cd mybuilddir
> cmake ..
> cmake --build . --config Release --target INSTALL

If I now use your CMake example I get:

-- Found LLVM 5.0.1
-- Using LLVMConfig.cmake in: C:/Program Files (x86)/LLVM/lib/cmake/llvm
LLVM_INCLUDE_DIRS=C:/Program Files (x86)/LLVM/include
LLVM_DEFINITIONS=-DLLVM_BUILD_GLOBAL_ISEL -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -DUNICODE -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Configuring done
like image 60
Florian Avatar answered Oct 02 '22 09:10

Florian