3

I recently built and installed llvm to my system with the expectation that this would be what is neccessary to build qtcreator: https://paste.ubuntu.com/p/23GCCS5xxS/

Based on what I saw there, I set the variable as such:

➜  qt6.2 git:(6.2) ✗ echo $LLVM_INSTALL_DIR

/usr/local/lib/cmake/llvm/

However when configuring Qt6.2, it still gives

WARNING: QDoc will not be compiled, probably because libclang could not be located. This means that you cannot build the Qt documentation.
Either set CMAKE_PREFIX_PATH or LLVM_INSTALL_DIR to the location of your llvm installation.

And from what I understand, when I built llvm, I didn't build Clang with it. Based on https://clang.llvm.org/get_started.html it gives the following line:

cmake -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm
make
#This builds both LLVM and Clang for debug mode.

Which is frustrating because I now have to build it again, which takes forever. I'd just like the command that builds and installs everything from llvm, so I don't have to keep going back to these things. Is that possible?

Anon
  • 2,267
  • 3
  • 34
  • 51

2 Answers2

7

To build everything, do this:

$ git clone --depth 1 --branch llvmorg-12.0.1 https://github.com/llvm/llvm-project.git
$ cmake -S llvm-project/llvm -B llvm-project/build \
        -DCMAKE_BUILD_TYPE=Release \
        -DLLVM_ENABLE_PROJECTS=all \
        -DCMAKE_CXX_COMPILER=clang++ \
        -DCMAKE_C_COMPILER=clang
$ cmake --build llvm-project/build -j8
$ cmake --install llvm-project/build --prefix /usr/local  # or somewhere else

You might also be interested in the following build flags for the first CMake command:

  • -DLLVM_ENABLE_TERMINFO=OFF -- removes dependency on terminfo
  • -DLLVM_ENABLE_ASSERTIONS=ON -- good for debugging
  • -DLLVM_ENABLE_EH=ON -- enable if your application uses C++ exceptions
  • -DLLVM_ENABLE_RTTI=ON -- enable if your application uses C++ RTTI

Also see the upstream documentation: https://llvm.org/docs/CMake.html


Note that some of the LLVM projects can only be built with clang. I won't get into bootstrapping issues, but if the build fails, you can winnow down the list of projects from all to a subset of the following: clang, clang-tools-extra, compiler-rt, cross-project-tests, libc, libclc, libcxx, libcxxabi, libunwind, lld, lldb, openmp, parallel-libs, polly, pstl.

Alex Reinking
  • 16,724
  • 5
  • 52
  • 86
  • I'm trying to build by your example, and its giving me this error `/home/anon/Library/llvm-project/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp:9:10: fatal error: 'utils/LibcTableGenUtil/APIIndexer.h' file not found` which is basically exactly as it sounds. There is no subfolder in utils called HdrGen. – Anon Aug 12 '21 at 14:10
  • 1
    @Anon - are you still having that issue? I don't know whether you accepted my answer before you commented. For what it's worth, I did actually test my answer (Ubuntu 20.04, system Clang 10 compiler) and I did not encounter that issue. – Alex Reinking Aug 12 '21 at 21:57
  • Yeah I don't know what is going on. I am on a relatively fresh kubuntu 20.10 minimal install. I did accept before I was able to finish building, and just assumed it was valid. It probably is, its just that I have the worst luck when it comes to compiling software I'm going to try a fresh manjaro install and see if I can get it working there. – Anon Aug 13 '21 at 01:27
  • 1
    @Anon - in case it helps, I just (successfully) tried those same commands again and recorded the terminal output [here](https://hastebin.com/olesobaxax.txt). Differences in the output from the first CMake command might prove useful. – Alex Reinking Aug 13 '21 at 02:21
1

These are the steps I use taken from here:

mkdir llvm
cd llvm

git clone https://github.com/llvm/llvm-project.git .
git clone https://github.com/KhronosGroup/SPIRV-LLVM-Translator.git
git clone https://github.com/intel/opencl-clang.git
git clone https://github.com/KhronosGroup/SPIRV-Headers.git ./llvm/projects/SPIRV-Headers
git clone https://github.com/intel/vc-intrinsics.git ./llvm/projects/vc-intrinsics

mkdir build
cd build

cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=”X86″ -DLLVM_ENABLE_PROJECTS=”clang” -DLLVM_EXTERNAL_PROJECTS=”llvm-spirv;opencl-clang” -DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR=”../SPIRV-LLVM-Translator” -DLLVM_EXTERNAL_OPENCL_CLANG_SOURCE_DIR=”../opencl-clang” ../llvm

make opencl-clang
Gardinal
  • 74
  • 6