Skip to content

Commit abf3aeb

Browse files
committed
Export everything!
1 parent 5a7ef6b commit abf3aeb

File tree

4 files changed

+306
-87
lines changed

4 files changed

+306
-87
lines changed

.github/workflows/build.yml

Lines changed: 157 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ name: Build
33
on: [push]
44

55
jobs:
6-
build:
6+
# Linux, MacOS
7+
build-unix:
78
name: ${{ matrix.config.name }}
89
runs-on: ${{ matrix.config.os }}
910
defaults:
@@ -13,77 +14,191 @@ jobs:
1314
fail-fast: false
1415
matrix:
1516
config:
16-
- os: windows-latest
17-
name: 'Windows 32'
18-
output: 'libtesseract32.dll'
19-
cmake_args: '-G "Visual Studio 16 2019" -A Win32'
20-
sw_args: '-platform x86 -win-mt'
21-
22-
- os: windows-latest
23-
name: 'Windows 64'
24-
output: 'libtesseract64.dll'
25-
cmake_args: '-G "Visual Studio 16 2019"'
26-
sw_args: '-platform x64 -win-mt'
27-
2817
- os: ubuntu-20.04
2918
name: 'Linux 64'
3019
output: 'libtesseract64.so'
3120
cmake_args: '-G "Unix Makefiles"'
32-
sw_args: '-platform x64'
21+
sw_args: '-platform x64'
3322

3423
- os: macos-latest
3524
name: 'MacOS 64'
3625
output: 'libtesseract64.dylib'
3726
cmake_args: '-G "Unix Makefiles"'
3827
sw_args: '-platform x64 -os macos-10.13'
39-
28+
4029
steps:
4130
- uses: actions/[email protected]
42-
with:
43-
submodules: true
44-
45-
- uses: egorpugin/sw-action@master
46-
31+
4732
- name: Cache
4833
id: cache
49-
uses: actions/[email protected]
34+
uses: actions/[email protected]
35+
with:
36+
key: ${{ matrix.config.name }}${{ matrix.config.sw_args }}
37+
path: |
38+
libs
39+
headers
40+
41+
- name: Download Python
42+
uses: actions/[email protected]
5043
with:
51-
path: storage
52-
key: ${{ matrix.config.os }}${{ matrix.config.sw_args }}
44+
python-version: '3.9'
45+
46+
- name: Download Tesseract
47+
if: steps.cache.outputs.cache-hit != 'true'
48+
uses: actions/[email protected]
49+
with:
50+
repository: tesseract-ocr/tesseract
51+
path: tesseract
52+
53+
- name: Download sw
54+
if: steps.cache.outputs.cache-hit != 'true'
55+
uses: egorpugin/sw-action@master
5356

5457
- name: Build Tesseract
58+
working-directory: tesseract
5559
if: steps.cache.outputs.cache-hit != 'true'
5660
run: |
57-
./sw build ${{ matrix.config.sw_args }} -storage-dir=storage -static -static-dependencies -config r org.sw.demo.google.tesseract.tesseract-master
61+
mv -f ../sw.cpp sw.cpp
62+
../sw ${{ matrix.config.sw_args }} -storage-dir=storage -static -static-dependencies -config r build
63+
64+
- name: Find
65+
shell: python
66+
run: |
67+
import os
68+
from pathlib import Path
69+
from distutils.file_util import copy_file
70+
71+
libs = ['leptonica', 'zstd', 'png', 'jpeg', 'zlib', 'jbig', 'tiff', 'openjpeg' ,'webp', 'libtesseract', 'lzma', 'gif']
72+
73+
os.makedirs('libs', exist_ok=True)
74+
os.makedirs('headers/tesseract', exist_ok=True)
75+
76+
for filename in list(Path('tesseract').glob('**/*.a')):
77+
for lib in libs:
78+
if lib in str(filename):
79+
copy_file(filename, os.path.join('libs', os.path.basename(filename)))
80+
81+
for filename in list(Path('tesseract').glob('**/include/tesseract/*.h')) + list(Path('tesseract').glob('**/tesseract/version.h')):
82+
copy_file(filename, os.path.join('headers/tesseract', os.path.basename(filename)))
83+
84+
for filename in list(Path('libs').glob('**/*')) + list(Path('headers').glob('**/*')):
85+
print(filename)
5886
59-
- name: Extract Headers & Libraries
87+
- name: Build Plugin
6088
continue-on-error: true
6189
run: |
62-
mkdir -p libs
63-
mkdir -p headers/tesseract
64-
mkdir -p headers/leptonica
90+
cmake -S . ${{ matrix.config.cmake_args }}
91+
cmake --build . --config Release
6592
66-
find "storage/pkg/" -name "*.a" -exec cp "{}" "libs" \;
67-
find "storage/pkg/" -name "*.lib" -exec cp "{}" "libs" \;
93+
- uses: actions/[email protected]
94+
with:
95+
path: ${{ matrix.config.output }}
96+
97+
# Windows
98+
build-windows:
99+
name: ${{ matrix.config.name }}
100+
runs-on: ${{ matrix.config.os }}
101+
defaults:
102+
run:
103+
shell: bash
104+
strategy:
105+
fail-fast: false
106+
matrix:
107+
config:
108+
- os: windows-latest
109+
name: 'Windows 32'
110+
output: 'libtesseract32.dll'
111+
cmake_args: '-G "MinGW Makefiles"'
112+
sw_args: '-compiler=gcc -os mingw -platform x86 -win-mt'
113+
114+
- os: windows-latest
115+
name: 'Windows 64'
116+
output: 'libtesseract64.dll'
117+
cmake_args: '-G "MinGW Makefiles"'
118+
sw_args: '-compiler=gcc -os mingw -platform x64 -win-mt'
119+
120+
steps:
121+
- uses: actions/[email protected]
122+
123+
- name: Cache
124+
id: cache
125+
uses: actions/[email protected]
126+
with:
127+
key: ${{ matrix.config.name }}${{ matrix.config.sw_args }}
128+
path: |
129+
libs
130+
headers
131+
132+
- name: Download Python
133+
uses: actions/[email protected]
134+
with:
135+
python-version: '3.9'
68136

69-
tesseract=$(find "storage/pkg/" -name "baseapi.h" -exec dirname {} \; -quit)
70-
find "$tesseract" -name "*.h*" -exec cp "{}" headers/tesseract/ \;
71-
find "storage/pkg/" -wholename "*tesseract/version.h" -exec cp "{}" headers/tesseract/ \;
137+
- name: Dependencies - Windows 64
138+
if: matrix.config.name == 'Windows 64'
139+
uses: msys2/setup-msys2@v2
140+
with:
141+
msystem: MINGW64
142+
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-cmake
143+
update: false
72144

73-
leptonica=$(find "storage/pkg/" -name "*leptonica*" -exec dirname {} \; -quit)/../../../../
74-
find "$leptonica" -name "*.h" -exec cp "{}" headers/leptonica/ \;
145+
- name: Dependencies - Windows 32
146+
if: matrix.config.name == 'Windows 32'
147+
uses: msys2/setup-msys2@v2
148+
with:
149+
msystem: MINGW32
150+
install: mingw-w64-i686-gcc mingw-w64-i686-make mingw-w64-i686-cmake
151+
update: false
75152

76-
# Delete crap that causes linking errors
77-
rm libs/*xxHash*
78-
rm libs/*boost.thread*
153+
- name: Download Tesseract
154+
if: steps.cache.outputs.cache-hit != 'true'
155+
uses: actions/[email protected]
156+
with:
157+
repository: tesseract-ocr/tesseract
158+
path: tesseract
159+
160+
- name: Download sw
161+
if: steps.cache.outputs.cache-hit != 'true'
162+
uses: egorpugin/sw-action@master
79163

164+
- name: Build Tesseract
165+
working-directory: tesseract
166+
shell: msys2 {0}
167+
if: steps.cache.outputs.cache-hit != 'true'
168+
run: |
169+
mv -f ../sw.cpp sw.cpp
170+
../sw ${{ matrix.config.sw_args }} -storage-dir=storage -static -static-dependencies -config r build
171+
172+
- name: Find
173+
shell: python
174+
run: |
175+
import os
176+
from pathlib import Path
177+
from distutils.file_util import copy_file
178+
179+
libs = ['leptonica', 'zstd', 'png', 'jpeg', 'zlib', 'jbig', 'tiff', 'openjpeg' ,'webp', 'libtesseract', 'lzma', 'gif']
180+
181+
os.makedirs('libs', exist_ok=True)
182+
os.makedirs('headers/tesseract', exist_ok=True)
183+
184+
for filename in list(Path('tesseract').glob('**/*.lib')):
185+
for lib in libs:
186+
if lib in str(filename):
187+
copy_file(filename, os.path.join('libs', os.path.basename(filename)))
188+
189+
for filename in list(Path('tesseract').glob('**/include/tesseract/*.h')) + list(Path('tesseract').glob('**/tesseract/version.h')):
190+
copy_file(filename, os.path.join('headers/tesseract', os.path.basename(filename)))
191+
192+
for filename in list(Path('libs').glob('**/*')) + list(Path('headers').glob('**/*')):
193+
print(filename)
194+
80195
- name: Build Plugin
81196
continue-on-error: true
197+
shell: msys2 {0}
82198
run: |
83199
cmake -S . ${{ matrix.config.cmake_args }}
84-
cmake --build . --config Release
85-
find . -name libtesseract.binary -exec cp "{}" ${{ matrix.config.output }} \;
86-
87-
- uses: actions/[email protected]
200+
cmake --build . --config Release
201+
202+
- uses: actions/[email protected]
88203
with:
89204
path: ${{ matrix.config.output }}

CMakeLists.txt

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,30 @@
1-
cmake_minimum_required(VERSION 3.15)
2-
project(Tesseract DESCRIPTION "tesseract")
1+
cmake_minimum_required(VERSION 3.2)
2+
project(Tesseract DESCRIPTION "libtesseract")
33

44
SET(CMAKE_CXX_STANDARD 20)
55
SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimum OS X deployment version" FORCE)
66

7-
# ----------------------------- LINKER -----------------------------
8-
9-
file(
10-
GLOB TESSERACT_LIBRARIES
7+
file(GLOB TESSERACT_LIBRARIES
118
"libs/*.a"
129
"libs/*.lib"
1310
)
1411

15-
IF(WIN32)
16-
set(EXTRA_LIBRARIES
17-
user32
18-
advapi32
19-
)
20-
ELSE()
21-
set(EXTRA_LIBRARIES
22-
pthread
23-
)
24-
ENDIF()
25-
26-
# ----------------------------- SOURCES -----------------------------
27-
28-
set(SOURCE_LIST
29-
main.cpp
30-
exports.cpp
31-
)
12+
add_library(${PROJECT_NAME} SHARED main.cpp exports.cpp)
3213

33-
set(INCLUDE_DIRECTORIES
34-
headers
35-
)
36-
37-
# ---------------------------- COMPILE ----------------------------
38-
39-
add_library(${PROJECT_NAME} SHARED ${SOURCE_LIST})
40-
41-
target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIRECTORIES})
14+
target_include_directories(${PROJECT_NAME} PRIVATE headers)
4215

4316
IF(WIN32)
44-
target_compile_options(${PROJECT_NAME} PRIVATE /MT)
45-
target_link_libraries(${PROJECT_NAME} ${TESSERACT_LIBRARIES} ${EXTRA_LIBRARIES})
17+
target_link_libraries(${PROJECT_NAME} -static -static-libgcc -static-libstdc++ -Wl,--whole-archive -Wl,--export-all-symbols ${TESSERACT_LIBRARIES} -Wl,--no-whole-archive ws2_32)
4618
ELSEIF(APPLE)
47-
target_compile_options(${PROJECT_NAME} PRIVATE -O3 -fvisibility=hidden)
48-
target_link_options(${PROJECT_NAME} PRIVATE -s)
49-
target_link_libraries(${PROJECT_NAME} ${TESSERACT_LIBRARIES} ${EXTRA_LIBRARIES})
19+
target_link_libraries(${PROJECT_NAME} -static -force_load ${TESSERACT_LIBRARIES} pthread)
5020
ELSE()
51-
target_compile_options(${PROJECT_NAME} PRIVATE -O3 -fvisibility=hidden)
52-
target_link_options(${PROJECT_NAME} PRIVATE -s)
53-
target_link_libraries(${PROJECT_NAME} -Wl,--whole-archive ${TESSERACT_LIBRARIES} -Wl,--no-whole-archive ${EXTRA_LIBRARIES})
21+
target_link_libraries(${PROJECT_NAME} -static-libgcc -static-libstdc++ -Wl,--whole-archive ${TESSERACT_LIBRARIES} -Wl,--no-whole-archive pthread)
5422
ENDIF()
5523

56-
# ---------------------------- OUTPUT NAME ------------------------
57-
5824
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "lib")
59-
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".binary")
60-
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "tesseract")
25+
26+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
27+
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "tesseract64")
28+
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
29+
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "tesseract32")
30+
endif()

exports.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
#ifndef EXPORTS_INCLUDED
1919
#define EXPORTS_INCLUDED
2020

21+
#if defined(_WIN32) || defined(_WIN64)
22+
#include <windows.h>
23+
#endif
24+
2125
#include <tesseract/baseapi.h>
26+
#include <tesseract/capi.h>
2227

2328
#if defined(_WIN32) || defined(_WIN64)
24-
#include <windows.h>
2529
#define EXPORT __declspec(dllexport)
2630
extern HMODULE module;
2731
#else

0 commit comments

Comments
 (0)