1

I'm currently building a compiler/interpreter in C/C++. When I noticed LLVM I thought it would fit greatly to what I needed and so I'm trying to integrate LLVM in my existing build system (I use CMake).

I read this bout integration of LLVM in CMake. I copy and pasted the example CMakeLists.txt, changed the LLVM_ROOT to ~/.llvm/ (that's where I downloaded and build LLVM and clang) and it says it isn't a valid LLVM-install. Best result I could achieve was the error message "Can't find LLVMConfig" by changing LLVM_ROOT to ~/.llvm/llvm.

My ~/.llvm/ folder looks like this:

~/.llvm/llvm         # this folder contains source files
~/.llvm/build        # this folder contains object, executable and library files

I downloaded LLVM and clang via SVN. I did not build it with CMake. Is it just me or is something wrong with the CMakeLists.txt?

bash0r
  • 605
  • 1
  • 7
  • 16
  • 2
    "t would fit greatly to what I needed" - it certainly would, but for that, you'll have to compile it first. And it's basically impossible. (To illustrate the situation: me too, I'm writing my own compiler. I decided to hand-write from scratch the lexer, the parser, the optimiser and the code generator, because doing all this is easier for me than trying to fix LLVM's broken build system.) –  Dec 17 '12 at 22:52
  • Lexer and parser are handwritten, but the JIT-compilation seems tasty. Isn't it something that's worth the work? – bash0r Dec 17 '12 at 22:54
  • it certainly is (basically because the principal role of LLVM is optimization), too bad they don't make the effort to use standard build tools (this is called the "We are Apple, we are eccentric-syndrome"). –  Dec 17 '12 at 22:56
  • What you get from LLVM is superb machine code generation with low-level optimizations. But that's also *all* you get - you have to generate correct LLVM IR yourself. If you want machine code, that's great, otherwise, there *may* be an easier way. @H2CO3 CMake and configure+make seem to be as standard as it gets. Or is this about the way they *use* these tools? –  Dec 17 '12 at 22:58
  • @H2CO3 Yeah but what should I do? Build another optimization framework? And I just don't want a language that sucks at runtime just because I was too lazy for it. ;) @ delnan Yes I want optimized JIT-compilation. I'd really like to have function pointers which I can map on events in a game or something like that. – bash0r Dec 17 '12 at 22:58
  • @delnan Yes, I meant the way... Cmake and configure build the LLVM build system, which is a mess, and then the LLVM build system would be supposed to do the actual build, but it's broken. –  Dec 17 '12 at 23:27
  • @bash0r I don't know, honestly. If you ever manage to create a sane, clean build of LLVM, let me know. –  Dec 17 '12 at 23:27
  • @H2CO3 Let's see if I can fix it myself. The last 2 days were full of failures... – bash0r Dec 18 '12 at 00:04
  • @H2CO3 Ok, I guess I fixed it. I changed the 'CMAKE_MODULE_PATH' from '/llvm/share/cmake/' to 'cmake/modules/' 'LLVMConfig' to 'LLVM-Config'. The CMake produces no errors, lets see if the examples build correctly. – bash0r Dec 18 '12 at 01:03

1 Answers1

1

This CMake documentation page got rotted, but setting up CMake for LLVM developing isn't different from any other project. If your headers/libs are installed into non-standard prefix, there is no way for CMake to guess it.

You need to set CMAKE_PREFIX_PATH to the LLVM installation prefix or CMAKE_MODULE_PATH to prefix/share/llvm/cmake to make it work.

And yes, use the second code snippet from documentation (under Alternativaly, you can utilize CMake’s find_package functionality. line).

arrowd
  • 33,231
  • 8
  • 79
  • 110
  • Thanks, that did what I wanted. My 'fix' had almost the same effect, but it was quiet messy. My only problem is that it does not find the library 'jit'. I can insert 'all' and 'native' without CMake-errors. Do I need to rebuild the libraries? I changed the folder from '~/.llvm/llvm' and '~/.llvm/build' to '~/.llvm' and '~/.llvm/build'. – bash0r Dec 18 '12 at 08:16
  • What's value of `LLVM_NATIVE_ARCH` in the CMake cache? – arrowd Dec 18 '12 at 09:42
  • Err, can I check it with 'message(FATAL_ERROR "${LLVM_NATIVE_ARCH}")'? – bash0r Dec 18 '12 at 09:46
  • You can use CMake GUI or just grep `builddir/CMakeCache.txt` file. – arrowd Dec 18 '12 at 09:48
  • The only LLVM-entry I could found via 'cat bin/CMakeCache.txt | grep LLVM' was this 'LLVM_DIR:PATH=/home/bash0r/.llvm/cmake/modules' – bash0r Dec 18 '12 at 10:02
  • Look into the file named `CMakeCache.txt` in the directory where you've configured you build. – arrowd Dec 18 '12 at 10:17
  • It contain's a lot of definitions about compiler specific things (ld-flags, c/cpp-flags, etc.). But there is no LLVM_NATIVE_ARCH. I found a LLVM_DIR. I googled LLVM_NATIVE_ARCH a few seconds ago and I got some results relating to 'config-ix.cmake'. 'config-ix.cmake' is in '~/.llvm/cmake/' but when I try to set 'CMAKE_PREFIX_PATH' to ~/.llvm/cmake/' then it fails. When I set it to '~/.llvm/cmake/modules/' it finds package LLVM but it can't map the libraries... – bash0r Dec 18 '12 at 10:22
  • Forget about llvm installation dir. I'm speaking about build dir of your project. – arrowd Dec 18 '12 at 10:23
  • Sorry for being a retard. :/ The CMakeCache.txt in it does NOT contain anything about LLVM but an 'LLVM_DIR'-entry. – bash0r Dec 18 '12 at 10:31
  • Oops, sorry, it's me who is retarted. This var is located in `LLVM installation dir/share/llvm/cmake/LLVMConfig.cmake`. – arrowd Dec 18 '12 at 10:41
  • Hmm, the `jit` component seem to be broken. I think, you can use `all` or `native` instead. But that's definitely a bug in the build system, which doesn't get much attention. – arrowd Dec 18 '12 at 10:50
  • Mhh kay, when it is broken for you too I just don't mind and use all instead. What H2CO3 about LLVM's build system is definitly true... So thank you all. : > – bash0r Dec 18 '12 at 11:11