Skip to content

Instantly share code, notes, and snippets.

@bolry
Created June 23, 2024 21:42
Show Gist options
  • Save bolry/42120a4048680119a7ee562a605e600c to your computer and use it in GitHub Desktop.
Save bolry/42120a4048680119a7ee562a605e600c to your computer and use it in GitHub Desktop.
CMake toolchain files for building Windows applications on Linux
# windows32-toolchain.cmake
# Specify the cross-compilation target system
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86)
# Specify the cross-compilation toolchain
set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
# Specify the target environment (optional)
set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32)
# Search for programs in the host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# For libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# Set the path for the linker
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
# windows64-toolchain.cmake
# Specify the cross-compilation target system
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
# Specify the cross-compilation toolchain
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
# Specify the target environment (optional)
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
# Search for programs in the host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# For libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# Set the path for the linker
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment