|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# Copyright (c) 2024 Martin Storsjo |
| 4 | +# |
| 5 | +# Permission to use, copy, modify, and/or distribute this software for any |
| 6 | +# purpose with or without fee is hereby granted, provided that the above |
| 7 | +# copyright notice and this permission notice appear in all copies. |
| 8 | +# |
| 9 | +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | + |
| 17 | +set -ex |
| 18 | + |
| 19 | +if [ $# -lt 1 ]; then |
| 20 | + echo $0 toolchain |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | +PREFIX="$1" |
| 24 | +PREFIX="$(cd "$PREFIX" && pwd)" |
| 25 | + |
| 26 | +if command -v ninja >/dev/null; then |
| 27 | + CMAKE_GENERATOR="Ninja" |
| 28 | +else |
| 29 | + : ${CORES:=$(nproc 2>/dev/null)} |
| 30 | + : ${CORES:=$(sysctl -n hw.ncpu 2>/dev/null)} |
| 31 | + : ${CORES:=4} |
| 32 | + |
| 33 | + case $(uname) in |
| 34 | + MINGW*) |
| 35 | + CMAKE_GENERATOR="MSYS Makefiles" |
| 36 | + ;; |
| 37 | + esac |
| 38 | +fi |
| 39 | + |
| 40 | +: ${ARCHS:=${TOOLCHAIN_ARCHS-i686 x86_64 armv7 aarch64 arm64ec}} |
| 41 | + |
| 42 | +case $(uname) in |
| 43 | +MINGW*|MSYS*) |
| 44 | + NATIVE=1 |
| 45 | + ;; |
| 46 | +*) |
| 47 | +esac |
| 48 | + |
| 49 | + |
| 50 | +cd test |
| 51 | + |
| 52 | +for arch in $ARCHS; do |
| 53 | + TEST_DIR="build-cmake-$arch" |
| 54 | + [ -z "$CLEAN" ] || rm -rf $TEST_DIR |
| 55 | + mkdir -p $TEST_DIR |
| 56 | + cd $TEST_DIR |
| 57 | + cmake \ |
| 58 | + ${CMAKE_GENERATOR+-G} "$CMAKE_GENERATOR" \ |
| 59 | + -DCMAKE_TOOLCHAIN_FILE=$PREFIX/share/cmake/$arch-w64-mingw32_toolchainfile.cmake \ |
| 60 | + .. |
| 61 | + cmake --build . ${CORES:+-j${CORES}} |
| 62 | + cd .. |
| 63 | +done |
| 64 | + |
| 65 | +if [ -n "$NATIVE" ] && [ -f "$PREFIX/bin/libc++.dll" ]; then |
| 66 | + # Test if we can build with the native toolchain file, and execute the |
| 67 | + # output right away, by just having $PREFIX/bin in $PATH. |
| 68 | + # |
| 69 | + # (For msys2/mingw64 builds, the bin directory doesn't contain any |
| 70 | + # libc++.dll, so so skip this test in that configuration.) |
| 71 | + |
| 72 | + TEST_DIR="build-cmake-native" |
| 73 | + [ -z "$CLEAN" ] || rm -rf $TEST_DIR |
| 74 | + mkdir -p $TEST_DIR |
| 75 | + cd $TEST_DIR |
| 76 | + cmake \ |
| 77 | + ${CMAKE_GENERATOR+-G} "$CMAKE_GENERATOR" \ |
| 78 | + -DCMAKE_TOOLCHAIN_FILE=$PREFIX/share/cmake/llvm-mingw_toolchainfile.cmake \ |
| 79 | + .. |
| 80 | + cmake --build . ${CORES:+-j${CORES}} |
| 81 | + |
| 82 | + # Add the toolchain bin directory to path, for dependency DLLs |
| 83 | + export PATH=$PREFIX/bin:$PATH |
| 84 | + for test in hello hello-cpp crt-test hello-res; do |
| 85 | + ./$test |
| 86 | + done |
| 87 | + cd .. |
| 88 | +fi |
| 89 | +echo All tests succeeded |
0 commit comments