comparison mupdf-source/thirdparty/tesseract/src/training/CMakeLists.txt @ 2:b50eed0cc0ef upstream

ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4. The directory name has changed: no version number in the expanded directory now.
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:43:07 +0200
parents
children
comparison
equal deleted inserted replaced
1:1d09e1dec1d9 2:b50eed0cc0ef
1 #
2 # tesseract
3 #
4 if(NOT ${CMAKE_VERSION} VERSION_LESS "3.12.0")
5 cmake_policy(SET CMP0074 NEW)
6 endif()
7
8 if(UNIX AND NOT ANDROID)
9 set(LIB_pthread pthread)
10 endif()
11
12 if(SW_BUILD)
13 set(ICU_FOUND 1)
14 else() # NOT SW_BUILD
15 find_package(PkgConfig)
16 endif()
17
18 # experimental
19 # If PkgConfig is not present training tools will not be build,
20 # so it does not make sense to set ICU.
21 if(MSVC
22 AND PKG_CONFIG_FOUND
23 AND NOT SW_BUILD
24 AND NOT USE_SYSTEM_ICU)
25 include(CheckTypeSize)
26 check_type_size("void *" SIZEOF_VOID_P)
27
28 if(SIZEOF_VOID_P EQUAL 8)
29 set(X64 1)
30 set(ARCH_NAME 64)
31 elseif(SIZEOF_VOID_P EQUAL 4)
32 set(X86 1)
33 set(ARCH_NAME 32)
34 else()
35 message(FATAL_ERROR "Cannot determine target architecture")
36 endif()
37
38 set(ICU_DIR "${CMAKE_CURRENT_BINARY_DIR}/icu")
39 set(ICU_ARCHIVE "${ICU_DIR}/icu${ARCH_NAME}.zip")
40
41 if(X86)
42 set(ICU_HASH 45167a240b60e36b59a87eda23490ce4)
43 else()
44 set(ICU_HASH 480c72491576c048de1218c3c5519399)
45 endif()
46
47 message(STATUS "Downloading latest ICU binaries")
48 set(COMPILER "msvc10")
49 set(ICU_URL "https://github.com/unicode-org/icu/releases/download")
50 set(ICU_R "56-1")
51 set(ICU_V "56_1")
52 file(
53 DOWNLOAD
54 "${ICU_URL}/release-${ICU_R}/icu4c-${ICU_V}-Win${ARCH_NAME}-${COMPILER}.zip"
55 "${ICU_ARCHIVE}"
56 SHOW_PROGRESS
57 INACTIVITY_TIMEOUT 300 # seconds
58 EXPECTED_HASH MD5=${ICU_HASH})
59 execute_process(
60 COMMAND ${CMAKE_COMMAND} -E tar xz "${ICU_ARCHIVE}"
61 WORKING_DIRECTORY "${ICU_DIR}"
62 RESULT_VARIABLE __result)
63 if(NOT __result EQUAL 0)
64 message(FATAL_ERROR "error ${__result}")
65 endif()
66
67 set(ICU_ROOT ${ICU_DIR}/icu)
68 endif()
69 # experimental
70
71 if(NOT SW_BUILD)
72 if(PKG_CONFIG_FOUND)
73 pkg_check_modules(ICU REQUIRED IMPORTED_TARGET icu-uc icu-i18n)
74 else()
75 find_package(ICU 52.1 COMPONENTS uc i18n)
76 endif()
77 if(ICU_FOUND)
78 message(">> ICU_FOUND ${ICU_FOUND} ${ICU_VERSION} ${ICU_LIBRARIES} ${ICU_INCLUDE_DIRS}")
79 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ICU_CXX_FLAGS}")
80 else()
81 message(">> ICU not found!")
82 endif()
83 endif()
84
85
86 # ##############################################################################
87 # LIBRARY common_training
88 # ##############################################################################
89
90 set(COMMON_TRAINING_SRC
91 common/commandlineflags.cpp
92 common/commandlineflags.h
93 common/commontraining.cpp
94 common/commontraining.h
95 common/ctc.cpp
96 common/ctc.h
97 common/networkbuilder.cpp
98 common/networkbuilder.h)
99
100 if(NOT DISABLED_LEGACY_ENGINE)
101 list(
102 APPEND
103 COMMON_TRAINING_SRC
104 common/errorcounter.cpp
105 common/errorcounter.h
106 common/intfeaturedist.cpp
107 common/intfeaturedist.h
108 common/intfeaturemap.cpp
109 common/intfeaturemap.h
110 common/mastertrainer.cpp
111 common/mastertrainer.h
112 common/sampleiterator.cpp
113 common/sampleiterator.h
114 common/trainingsampleset.cpp
115 common/trainingsampleset.h)
116 endif()
117
118 add_library(common_training ${COMMON_TRAINING_SRC})
119 target_include_directories(common_training PUBLIC common
120 ${CMAKE_CURRENT_BINARY_DIR})
121 target_link_libraries(common_training PUBLIC libtesseract)
122 install(
123 TARGETS common_training
124 RUNTIME DESTINATION bin
125 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
126 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
127 generate_export_header(common_training EXPORT_MACRO_NAME
128 TESS_COMMON_TRAINING_API)
129 if (MSVC AND BUILD_SHARED_LIBS)
130 install(FILES $<TARGET_PDB_FILE:common_training> DESTINATION bin OPTIONAL)
131 endif()
132 project_group(common_training "Training Tools")
133
134 # ##############################################################################
135 # EXECUTABLE ambiguous_words
136 # ##############################################################################
137
138 if(NOT DISABLED_LEGACY_ENGINE)
139 add_executable(ambiguous_words ambiguous_words.cpp)
140 target_link_libraries(ambiguous_words common_training)
141 project_group(ambiguous_words "Training Tools")
142 install(
143 TARGETS ambiguous_words
144 RUNTIME DESTINATION bin
145 LIBRARY DESTINATION lib
146 ARCHIVE DESTINATION lib)
147 if (MSVC)
148 install(FILES $<TARGET_PDB_FILE:ambiguous_words> DESTINATION bin OPTIONAL)
149 endif()
150 endif()
151
152 # ##############################################################################
153 # EXECUTABLE classifier_tester
154 # ##############################################################################
155
156 if(NOT DISABLED_LEGACY_ENGINE)
157 add_executable(classifier_tester classifier_tester.cpp)
158 target_link_libraries(classifier_tester common_training)
159 project_group(classifier_tester "Training Tools")
160 install(
161 TARGETS classifier_tester
162 RUNTIME DESTINATION bin
163 LIBRARY DESTINATION lib
164 ARCHIVE DESTINATION lib)
165 if (MSVC)
166 install(FILES $<TARGET_PDB_FILE:classifier_tester> DESTINATION bin OPTIONAL)
167 endif()
168 endif()
169
170 # ##############################################################################
171 # EXECUTABLE combine_tessdata
172 # ##############################################################################
173
174 add_executable(combine_tessdata combine_tessdata.cpp)
175 target_link_libraries(combine_tessdata common_training)
176 project_group(combine_tessdata "Training Tools")
177 install(
178 TARGETS combine_tessdata
179 RUNTIME DESTINATION bin
180 LIBRARY DESTINATION lib
181 ARCHIVE DESTINATION lib)
182 if (MSVC)
183 install(FILES $<TARGET_PDB_FILE:combine_tessdata> DESTINATION bin OPTIONAL)
184 endif()
185
186 # ##############################################################################
187 # EXECUTABLE cntraining
188 # ##############################################################################
189
190 if(NOT DISABLED_LEGACY_ENGINE)
191 add_executable(cntraining cntraining.cpp)
192 target_link_libraries(cntraining common_training)
193 project_group(cntraining "Training Tools")
194 install(
195 TARGETS cntraining
196 RUNTIME DESTINATION bin
197 LIBRARY DESTINATION lib
198 ARCHIVE DESTINATION lib)
199 if (MSVC)
200 install(FILES $<TARGET_PDB_FILE:cntraining> DESTINATION bin OPTIONAL)
201 endif()
202 endif()
203
204 # ##############################################################################
205 # EXECUTABLE dawg2wordlist
206 # ##############################################################################
207
208 add_executable(dawg2wordlist dawg2wordlist.cpp)
209 target_link_libraries(dawg2wordlist common_training)
210 project_group(dawg2wordlist "Training Tools")
211 install(
212 TARGETS dawg2wordlist
213 RUNTIME DESTINATION bin
214 LIBRARY DESTINATION lib
215 ARCHIVE DESTINATION lib)
216 if (MSVC)
217 install(FILES $<TARGET_PDB_FILE:dawg2wordlist> DESTINATION bin OPTIONAL)
218 endif()
219
220 # ##############################################################################
221 # EXECUTABLE mftraining
222 # ##############################################################################
223
224 if(NOT DISABLED_LEGACY_ENGINE)
225 add_executable(mftraining mftraining.cpp mergenf.cpp mergenf.h)
226 target_link_libraries(mftraining common_training)
227 project_group(mftraining "Training Tools")
228 install(
229 TARGETS mftraining
230 RUNTIME DESTINATION bin
231 LIBRARY DESTINATION lib
232 ARCHIVE DESTINATION lib)
233 if (MSVC)
234 install(FILES $<TARGET_PDB_FILE:mftraining> DESTINATION bin OPTIONAL)
235 endif()
236 endif()
237
238 # ##############################################################################
239 # EXECUTABLE shapeclustering
240 # ##############################################################################
241
242 if(NOT DISABLED_LEGACY_ENGINE)
243 add_executable(shapeclustering shapeclustering.cpp)
244 target_link_libraries(shapeclustering common_training)
245 project_group(shapeclustering "Training Tools")
246 install(
247 TARGETS shapeclustering
248 RUNTIME DESTINATION bin
249 LIBRARY DESTINATION lib
250 ARCHIVE DESTINATION lib)
251 if (MSVC)
252 install(FILES $<TARGET_PDB_FILE:shapeclustering> DESTINATION bin OPTIONAL)
253 endif()
254 endif()
255
256 # ##############################################################################
257 # EXECUTABLE wordlist2dawg
258 # ##############################################################################
259
260 add_executable(wordlist2dawg wordlist2dawg.cpp)
261 target_link_libraries(wordlist2dawg common_training)
262 project_group(wordlist2dawg "Training Tools")
263 install(
264 TARGETS wordlist2dawg
265 RUNTIME DESTINATION bin
266 LIBRARY DESTINATION lib
267 ARCHIVE DESTINATION lib)
268 if (MSVC)
269 install(FILES $<TARGET_PDB_FILE:wordlist2dawg> DESTINATION bin OPTIONAL)
270 endif()
271
272 if(ICU_FOUND)
273 if(NOT SW_BUILD)
274 include_directories(${ICU_INCLUDE_DIRS})
275 endif()
276
277 # ############################################################################
278 # LIBRARY unicharset_training
279 # ############################################################################
280
281 file(GLOB unicharset_training_src unicharset/*)
282
283 add_library(unicharset_training ${unicharset_training_src})
284 if(SW_BUILD)
285 target_link_libraries(unicharset_training
286 PUBLIC common_training org.sw.demo.unicode.icu.i18n)
287 else()
288 if(PKG_CONFIG_FOUND)
289 target_link_libraries(unicharset_training PUBLIC common_training PkgConfig::ICU)
290 else()
291 target_link_libraries(unicharset_training PUBLIC common_training ${ICU_LIBRARIES})
292 endif()
293 endif()
294 target_include_directories(unicharset_training
295 PUBLIC unicharset ${CMAKE_CURRENT_BINARY_DIR})
296 install(
297 TARGETS unicharset_training
298 RUNTIME DESTINATION bin
299 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
300 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
301 if (MSVC AND BUILD_SHARED_LIBS)
302 install(FILES $<TARGET_PDB_FILE:unicharset_training> DESTINATION bin OPTIONAL)
303 endif()
304 generate_export_header(unicharset_training EXPORT_MACRO_NAME
305 TESS_UNICHARSET_TRAINING_API)
306 project_group(unicharset_training "Training Tools")
307
308 # ############################################################################
309 # EXECUTABLE combine_lang_model
310 # ############################################################################
311
312 add_executable(combine_lang_model combine_lang_model.cpp)
313 target_link_libraries(combine_lang_model unicharset_training)
314 project_group(combine_lang_model "Training Tools")
315 install(
316 TARGETS combine_lang_model
317 RUNTIME DESTINATION bin
318 LIBRARY DESTINATION lib
319 ARCHIVE DESTINATION lib)
320 if (MSVC)
321 install(FILES $<TARGET_PDB_FILE:combine_lang_model> DESTINATION bin OPTIONAL)
322 endif()
323
324 # ############################################################################
325 # EXECUTABLE lstmeval
326 # ############################################################################
327
328 add_executable(lstmeval lstmeval.cpp)
329 target_link_libraries(lstmeval unicharset_training ${LIB_pthread})
330 project_group(lstmeval "Training Tools")
331 install(
332 TARGETS lstmeval
333 RUNTIME DESTINATION bin
334 LIBRARY DESTINATION lib
335 ARCHIVE DESTINATION lib)
336 if (MSVC)
337 install(FILES $<TARGET_PDB_FILE:lstmeval> DESTINATION bin OPTIONAL)
338 endif()
339
340 # ############################################################################
341 # EXECUTABLE lstmtraining
342 # ############################################################################
343
344 add_executable(lstmtraining lstmtraining.cpp)
345 target_link_libraries(lstmtraining unicharset_training ${LIB_pthread})
346 project_group(lstmtraining "Training Tools")
347 install(
348 TARGETS lstmtraining
349 RUNTIME DESTINATION bin
350 LIBRARY DESTINATION lib
351 ARCHIVE DESTINATION lib)
352 if (MSVC)
353 install(FILES $<TARGET_PDB_FILE:lstmtraining> DESTINATION bin OPTIONAL)
354 endif()
355
356 # ############################################################################
357 # EXECUTABLE merge_unicharsets
358 # ############################################################################
359
360 add_executable(merge_unicharsets merge_unicharsets.cpp)
361 target_link_libraries(merge_unicharsets common_training)
362 project_group(merge_unicharsets "Training Tools")
363 install(
364 TARGETS merge_unicharsets
365 RUNTIME DESTINATION bin
366 LIBRARY DESTINATION lib
367 ARCHIVE DESTINATION lib)
368 if (MSVC)
369 install(FILES $<TARGET_PDB_FILE:merge_unicharsets> DESTINATION bin OPTIONAL)
370 endif()
371
372 # ############################################################################
373 # EXECUTABLE set_unicharset_properties
374 # ############################################################################
375
376 add_executable(set_unicharset_properties set_unicharset_properties.cpp)
377 target_link_libraries(set_unicharset_properties unicharset_training)
378 project_group(set_unicharset_properties "Training Tools")
379 install(
380 TARGETS set_unicharset_properties
381 RUNTIME DESTINATION bin
382 LIBRARY DESTINATION lib
383 ARCHIVE DESTINATION lib)
384 if (MSVC)
385 install(FILES $<TARGET_PDB_FILE:set_unicharset_properties> DESTINATION bin OPTIONAL)
386 endif()
387
388 # ############################################################################
389 # EXECUTABLE unicharset_extractor
390 # ############################################################################
391
392 add_executable(unicharset_extractor unicharset_extractor.cpp)
393 target_compile_features(unicharset_extractor PRIVATE cxx_std_17)
394 target_link_libraries(unicharset_extractor unicharset_training)
395 project_group(unicharset_extractor "Training Tools")
396 install(
397 TARGETS unicharset_extractor
398 RUNTIME DESTINATION bin
399 LIBRARY DESTINATION lib
400 ARCHIVE DESTINATION lib)
401 if (MSVC)
402 install(FILES $<TARGET_PDB_FILE:unicharset_extractor> DESTINATION bin OPTIONAL)
403 endif()
404
405 # ############################################################################
406
407 if(PKG_CONFIG_FOUND OR SW_BUILD)
408
409 if(PKG_CONFIG_FOUND)
410 pkg_check_modules(
411 PANGO
412 REQUIRED
413 IMPORTED_TARGET
414 pango>=1.38.0
415 cairo
416 pangoft2
417 pangocairo
418 fontconfig)
419 endif()
420
421 # ##########################################################################
422 # LIBRARY pango_training
423 # ##########################################################################
424
425 file(GLOB pango_training_src pango/*)
426
427 add_library(pango_training ${pango_training_src})
428 target_link_libraries(pango_training PUBLIC unicharset_training)
429 if(SW_BUILD)
430 target_link_libraries(pango_training
431 PUBLIC org.sw.demo.gnome.pango.pangocairo)
432 else()
433 if(PKG_CONFIG_FOUND)
434 target_include_directories(pango_training BEFORE
435 PUBLIC ${PANGO_INCLUDE_DIRS})
436 target_compile_definitions(pango_training PUBLIC -DPANGO_ENABLE_ENGINE)
437 target_link_libraries(pango_training PUBLIC PkgConfig::PANGO)
438 endif()
439 endif()
440 target_include_directories(pango_training
441 PUBLIC pango ${CMAKE_CURRENT_BINARY_DIR})
442 generate_export_header(pango_training EXPORT_MACRO_NAME
443 TESS_PANGO_TRAINING_API)
444 project_group(pango_training "Training Tools")
445
446 # ##########################################################################
447 # EXECUTABLE text2image
448 # ##########################################################################
449
450 set(TEXT2IMAGE_SRC text2image.cpp degradeimage.cpp degradeimage.h)
451
452 add_executable(text2image ${TEXT2IMAGE_SRC})
453 target_link_libraries(text2image pango_training)
454 project_group(text2image "Training Tools")
455 install(
456 TARGETS text2image
457 RUNTIME DESTINATION bin
458 LIBRARY DESTINATION lib
459 ARCHIVE DESTINATION lib)
460 if (MSVC)
461 install(FILES $<TARGET_PDB_FILE:text2image> DESTINATION bin OPTIONAL)
462 endif()
463 endif()
464 endif(ICU_FOUND)
465
466 # ##############################################################################