Use LLVM in a cmake build

时光总嘲笑我的痴心妄想 提交于 2019-12-01 06:30:53

问题


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


回答1:


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)

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


来源:https://stackoverflow.com/questions/48947973/use-llvm-in-a-cmake-build

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!