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" ../llvmmake#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?

2

Best Answer


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.

These are the steps I use taken from here:

mkdir llvmcd llvmgit clone https://github.com/llvm/llvm-project.git .git clone https://github.com/KhronosGroup/SPIRV-LLVM-Translator.gitgit clone https://github.com/intel/opencl-clang.gitgit clone https://github.com/KhronosGroup/SPIRV-Headers.git ./llvm/projects/SPIRV-Headersgit clone https://github.com/intel/vc-intrinsics.git ./llvm/projects/vc-intrinsicsmkdir buildcd buildcmake -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” ../llvmmake opencl-clang