1# 2# CMake Toolchain file for crosscompiling on 64bit Windows platforms. 3# 4# This can be used when running cmake in the following way: 5# cd build/ 6# cmake .. -DCMAKE_TOOLCHAIN_FILE=../contrib/cross-w64.cmake 7# 8 9# the outermost path to your cross toolchain 10#set(CROSS_PATH /opt/mingw64) 11set(CROSS_PATH /usr) 12# your cross root 13set(CROSS_ROOT ${CROSS_PATH}/x86_64-w64-mingw32/sys-root/) 14 15# Target operating system name. 16set(CMAKE_SYSTEM_NAME Windows) 17set(CMAKE_SYSROOT ${CROSS_ROOT}) 18 19# Name of C compiler. 20set(CMAKE_C_COMPILER "${CROSS_PATH}/bin/x86_64-w64-mingw32-gcc") 21set(CMAKE_CXX_COMPILER "${CROSS_PATH}/bin/x86_64-w64-mingw32-g++") 22set(CMAKE_RC_COMPILER "${CROSS_PATH}/bin/x86_64-w64-mingw32-windres") 23set(CMAKE_C_FLAGS "-Wno-error") 24 25# 26# Different build system distros set release optimization level to different 27# things according to their local policy, eg, Fedora is -O2 and Ubuntu is -O3 28# here. Actually the build system's local policy is completely unrelated to 29# our desire for cross-build release optimization policy for code built to run 30# on a completely different target than the build system itself. 31# 32# Since this goes last on the compiler commandline we have to override it to a 33# sane value for cross-build here. Notice some gcc versions enable broken 34# optimizations with -O3. 35# 36if (CMAKE_BUILD_TYPE MATCHES RELEASE OR CMAKE_BUILD_TYPE MATCHES Release OR CMAKE_BUILD_TYPE MATCHES release) 37 set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") 38 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2") 39endif() 40 41# Where to look for the target environment. (More paths can be added here) 42set(CMAKE_FIND_ROOT_PATH "${CROSS_ROOT}/mingw") 43 44# Adjust the default behavior of the FIND_XXX() commands: 45# search programs in the host environment only. 46set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 47 48# Search headers and libraries in the target environment only. 49set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 50set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 51