Installing selected subset of LLVM Tools with shared build

Hi all,

I have an application that requires a select subset of LLVM tools to be installed into a custom-built sysroot. Until recently, I’ve been building LLVM statically and everything seemed fine, but recently, due to disk space limits, I have decided to give shared build a try.

The problem I encountered, however, is that when I ask ninja to only build and install a specific component, its dependencies are being built, but not installed. In particular:

cmake $sources_path/llvm
-G Ninja
-DBUILD_SHARED_LIBS=On
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=$target_path
-DLLVM_ENABLE_ASSERTIONS=On
-DLLVM_TARGETS_TO_BUILD=X86

cmake --build $build_dir --target llvm-ar

cmake --build $build_dir --target install-llvm-ar

This compiles all the required shared libraries, but installs only the llvm-ar executable, which causes:

$target_path/bin/llvm-ar --version
build-env/sysroot/bin/llvm-ar: error while loading shared libraries: libLLVMX86CodeGen.so.5: cannot open shared object file: No such file or directory

Is there a way to force the existing build system to also install dependencies, when using install-$tool target? AFAIK, plain install builds and installs everything, which would require a manual search through the output directory in order to clean up the unneeded tools.

Alternatively, is there an easy way to list the targets required by a specific component in such a way, a proper collection of install targets can be invoked later?

Cheers,
Marcin