Creating reliable C++/WinRT builds with CMake?


I’ve been working on a project that’s half-using CMake at the moment - a ‘core’ library is built using CMake, and then include_external_msproject is used to include a Visual Studio project that builds a C++/WinRT library (winmd file + dll.)

This is proving difficult to make work across every developer’s device, difficult to retarget to new versions and different architectures, and especially difficult to automate, so we’d like to move toward a full CMake setup. Thing is, I can’t figure out how to set up a C++/WinRT project from CMake.

I’ve tried things along these lines to make a simple test command-line C++/WinRT program build:

cmake_minimum_required(VERSION 3.19)


add_executable(TEST main.cpp pch.h)

I’ve also tried adding NuGet package references, etc. (And of course modifying the environment / toolchain.) No matter what, upon running, it has issues finding dozens of DLLs.

Is there a good way to set up a C++/WinRT project (Command-line app + separate winmd library, ideally) with CMake?

I wouldn’t say that a test project is necessarily a good template, but the elements should be in CMake’s own Tests/VSWinStorePhone directory.

Oh, thank you! I’ll see if those are helpful. They don’t seem to make use of IDL definitions, though, so I’m not entirely sure if they’re the right kind of project (I’m a little fuzzy on differentiating C++/WinRT, C++/CX, and the UWP variations vs. regular .NET, etc…)

Those examples do not seem to actually build the right kind of project. When using the same options in a project, I receive errors such as:

Project "WrtTest" targets platform "Windows", but references SDK "Visual C++ 2015-2019 Runtime for Universal Windows Platform Apps v14.0" which targets platform "UAP"

Note that my target project is a modern C++/WinRT project involving .idl definition files, etc. - not the older C++/CX language which those examples appear to be using.