8

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

CDZ
  • 813
  • 1
  • 11
  • 27
  • Your CMake version is verified to be 3.4.3 or later? (As that's what the instructions you linked assume, in `cmake_minimum_required()`....) – DevSolar Feb 23 '18 at 14:48
  • @DevSolar Yes, I use cmake 3.10.2 ! Thanks – CDZ Feb 23 '18 at 15:01
  • Something strange is that I have search for the LLVM_INCLUDE_DIRS in all the files, and it is nowhere !!!! Is it possible that I downloaded the wrong package ? BTW, I also tried to compile other LLVM samples projects, same issue :-( – CDZ Feb 23 '18 at 15:34

1 Answers1

6

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
Florian
  • 39,996
  • 9
  • 133
  • 149
  • 1
    I don't think this is quite right (but very close, and helped me regardless). Perhaps the OP just needs to download and install the development versions of llvm in addition. For example, the llvm-toolset-*-llvm-devel package contains cmake info, likely to be required for his sub project to properly build. – Aaron B. Oct 20 '20 at 21:32
  • That's very nice from LLVM developer not to include cmake files into prebuilt version. And nevertheless during build LLVM wants llvm-config.cmake... very production ready. – mblw Dec 21 '22 at 07:35