Skip to content

Instantly share code, notes, and snippets.

@zepinto
Forked from peterspackman/mingw-w64-x86_64.cmake
Last active May 21, 2020 15:35
Show Gist options
  • Save zepinto/dbbe84fa4ca6e7f59954adabc5bc3dcc to your computer and use it in GitHub Desktop.
Save zepinto/dbbe84fa4ca6e7f59954adabc5bc3dcc to your computer and use it in GitHub Desktop.
cmake toolchain file for mingw-w64 x86_64 builds on Ubuntu
# Sample toolchain file for creating Windows installer.
#
# Typical usage:
# 1) install cross compiler and packager: `sudo apt-get install mingw-w64 nsis`
# 2) cd <path/to/build/folder>
# 3) cmake -DCMAKE_TOOLCHAIN_FILE=~/mingw-w64-x86_64.cmake <path/to/source/folder>
# 4) make -j<cores>
# 5) make package
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
# cross compilers to use for C, C++ and Fortran
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# perform static compilation
set(CMAKE_EXE_LINKER_FLAGS "-static" CACHE STRING "" FORCE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment