Use LLVM in a cmake build

2020-02-29 04:31发布

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

标签: cmake llvm
1条回答
做个烂人
2楼-- · 2020-02-29 04:41

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
查看更多
登录 后发表回答