We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5287 - Support building for UWP with CMake
Summary: Support building for UWP with CMake
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: build (show other bugs)
Version: HG 2.1
Hardware: x86 Windows 10
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-14 18:08 UTC by Jan Niklas Hasse
Modified: 2021-01-14 22:54 UTC (History)
1 user (show)

See Also:


Attachments
Adjust CMake files to support UWP (6.57 KB, patch)
2020-10-19 08:23 UTC, Jan Niklas Hasse
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Niklas Hasse 2020-09-14 18:08:49 UTC
Currently I'm using VisualC-WinRT/UWP_VS2015/SDL-UWP.sln. But I would like to use CMake for my game and integrate SDL using add_subdirectory.

Building for the UWP with CMake is possible in newer versions using:

cmake .. -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0

while generating a Visual Studio project this way works, there are compile errors in SDL_config.h. I think CMake needs to be taught to use SDL_config_winrt.h. In CMake UWP can be detected using if(WINDOWS_STORE).
Comment 1 Jan Niklas Hasse 2020-10-19 08:23:30 UTC
Created attachment 4481 [details]
Adjust CMake files to support UWP
Comment 2 Jan Niklas Hasse 2020-10-19 08:23:50 UTC
I've added CMake support using the SDL-UWP project as a blueprint. It compiles fine so far but fails with linker errors:

2>SDL.obj : error LNK2019: unresolved external symbol _exit referenced in function SDL_ExitProcess
2>SDL_winrtapp_common.obj : error LNK2019: unresolved external symbol "void __cdecl `eh vector destructor iterator'(void *,unsigned __int64,unsigned __int64,void (__cdecl*)(void *))" (??_M@YAXPEAX_K1P6AX0@Z@Z) referenced in function "public: void * __cdecl Microsoft::WRL::ComPtr<struct IUnknown>::`vector deleting destructor'(unsigned int)" (??_E?$ComPtr@UIUnknown@@@WRL@Microsoft@@QEAAPEAXI@Z)
2>SDL_winrtmouse.obj : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *,unsigned __int64)" (??3@YAXPEAX_K@Z)
...

This seems to be some sort of C runtime mismatch. I've found https://stackoverflow.com/questions/44826818/link-errors-when-trying-to-compile-against-an-old-std-library-and-windows-sdk so far.

Any ideas?
Comment 3 Sam Lantinga 2020-12-09 14:40:22 UTC
Can you try the latest SDL snapshot?
http://www.libsdl.org/tmp/SDL-2.0.zip

Thanks!
Comment 4 Jan Niklas Hasse 2020-12-22 21:06:00 UTC
I think you have https://github.com/microsoft/vcpkg/blob/master/ports/sdl2/enable-winrt-cmake.patch in mind? I'm getting the same kind of linker errors with it (target SDL2, not SDL2-static).
Comment 5 Jan Niklas Hasse 2021-01-13 17:24:51 UTC
Actually the SDL2-static target works, if I set SDL_SENSOR to OFF. Awesome!

See this patch: https://github.com/microsoft/vcpkg/blob/master/ports/sdl2/0003-sdl2-fix-uwp-build.patch
Comment 6 Sam Lantinga 2021-01-14 22:54:18 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL/rev/01a3c077ff1f