Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

mingw cross compilation from Linux to Windows #153

Closed
NeroBurner opened this issue Jun 21, 2017 · 9 comments
Closed

mingw cross compilation from Linux to Windows #153

NeroBurner opened this issue Jun 21, 2017 · 9 comments

Comments

@NeroBurner
Copy link

as mentioned over at hunter ruslo/hunter#846

I don't know where to put this file so I created this issue

contents of Toolchain-Ubuntu-mingw64.cmake

# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
#    *) install cross compiler: `sudo apt-get install mingw-w64 g++-mingw-w64`
#    *) cd build
#    *) cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-Ubuntu-mingw64.cmake ..

set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

# cross compilers to use for C and C++
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 1st to dir with the cross compiler's C/C++ headers/libs
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands to
# search for headers/libs in the target environment and
# search for programs in the build host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
@ruslo
Copy link
Owner

ruslo commented Jun 21, 2017

Looks similar to:

I guess you can start with:

To create linux-mingw64 toolchain.

@ruslo
Copy link
Owner

ruslo commented Jun 21, 2017

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

I think we don't need this if you're using Hunter. find_package should never return anything from system if Hunter used, see:

@NeroBurner
Copy link
Author

NeroBurner commented Jun 21, 2017

where should I set the windres variable needed for cross-compiling to windows

set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

Edit:
and more importantly, where is the following variable set?

set(CMAKE_SYSTEM_NAME Windows)

@ruslo
Copy link
Owner

ruslo commented Jun 21, 2017

set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

I think it will not hurt if we will add it to the compiler/gcc-cross-compile.cmake.

set(CMAKE_SYSTEM_NAME Windows)

In top linux-mingw64.

@NeroBurner
Copy link
Author

should we add emulator support?
https://cmake.org/cmake/help/v3.3/variable/CMAKE_CROSSCOMPILING_EMULATOR.html

with this we could run mingw-w64 cross compiled tests with wine64 or armhf targets with qemu

@ruslo
Copy link
Owner

ruslo commented Jun 22, 2017

should we add emulator support?

It will not hurt I guess. Is emulator a part of mingw-w64 package?

@NeroBurner
Copy link
Author

no, it would need an extra emulator installed. And for mingw that would be wine (to run windows binaries)

@ruslo
Copy link
Owner

ruslo commented Jun 22, 2017

no, it would need an extra emulator installed

In this case we can add CMAKE_CROSSCOMPILING_EMULATOR variable but only if it will not return error if emulator not found.

@ruslo
Copy link
Owner

ruslo commented Jan 7, 2018

Closing inactive discussion.

@ruslo ruslo closed this as completed Jan 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants