discord / gamesdk-and-dispatch

Public issue tracker for the Discord Game SDK and Dispatch
22 stars 7 forks source link

Use of uppercase `Windows.h` breaks mingw #100

Open oznogon opened 3 years ago

oznogon commented 3 years ago

Describe the bug

When cross-compiling a project implementing the Game SDK on case-sensitive filesystems with mingw, compilation for Windows targets can fail because Windows is capitalized in #include <Windows.h>.

Steps to reproduce

Build any project that includes the Discord Game SDK (#include <discord_game_sdk.h>) with a Windows build target using mingw on a case-sensitive filesystem. For example, this is reproducible when cross-compiling a project using Ubuntu 18.04, 20.04, and Debian 10.5, including builds from WSL.

Expected behavior

Cross-compiling for Windows works without errors.

Observed behavior

A fatal compiler error terminates compilation because the case-sensitive Windows.h doesn't exist:

.../_build_win32/discord/c/discord_game_sdk.h:5:10: fatal error: Windows.h: No such file or directory
 #include <Windows.h>
          ^~~~~~~~~~~
compilation terminated.

Screenshots

N/A

Implementation specifics

Additional context

Workarounds:

In line 5 of c/discord_game_sdk.h in the Game SDK, lowercase Windows.h.

#ifndef _DISCORD_GAME_SDK_H_
#define _DISCORD_GAME_SDK_H_

#ifdef _WIN32
- #include <Windows.h>
+ #include <windows.h>

OR add conditional defines to discord_game_sdk.h to use the lowercase filename, depending on your project:

#ifndef _DISCORD_GAME_SDK_H_
#define _DISCORD_GAME_SDK_H_

- #ifdef _WIN32
+ #if defined(__MINGW32__) || defined(__MINGW64__)
+ #include <windows.h>
+ #else
#include <Windows.h>
+ #endif

For an automated build process, hack through it with a regex (s/Windows\.h/windows\.h/).

OR, on the build system, symlink mingw's Windows.h to windows.h. Implementation can vary between operating systems and distributions.

OR, create a Windows.h in the project that does nothing but include windows.h.

OR, conditionally omit Discord integration from the project when cross-compiling Windows builds. :(

Context: https://stackoverflow.com/questions/15466613/lowercase-windows-h-and-uppercase-windows-h-difference

See also:

oznogon commented 3 years ago

Project gave up on an upstream fix. For anyone who comes across this, here's what was added to CMake as a workaround.

    if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
      execute_process(COMMAND sed -i -e s/Windows.h/windows.h/ "${CMAKE_CURRENT_BINARY_DIR}/discord/c/discord_game_sdk.h")
    endif()