Monday, September 14, 2020

CMake and C++/WinRT Pt. 2

     Another slow week but not due to lack of work. I've been stuck in CMake again for the last week as it is very crucial to have it working correctly before we start porting Gateware over to UWP. Last week had me getting CMake to compile a C++/WinRT project in a Gateware test environment. While I was successful, it was not without it's faults.

The Problem:

    The first problem that became clear was that the library that Gateware uses for unit tests, Catch2, was not giving output for the tests it was running. UWP works fundamentally different from anything Gateware has seen. UWP is not able to launch windows dynamically from a console application like all current supported platforms of Gateware. This means that a console is not present, therefore no console output.

    This led to the discovery of another problem. The first thing that was done after discovering that there was no output was to run through the code of Catch2 to see where it was outputting the test data and see what alternatives were available. That is when it was discovered that I could not debug in this project. It was possible in other C++/WinRT projects that Visual Studio provided, but not in the one CMake made.

 The Solution:

    While the debugging problem was discovered 2nd, it was important to solve it first so that the output problem can be found and fixed. After many hours of Googling and going over Stack Overflow forums, it turned out to be a one line fix. It was one linker debug flag that needed to be set by CMake, DEBUG:FASTLINK. 

    With that out of the way I was able to dig into Catch2 to find where it was outputting the test information. I narrowed it down to an if statement checking a config data structure that is never set in the current implementation of our tests. By changing a string in that config structure to "%debug", it used used OutputDebugString() instead of cout. OutputDebugString() displays a string in the debug output window in Visual Studios. With the test session now using the config struct, it started outputting test output data to the debug output window for devs to read. This now allows us to know what libraries are going to need ported and which ones are going to work as is.

To Do:

    I am still currently trying to get the UWP unit tests and the Win32 unit tests in the same solution via CMake. This has proven to be very difficult as the current version of CMake does not support different target platforms in the same Visual Studios solution.

No comments:

Post a Comment