build(windows-runtime): fall back to mmsystem.h on older MinGW

platforms/posix/src/px4/windows/runtime/init.cpp pulls in timeBeginPeriod / timeEndPeriod via #include <timeapi.h>. The standalone <timeapi.h> header was split out of <mmsystem.h> in newer Windows SDKs and mingw-w64, but Ubuntu's stock mingw-w64-common 8.0.0-1 (the version Ubuntu 22.04/24.04 ship for x86_64-w64-mingw32) still keeps the prototypes inside <mmsystem.h> and does not provide a shim. Local cross-builds on those hosts fail at:

  platforms/posix/src/px4/windows/runtime/init.cpp:57:10:
  fatal error: timeapi.h: No such file or directory
     57 | #include <timeapi.h>

CI does not catch this because the GitHub Actions ubuntu-24.04 image carries a newer mingw-w64 that ships the split header.

Gate the include on __MINGW64_VERSION_MAJOR < 9 and fall back to <mmsystem.h> (which transitively pulls timeBeginPeriod/timeEndPeriod on older mingw), keeping the modern <timeapi.h> path on newer mingw and on MSVC/clang-cl. The else branch is unchanged on the toolchains that work today.

Verification: cross-build via CMAKE_ARGS="-DCMAKE_TOOLCHAIN_FILE=Toolchain-mingw-w64-x86_64" make px4_sitl_default succeeds on Ubuntu 24.04 with mingw-w64 8.0.0-1 and produces a PE32+ px4.exe; Wine boot of the resulting binary still raises the system timer resolution (no SIGSEGV at the timeBeginPeriod call site).
Signed-off-by: Nuno Marques <n.marques21@hotmail.com>
This commit is contained in:
Nuno Marques
2026-05-08 13:52:55 -07:00
parent 3bec843dfc
commit 5e9c93b1a8
@@ -54,7 +54,13 @@
// the default ~15.6 ms HPET tick, which throttles SITL sim time to
// ~40 % of wall time. Requesting 1 ms resolution drops the floor to
// the documented minimum.
// Older MinGW-w64 headers (<= 8.0) ship the prototypes via <mmsystem.h>
// instead of the split <timeapi.h> introduced in newer SDKs.
#if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR < 9)
#include <mmsystem.h>
#else
#include <timeapi.h>
#endif
// CREATE_WAITABLE_TIMER_HIGH_RESOLUTION (Windows 10 1803+, build 17134)
// may not be defined in older SDK headers. Mirror the literal values