Skip to content

Commit 442b5b7

Browse files
committed
Fix building of training tools in shared configuration.
1 parent fc13f96 commit 442b5b7

File tree

8 files changed

+86
-59
lines changed

8 files changed

+86
-59
lines changed

CMakeLists.txt

+12-3
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,15 @@ if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.cppan)
5454
find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
5555
endif()
5656
else()
57+
if (STATIC)
58+
set(CPPAN_BUILD_SHARED_LIBS 0)
59+
else()
60+
set(CPPAN_BUILD_SHARED_LIBS 1)
61+
endif()
5762
add_subdirectory(.cppan)
5863
endif()
5964

6065
find_package(OpenCL QUIET)
61-
find_package(PkgConfig)
6266

6367
###############################################################################
6468
#
@@ -203,7 +207,11 @@ set(tesseract_src ${tesseract_src}
203207

204208
add_library (tesseract ${LIBRARY_TYPE} ${tesseract_src} ${tesseract_hdr})
205209
if (NOT STATIC)
206-
target_compile_definitions (tesseract PUBLIC -DTESS_EXPORTS)
210+
target_compile_definitions (tesseract
211+
PRIVATE -DTESS_EXPORTS
212+
INTERFACE -DTESS_IMPORTS
213+
)
214+
set_target_properties (tesseract PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS True)
207215
endif()
208216
target_link_libraries (tesseract ${LIB_Ws2_32} ${LIB_pthread})
209217
set_target_properties (tesseract PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR_0}.${VERSION_MINOR_1})
@@ -217,7 +225,8 @@ if (NOT CPPAN_BUILD)
217225
target_link_libraries (tesseract ${Leptonica_LIBRARIES})
218226
export(TARGETS tesseract FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake)
219227
else()
220-
target_link_libraries (tesseract cppan)
228+
target_link_libraries (tesseract pvt.cppan.demo.leptonica)
229+
add_dependencies (tesseract cppan)
221230
file(WRITE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake "include(${CMAKE_BINARY_DIR}/cppan.cmake)\n")
222231
export(TARGETS tesseract APPEND FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake)
223232
endif()

ccutil/unicharset.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class UNICHARSET {
141141
// Custom list of characters and their ligature forms (UTF8)
142142
// These map to unicode values in the private use area (PUC) and are supported
143143
// by only few font families (eg. Wyld, Adobe Caslon Pro).
144-
static const char* kCustomLigatures[][2];
144+
static TESS_API const char* kCustomLigatures[][2];
145145

146146
// List of strings for the SpecialUnicharCodes. Keep in sync with the enum.
147147
static const char* kSpecialUnicharCodes[SPECIAL_UNICHAR_CODES_COUNT];

classify/featdefs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int ShortNameToFeatureType(const FEATURE_DEFS_STRUCT &FeatureDefs,
7777
Global Data Definitions and Declarations
7878
----------------------------------------------------------------------------**/
7979
extern const FEATURE_DESC_STRUCT MicroFeatureDesc;
80-
extern const FEATURE_DESC_STRUCT PicoFeatDesc;
80+
extern TESS_API const FEATURE_DESC_STRUCT PicoFeatDesc;
8181
extern const FEATURE_DESC_STRUCT CharNormDesc;
8282
extern const FEATURE_DESC_STRUCT OutlineFeatDesc;
8383
extern const FEATURE_DESC_STRUCT IntFeatDesc;

classify/picofeat.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ extern double_VAR_H(classify_pico_feature_length, 0.05, "Pico Feature Length");
6161
/**----------------------------------------------------------------------------
6262
Global Data Definitions and Declarations
6363
----------------------------------------------------------------------------**/
64-
extern FLOAT32 PicoFeatureLength;
64+
extern TESS_API FLOAT32 PicoFeatureLength;
6565
#endif

cppan.yml

+9-5
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,14 @@ options:
122122
- WINDLLNAME="tesseract"
123123
shared:
124124
definitions:
125-
public: TESS_EXPORTS
125+
private:
126+
- TESS_EXPORTS
127+
interface:
128+
- TESS_IMPORTS
126129

127130
dependencies:
128-
private:
129-
# tesseract uses leptonica only internally
130-
# and does not expose its interface to users
131-
pvt.cppan.demo.leptonica: master
131+
private:
132+
pvt.cppan.demo.leptonica: master
133+
# only for training tools, move to them later
134+
pvt.cppan.demo.unicode.icu.i18n: "*"
135+

dict/trie.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ class Trie : public Dawg {
402402
EDGE_VECTOR* backward_edges,
403403
NODE_MARKER reduced_nodes);
404404

405-
/**
405+
/**
406406
* Order num_edges of consequtive EDGE_RECORDS in the given EDGE_VECTOR in
407407
* increasing order of unichar ids. This function is normally called
408408
* for all edges in a single node, and since number of edges in each node

training/CMakeLists.txt

+59-44
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,62 @@
22
# tesseract
33
#
44

5-
if (STATIC OR NOT (WIN32 OR CYGWIN))
6-
7-
# experimental
8-
if (MSVC)
9-
10-
include(CheckTypeSize)
11-
check_type_size("void *" SIZEOF_VOID_P)
12-
13-
if (SIZEOF_VOID_P EQUAL 8)
14-
set(X64 1)
15-
set(ARCH_DIR_NAME 64)
16-
elseif (SIZEOF_VOID_P EQUAL 4)
17-
set(X86 1)
18-
set(ARCH_DIR_NAME 32)
19-
else()
20-
message(FATAL_ERROR "Cannot determine target architecture")
5+
if (NOT CPPAN_BUILD AND NOT (WIN32 OR CYGWIN))
6+
return()
217
endif()
228

23-
set(icu_dir "${CMAKE_CURRENT_BINARY_DIR}/icu")
24-
set(icu_archive "${icu_dir}/icu${ARCH_DIR_NAME}.zip")
25-
26-
if (X86)
27-
set(icu_hash 45167a240b60e36b59a87eda23490ce4)
28-
else()
29-
set(icu_hash 480c72491576c048de1218c3c5519399)
9+
if (CPPAN_BUILD)
10+
set(ICU_FOUND 1)
3011
endif()
3112

32-
message(STATUS "Downloading latest ICU binaries")
33-
34-
file(DOWNLOAD
35-
"http://download.icu-project.org/files/icu4c/56.1/icu4c-56_1-Win${ARCH_DIR_NAME}-msvc10.zip"
36-
"${icu_archive}"
37-
SHOW_PROGRESS
38-
INACTIVITY_TIMEOUT 60 # seconds
39-
EXPECTED_HASH MD5=${icu_hash}
40-
)
41-
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xz "${icu_archive}"
42-
WORKING_DIRECTORY "${icu_dir}"
43-
RESULT_VARIABLE __result
44-
)
45-
if(NOT __result EQUAL 0)
46-
message(FATAL_ERROR "error ${__result}")
13+
# experimental
14+
if (MSVC AND NOT CPPAN_BUILD)
15+
include(CheckTypeSize)
16+
check_type_size("void *" SIZEOF_VOID_P)
17+
18+
if (SIZEOF_VOID_P EQUAL 8)
19+
set(X64 1)
20+
set(ARCH_DIR_NAME 64)
21+
elseif (SIZEOF_VOID_P EQUAL 4)
22+
set(X86 1)
23+
set(ARCH_DIR_NAME 32)
24+
else()
25+
message(FATAL_ERROR "Cannot determine target architecture")
26+
endif()
27+
28+
set(icu_dir "${CMAKE_CURRENT_BINARY_DIR}/icu")
29+
set(icu_archive "${icu_dir}/icu${ARCH_DIR_NAME}.zip")
30+
31+
if (X86)
32+
set(icu_hash 45167a240b60e36b59a87eda23490ce4)
33+
else()
34+
set(icu_hash 480c72491576c048de1218c3c5519399)
35+
endif()
36+
37+
message(STATUS "Downloading latest ICU binaries")
38+
39+
file(DOWNLOAD
40+
"http://download.icu-project.org/files/icu4c/56.1/icu4c-56_1-Win${ARCH_DIR_NAME}-msvc10.zip"
41+
"${icu_archive}"
42+
SHOW_PROGRESS
43+
INACTIVITY_TIMEOUT 60 # seconds
44+
EXPECTED_HASH MD5=${icu_hash}
45+
)
46+
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xz "${icu_archive}"
47+
WORKING_DIRECTORY "${icu_dir}"
48+
RESULT_VARIABLE __result
49+
)
50+
if(NOT __result EQUAL 0)
51+
message(FATAL_ERROR "error ${__result}")
52+
endif()
53+
54+
set(ICU_ROOT ${icu_dir}/icu)
4755
endif()
48-
49-
set(ICU_ROOT ${icu_dir}/icu)
50-
51-
endif(MSVC)
5256
# experimental
5357

58+
if (NOT CPPAN_BUILD)
5459
find_package(ICU COMPONENTS uc i18n)
60+
endif()
5561

5662
########################################
5763
# LIBRARY tessopt
@@ -159,7 +165,9 @@ project_group (wordlist2dawg "Training Tools")
159165

160166
if (ICU_FOUND)
161167

168+
if (NOT CPPAN_BUILD)
162169
include_directories(${ICU_INCLUDE_DIRS})
170+
endif()
163171

164172
########################################
165173
# LIBRARY unicharset_training
@@ -177,7 +185,11 @@ set(unicharset_training_src
177185
unicharset_training_utils.h
178186
)
179187
add_library (unicharset_training ${unicharset_training_src})
188+
if (NOT CPPAN_BUILD)
180189
target_link_libraries (unicharset_training common_training ${ICU_LIBRARIES})
190+
else()
191+
target_link_libraries (unicharset_training common_training pvt.cppan.demo.unicode.icu.i18n)
192+
endif()
181193
project_group (unicharset_training "Training Tools")
182194

183195

@@ -198,6 +210,7 @@ add_executable (lstmtraining lstmtraining.cpp)
198210
target_link_libraries (lstmtraining unicharset_training)
199211
project_group (lstmtraining "Training Tools")
200212

213+
201214
########################################
202215
# EXECUTABLE set_unicharset_properties
203216
########################################
@@ -211,6 +224,10 @@ project_group (set_unicharset_properties "Training Tools")
211224
# EXECUTABLE text2image
212225
########################################
213226

227+
if (NOT CPPAN_BUILD)
228+
find_package(PkgConfig)
229+
endif()
230+
214231
if (PKG_CONFIG_FOUND)
215232

216233
pkg_check_modules(Pango REQUIRED pango)
@@ -246,7 +263,6 @@ add_executable (text2image ${text2image_src})
246263
target_include_directories (text2image BEFORE PRIVATE ${Cairo_INCLUDE_DIRS} ${Pango_INCLUDE_DIRS})
247264
target_compile_definitions (text2image PRIVATE -DPANGO_ENABLE_ENGINE)
248265
target_link_libraries (text2image tesseract unicharset_training
249-
${ICU_LIBRARIES}
250266
${Pango_LIBRARIES}
251267
${Cairo_LIBRARIES}
252268
${PangoCairo_LIBRARIES}
@@ -257,6 +273,5 @@ project_group (text2image "Training Tools")
257273

258274
endif(PKG_CONFIG_FOUND)
259275
endif(ICU_FOUND)
260-
endif(STATIC OR NOT (WIN32 OR CYGWIN))
261276

262277
###############################################################################

training/mergenf.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <string.h>
3434
#include <math.h>
3535

36-
3736
/*-------------------once in subfeat---------------------------------*/
3837
double_VAR(training_angle_match_scale, 1.0, "Angle Match Scale ...");
3938

@@ -199,9 +198,9 @@ int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[],
199198
*
200199
* @param New new proto to be filled in
201200
* @param Old old proto to be converted
202-
*
201+
*
203202
* Globals: none
204-
*
203+
*
205204
* Exceptions: none
206205
* History: Mon Nov 26 09:45:39 1990, DSJ, Created.
207206
*/

0 commit comments

Comments
 (0)