Files
negative-converter/cmake/toolchain-mingw64.cmake
Christoph K. 54efb58c65 feat: add MinGW-w64 cross-compilation toolchain and CPack packaging
- CMakeLists.txt: adds AppConfig to converter_core sources, LibRaw fallback
  find_library for MinGW, CPack config for NSIS+ZIP (Windows) and TGZ+DEB
  (Linux), install rules for binary and example config
- cmake/toolchain-mingw64.cmake: x86_64-w64-mingw32 toolchain, static
  libgcc/libstdc++ linking, optional vcpkg x64-mingw-static triplet

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-14 09:41:33 +01:00

58 lines
3.0 KiB
CMake

# cmake/toolchain-mingw64.cmake
#
# MinGW-w64 cross-compilation toolchain for Linux → Windows builds.
#
# Usage:
# cmake -B build-win -G Ninja \
# -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-mingw64.cmake \
# -DCMAKE_BUILD_TYPE=Release
#
# Prerequisites (Ubuntu/Debian):
# sudo apt install mingw-w64
#
# After building, collect runtime DLLs with scripts/build-windows.sh.
# ── Target system ────────────────────────────────────────────────────────────
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_VERSION 10)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
# ── Compilers ────────────────────────────────────────────────────────────────
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
# ── Linker / archiver ────────────────────────────────────────────────────────
set(CMAKE_AR x86_64-w64-mingw32-ar)
set(CMAKE_RANLIB x86_64-w64-mingw32-ranlib)
set(CMAKE_STRIP x86_64-w64-mingw32-strip)
# ── Sysroot search paths ─────────────────────────────────────────────────────
# Allow CMake find_* commands to search the MinGW sysroot.
set(CMAKE_FIND_ROOT_PATH
/usr/x86_64-w64-mingw32
)
# Headers and libraries from the sysroot only; programmes (host tools) from host.
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
# ── Static linking ───────────────────────────────────────────────────────────
# Link the MinGW C++ and GCC runtime libraries statically so the produced
# .exe does not depend on MinGW DLLs on the target machine.
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static-libgcc -static-libstdc++")
# ── Executable suffix ─────────────────────────────────────────────────────────
set(CMAKE_EXECUTABLE_SUFFIX ".exe")
# ── vcpkg triplet (optional) ─────────────────────────────────────────────────
# If you are using vcpkg for Windows dependencies, set:
# -DVCPKG_TARGET_TRIPLET=x64-mingw-static
# and point VCPKG_ROOT to your vcpkg installation.
if(DEFINED ENV{VCPKG_ROOT})
set(VCPKG_TARGET_TRIPLET "x64-mingw-static" CACHE STRING "vcpkg triplet")
include("$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
endif()