Integrating Clang with vcpkg

Integrating Clang with vcpkg

June 17, 2025

One major benefit of using a package manager like vcpkg is that it automatically builds all your dependencies with a compiler of your choice, as long as it knows about the compiler. In case of vcpkg, the finer details of this process are managed through a mechanism called triplets. Out of the box vcpkg ships with triplets for many different compilers and platforms. However, unfortunately there is no such triplet available for using clang on Windows.

Fortunately, though, there are two different repositories available that provide some inspiration for this. The first repository is somewhat active, but wraps clang-cl which is the clang based front-end for MSVC. The other repository is archived, but attempted to integrate with the LLVM provided clang compiler. And when I say “attempted” it turns out that works quite fine. The only downside of the provided scripts there is that it hard-codes the path to the clang installation. But that is solved with CMake’s find_program() command. The only aspect to consider is that find_program() likely needs a hint, so it considers the LLVMInstallDir environment variable.

Even though we now have a working triplet, then vcpkg will not know about it out of the box. But it is possible to tell vcpkg where to find the triplet. Since we are using CMake then this is done by passing the VCPKG_OVERLAY_TRIPLETS when confinguring the build.

Now that the required triplet exists, it can simply be passed to vcpkg using the usual configuration options, for example VCPKG_HOST_TRIPLET and VCPKG_TARGET_TRIPLET when integrating vcpkg with CMake. However, it may not be able to find the compiler, even if you specified LLVMInstallDir correctly in your system environment. The reason for this is that vcpkg strips almost all environment variables before compiling requested dependencies. It does this to prevent the user from accidentally poisoning the vcpkg build environment with local machine settings. But there is a mechanism to forward environment variables. This is controlled by the environment variable VCPKG_KEEP_ENV_VARS, which in our case is simply specified to LLVMInstallDir

That’s quite a bit of configuration for the build system. Fortunately, CMake offers a feature called presets which can be leveraged to keep this simple. But that is for another post.