Claim by Java programmers.
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.
# Clean up previous runs
cd example
rm -f dockcross-*
rm -rf build
mkdir build
cd ..
cd example
find .
. ./src ./src/IntrospectionDemo.cxx ./src/IntrospectionDemoConfigure.h.in ./src/CMakeLists.txt ./build
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
docker pull dockcross/windows-x64
docker run --rm dockcross/windows-x64 > dockcross-windows-x64
chmod +x ./dockcross-windows-x64
Using default tag: latest latest: Pulling from dockcross/windows-x64 Digest: sha256:be93869c5df9c17cc1fbc430bb3ed75d73ba0c5d5a6704f4811792659f7a0878 Status: Downloaded newer image for dockcross/windows-x64:latest
./dockcross-windows-x64 cmake -Hsrc -Bbuild -GNinja
./dockcross-windows-x64 ninja -Cbuild
-- The C compiler identification is GNU 4.9.4 -- The CXX compiler identification is GNU 4.9.4 -- Check for working C compiler: /usr/src/mxe/usr/bin/x86_64-w64-mingw32.static-gcc -- Check for working C compiler: /usr/src/mxe/usr/bin/x86_64-w64-mingw32.static-gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/src/mxe/usr/bin/x86_64-w64-mingw32.static-g++ -- Check for working CXX compiler: /usr/src/mxe/usr/bin/x86_64-w64-mingw32.static-g++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Check size of long -- Check size of long - done -- Double correction test returned: 89255.0/1e22 = 8.9255e-018 -- Configuring done -- Generating done -- Build files have been written to: /work/build ninja: Entering directory `build' [2/2] Linking CXX executable IntrospectionDemo.exe
docker pull
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)
rm -rf build/*
./dockcross-windows-x86 cmake -Hsrc -Bbuild -GNinja | tail -n 6
-- Check size of long -- Check size of long - done -- Double correction test returned: 89255.0/1e22 = 8.9255e-018 -- Configuring done -- Generating done -- Build files have been written to: /work/build
grep SIZEOF_LONG ./build/IntrospectionDemoConfigure.h
#define IntrospectionDemo_SIZEOF_LONG 4
rm -rf build/*
./dockcross-linux-arm64 cmake -Hsrc -Bbuild -GNinja | tail -n 6
grep SIZEOF_LONG ./build/IntrospectionDemoConfigure.h
#define IntrospectionDemo_SIZEOF_LONG 8
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}")
rm -rf build/*
./dockcross-linux-arm64 cmake -Hsrc -Bbuild -GNinja | tail -n 4
How do we know the build works -- we need to test it!
Tests can be executed with the target system emulator.
./dockcross-linux-arm64 ninja -Cbuild
ninja: Entering directory `build' [2/2] Linking CXX executable IntrospectionDemo
./dockcross-linux-arm64 bash -c 'cd build && ctest -V'
UpdateCTestConfiguration from :/work/build/DartConfiguration.tcl Parse Config file:/work/build/DartConfiguration.tcl UpdateCTestConfiguration from :/work/build/DartConfiguration.tcl Parse Config file:/work/build/DartConfiguration.tcl Test project /work/build Constructing a list of tests Done constructing a list of tests Updating test list for fixtures Added 0 tests to meet fixture requirements Checking test dependency graph... Checking test dependency graph end test 1 Start 1: IntrospectionDemoTest 1: Test command: /usr/bin/qemu-aarch64 "/work/build/IntrospectionDemo" 1: Test timeout computed to be: 1500 1: 1: The 'long' type has 8 bytes. 1: This platform needs double correction. 1: 1/1 Test #1: IntrospectionDemoTest ............ Passed 0.04 sec 100% tests passed, 0 tests failed out of 1 Total Test time (real) = 0.04 sec