Commit 322d0216 for tesseract
commit 322d0216cd9b6368f3fc571b1b09ae94137323e0
Author: Stefan Weil <sw@weilnetz.de>
Date: Fri Nov 27 12:03:36 2026 +0100
Add a version resource to the Windows programs and the library
MinGW builds with autotools now compile src/tesseract.rc with windres
and link it to tesseract.exe, the training tools, winpath.exe and the
Tesseract library. Until now none of them had a version resource, so
the file properties in Windows showed no product name and no version.
All files get the product name "Tesseract-OCR", which is also used for
the installer, and the same product version as the installer: the
package version without the "v" which a version from git starts with.
Code signing with a certificate of SignPath Foundation requires that
all signed files have a product name and the same product version.
configure now needs windres for MinGW hosts.
Tested with cross builds for the MSYS2 environments CLANG64, UCRT64 and
CLANGARM64: the 16 programs, winpath.exe, the library and the installer
have the product name Tesseract-OCR and the product version
5.5.5.20261127 (read with the Python module pefile). The file
properties were not looked at on Windows, and CMake builds are not
changed.
Assisted-by: Claude Fable 5.2 (Anthropic)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
diff --git a/Makefile.am b/Makefile.am
index da397595..d32aa134 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -18,6 +18,7 @@ if !GRAPHICS_DISABLED
EXTRA_DIST += java
endif
EXTRA_DIST += CMakeLists.txt tesseract.pc.cmake cmake VERSION
+EXTRA_DIST += src/tesseract.rc
# Header shared by the unit tests, not listed in any _SOURCES.
EXTRA_DIST += unittest/util/tempdir.h
EXTRA_DIST += unittest/weightmatrix_test_helper.h
@@ -728,6 +729,25 @@ if T_WIN
tesseract_LDADD += -ltiff
tesseract_LDADD += -lws2_32
endif
+
+if MINGW
+# Windows version resource for all programs and for the library.
+# It gives them a product name and a product version. The version is the
+# same as for the installer (without the "v" of a version from git).
+TESS_RC_FLAGS = -DTESS_RC_PRODUCT_VERSION=$(PACKAGE_VERSION:v%=%)
+TESS_RC_FLAGS += -I$(top_builddir)/include
+
+tesseract_rc.o: $(top_srcdir)/src/tesseract.rc include/tesseract/version.h
+ $(WINDRES) $(TESS_RC_FLAGS) -i $(top_srcdir)/src/tesseract.rc -o $@
+
+libtesseract_rc.o: $(top_srcdir)/src/tesseract.rc include/tesseract/version.h
+ $(WINDRES) -DTESS_RC_DLL $(TESS_RC_FLAGS) -i $(top_srcdir)/src/tesseract.rc -o $@
+
+CLEANFILES += tesseract_rc.o libtesseract_rc.o
+EXTRA_libtesseract_la_DEPENDENCIES = libtesseract_rc.o
+libtesseract_la_LDFLAGS += -Wl,libtesseract_rc.o
+tesseract_LDADD += tesseract_rc.o
+endif
if ADD_RT
tesseract_LDADD += -lrt
endif
@@ -893,6 +913,9 @@ extralib += $(LEPTONICA_LIBS)
if T_WIN
extralib += -lws2_32
endif
+if MINGW
+extralib += tesseract_rc.o
+endif
if !DISABLED_LEGACY_ENGINE
ambiguous_words_CPPFLAGS = $(training_CPPFLAGS)
diff --git a/configure.ac b/configure.ac
index 92d8a199..f1905562 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,6 +93,10 @@ case "${host_os}" in
AM_CONDITIONAL([MINGW], true)
AM_CONDITIONAL([ADD_RT], false)
AC_SUBST([AM_LDFLAGS], ['-no-undefined'])
+ # The resource compiler is needed for the version resource.
+ AC_CHECK_TOOL([WINDRES], [windres])
+ AS_IF([test -z "$WINDRES"],
+ [AC_MSG_ERROR([windres is required for the Windows version resource])])
;;
cygwin*)
AM_CONDITIONAL([ADD_RT], false)
diff --git a/nsis/Makefile.am b/nsis/Makefile.am
index 5b6b63fc..93ad1d05 100644
--- a/nsis/Makefile.am
+++ b/nsis/Makefile.am
@@ -12,8 +12,11 @@ Plugins/x86-unicode/INetC.dll:
curl -OsS https://nsis.sourceforge.io/mediawiki/images/c/c9/Inetc.zip
unzip Inetc.zip $@
-winpath.exe: winpath.cpp
- $(CXX) -Os -o $@ $<
+winpath_rc.o: $(top_srcdir)/src/tesseract.rc
+ $(WINDRES) -DTESS_RC_PRODUCT_VERSION=$(PACKAGE_VERSION:v%=%) -I$(top_builddir)/include -i $(top_srcdir)/src/tesseract.rc -o $@
+
+winpath.exe: winpath.cpp winpath_rc.o
+ $(CXX) -Os -o $@ $< winpath_rc.o
$(STRIP) --strip-unneeded $@
winsetup: Plugins/x86-unicode/INetC.dll winpath.exe
diff --git a/src/tesseract.rc b/src/tesseract.rc
new file mode 100644
index 00000000..06dbe9e1
--- /dev/null
+++ b/src/tesseract.rc
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: Apache-2.0
+//
+// Windows version resource for the Tesseract programs and for the library.
+//
+// It gives all of them the same product name and product version, which
+// are shown in the file properties and are needed for code signing.
+//
+// TESS_RC_DLL must be defined when the resource is used for the library.
+// TESS_RC_PRODUCT_VERSION can be defined to set the version string (without
+// quotes). All programs, the library and the installer must use the same.
+
+#include <winver.h>
+#include <tesseract/version.h>
+
+#ifdef TESS_RC_DLL
+#define TESS_RC_FILETYPE VFT_DLL
+#define TESS_RC_DESCRIPTION "Tesseract OCR library"
+#else
+#define TESS_RC_FILETYPE VFT_APP
+#define TESS_RC_DESCRIPTION "Tesseract OCR"
+#endif
+
+#ifdef TESS_RC_PRODUCT_VERSION
+#define TESS_RC_STRING2(x) #x
+#define TESS_RC_STRING(x) TESS_RC_STRING2(x)
+#define TESS_RC_VERSION_STR TESS_RC_STRING(TESS_RC_PRODUCT_VERSION)
+#else
+#define TESS_RC_VERSION_STR TESSERACT_VERSION_STR
+#endif
+
+#define TESS_RC_VERSION \
+ TESSERACT_MAJOR_VERSION, TESSERACT_MINOR_VERSION, TESSERACT_MICRO_VERSION, 0
+
+VS_VERSION_INFO VERSIONINFO
+FILEVERSION TESS_RC_VERSION
+PRODUCTVERSION TESS_RC_VERSION
+FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
+FILEFLAGS 0
+FILEOS VOS_NT_WINDOWS32
+FILETYPE TESS_RC_FILETYPE
+FILESUBTYPE VFT2_UNKNOWN
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ // Language U.S. English, character set Unicode.
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "CompanyName", "Tesseract-OCR community"
+ VALUE "FileDescription", TESS_RC_DESCRIPTION
+ VALUE "FileVersion", TESS_RC_VERSION_STR
+ VALUE "LegalCopyright", "Apache-2.0"
+ VALUE "ProductName", "Tesseract-OCR"
+ VALUE "ProductVersion", TESS_RC_VERSION_STR
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END