From 14b2e6dc6f8545740feb13a2ff1467cc3c3d579b Mon Sep 17 00:00:00 2001 From: maj00r Date: Thu, 10 Sep 2026 14:24:15 +0200 Subject: [PATCH] define WIN32 when not building with the MSVC driver Only Platform/Windows-MSVC.cmake passes /DWIN32; neither Windows-GNU nor the GNU branch of Windows-Clang does. Switching drivers silently took the macro away from every translation unit, and third-party code that tests the unprefixed WIN32 took its non-Windows path: FSR2 defined wcscpy_s as wcscpy, which then failed against the SDK's own three-argument call. asio reads the same macro. Defined before any add_subdirectory so every target sees it. --- CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21340ce2..49bc8170 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,15 @@ if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang|MSVC") "Build with Clang (CI uses 22) or MSVC.") endif() +# Only Platform/Windows-MSVC.cmake passes /DWIN32; the GNU-driver platform files +# do not. Plenty of third-party code tests the unprefixed WIN32 rather than +# _WIN32 - asio and AMD's FSR2 among it, the latter swapping in POSIX shims for +# wcscpy_s and _countof that then collide with the real CRT. Define it here, +# before any add_subdirectory, so every target sees what an MSVC build saw. +if (WIN32 AND NOT MSVC) + add_compile_definitions(WIN32) +endif() + #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=undefined") #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined -Wformat") #set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -fsanitize=address -fsanitize=undefined")