[CMake] toolchain file - cross-compiling windows-amd64->windows-x86

Albrecht Schlosser AlbrechtS.fltk at online.de
Tue Sep 17 11:23:59 EDT 2019


On 9/17/19 2:17 PM Joao Pedro Abreu De Souza wrote:
> cl from visual studio 2017.
> 
> Em ter, 17 de set de 2019 03:26, Stéphane Ancelot 
> <sancelot at numalliance.com <mailto:sancelot at numalliance.com>> escreveu:
> 
>     Hi,
> 
>     That first depends on which compiler you will use ?
> 
>     Regards,
> 
>     S.Ancelot
> 
>     Le 16/09/2019 à 22:32, Joao Pedro Abreu De Souza a écrit :
>>     Hi guys. I am trying to generate,using cmake, a executable with
>>     target Windows 32 bits using Windows 64 bits, but cannot find a
>>     standard toolchain file (I find to Linux, to Android, but can't
>>     find to Windows 32 bits) to build. Do you know some repository of
>>     toolchain files that has Windows 32 bits from Windows 64 bits? Or
>>     maybe someone has a standard toolchain file to this type of thing.

Well, I don't have a toolchain file for your compiler, but maybe my 
toolchain file for cross compilation under Linux for Windows (64-bit) 
can help. You'll need to adjust compiler and paths...

$ cat mingw-w64_toolchain.cmake
# CMake Toolchain File for MinGW-w64 (64-bit) Cross Compilation

# the name of the target operating system
set(CMAKE_SYSTEM_NAME Windows)

# which tools to use
set(CMAKE_C_COMPILER   /usr/bin/x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER /usr/bin/x86_64-w64-mingw32-g++)

# here is where the target environment located
set(CMAKE_FIND_ROOT_PATH  /usr/x86_64-w64-mingw32)

# adjust the default behavior of the FIND_XXX() commands:

# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

set(CMAKE_INSTALL_PREFIX ${CMAKE_FIND_ROOT_PATH}/usr CACHE FILEPATH
    "install path prefix")

# initialize required linker flags
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static-libgcc -static-libstdc++")

# end of toolchain file

HTH. YMMV


More information about the CMake mailing list