Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 1 | # Sample toolchain file for building for Windows from an Ubuntu Linux system. |
| 2 | # |
| 3 | # Typical usage: |
| 4 | # *) install cross compiler: `sudo apt-get install mingw-w64` |
| 5 | # *) cmake -H. -B_build_mingw -DCMAKE_TOOLCHAIN_FILE="${PWD}/toolchains/linux-mingw-w64.cmake" |
| 6 | |
| 7 | set(CMAKE_SYSTEM_NAME Windows) |
| 8 | set(CMAKE_SYSTEM_PROCESSOR x86_64) |
| 9 | set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) |
| 10 | |
| 11 | # set compiler |
| 12 | set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) |
| 13 | set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) |
| 14 | set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) |
| 15 | |
| 16 | # target environment on the build host system |
| 17 | # set 1st to dir with the cross compiler's C/C++ headers/libs |
| 18 | set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) |
| 19 | |
| 20 | # modify default behavior of FIND_XXX() commands to |
| 21 | # search for headers/libs in the target environment and |
| 22 | # search for programs in the build host environment |
| 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) |
| 24 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) |
| 25 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) |
| 26 | |
| 27 | # use emulator for `try_run` calls |
| 28 | set(CMAKE_CROSSCOMPILING_EMULATOR wine64) |
| 29 | |
| 30 | # set c++ standard |
| 31 | set(CMAKE_CXX_STANDARD 11) |
| 32 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 33 | set(CMAKE_CXX_EXTENSIONS ON) |