How to build only the necessary components with MSVC

I configure LLVM build with this command

cd llvm-8.0.0.src & md buildsys-x64-MT & cd buildsys-x64-MT & cmake -G “Ninja” -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_CRT_RELEASE=MT -DLLVM_ENABLE_RTTI=1 -DLLVM_ENABLE_TERMINFO=OFF -DCMAKE_INSTALL_PREFIX=…/x64-MT …

The number of build objects grew with every major release to 1660 for LLVM 7 and 1761 for LLVM 8.

I only need the components requested here

https://gitlab.freedesktop.org/mesa/mesa/blob/master/scons/llvm.py#L103

After reading

https://llvm.org/devmtg/2015-04/slides/eurollvm-2015-build.pdf

and

https://llvm.org/docs/CMake.html

I found these options to be relevant: LLVM_DYLIB_COMPONENTS, LLVM_BUILD_LLVM_DYLIB, LLVM_LINK_LLVM_DYLIB, LLVM_BUILD_TOOLS and LLVM_INCLUDE_TOOLS. Unfortunately LLVM_DYLIB_COMPONENTS depends on LLVM_BUILD_LLVM_DYLIB which doesn’t support MSVC, I can turn off LLVM_BUILD_TOOLS and LLVM_INCLUDE_TOOLS if I figure out how to filter unneeded components as I would no longer need llvm-config anymore.

You don’t actually need to change your CMake configuration to reduce the number of components you build. Just don’t build the all target, instead build the components you need.

Alternatively you can set the CMake variable LLVM_DISTRIBUTION_COMPONENTS to the list of things you need, which will result in the generation of a distribution target which will build just those pieces.

-Chris

I kind of figured it out and scripted the targets picking solution myself but that ‘LLVM_DISTRIBUTION_COMPONENTS’ option is definitely better as it should work with both MsBuild and ninja. Too bad this isn’t in the docs though:

https://llvm.org/docs/CMake.html#llvm-specific-variables

You don’t actually need to change your CMake configuration to reduce the number of components you build. Just don’t build the all target, instead build the components you need.

Alternatively you can set the CMake variable LLVM_DISTRIBUTION_COMPONENTS to the list of things you need, which will result in the generation of a distribution target which will build just those pieces.

-Chris

Tested '‘LLVM_DISTRIBUTION_COMPONENTS’ and it doesn’t work as I expected so I am sticking to I found working for me. In case anyone is interested here is what I did:

https://github.com/pal1000/mesa-dist-win/blob/master/buildscript/modules/ninjallvmbuild.cmd