Skip to content

Commit

Permalink
Use single tesseract library
Browse files Browse the repository at this point in the history
Link with it during compilation.
Bump to 5.2.0.
  • Loading branch information
OneMoreGres committed Jul 29, 2022
1 parent cb203b9 commit 7be0707
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 375 deletions.
2 changes: 1 addition & 1 deletion screen-translator.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DEPS_DIR=$$(ST_DEPS_DIR)
isEmpty(DEPS_DIR):DEPS_DIR=$$PWD/../deps
INCLUDEPATH += $$DEPS_DIR/include
LIBS += -L$$DEPS_DIR/lib
LIBS += -lhunspell -lleptonica
LIBS += -lhunspell -lleptonica -ltesseract

win32{
LIBS += -lUser32
Expand Down
3 changes: 1 addition & 2 deletions share/ci/appimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
flags = '' if os.getenv("DEBUG") is None else '-unsupported-allow-new-glibc'

additional_files = glob(ssl_dir + '/lib/lib*.so.*') + \
glob('/usr/lib/x86_64-linux-gnu/nss/*') + \
glob(dependencies_dir + '/lib/libtesseract-*.so')
glob('/usr/lib/x86_64-linux-gnu/nss/*')
out_lib_dir = install_dir + '/usr/lib'
os.makedirs(out_lib_dir, exist_ok=True)
for f in additional_files:
Expand Down
116 changes: 32 additions & 84 deletions share/ci/get_tesseract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,12 @@
c.print('>> Installing tesseract')

install_dir = dependencies_dir
url = 'https://github.com/tesseract-ocr/tesseract/archive/5.1.0.tar.gz'
required_version = '5.1.0'
required_version = '5.2.0'
url = 'https://github.com/tesseract-ocr/tesseract/archive/{}.tar.gz'.format(required_version)

build_type_flag = 'Debug' if build_type == 'debug' else 'Release'

# compatibility flags
compat_flags = ''
compat_flags += ' -D DISABLE_LEGACY_ENGINE=ON '
compat_flags += ' -D DISABLE_ARCHIVE=ON '
compat_flags += ' -D DISABLE_CURL=ON '

version_tag = os.environ.get('TAG', '')
if version_tag == 'compatible':
compat_flags += ' -D HAVE_AVX2=0 '
compat_flags += ' -D HAVE_FMA=0 '

lib_suffix = version_tag
if len(lib_suffix) > 0:
lib_suffix = '-' + lib_suffix

cache_file = install_dir + '/tesseract{}.cache'.format(lib_suffix)
cache_file = install_dir + '/tesseract.cache'
cache_file_data = required_version + build_type_flag

def check_existing():
Expand All @@ -42,22 +27,25 @@ def check_existing():
return False

if platform.system() == "Windows":
lib = install_dir + '/bin/tesseract{}.dll'.format(lib_suffix)
orig_lib = install_dir + '/bin/tesseract51.dll'
file_name_ver = required_version[0] + required_version[2]
dll = install_dir + '/bin/tesseract{}.dll'.format(file_name_ver)
lib = install_dir + '/lib/tesseract{}.lib'.format(file_name_ver)
if not os.path.exists(dll) or not os.path.exists(lib):
return False
c.symlink(dll, install_dir + '/bin/tesseract.dll')
c.symlink(lib, install_dir + '/lib/tesseract.lib')
elif platform.system() == "Darwin":
lib = install_dir + '/lib/libtesseract{}.dylib'.format(lib_suffix)
orig_lib = install_dir + '/lib/libtesseract.{}.dylib'.format(required_version)
lib = install_dir + '/lib/libtesseract.{}.dylib'.format(required_version)
if not os.path.exists(lib):
return False
c.symlink(lib, install_dir + '/lib/libtesseract.dylib')
else:
lib = install_dir + '/lib/libtesseract{}.so'.format(lib_suffix)
orig_lib = install_dir + '/lib/libtesseract.so.{}'.format(required_version)

if os.path.exists(lib):
return True
if os.path.exists(orig_lib):
os.rename(orig_lib, lib)
return True
lib = install_dir + '/lib/libtesseract.so.{}'.format(required_version)
if not os.path.exists(lib):
return False
c.symlink(lib, install_dir + '/lib/libtesseract.so')

return False
return True


if check_existing() and not 'FORCE' in os.environ:
Expand All @@ -71,60 +59,24 @@ def check_existing():
c.extract(archive, '.')
c.symlink(c.get_archive_top_dir(archive), src_dir)

if platform.system() == "Windows":
# workaround for not found 'max'
modify_data = ''
modify_file = '{}/src/ccmain/thresholder.cpp'.format(src_dir)
with open(modify_file, 'r') as f:
modify_data = f.read()

if modify_data.find('<algorithm>') == -1:
modify_data = modify_data.replace(
'''<tuple>''',
'''<tuple>\n#include <algorithm>''')

with open(modify_file, 'w') as f:
f.write(modify_data)

# ignore libtiff
modify_data = ''
modify_file = '{}/CMakeLists.txt'.format(src_dir)
with open(modify_file, 'r') as f:
modify_data = f.read()

if modify_data.find('#pkg_check_modules(TIFF libtiff-4)') == -1:
modify_data = modify_data.replace(
'''pkg_check_modules(TIFF libtiff-4)''',
'''#pkg_check_modules(TIFF libtiff-4)''')

with open(modify_file, 'w') as f:
f.write(modify_data)

if platform.system() == "Linux":
# FIXME fix crash on ubuntu
modify_data = ''
modify_file = '{}/src/ccmain/tessedit.cpp'.format(src_dir)
with open(modify_file, 'r') as f:
modify_data = f.read()

lines = modify_data.split('\n')
for line in [250,253,255,256]:
if not lines[line].startswith('//'):
lines[line] = '// ' + lines[line]
modify_data = '\n'.join(lines)

with open(modify_file, 'w') as f:
f.write(modify_data)



c.ensure_got_path(install_dir)

c.recreate_dir(build_dir)
os.chdir(build_dir)

cmake_args = '"{0}" -DCMAKE_INSTALL_PREFIX="{1}" -DLeptonica_DIR="{1}/cmake" \
-DBUILD_TRAINING_TOOLS=OFF -DBUILD_TESTS=OFF -DBUILD_SHARED_LIBS=ON -DSW_BUILD=OFF \
cmake_args = '"{0}" \
-DCMAKE_INSTALL_PREFIX="{1}" \
-DLeptonica_DIR="{1}/cmake" \
-DSW_BUILD=OFF \
-DBUILD_TRAINING_TOOLS=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_SHARED_LIBS=ON \
-DDISABLE_CURL=ON \
-DDISABLE_ARCHIVE=ON \
-DUSE_SYSTEM_ICU=ON \
-DENABLE_LTO=ON \
-DGRAPHICS_DISABLED=ON \
-DDISABLED_LEGACY_ENGINE=ON \
'.format(src_dir, install_dir)

if platform.system() == "Windows":
Expand All @@ -135,10 +87,6 @@ def check_existing():
c.set_make_threaded()
c.run('cmake {}'.format(cmake_args))

if len(compat_flags) > 0:
c.run('cmake {} .'.format(compat_flags))
c.run('cmake {} .'.format(compat_flags)) # for sure :)

c.run('cmake --build . --config {}'.format(build_type_flag))
c.run('cmake --build . --target install --config {}'.format(build_type_flag))

Expand Down
7 changes: 0 additions & 7 deletions share/ci/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,8 @@ def r(script):
r('get_qt.py')
r('get_qt_ssl.py')
r('get_leptonica.py')

os.environ['TAG'] = 'optimized'
r('get_tesseract.py')

os.environ['TAG'] = 'compatible'
r('get_tesseract.py')

del os.environ['TAG']

r('get_hunspell.py')
r('test.py')
r('build.py')
Expand Down
Loading

0 comments on commit 7be0707

Please sign in to comment.