cmakeclangllvmlibc++

How to build only libc++ and not the rest of the llvm on version 19?


I have been trying to find CMake option to build libc++ only. In the past (LLVM 13.0.0) I was able to launch a Cmake command directly from the libcxx directory but from the more recent version, I seem to need to build it from the root of the llvm-project with the option -DLLVM_ENABLE_RUNTIMES="libcxx". This takes way longer (>3K build targets instead of the 300 I'm used to).

cmake -GNinja -DLLVM_PATH="${LLVM_FOLDER}/llvm" \
 -DCMAKE_BUILD_TYPE=Release \
 -DCMAKE_CXX_COMPILER="clang++" \
 -DCMAKE_C_COMPILER="clang" \
 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="${LLVM_FOLDER}/libcxxabi/include" \
 -DLIBCXX_CXX_ABI=libcxxabi \
 -DLIBCXX_CXX_ABI_LIBRARY_PATH="${BUILD_DIR}/lib" \
 -DLIBCXX_HAS_GCC_S_LIB=ON \
 -DLIBCXX_ENABLE_SHARED=ON \
 -DLIBCXX_ENABLE_FILESYSTEM=OFF \
 -DLLVM_ENABLE_RUNTIMES="libunwind;libcxxabi;libcxx" \
 -DLIBCXX_BUILD_BENCHMARKS_NATIVE_STDLIB=OFF \
 -DLLVM_THIRD_PARTY_DIR=. \
 -DLIBCXX_INCLUDE_BENCHMARKS=OFF \
 "${LLVM_FOLDER}/libcxx"

This return an error about a missing build target:

CMake Error at src/CMakeLists.txt:309 (add_dependencies):
  The dependency target "cxx" of target "cxxabi-test-depends" does not exist.

I face the same issue with libcxxabi.

Google only returns outdated documentation. Any help would be welcome!


Solution

  • For me the key was to set -S runtimes and it went down to around 1'000 targets which are quickly compiled.