Skip to content

Cross compilation

Daijiro Fukuda edited this page Dec 16, 2022 · 2 revisions

Cross-compilation with CMake and MinGW

The way to build and run Windows-exe from Ubuntu using external GLFW is as follows.

Refer to https://www.glfw.org/docs/3.3/compile.html#compile_mingw_cross

  1. Prepare tools

Install mingw-w64 and wine.

$ sudo apt install mingw-w64 wine

Clone freetype binaries: https://github.com/ubawurinna/freetype-windows-binaries

$ git clone https://github.com/ubawurinna/freetype-windows-binaries.git
  1. Build the forked GLFW in which we are developing IME support: https://github.com/clear-code/glfw/tree/3.4-2022-09-21+im-support-all
    • Specify CMAKE_TOOLCHAIN_FILE as follows for cross-build
$ git clone --branch=3.4-2022-09-21+im-support-all https://github.com/clear-code/glfw.git
$ cd glfw
$ cmake -B build \
  -DCMAKE_INSTALL_PREFIX=bin \
  -DCMAKE_TOOLCHAIN_FILE=CMake/x86_64-w64-mingw32.cmake
$ make -C build -j$(nproc) install
  1. Build the forked raylib in which we are developing IME support: https://github.com/clear-code/raylib/tree/4.2-2022-12-14+better-ime-support-all
    • Set USE_EXTERNAL_GLFW ON
    • Specify the path of x86_64-w64-mingw32.cmake to CMAKE_TOOLCHAIN_FILE
      • We can use the file in GLFW repo (the same file as step-2)
      • Ex: /test/glfw/CMake/x86_64-w64-mingw32.cmake
    • Specify the path of GLFW built in step-2 to CMAKE_PREFIX_PATH
      • Ex: -DCMAKE_PREFIX_PATH=/test/glfw/bin
$ git clone --branch=4.2-2022-12-14+better-ime-support-all https://github.com/clear-code/raylib.git
$ cd raylib
$ cmake -B build \
  -DCMAKE_INSTALL_PREFIX=bin \
  -DUSE_EXTERNAL_GLFW=ON \
  -DCMAKE_TOOLCHAIN_FILE="{path of GLFW repo}/CMake/x86_64-w64-mingw32.cmake" \
  -DCMAKE_PREFIX_PATH="{path of GLFW built in step-2}"
$ make -C build -j$(nproc) install
  1. Build and run this app
    • Set USE_EXTERNAL_GLFW ON
    • Set USE_SOFT_FULLSCREEN ON
    • Specify the path of x86_64-w64-mingw32.cmake to CMAKE_TOOLCHAIN_FILE
      • We can use the file in GLFW repo (the same file as step-2)
      • Ex: /test/glfw/CMake/x86_64-w64-mingw32.cmake
    • Specify the path of freetype to FREETYPE
      • Ex: -DFREETYPE="/test/freetype-windows-binaries"
    • Specify the path of GLFW built in step-2 to GLFW
      • Ex: -DGLFW="/test/glfw/bin"
    • Specify the path of raylib built in step-3 to RAYLIB
      • Ex: -DRAYLIB="/test/raylib/bin"
    • Use wine to run the exe
$ cmake -B build \
  -DCMAKE_INSTALL_PREFIX=bin \
  -DUSE_EXTERNAL_GLFW=ON \
  -DUSE_SOFT_FULLSCREEN=ON \
  -DCMAKE_TOOLCHAIN_FILE="{path of GLFW repo}/CMake/x86_64-w64-mingw32.cmake" \
  -DFREETYPE="{path of freetype windows binaries}" \
  -DGLFW="{path of GLFW built in step-2}" \
  -DRAYLIB="{path of raylib built in step-3}"
$ make -C build -j$(nproc) install
$ wine bin/RaylibIMEInputSampleApp.exe
Clone this wiki locally