summarylogtreecommitdiffstats
path: root/tesseract.patch
blob: 06c34625e4bc81bbbd0d18846ad39db506ec83bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
diff '--color=auto' --unified --recursive --text doccreator-git/CMakeLists.txt doccreator-git2/CMakeLists.txt
--- doccreator-git/CMakeLists.txt	2023-06-21 21:28:54.596985617 -0500
+++ doccreator-git2/CMakeLists.txt	2023-06-21 21:29:59.322704036 -0500
@@ -94,173 +94,13 @@
 
 SET(CMAKE_CXX_VISIBILITY_PRESET hidden)
 
-OPTION(BUILD_TESSERACT "Build tesseract from sources" OFF)
+include(FindPkgConfig)
 
-IF(NOT BUILD_TESSERACT)
-  FIND_PACKAGE(Tesseract QUIET)
-  #if Tesseract is found, Tesseract_TESSDATA_PARENT_DIR should be set
-  IF(NOT Tesseract_FOUND)
-    SET(BUILD_TESSERACT ON CACHE STRING "Build Leptonica/Tesseract from sources." FORCE)
-  else()
-    message(STATUS "Found Tesseract.")
-  ENDIF(NOT Tesseract_FOUND)
-ENDIF(NOT BUILD_TESSERACT)
-
-
-IF(BUILD_TESSERACT)
-  
-  message(STATUS "Will build leptonica and tesseract from sources")
-
-  IF(NOT MSVC AND NOT MINGW)
-    SET(LEPTONICA_LIBRARY "${PROJECT_BINARY_DIR}/leptonica/lib/${CMAKE_STATIC_LIBRARY_PREFIX}leptonica${CMAKE_STATIC_LIBRARY_SUFFIX}")
-    SET(TESSERACT_LIBRARY "${PROJECT_BINARY_DIR}/tesseract/lib/${CMAKE_STATIC_LIBRARY_PREFIX}libtesseract${CMAKE_STATIC_LIBRARY_SUFFIX}")
-  ELSE(NOT MSVC AND NOT MINGW)
-
-    SET(LEPTONICA_VERSION 1.74.4)
-    SET(TESSERACT_VERSION 305)
-    #TODO: these version numbers should be extracted automatically...
-
-    #set(MY_DEFINITION 
-    #  $<$<CONFIG:Debug>:definition_for_debug>
-    #  $<$<CONFIG:RelWithDebInfo>:definition_for_rel_with_debug>
-    #  $<$<CONFIG:Release>:definition_for_release> 
-    #  $<$<CONFIG:MinSizeRel>:definition_for_tight_release>
-    #  )
-    
-    #set(DEBUG_EXT "$<$<CONFIG:Debug>:d>")
-    set(DEBUG_EXT "")
-    IF(NOT CMAKE_CONFIGURATION_TYPES)
-      #mono-config, e.g., ninja
-      IF("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" OR
-         "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebugInfo")
-	set(DEBUG_EXT "d")
-      ENDIF()
-    ENDIF()
-    
-    
-
-    #SET(LEPTONICA_LIBRARY "${PROJECT_BINARY_DIR}/leptonica/lib/${CMAKE_STATIC_LIBRARY_PREFIX}lept${LEPTONICA_VERSION}${DEBUG_EXT}${CMAKE_STATIC_LIBRARY_SUFFIX}")
-    SET(LEPTONICA_LIBRARY "${PROJECT_BINARY_DIR}/leptonica/lib/${CMAKE_STATIC_LIBRARY_PREFIX}leptonica-${LEPTONICA_VERSION}${DEBUG_EXT}${CMAKE_STATIC_LIBRARY_SUFFIX}")
-    #SET(TESSERACT_LIBRARY "${PROJECT_BINARY_DIR}/tesseract/lib/${CMAKE_STATIC_LIBRARY_PREFIX}tesseract${TESSERACT_VERSION}${DEBUG_EXT}${CMAKE_STATIC_LIBRARY_SUFFIX};${PROJECT_BINARY_DIR}/tesseract/lib/${CMAKE_STATIC_LIBRARY_PREFIX}tessopt${CMAKE_STATIC_LIBRARY_SUFFIX};Ws2_32")
-    SET(TESSERACT_LIBRARY "${PROJECT_BINARY_DIR}/tesseract/lib/${CMAKE_STATIC_LIBRARY_PREFIX}tesseract${TESSERACT_VERSION}${DEBUG_EXT}${CMAKE_STATIC_LIBRARY_SUFFIX}")
-  ENDIF(NOT MSVC AND NOT MINGW)
-  
-  include(ExternalProject)
-
-  #build static library with -DSTATIC=ON
-  ExternalProject_Add(leptonica
-    URL ${PROJECT_SOURCE_DIR}/thirdparty/leptonica
-    PREFIX ${PROJECT_BINARY_DIR}/leptonica
-    CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/leptonica -DSTATIC=ON -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-    BUILD_BYPRODUCTS ${LEPTONICA_LIBRARY}
-    )
-  #The client does: #include<leptonica/allheaders.h>
-  #I had to modify leptonica CMakeLists.txt to correctly install headers, in leptonica directory
-
-  #-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} is to ensure that leptonica&tesseract are built with the same compiler than DocCreator
-  # It is for example useful on Linux, when compiled with a non-default compiler.
-  
-  
-  ExternalProject_Get_Property(leptonica binary_dir)
-  ExternalProject_Get_Property(leptonica source_dir)
-  ExternalProject_Get_Property(leptonica install_dir)
-  set(leptonica_prefix "${install_dir}")
-
-  set(Lept_INCLUDE_DIRS "${install_dir}/include;${install_dir}/include/leptonica") #(not needed to install tesseract), just later
-  set(lept_lib_dirs "${install_dir}/lib")
-
-  #library is in ${binary_dir}/src
-  #headers are in ${source_dir}/src
-
-  ADD_LIBRARY(leptonicaLib STATIC IMPORTED GLOBAL)
-  SET_TARGET_PROPERTIES(leptonicaLib PROPERTIES IMPORTED_LOCATION ${LEPTONICA_LIBRARY})
-  ADD_DEPENDENCIES(leptonicaLib leptonica)
-
-  #Tesseract is built with -std=c++11
-  #If clang is used, we ensure that libc++ is also used.
-  SET(ADDITIONAL_FLAG "")
-  IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
-    SET(ADDITIONAL_FLAG "-DCMAKE_CXX_FLAGS=-stdlib=libc++")
-  ENDIF()
-
-  ExternalProject_Add(tesseract
-    DEPENDS leptonica
-    URL ${PROJECT_SOURCE_DIR}/thirdparty/tesseract
-    PREFIX ${PROJECT_BINARY_DIR}/tesseract
-    CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DLeptonica_DIR=${install_dir}/cmake -DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/tesseract -DSTATIC=ON -DBUILD_TRAINING_TOOLS=OFF -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} ${ADDITIONAL_FLAG}
-    BUILD_BYPRODUCTS ${TESSERACT_LIBRARY}
-    )
-
-  ExternalProject_Get_Property(tesseract binary_dir)
-  ExternalProject_Get_Property(tesseract source_dir)
-  ExternalProject_Get_Property(tesseract install_dir)
-  set(tesseract_prefix "${install_dir}")
-  set(Tesseract_INCLUDE_DIRS "${install_dir}/include;${install_dir}/include/tesseract") 
-  set(tess_lib_dirs "${install_dir}/lib") 
-
-  ADD_LIBRARY(tesseractLib STATIC IMPORTED GLOBAL)
-  SET_TARGET_PROPERTIES(tesseractLib PROPERTIES IMPORTED_LOCATION ${TESSERACT_LIBRARY})
-  ADD_DEPENDENCIES(tesseractLib tesseract)
-
-  #TODO: the following libraries are already searched by leptonica.
-  # CMakeLists for leptonica should provide a way to retrieve them !
-
-  FIND_PACKAGE(ZLIB QUIET)  #ZLIB brought by PNG on linux but not on OSX 
-  IF(ZLIB_FOUND)
-    SET(OTHER_LIBS ${ZLIB_LIBRARIES})
-  ENDIF()
-
-  FIND_PACKAGE(PNG QUIET)
-  IF(PNG_FOUND)
-    SET(OTHER_LIBS "${PNG_LIBRARIES};${OTHER_LIBS}")
-  ENDIF()
-
-  FIND_PACKAGE(JPEG QUIET)
-  IF(JPEG_FOUND)
-    SET(OTHER_LIBS "${JPEG_LIBRARIES};${OTHER_LIBS}")
-  ENDIF()
-
-  FIND_PACKAGE(TIFF QUIET)
-  IF(TIFF_FOUND)
-    SET(OTHER_LIBS "${TIFF_LIBRARIES};${OTHER_LIBS}")
-  ENDIF()
-
-  FIND_PACKAGE(GIF QUIET)
-  IF(GIF_FOUND)
-    SET(OTHER_LIBS "${GIF_LIBRARIES};${OTHER_LIBS}")
-  ENDIF()
-  
-  FIND_PACKAGE(PkgConfig QUIET)
-  IF (PKG_CONFIG_FOUND)
-    pkg_check_modules(WEBP QUIET libwebp)
-    IF(WEBP_FOUND)
-      SET(OTHER_LIBS "${WEBP_LIBRARIES};${OTHER_LIBS}")
-    ENDIF()
-    pkg_check_modules(JP2K QUIET libopenjp2)
-    IF(JP2K_FOUND)
-      SET(OTHER_LIBS "${JP2K_LIBRARIES};${OTHER_LIBS}")
-    ENDIF()
-  ENDIF()
-
-  SET(Lept_LIBRARIES "${LEPTONICA_LIBRARY};${OTHER_LIBS}")
-  SET(Tesseract_LIBRARIES ${TESSERACT_LIBRARY})
-  IF(MSVC OR MINGW)
-    SET(Tesseract_LIBRARIES "${TESSERACT_LIBRARY};Ws2_32")
-  ENDIF()
-
-  #download tessdata
-  SET(TESSDATA_URL https://github.com/tesseract-ocr/tessdata/raw/master)
-  IF(NOT EXISTS ${PROJECT_SOURCE_DIR}/thirdparty/tessdata/eng.traineddata)
-    FILE(DOWNLOAD ${TESSDATA_URL}/eng.traineddata ${PROJECT_SOURCE_DIR}/thirdparty/tessdata/eng.traineddata)
-    FILE(DOWNLOAD ${TESSDATA_URL}/fra.traineddata ${PROJECT_SOURCE_DIR}/thirdparty/tessdata/fra.traineddata)
-  ENDIF()
-  
-  #install tessdata
-  install(DIRECTORY ${PROJECT_SOURCE_DIR}/thirdparty/tessdata DESTINATION share/DocCreator)
-
-  set(Tesseract_TESSDATA_PARENT_DIR "") #empty to be found dynamically
-
-ENDIF()
+# Shared libraries
+pkg_check_modules(libraries
+	REQUIRED IMPORTED_TARGET
+		tesseract
+)
 
 OPTION(BUILD_OTHER_PROGS "Build other programs than DocCreator" OFF)
 
diff '--color=auto' --unified --recursive --text doccreator-git/software/DocCreator/CMakeLists.txt doccreator-git2/software/DocCreator/CMakeLists.txt
--- doccreator-git/software/DocCreator/CMakeLists.txt	2023-06-21 21:28:55.843018700 -0500
+++ doccreator-git2/software/DocCreator/CMakeLists.txt	2023-06-21 21:30:25.767406079 -0500
@@ -309,7 +309,7 @@
 
 ADD_LIBRARY(${LIBNAME} STATIC ${DocCreatorQ_sources} ${DocCreatorQ_headers} ${MOC_LIB})
 TARGET_INCLUDE_DIRECTORIES(${LIBNAME} PUBLIC ${FRAMEWORK_INCLUDE_DIRS} $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
-TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
+TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS} PkgConfig::libraries)
 
 ADD_EXECUTABLE(${PROGNAME} ${DocCreator_sources} ${DocCreator_headers} ${MOC} ${RCS} ${UI} ${WIN_RESOURCE_FILE})
 TARGET_INCLUDE_DIRECTORIES(${PROGNAME} PRIVATE ${FRAMEWORK_INCLUDE_DIRS} ${DOC3D_INCLUDE_DIRS} $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${Lept_INCLUDE_DIRS} ${Tesseract_INCLUDE_DIRS})
@@ -319,7 +319,7 @@
 # Cf http://www.kitware.com/blog/home/post/510
 #As CMAKE_MACOSX_RPATH is defined to 1,
 # Cmake  will automatically add an RPATH to this executable which is the absolute location of libDocCreator in the build tree.
-TARGET_LINK_LIBRARIES(${PROGNAME} ${EXTRA_LIBS} ${LIBNAME})
+TARGET_LINK_LIBRARIES(${PROGNAME} ${EXTRA_LIBS} ${LIBNAME} PkgConfig::libraries)
 #TARGET_LINK_LIBRARIES(${PROGNAME} ${ALL_LIBS})