Tuesday, September 8, 2020

CMake and C++/WinRT

    Not a long blog post this time as not a lot has happened in the beginning week of month 2, as I was still finishing up and incorporating feedback into my final draft of my research paper while also packing up and flying back to Florida. That being said, I was still given a task to complete.

The Problem    

    CMake is an open-source, cross-platform family of tools to build, test, and package software (CMake, n.d.). Because of CMake's cross-platform capabilities, it is used for the distribution of Gateware. That way, whatever platform an end-user is on, a project file is compiled and made correctly for them to use and develop on. My task for this week was to make a CMakeLists.txt, the file that CMake uses to set up the IDE project files, that will make a C++/WinRT project. The problem that made itself evident very quickly was the very little documentation available on how to do that task.

The Solution

    After many hours of scouring over the internet, I found a reply to a GitHub issue post that claimed to have done was I was searching for (Lindfors, 2017). They linked to a CMakeList.txt file that they had made, and it did appear to have everything that would be needed for a C++ UWP Visual Studios project. The only thing that appeared to be missing was the C++/WinRT NuGet package that is required to link to the WinRT APIs.

    Taking that post as inspiration and something to bounce off of, I made my own version of it using the code from the C++/WinRT Core Application template that Microsoft provides. This worked great, the only issue was that the NuGet package for C++/WinRT was not installed, just as I suspected. Because it wasn't installed the project did not compile, but it would once I manually installed the package from the NuGet Manager. While this worked, this creates more work for the end-user. The less work the end-user has to get their code running the better, so I set out to fix this issue. 

     This led me to finding out that NuGet has a restore feature built right into Visual Studios. All I needed to do was make sure to include a packages.config file in the Visual Studio solution that CMake compiles. That file lets Visual Studio know what NuGet packages are installed. It checks that file every time the end-user builds the solution and re-installs any missing packages if need be. Including that file let Visual Studios install the C++/WinRT NuGet package without doing so manually, therefore fixing that problem.

References

CMake. (n.d.). CMake. Retrieved September 8, 2020, from cmake.org

Lindfors, J. (2017). Leverage CMake to generate project using cppwinrt. Retrieved on September 2, 2020 from https://github.com/microsoft/cppwinrt/pull/126/files

No comments:

Post a Comment