diff --git a/CMakeLists.txt b/CMakeLists.txt index d85a23d215..de06c8ed4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ +# cmake-format: off # SPDX-License-Identifier: GPL-3.0-or-later. -# Copyright © 2019 by The qTox Project Contributors. -# Copyright © 2024 The TokTok team. +# Copyright © 2019 by The qTox Project Contributors +# Copyright © 2024 The TokTok team +# cmake-format: on # ############################################################################## # diff --git a/windows/cross-compile/build.sh b/windows/cross-compile/build.sh index 0279f57ea7..c70b74d4b6 100755 --- a/windows/cross-compile/build.sh +++ b/windows/cross-compile/build.sh @@ -13,14 +13,29 @@ set -euo pipefail RUN_TESTS=0 -while (( $# > 0 )); do - case $1 in - --src-dir) QTOX_SRC_DIR=$2; shift 2 ;; - --arch) ARCH=$2; shift 2 ;; - --run-tests) RUN_TESTS=1; shift ;; - --build-type) BUILD_TYPE=$2; shift 2;; - *) "Unexpected argument $1"; exit 1 ;; - esac +while (($# > 0)); do + case $1 in + --src-dir) + QTOX_SRC_DIR=$2 + shift 2 + ;; + --arch) + ARCH=$2 + shift 2 + ;; + --run-tests) + RUN_TESTS=1 + shift + ;; + --build-type) + BUILD_TYPE=$2 + shift 2 + ;; + *) + "Unexpected argument $1" + exit 1 + ;; + esac done # Common directory paths @@ -30,14 +45,12 @@ readonly QTOX_PREFIX_DIR QTOX_PACKAGE_DIR="$(realpath package-prefix)" readonly QTOX_PACKAGE_DIR -if [ -z "$ARCH" ] -then +if [ -z "$ARCH" ]; then echo "Error: No architecture was specified. Please specify either 'i686' or 'x86_64', case sensitive, as the first argument to the script." exit 1 fi -if [[ "$ARCH" != "i686" ]] && [[ "$ARCH" != "x86_64" ]] -then +if [[ "$ARCH" != "i686" ]] && [[ "$ARCH" != "x86_64" ]]; then echo "Error: Incorrect architecture was specified. Please specify either 'i686' or 'x86_64', case sensitive, as the first argument to the script." exit 1 fi @@ -46,14 +59,12 @@ if [ -z "$QTOX_SRC_DIR" ]; then echo "--src-dir must be specified" fi -if [ -z "$BUILD_TYPE" ] -then +if [ -z "$BUILD_TYPE" ]; then echo "Error: No build type was specified. Please specify either 'Release' or 'Debug', case sensitive, as the second argument to the script." exit 1 fi -if [[ "$BUILD_TYPE" != "Release" ]] && [[ "$BUILD_TYPE" != "Debug" ]] -then +if [[ "$BUILD_TYPE" != "Release" ]] && [[ "$BUILD_TYPE" != "Debug" ]]; then echo "Error: Incorrect build type was specified. Please specify either 'Release' or 'Debug', case sensitive, as the second argument to the script." exit 1 fi @@ -61,45 +72,42 @@ fi export PKG_CONFIG_PATH=/windows/lib64/pkgconfig # Spell check on windows currently not supported, disable -if [[ "$BUILD_TYPE" == "Release" ]] -then +if [[ "$BUILD_TYPE" == "Release" ]]; then cmake -DCMAKE_TOOLCHAIN_FILE=/build/windows-toolchain.cmake \ - -DCMAKE_LIBRARY_PATH=/windows/lib64 \ - -DCMAKE_PREFIX_PATH=/windows \ - -DCMAKE_BUILD_TYPE=Release \ - -DSPELL_CHECK=OFF \ - -DDESKTOP_NOTIFICATIONS=OFF \ - -DUPDATE_CHECK=ON \ - -DSTRICT_OPTIONS=ON \ - -DTEST_CROSSCOMPILING_EMULATOR=wine \ - -GNinja \ - "$QTOX_SRC_DIR" -elif [[ "$BUILD_TYPE" == "Debug" ]] -then + -DCMAKE_LIBRARY_PATH=/windows/lib64 \ + -DCMAKE_PREFIX_PATH=/windows \ + -DCMAKE_BUILD_TYPE=Release \ + -DSPELL_CHECK=OFF \ + -DDESKTOP_NOTIFICATIONS=OFF \ + -DUPDATE_CHECK=ON \ + -DSTRICT_OPTIONS=ON \ + -DTEST_CROSSCOMPILING_EMULATOR=wine \ + -GNinja \ + "$QTOX_SRC_DIR" +elif [[ "$BUILD_TYPE" == "Debug" ]]; then cmake -DCMAKE_TOOLCHAIN_FILE=/build/windows-toolchain.cmake \ - -DCMAKE_LIBRARY_PATH=/windows/lib64 \ - -DCMAKE_PREFIX_PATH=/windows \ - -DCMAKE_BUILD_TYPE=Debug \ - -DSPELL_CHECK=OFF \ - -DDESKTOP_NOTIFICATIONS=OFF \ - -DUPDATE_CHECK=ON \ - -DSTRICT_OPTIONS=ON \ - -DTEST_CROSSCOMPILING_EMULATOR=wine \ - -GNinja \ - -DCMAKE_EXE_LINKER_FLAGS="-mconsole" \ - "$QTOX_SRC_DIR" + -DCMAKE_LIBRARY_PATH=/windows/lib64 \ + -DCMAKE_PREFIX_PATH=/windows \ + -DCMAKE_BUILD_TYPE=Debug \ + -DSPELL_CHECK=OFF \ + -DDESKTOP_NOTIFICATIONS=OFF \ + -DUPDATE_CHECK=ON \ + -DSTRICT_OPTIONS=ON \ + -DTEST_CROSSCOMPILING_EMULATOR=wine \ + -GNinja \ + -DCMAKE_EXE_LINKER_FLAGS="-mconsole" \ + "$QTOX_SRC_DIR" fi cmake --build . -mkdir -p "${QTOX_PREFIX_DIR}" -cp qtox.exe $QTOX_PREFIX_DIR -cp -r /export/* $QTOX_PREFIX_DIR +mkdir -p "$QTOX_PREFIX_DIR" +cp qtox.exe "$QTOX_PREFIX_DIR" +cp -r /export/* "$QTOX_PREFIX_DIR" # Run tests set +u -if [[ $RUN_TESTS -ne 0 ]] -then +if [[ $RUN_TESTS -ne 0 ]]; then export WINEPATH='/export;/windows/bin' export CTEST_OUTPUT_ON_FAILURE=1 export PATH="$PATH:/opt/wine-stable/bin" @@ -110,41 +118,36 @@ set -u # Strip set +e -if [[ "$BUILD_TYPE" == "Release" ]] -then - $ARCH-w64-mingw32-strip -s $QTOX_PREFIX_DIR/*.exe +if [[ "$BUILD_TYPE" == "Release" ]]; then + "$ARCH-w64-mingw32-strip" -s "$QTOX_PREFIX_DIR"/*.exe fi -$ARCH-w64-mingw32-strip -s $QTOX_PREFIX_DIR/*.dll -$ARCH-w64-mingw32-strip -s $QTOX_PREFIX_DIR/*/*.dll +"$ARCH-w64-mingw32-strip" -s "$QTOX_PREFIX_DIR"/*.dll +"$ARCH-w64-mingw32-strip" -s "$QTOX_PREFIX_DIR"/*/*.dll set -e -if [[ "$BUILD_TYPE" == "Debug" ]] -then - cp -r /debug_export/* ${QTOX_PREFIX_DIR} +if [[ "$BUILD_TYPE" == "Debug" ]]; then + cp -r /debug_export/* "$QTOX_PREFIX_DIR" fi # Create zip -pushd $QTOX_PREFIX_DIR -zip qtox-"$ARCH"-"$BUILD_TYPE".zip -r * +pushd "$QTOX_PREFIX_DIR" +zip "qtox-$ARCH-$BUILD_TYPE.zip" -r * popd # Create installer -if [[ "$BUILD_TYPE" == "Release" ]] -then - mkdir -p $QTOX_PACKAGE_DIR - pushd $QTOX_PACKAGE_DIR +if [[ "$BUILD_TYPE" == "Release" ]]; then + mkdir -p "$QTOX_PACKAGE_DIR" + pushd "$QTOX_PACKAGE_DIR" # The installer creation script expects all the files to be in qtox/* mkdir -p qtox - cp -r $QTOX_PREFIX_DIR/* ./qtox + cp -r "$QTOX_PREFIX_DIR"/* ./qtox rm ./qtox/*.zip - cp -r $QTOX_SRC_DIR/windows/* . + cp -r "$QTOX_SRC_DIR"/windows/* . # Select the installer script for the correct architecture - if [[ "$ARCH" == "i686" ]] - then + if [[ "$ARCH" == "i686" ]]; then makensis qtox.nsi - elif [[ "$ARCH" == "x86_64" ]] - then + elif [[ "$ARCH" == "x86_64" ]]; then makensis qtox64.nsi fi @@ -153,8 +156,8 @@ fi # dll check # Create lists of all .exe and .dll files -find "$QTOX_PREFIX_DIR" -iname '*.dll' > dlls -find "$QTOX_PREFIX_DIR" -iname '*.exe' > exes +find "$QTOX_PREFIX_DIR" -iname '*.dll' >dlls +find "$QTOX_PREFIX_DIR" -iname '*.exe' >exes # Create a list of dlls that are loaded during the runtime (not listed in the PE # import table, thus ldd doesn't print those) @@ -180,42 +183,35 @@ fi # Create a tree of all required dlls # Assumes all .exe files are directly in $QTOX_PREFIX_DIR, not in subdirs -while IFS= read -r line -do - if [[ "$ARCH" == "i686" ]] - then - WINE_DLL_DIR="/usr/lib/x86_64-linux-gnu/wine/i386-windows" - elif [[ "$ARCH" == "x86_64" ]] - then - WINE_DLL_DIR="/usr/lib/x86_64-linux-gnu/wine/x86_64-windows /usr/lib/x86_64-linux-gnu/wine/i386-windows" +while IFS= read -r line; do + if [[ "$ARCH" == "i686" ]]; then + WINE_DLL_DIR=("/usr/lib/x86_64-linux-gnu/wine/i386-windows") + elif [[ "$ARCH" == "x86_64" ]]; then + WINE_DLL_DIR=("/usr/lib/x86_64-linux-gnu/wine/x86_64-windows" "/usr/lib/x86_64-linux-gnu/wine/i386-windows") fi - python3 /usr/local/bin/mingw-ldd.py $line --dll-lookup-dirs $QTOX_PREFIX_DIR $WINE_DLL_DIR --output-format tree >> dlls-required + python3 /usr/local/bin/mingw-ldd.py "$line" --dll-lookup-dirs "$QTOX_PREFIX_DIR" "${WINE_DLL_DIR[@]}" --output-format tree >>dlls-required done < <(cat exes runtime-dlls) # Check that no extra dlls get bundled -while IFS= read -r line -do - if ! grep -q "$line" dlls-required - then +while IFS= read -r line; do + if ! grep -q "$line" dlls-required; then echo "Error: extra dll included: $line. If this is a mistake and the dll is actually needed (e.g. it's loaded at runtime), please add it to the runtime dll list." exit 1 fi -done < dlls +done