Sunbreak / BlankApp

A simple C++/WinRT UWP solution generated with custom version of CMake

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use CMake and C++/WinRT to build UWP Xaml apps

This small sample demonstrates some of the issues that currently exists when trying to leverage CMake to generate a UWP solution built with C++/WinRT. The sample is originally based on the C++/WinRT BlankApp sample and I've tried as much as possible to not change the source files. The existing BlankApp.sln can be opened in Visual Studio 2017 or Visual Studio 2019 and will build as is.

If you want to generate a pure CMake solution (either by overwriting the current project files or in a separate directory) here is the steps required.

  1. Install CMake and Python

  2. Clone this repo

git clone https://github.com/coderox/BlankApp.git

  1. Change into the cloned directory and update submodules

cd BlankApp

git submodule update --init

  1. Build a custom version of CMake There are a couple of issues with the current CMake releases that requires manual steps, or this minor update to CMake which fixes this by adding two features. The updated CMake doesn't modify the MIDL settings for the project, and it also makes the required sources files to be dependent on appropriate files. This requires us to build CMake with CMake as follows:

cd CMake

cmake .

cmake --build

cd ..

  1. Generate and build the solution with a python wrapper around the cmake commands, including some additional steps required to populate project file with C++/WinRT nuget package

mkdir output

cd output

python ../scripts/build.py BlankApp.vcxproj 1.0.190211.5

Why do I need a custom CMake?

There are two issues I haven't found a way to mitigate without a custom CMake version.

The first issue is that since we are adding .IDL files in the solution, CMake will automatically add a <MIDL>...</MIDL> element in the project file and the properties included in this section will break the C++/WinRT generation. This is now being handled in the CMakeLists.txt by specifying a property on the target called VS_CPPWINRT (which is set to true). Line 65 in CMakeLists.txt

The second issue is that C++/WinRT requires the header files to be dependent upon the appropriate .xaml files, otherwise the header files will not be #included in the XamlTypeInfo.g.cpp. Hence in CMakeLists.txt I add some properties to the .h-files through leveraging the OBJECT_DEPENDS . Line 63 and 64 in CMakeLists.txt

Other issues found

There is also a somewhat creative fix since we have to include the module.g.cpp in the solution but this file will be automatically generated by C++/WinRT. In the repo I have added a placeholder file and uses configure_file(<input> <output> COPYONLY) to make sure it is placed in the Generated Files folder, but still keeps these files out of version control. Lines 6 and 12 in CMakeLists.txt

About

A simple C++/WinRT UWP solution generated with custom version of CMake


Languages

Language:C++ 47.4%Language:Python 30.0%Language:CMake 18.6%Language:C 4.0%