crossbuild cmake tutorial for Linux, Mac and Windows

355 Views Asked by At

CMake has a tutorial here:

https://github.com/Kitware/CMake/tree/master/Help/guide/tutorial/Complete

I would like to crossbuild it for Linux, Mac and Windows using:

https://github.com/multiarch/crossbuild

Crossbuild provides a docker image for ease-of-use:

https://hub.docker.com/r/multiarch/crossbuild

I've made a fork using Debian bullseye instead of stretch:

https://hub.docker.com/r/kmturley/crossbuild

I downloaded the files and placed in a /src folder:

https://github.com/kmturley/cmake-multiarch-docker/tree/feature/crossbuild-new

I then created a docker-compose file containing:

version: '3'
services:

  linux:
    image: kmturley/crossbuild
    environment:
      CROSS_TRIPLE: x86_64-linux-gnu
    working_dir: /app
    command: >
      sh -c "cmake -DUSE_MYMATH=0 -S ./src -B ./build/linux &&
             cmake --build ./build/linux &&
            file ./build/linux/Tutorial"
    volumes:
      - ./src:/app/src
      - ./build:/app/build

  mac:
    image: kmturley/crossbuild
    environment:
      CROSS_TRIPLE: x86_64-apple-darwin
    working_dir: /app
    command: >
      sh -c "cmake -DUSE_MYMATH=0 -S ./src -B ./build/mac &&
             cmake --build ./build/mac &&
            file ./build/mac/Tutorial"
    volumes:
      - ./src:/app/src
      - ./build:/app/build

  win:
    image: kmturley/crossbuild
    environment:
      CROSS_TRIPLE: x86_64-w64-mingw32
    working_dir: /app
    command: >
      sh -c "cmake -DUSE_MYMATH=0 -S ./src -B ./build/win &&
             cmake --build ./build/win &&
            file ./build/win/Tutorial.exe"
    volumes:
      - ./src:/app/src
      - ./build:/app/build

When running docker-compose up it successfully generates Linux and Windows binaries. However Mac binary is not generated:

./build/linux/Tutorial: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=8ead361bd8494da68a47a4307cff733791777689, for GNU/Linux 3.2.0, not stripped

./build/mac/Tutorial: cannot open `./build/mac/Tutorial' (No such file or directory)

./build/win/Tutorial.exe: PE32+ executable (console) x86-64, for MS Windows

CMakeOutput.log file for each Docker image:

There doesn't appear to be any error shown, it fails silently even when using cmake --debug-output.

Why is the Mac Tutorial binary not generated?

0

There are 0 best solutions below