# mb2fix.dll - display fixes for the unboxed Magic Ball 2
# Must be built as a 32-bit DLL. With MSYS2, use the MINGW32 (or CLANG32) environment:
#   pacman -S mingw-w64-i686-gcc mingw-w64-i686-cmake mingw-w64-i686-ninja
cmake_minimum_required(VERSION 3.16)
project(mb2fix C)

if(NOT CMAKE_SIZEOF_VOID_P EQUAL 4)
  message(FATAL_ERROR "mb2fix must be built 32-bit (MSYS2 MINGW32 / CLANG32 shell, i686 toolchain).")
endif()

add_library(mb2fix SHARED mb2fix.c mb2fix.def)
set_target_properties(mb2fix PROPERTIES PREFIX "" OUTPUT_NAME "mb2fix")

# No C runtime at all: the DLL resolves everything it needs from kernel32/user32 at runtime.
target_compile_options(mb2fix PRIVATE -O2 -ffreestanding -fno-builtin -fno-stack-protector
  $<$<C_COMPILER_ID:GNU>:-fno-tree-loop-distribute-patterns>)   # stop GCC turning loops into memset calls
target_link_options(mb2fix PRIVATE -nostdlib -Wl,--entry,_DllMain@12
  $<$<C_COMPILER_ID:GNU>:-Wl,--enable-stdcall-fixup>)
