mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-10 20:07:37 +00:00
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.
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user