summaryrefslogtreecommitdiffstats
path: root/windows
diff options
context:
space:
mode:
Diffstat (limited to 'windows')
-rwxr-xr-xwindows/cross_build_mxe.sh35
-rw-r--r--windows/zxing-cpp-test.cpp49
-rw-r--r--windows/zxing-cpp.mk41
3 files changed, 123 insertions, 2 deletions
diff --git a/windows/cross_build_mxe.sh b/windows/cross_build_mxe.sh
index 4862d32..827ea94 100755
--- a/windows/cross_build_mxe.sh
+++ b/windows/cross_build_mxe.sh
@@ -26,8 +26,12 @@ set -o pipefail
MXE_REPO_URL='https://github.com/mxe/mxe.git'
MXE_COMMIT=${MXE_COMMIT:-a9135e50775889ef9448cf12b72da0ea25aa04c1}
MXE_TARGETS='i686-w64-mingw32.shared x86_64-w64-mingw32.shared'
-MXE_PACKAGES='cc qtbase ffmpeg openssl miniupnpc libevent sqlite webrtc-audio-processing nsis'
+MXE_PACKAGES='cc qtbase ffmpeg openssl miniupnpc libevent sqlite webrtc-audio-processing zxing-cpp nsis'
MXE_PATCHES='mxe_qtbase_strip_excess_deps.patch mxe_ffmpeg_strip_excess_deps.patch'
+# Package recipes MXE does not have (yet), kept in this directory and copied
+# into the MXE tree's src/ - the recipe and, where there is one, the test
+# program it compiles.
+MXE_EXTRA_RECIPES='zxing-cpp.mk zxing-cpp-test.cpp'
windows_dir=$(cd "$(dirname "$0")" && pwd)
mxe_dir=$windows_dir/mxe
@@ -143,6 +147,32 @@ apply the patch again (the affected libraries will be rebuilt by MXE)."
done
}
+# step 3b: copy our own package recipes into the MXE tree. They are new files
+# there, untracked by MXE's git, so they neither count as local modifications
+# for checkout_mxe_commit nor get in the way of the patches above. Copied on
+# every run so that a recipe changed here reaches the tree; MXE does not rebuild
+# a package that is already built because its recipe changed, though - remove
+# usr/<target>/installed/<package> for that.
+function copy_mxe_recipes {
+ local recipe
+
+ for recipe in $MXE_EXTRA_RECIPES
+ do
+ test -f "$windows_dir/$recipe" || die "recipe $windows_dir/$recipe not found"
+
+ if cmp -s "$windows_dir/$recipe" "$mxe_dir/src/$recipe"
+ then
+ echo "*** $recipe is already in place, skipping"
+ continue
+ fi
+
+ test -e "$mxe_dir/src/$recipe" && echo "*** WARNING: replacing $mxe_dir/src/$recipe, which differs from $windows_dir/$recipe" >&2
+
+ echo "*** copying $recipe into $mxe_dir/src"
+ cp "$windows_dir/$recipe" "$mxe_dir/src/$recipe"
+ done
+}
+
# MXE packages from $MXE_PACKAGES that are not built yet, as 'package (target)'
function missing_mxe_packages {
local target package
@@ -228,7 +258,7 @@ rm -rf build_pica-pica
mkdir -p build_pica-pica
cd build_pica-pica
#MXE builds qtbase 5, while configure defaults to Qt 6
-../../../configure --host=$arch --prefix=$PREFIX --with-qt=qt5 --enable-d3d12va
+../../../configure --host=$arch --prefix=$PREFIX --with-qt=qt5 --enable-d3d12va --enable-qrcode
make -j$(nproc)
make install
make clean
@@ -300,6 +330,7 @@ cd ..
clone_mxe
checkout_mxe_commit
apply_mxe_patches
+copy_mxe_recipes
build_mxe_packages
cd "$mxe_dir"
diff --git a/windows/zxing-cpp-test.cpp b/windows/zxing-cpp-test.cpp
new file mode 100644
index 0000000..cf03c67
--- /dev/null
+++ b/windows/zxing-cpp-test.cpp
@@ -0,0 +1,49 @@
+/*
+ * This file is part of MXE. See LICENSE.md for licensing information.
+ */
+
+// Round trip: encode a QR code with the writer, render it to a grayscale
+// image and read it back with the reader.
+
+#include <ZXing/BitMatrix.h>
+#include <ZXing/MultiFormatWriter.h>
+#include <ZXing/ReadBarcode.h>
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+int main()
+{
+ const std::string text = "MXE zxing-cpp test";
+ const int scale = 4;
+ const int quiet = 4;
+
+ ZXing::BitMatrix matrix =
+ ZXing::MultiFormatWriter(ZXing::BarcodeFormat::QRCode).setMargin(0).encode(text, 0, 0);
+
+ const int size = (matrix.width() + 2 * quiet) * scale;
+ std::vector<unsigned char> pixels(size * size, 0xff);
+
+ for (int y = 0; y < matrix.height(); y++)
+ for (int x = 0; x < matrix.width(); x++)
+ if (matrix.get(x, y))
+ for (int dy = 0; dy < scale; dy++)
+ for (int dx = 0; dx < scale; dx++)
+ pixels[((y + quiet) * scale + dy) * size + (x + quiet) * scale + dx] = 0;
+
+ ZXing::ImageView image(pixels.data(), size, size, ZXing::ImageFormat::Lum);
+ ZXing::ReaderOptions options;
+ options.setFormats(ZXing::BarcodeFormat::QRCode);
+
+ const ZXing::Result result = ZXing::ReadBarcode(image, options);
+
+ if (!result.isValid() || result.text() != text)
+ {
+ std::cerr << "decoded \"" << result.text() << "\" instead of \"" << text << "\"" << std::endl;
+ return 1;
+ }
+
+ std::cout << result.text() << std::endl;
+ return 0;
+}
diff --git a/windows/zxing-cpp.mk b/windows/zxing-cpp.mk
new file mode 100644
index 0000000..9c52db6
--- /dev/null
+++ b/windows/zxing-cpp.mk
@@ -0,0 +1,41 @@
+# This file is part of MXE. See LICENSE.md for licensing information.
+
+PKG := zxing-cpp
+$(PKG)_WEBSITE := https://github.com/zxing-cpp/zxing-cpp
+$(PKG)_DESCR := ZXing-C++, a barcode and QR code reading and writing library
+$(PKG)_IGNORE :=
+$(PKG)_VERSION := 2.3.0
+$(PKG)_CHECKSUM := 64e4139103fdbc57752698ee15b5f0b0f7af9a0331ecbdc492047e0772c417ba
+$(PKG)_GH_CONF := zxing-cpp/zxing-cpp/tags,v
+$(PKG)_DEPS := cc
+
+# ZXING_WRITERS=OLD builds the MultiFormatWriter encoder, which needs nothing
+# else. The new CreateBarcodeFromText() one would pull in libzint, either the
+# copy bundled with the sources or one fetched from GitHub at build time.
+#
+# The examples are off because they fetch stb from GitHub at build time, and the
+# tests, the C API and the Python module because nothing here uses them.
+#
+# 2.3 prefers C++20 but builds as C++17 too; asking for 17 keeps MXE's
+# compiler from having to handle C++20 library features it may only partly
+# support.
+define $(PKG)_BUILD
+ cd '$(BUILD_DIR)' && $(TARGET)-cmake '$(SOURCE_DIR)' \
+ -DCMAKE_CXX_STANDARD=17 \
+ -DZXING_READERS=ON \
+ -DZXING_WRITERS=OLD \
+ -DZXING_EXAMPLES=OFF \
+ -DZXING_BLACKBOX_TESTS=OFF \
+ -DZXING_UNIT_TESTS=OFF \
+ -DZXING_C_API=OFF \
+ -DZXING_PYTHON_MODULE=OFF \
+ -DZXING_DEPENDENCIES=LOCAL
+ $(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)'
+ $(MAKE) -C '$(BUILD_DIR)' -j 1 install
+
+ # compile test
+ '$(TARGET)-g++' \
+ -W -Wall -Werror -std=c++17 \
+ '$(TEST_FILE)' -o '$(PREFIX)/$(TARGET)/bin/test-$(PKG).exe' \
+ `'$(TARGET)-pkg-config' zxing --cflags --libs`
+endef