Skip to content

Commit 56a5195

Browse files
committed
Initial CMake implementation.
1 parent 73b2898 commit 56a5195

File tree

5 files changed

+405
-0
lines changed

5 files changed

+405
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,6 @@ training/wordlist2dawg
6969
tesseract_opencl_profile_devices.dat
7070
kernel*.bin
7171

72+
# build dirs
73+
/build*
74+
/win*

CMakeLists.txt

+211
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
#
2+
# tesseract
3+
#
4+
5+
###############################################################################
6+
#
7+
# cmake settings
8+
#
9+
###############################################################################
10+
11+
cmake_minimum_required(VERSION 2.8.12)
12+
13+
# In-source builds are disabled.
14+
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
15+
message(FATAL_ERROR
16+
"CMake generation is not possible within the source directory!"
17+
"\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
18+
"\n "
19+
"\n rm CMakeCache.txt"
20+
"\n mkdir build"
21+
"\n cd build"
22+
"\n cmake .."
23+
)
24+
endif()
25+
26+
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake")
27+
28+
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
29+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}")
30+
31+
# Use solution folders.
32+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
33+
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake Targets")
34+
35+
###############################################################################
36+
#
37+
# project settings
38+
#
39+
###############################################################################
40+
41+
project(tesseract C CXX)
42+
43+
set(VERSION_MAJOR 3)
44+
set(VERSION_MINOR 05)
45+
set(VERSION_PLAIN ${VERSION_MAJOR}.${VERSION_MINOR})
46+
47+
find_package(Leptonica 1.72 REQUIRED)
48+
49+
###############################################################################
50+
#
51+
# compiler and linker
52+
#
53+
###############################################################################
54+
55+
set(LIBRARY_TYPE SHARED)
56+
if (STATIC)
57+
set(LIBRARY_TYPE)
58+
endif()
59+
60+
if (WIN32)
61+
if (MSVC)
62+
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
63+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
64+
65+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
66+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0")
67+
endif()
68+
endif()
69+
70+
###############################################################################
71+
#
72+
# configure
73+
#
74+
###############################################################################
75+
76+
set(AUTOCONFIG_SRC ${CMAKE_BINARY_DIR}/config_auto.h.in)
77+
set(AUTOCONFIG ${CMAKE_BINARY_DIR}/src/config_auto.h)
78+
79+
include(Configure)
80+
81+
configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY)
82+
83+
set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/api)
84+
85+
configure_file(
86+
${CMAKE_SOURCE_DIR}/cmake/templates/TesseractConfig-version.cmake.in
87+
${CMAKE_BINARY_DIR}/TesseractConfig-version.cmake @ONLY)
88+
configure_file(
89+
${CMAKE_SOURCE_DIR}/cmake/templates/TesseractConfig.cmake.in
90+
${CMAKE_BINARY_DIR}/TesseractConfig.cmake @ONLY)
91+
92+
###############################################################################
93+
#
94+
# build
95+
#
96+
###############################################################################
97+
98+
########################################
99+
# FUNCTION build_dir
100+
########################################
101+
function(build_dir target_name)
102+
if (${ARGC} GREATER 1)
103+
set(dir ${ARGV1})
104+
else()
105+
set(dir ${target_name})
106+
endif()
107+
file(GLOB ${dir}_src "${dir}/*.cpp")
108+
file(GLOB ${dir}_hdr "${dir}/*.h")
109+
add_library(${target_name} ${${dir}_src} ${${dir}_hdr})
110+
endfunction(build_dir)
111+
########################################
112+
113+
add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1)
114+
add_definitions(-DUSE_STD_NAMESPACE=1)
115+
add_definitions(-DWINDLLNAME="libtesseract${VERSION_MAJOR}${VERSION_MINOR}.dll")
116+
add_definitions(-DTESS_EXPORTS)
117+
118+
include_directories(${Leptonica_INCLUDE_DIRS})
119+
120+
include_directories(ccmain)
121+
include_directories(ccstruct)
122+
include_directories(ccutil)
123+
include_directories(classify)
124+
include_directories(cube)
125+
include_directories(cutil)
126+
include_directories(dict)
127+
include_directories(neural_networks/runtime)
128+
include_directories(opencl)
129+
include_directories(textord)
130+
include_directories(vs2010/port)
131+
include_directories(viewer)
132+
include_directories(wordrec)
133+
134+
########################################
135+
# LIBRARY api
136+
########################################
137+
138+
set(api_src
139+
api/baseapi.cpp
140+
api/capi.cpp
141+
api/renderer.cpp
142+
api/pdfrenderer.cpp
143+
)
144+
file(GLOB api_hdr "api/*.h")
145+
add_library(api ${api_src} ${api_hdr})
146+
147+
148+
########################################
149+
150+
########################################
151+
# LIBRARIES tesseract
152+
########################################
153+
154+
build_dir(main ccmain)
155+
build_dir(struct ccstruct)
156+
build_dir(ccutil)
157+
build_dir(classify)
158+
build_dir(cube)
159+
build_dir(cutil)
160+
build_dir(dict)
161+
build_dir(neural neural_networks/runtime)
162+
build_dir(opencl)
163+
build_dir(textord)
164+
build_dir(viewer)
165+
build_dir(port vs2010/port)
166+
build_dir(wordrec)
167+
168+
169+
########################################
170+
# LIBRARY tesseract
171+
########################################
172+
173+
add_library (tesseract ${LIBRARY_TYPE} ${tesseract_src} ${tesseract_hdr})
174+
target_link_libraries (tesseract
175+
PRIVATE
176+
main
177+
struct
178+
ccutil
179+
classify
180+
cube
181+
cutil
182+
dict
183+
neural
184+
opencl
185+
textord
186+
viewer
187+
port
188+
wordrec
189+
190+
PUBLIC
191+
${Leptonica_LIBRARIES}
192+
Ws2_32
193+
)
194+
set_target_properties (tesseract PROPERTIES OUTPUT_NAME libtesseract${VERSION_MAJOR}${VERSION_MINOR})
195+
set_target_properties (tesseract PROPERTIES DEBUG_OUTPUT_NAME libtesseract${VERSION_MAJOR}${VERSION_MINOR}d)
196+
export(TARGETS tesseract FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake)
197+
198+
199+
########################################
200+
# EXECUTABLE tesseractmain
201+
########################################
202+
203+
set(tesseractmain_src
204+
api/tesseractmain.cpp
205+
vs2010/tesseract/resource.h
206+
vs2010/tesseract/tesseract.rc
207+
)
208+
add_executable (tesseractmain ${tesseractmain_src})
209+
target_link_libraries (tesseractmain tesseract)
210+
211+
###############################################################################

cmake/Configure.cmake

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
################################################################################
2+
#
3+
# configure
4+
#
5+
################################################################################
6+
7+
########################################
8+
# FUNCTION check_includes
9+
########################################
10+
function(check_includes files)
11+
foreach(F ${${files}})
12+
set(name ${F})
13+
string(REPLACE "-" "_" name ${name})
14+
string(REPLACE "." "_" name ${name})
15+
string(REPLACE "/" "_" name ${name})
16+
string(TOUPPER ${name} name)
17+
check_include_files(${F} HAVE_${name})
18+
file(APPEND ${AUTOCONFIG_SRC} "/* Define to 1 if you have the <${F}> header file. */\n")
19+
file(APPEND ${AUTOCONFIG_SRC} "#cmakedefine HAVE_${name} 1\n")
20+
file(APPEND ${AUTOCONFIG_SRC} "\n")
21+
endforeach()
22+
endfunction(check_includes)
23+
24+
########################################
25+
# FUNCTION check_functions
26+
########################################
27+
function(check_functions functions)
28+
foreach(F ${${functions}})
29+
set(name ${F})
30+
string(TOUPPER ${name} name)
31+
check_function_exists(${F} HAVE_${name})
32+
file(APPEND ${AUTOCONFIG_SRC} "/* Define to 1 if you have the `${F}' function. */\n")
33+
file(APPEND ${AUTOCONFIG_SRC} "#cmakedefine HAVE_${name} 1\n")
34+
file(APPEND ${AUTOCONFIG_SRC} "\n")
35+
endforeach()
36+
endfunction(check_functions)
37+
38+
########################################
39+
40+
file(WRITE ${AUTOCONFIG_SRC})
41+
42+
include(CheckCSourceCompiles)
43+
include(CheckCSourceRuns)
44+
include(CheckCXXSourceCompiles)
45+
include(CheckCXXSourceRuns)
46+
include(CheckFunctionExists)
47+
include(CheckIncludeFiles)
48+
include(CheckLibraryExists)
49+
include(CheckPrototypeDefinition)
50+
include(CheckStructHasMember)
51+
include(CheckSymbolExists)
52+
include(CheckTypeSize)
53+
include(TestBigEndian)
54+
55+
set(include_files_list
56+
dlfcn.h
57+
inttypes.h
58+
memory.h
59+
stdint.h
60+
stdlib.h
61+
strings.h
62+
string.h
63+
sys/stat.h
64+
sys/types.h
65+
unistd.h
66+
67+
openjpeg-2.0/openjpeg.h
68+
openjpeg-2.1/openjpeg.h
69+
openjpeg-2.2/openjpeg.h
70+
)
71+
check_includes(include_files_list)
72+
73+
set(functions_list
74+
fmemopen
75+
)
76+
check_functions(functions_list)
77+
78+
test_big_endian(WORDS_BIGENDIAN)
79+
80+
set(STDC_HEADERS 1)
81+
82+
if (GIF_FOUND)
83+
set(HAVE_LIBGIF 1)
84+
endif()
85+
86+
if (JPEG_FOUND)
87+
set(HAVE_LIBJPEG 1)
88+
endif()
89+
90+
if (PNG_FOUND)
91+
set(HAVE_LIBPNG 1)
92+
endif()
93+
94+
if (TIFF_FOUND)
95+
set(HAVE_LIBTIFF 1)
96+
endif()
97+
98+
if (ZLIB_FOUND)
99+
set(HAVE_LIBZ 1)
100+
endif()
101+
102+
file(APPEND ${AUTOCONFIG_SRC} "
103+
/* Define to 1 if you have the ANSI C header files. */
104+
#cmakedefine STDC_HEADERS 1
105+
106+
/* Define to 1 if you have giflib. */
107+
#cmakedefine HAVE_LIBGIF 1
108+
109+
/* Define to 1 if you have libopenjp2. */
110+
#cmakedefine HAVE_LIBJP2K 1
111+
112+
/* Define to 1 if you have jpeg. */
113+
#cmakedefine HAVE_LIBJPEG 1
114+
115+
/* Define to 1 if you have libpng. */
116+
#cmakedefine HAVE_LIBPNG 1
117+
118+
/* Define to 1 if you have libtiff. */
119+
#cmakedefine HAVE_LIBTIFF 1
120+
121+
/* Define to 1 if you have libwebp. */
122+
#cmakedefine HAVE_LIBWEBP 1
123+
124+
/* Define to 1 if you have zlib. */
125+
#cmakedefine HAVE_LIBZ 1
126+
127+
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
128+
significant byte first (like Motorola and SPARC, unlike Intel). */
129+
#cmakedefine WORDS_BIGENDIAN 1
130+
")
131+
132+
########################################
133+
134+
################################################################################
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
set(Tesseract_VERSION @VERSION_PLAIN@)
2+
set(PACKAGE_VERSION ${Tesseract_VERSION})
3+
4+
set(PACKAGE_VERSION_EXACT False)
5+
set(PACKAGE_VERSION_COMPATIBLE False)
6+
7+
if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
8+
set(PACKAGE_VERSION_EXACT True)
9+
set(PACKAGE_VERSION_COMPATIBLE True)
10+
endif()
11+
12+
if(PACKAGE_FIND_VERSION VERSION_LESS PACKAGE_VERSION)
13+
set(PACKAGE_VERSION_COMPATIBLE True)
14+
endif()

0 commit comments

Comments
 (0)