A cross-compiling toolchain exists, but Apple's SDK terms of service states:
You agree not to rent, lease, lend, upload to or host on any website or server, sell, redistribute, or sublicense the Apple Software and Apple Services, in whole or in part, or to enable others to do so.
and
You are expressly prohibited from separately using the Apple SDKs or attempting to run any part of the Apple Software on non-Apple-branded hardware.
In [1]:
# Clean up previous runs
cd example
rm -f dockcross-*
rm -rf build
mkdir build
cd ..
In [2]:
cd example
find .
In [3]:
docker run --rm dockcross/windows-x64 > dockcross-windows-x64
chmod +x ./dockcross-windows-x64
docker run --rm dockcross/windows-x86 > dockcross-windows-x86
chmod +x ./dockcross-windows-x86
docker run --rm dockcross/linux-arm64 > dockcross-linux-arm64
chmod +x ./dockcross-linux-arm64
In [4]:
docker pull dockcross/windows-x64
docker run --rm dockcross/windows-x64 > dockcross-windows-x64
chmod +x ./dockcross-windows-x64
In [5]:
./dockcross-windows-x64 cmake -Hsrc -Bbuild -GNinja
./dockcross-windows-x64 ninja -Cbuild
CMake has a try_compile command to perform compiler-based platform introspection. It learns about the system by trying to compile a small source file.
# The CheckTypeSize CMake module uses the
# try_compile command internally
include(CheckTypeSize)
check_type_size("long" IntrospectionDemo_SIZEOF_LONG)
configure_file(IntrospectionDemoConfigure.h.in
IntrospectionDemoConfigure.h)
In [6]:
rm -rf build/*
./dockcross-windows-x86 cmake -Hsrc -Bbuild -GNinja | tail -n 6
In [7]:
grep SIZEOF_LONG ./build/IntrospectionDemoConfigure.h
In [8]:
rm -rf build/*
./dockcross-linux-arm64 cmake -Hsrc -Bbuild -GNinja | tail -n 6
In [9]:
grep SIZEOF_LONG ./build/IntrospectionDemoConfigure.h
CMake also has a try_run command to perform command execution-based platform introspection. It learns about the system by trying to run a small source file. An emulator can be used to automatically generate this information when cross-compiling.
To determine if there is an 80 bit or 64 bit floating point stack
set(_test_source "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/double-correction-needed.cc")
file(WRITE ${_test_source} "
#include <stdio.h>
int main(int, char **)
{
const double correct = 89255.0/1e22;
printf(\"89255.0/1e22 = %g\", correct);
if( correct != 89255e-22 )
{
// correction required
return 0;
}
return 1;
}")
try_run(IntrospectionDemo_DOUBLE_CORRECTION_NEEDED
DOUBLE_CORRECT_NEEDED_COMPILED
${CMAKE_CURRENT_BINARY_DIR} ${_test_source}
RUN_OUTPUT_VARIABLE _double_correction_out)
message(STATUS "Double correction test returned: ${_double_correction_out}")
In [10]:
rm -rf build/*
./dockcross-linux-arm64 cmake -Hsrc -Bbuild -GNinja | tail -n 4
In [11]:
./dockcross-linux-arm64 ninja -Cbuild
In [12]:
./dockcross-linux-arm64 bash -c 'cd build && ctest -V'