From 9d8f1b1b5d124d9e26b4b20e61f2013eb38aa328 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Thu, 10 Sep 2026 15:22:09 -0500 Subject: [PATCH] build: pin the project to Win32 with a preset and a configure guard WoW.exe is x86, so there is no valid 64-bit configure. Nothing in the repo said so, which let VS Code decide instead: CMake Tools configures on folder open by default, and with no presets file it takes the architecture from a scanned kit. Here it chose the x86_amd64 cross kit (-T host=x86 -A x64) and flipped the shared build directory to x64. That failure is badly disguised. A 64-bit build first shows up as a static_assert deep in a struct-layout check, which reads as an unrelated code fault rather than a build-configuration one. Add CMakePresets.json with a single win32 configure preset. A presets file makes CMake Tools use presets and stop using kits, so the architecture becomes a property of the project instead of whichever kit a machine happens to select. The preset names no generator, matching the documented command line: CMake then resolves the newest installed Visual Studio, which a pinned version would get wrong. Schema version 3 is the earliest that allows omitting the generator. Add a CMAKE_SIZEOF_VOID_P guard after project() for whatever gets past the preset -- a hand-typed -A x64, or a stale cache -- so the configure fails with the recovery steps instead of building something unloadable. The existing `cmake -B build -A Win32` flow keeps working; presets are opt-in on the command line. --- CMakeLists.txt | 15 +++++++++++++++ CMakePresets.json | 25 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 CMakePresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 86307824..830adb8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,21 @@ cmake_minimum_required(VERSION 3.10) project(ClassicAPI LANGUAGES CXX RC) +# WoW.exe is x86, so the injected DLL must be x86 too — there is no valid +# 64-bit configure of this project. Fail here rather than let one through: +# a 64-bit build's first visible symptom is a static_assert deep in a +# struct-layout check, which reads as an unrelated code fault. An IDE that +# configures on its own (VS Code's CMake Tools picks an architecture from a +# scanned kit) can flip an existing build directory this way, which is what +# CMakePresets.json's `win32` preset exists to prevent. +if(NOT CMAKE_SIZEOF_VOID_P EQUAL 4) + message(FATAL_ERROR + "ClassicAPI builds 32-bit only. This configure uses " + "${CMAKE_SIZEOF_VOID_P}-byte pointers. Delete the build directory, " + "because CMake cannot switch platform in place. Then configure with " + "`cmake --preset win32` or `cmake -B build -A Win32`.") +endif() + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded") diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000..4d91d0b2 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,25 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 21, + "patch": 0 + }, + "configurePresets": [ + { + "name": "win32", + "displayName": "Win32 (x86)", + "description": "The only supported configuration: WoW.exe is 32-bit, so the DLL must be 32-bit too. No generator is named, so CMake picks the newest installed Visual Studio, matching the documented command line.", + "binaryDir": "${sourceDir}/build", + "architecture": "Win32" + } + ], + "buildPresets": [ + { + "name": "release", + "displayName": "Release", + "configurePreset": "win32", + "configuration": "Release" + } + ] +}