mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-18 14:41:36 +08:00
Initial CMake implementation.
This commit is contained in:
parent
73b28982aa
commit
56a5195293
3
.gitignore
vendored
3
.gitignore
vendored
@ -69,3 +69,6 @@ training/wordlist2dawg
|
|||||||
tesseract_opencl_profile_devices.dat
|
tesseract_opencl_profile_devices.dat
|
||||||
kernel*.bin
|
kernel*.bin
|
||||||
|
|
||||||
|
# build dirs
|
||||||
|
/build*
|
||||||
|
/win*
|
211
CMakeLists.txt
Normal file
211
CMakeLists.txt
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
#
|
||||||
|
# tesseract
|
||||||
|
#
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# cmake settings
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 2.8.12)
|
||||||
|
|
||||||
|
# In-source builds are disabled.
|
||||||
|
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"CMake generation is not possible within the source directory!"
|
||||||
|
"\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
|
||||||
|
"\n "
|
||||||
|
"\n rm CMakeCache.txt"
|
||||||
|
"\n mkdir build"
|
||||||
|
"\n cd build"
|
||||||
|
"\n cmake .."
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}")
|
||||||
|
|
||||||
|
# Use solution folders.
|
||||||
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||||
|
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake Targets")
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# project settings
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
project(tesseract C CXX)
|
||||||
|
|
||||||
|
set(VERSION_MAJOR 3)
|
||||||
|
set(VERSION_MINOR 05)
|
||||||
|
set(VERSION_PLAIN ${VERSION_MAJOR}.${VERSION_MINOR})
|
||||||
|
|
||||||
|
find_package(Leptonica 1.72 REQUIRED)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# compiler and linker
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
set(LIBRARY_TYPE SHARED)
|
||||||
|
if (STATIC)
|
||||||
|
set(LIBRARY_TYPE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
if (MSVC)
|
||||||
|
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
|
||||||
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# configure
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
set(AUTOCONFIG_SRC ${CMAKE_BINARY_DIR}/config_auto.h.in)
|
||||||
|
set(AUTOCONFIG ${CMAKE_BINARY_DIR}/src/config_auto.h)
|
||||||
|
|
||||||
|
include(Configure)
|
||||||
|
|
||||||
|
configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY)
|
||||||
|
|
||||||
|
set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/api)
|
||||||
|
|
||||||
|
configure_file(
|
||||||
|
${CMAKE_SOURCE_DIR}/cmake/templates/TesseractConfig-version.cmake.in
|
||||||
|
${CMAKE_BINARY_DIR}/TesseractConfig-version.cmake @ONLY)
|
||||||
|
configure_file(
|
||||||
|
${CMAKE_SOURCE_DIR}/cmake/templates/TesseractConfig.cmake.in
|
||||||
|
${CMAKE_BINARY_DIR}/TesseractConfig.cmake @ONLY)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# build
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
########################################
|
||||||
|
# FUNCTION build_dir
|
||||||
|
########################################
|
||||||
|
function(build_dir target_name)
|
||||||
|
if (${ARGC} GREATER 1)
|
||||||
|
set(dir ${ARGV1})
|
||||||
|
else()
|
||||||
|
set(dir ${target_name})
|
||||||
|
endif()
|
||||||
|
file(GLOB ${dir}_src "${dir}/*.cpp")
|
||||||
|
file(GLOB ${dir}_hdr "${dir}/*.h")
|
||||||
|
add_library(${target_name} ${${dir}_src} ${${dir}_hdr})
|
||||||
|
endfunction(build_dir)
|
||||||
|
########################################
|
||||||
|
|
||||||
|
add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1)
|
||||||
|
add_definitions(-DUSE_STD_NAMESPACE=1)
|
||||||
|
add_definitions(-DWINDLLNAME="libtesseract${VERSION_MAJOR}${VERSION_MINOR}.dll")
|
||||||
|
add_definitions(-DTESS_EXPORTS)
|
||||||
|
|
||||||
|
include_directories(${Leptonica_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
include_directories(ccmain)
|
||||||
|
include_directories(ccstruct)
|
||||||
|
include_directories(ccutil)
|
||||||
|
include_directories(classify)
|
||||||
|
include_directories(cube)
|
||||||
|
include_directories(cutil)
|
||||||
|
include_directories(dict)
|
||||||
|
include_directories(neural_networks/runtime)
|
||||||
|
include_directories(opencl)
|
||||||
|
include_directories(textord)
|
||||||
|
include_directories(vs2010/port)
|
||||||
|
include_directories(viewer)
|
||||||
|
include_directories(wordrec)
|
||||||
|
|
||||||
|
########################################
|
||||||
|
# LIBRARY api
|
||||||
|
########################################
|
||||||
|
|
||||||
|
set(api_src
|
||||||
|
api/baseapi.cpp
|
||||||
|
api/capi.cpp
|
||||||
|
api/renderer.cpp
|
||||||
|
api/pdfrenderer.cpp
|
||||||
|
)
|
||||||
|
file(GLOB api_hdr "api/*.h")
|
||||||
|
add_library(api ${api_src} ${api_hdr})
|
||||||
|
|
||||||
|
|
||||||
|
########################################
|
||||||
|
|
||||||
|
########################################
|
||||||
|
# LIBRARIES tesseract
|
||||||
|
########################################
|
||||||
|
|
||||||
|
build_dir(main ccmain)
|
||||||
|
build_dir(struct ccstruct)
|
||||||
|
build_dir(ccutil)
|
||||||
|
build_dir(classify)
|
||||||
|
build_dir(cube)
|
||||||
|
build_dir(cutil)
|
||||||
|
build_dir(dict)
|
||||||
|
build_dir(neural neural_networks/runtime)
|
||||||
|
build_dir(opencl)
|
||||||
|
build_dir(textord)
|
||||||
|
build_dir(viewer)
|
||||||
|
build_dir(port vs2010/port)
|
||||||
|
build_dir(wordrec)
|
||||||
|
|
||||||
|
|
||||||
|
########################################
|
||||||
|
# LIBRARY tesseract
|
||||||
|
########################################
|
||||||
|
|
||||||
|
add_library (tesseract ${LIBRARY_TYPE} ${tesseract_src} ${tesseract_hdr})
|
||||||
|
target_link_libraries (tesseract
|
||||||
|
PRIVATE
|
||||||
|
main
|
||||||
|
struct
|
||||||
|
ccutil
|
||||||
|
classify
|
||||||
|
cube
|
||||||
|
cutil
|
||||||
|
dict
|
||||||
|
neural
|
||||||
|
opencl
|
||||||
|
textord
|
||||||
|
viewer
|
||||||
|
port
|
||||||
|
wordrec
|
||||||
|
|
||||||
|
PUBLIC
|
||||||
|
${Leptonica_LIBRARIES}
|
||||||
|
Ws2_32
|
||||||
|
)
|
||||||
|
set_target_properties (tesseract PROPERTIES OUTPUT_NAME libtesseract${VERSION_MAJOR}${VERSION_MINOR})
|
||||||
|
set_target_properties (tesseract PROPERTIES DEBUG_OUTPUT_NAME libtesseract${VERSION_MAJOR}${VERSION_MINOR}d)
|
||||||
|
export(TARGETS tesseract FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake)
|
||||||
|
|
||||||
|
|
||||||
|
########################################
|
||||||
|
# EXECUTABLE tesseractmain
|
||||||
|
########################################
|
||||||
|
|
||||||
|
set(tesseractmain_src
|
||||||
|
api/tesseractmain.cpp
|
||||||
|
vs2010/tesseract/resource.h
|
||||||
|
vs2010/tesseract/tesseract.rc
|
||||||
|
)
|
||||||
|
add_executable (tesseractmain ${tesseractmain_src})
|
||||||
|
target_link_libraries (tesseractmain tesseract)
|
||||||
|
|
||||||
|
###############################################################################
|
134
cmake/Configure.cmake
Normal file
134
cmake/Configure.cmake
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
################################################################################
|
||||||
|
#
|
||||||
|
# configure
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
########################################
|
||||||
|
# FUNCTION check_includes
|
||||||
|
########################################
|
||||||
|
function(check_includes files)
|
||||||
|
foreach(F ${${files}})
|
||||||
|
set(name ${F})
|
||||||
|
string(REPLACE "-" "_" name ${name})
|
||||||
|
string(REPLACE "." "_" name ${name})
|
||||||
|
string(REPLACE "/" "_" name ${name})
|
||||||
|
string(TOUPPER ${name} name)
|
||||||
|
check_include_files(${F} HAVE_${name})
|
||||||
|
file(APPEND ${AUTOCONFIG_SRC} "/* Define to 1 if you have the <${F}> header file. */\n")
|
||||||
|
file(APPEND ${AUTOCONFIG_SRC} "#cmakedefine HAVE_${name} 1\n")
|
||||||
|
file(APPEND ${AUTOCONFIG_SRC} "\n")
|
||||||
|
endforeach()
|
||||||
|
endfunction(check_includes)
|
||||||
|
|
||||||
|
########################################
|
||||||
|
# FUNCTION check_functions
|
||||||
|
########################################
|
||||||
|
function(check_functions functions)
|
||||||
|
foreach(F ${${functions}})
|
||||||
|
set(name ${F})
|
||||||
|
string(TOUPPER ${name} name)
|
||||||
|
check_function_exists(${F} HAVE_${name})
|
||||||
|
file(APPEND ${AUTOCONFIG_SRC} "/* Define to 1 if you have the `${F}' function. */\n")
|
||||||
|
file(APPEND ${AUTOCONFIG_SRC} "#cmakedefine HAVE_${name} 1\n")
|
||||||
|
file(APPEND ${AUTOCONFIG_SRC} "\n")
|
||||||
|
endforeach()
|
||||||
|
endfunction(check_functions)
|
||||||
|
|
||||||
|
########################################
|
||||||
|
|
||||||
|
file(WRITE ${AUTOCONFIG_SRC})
|
||||||
|
|
||||||
|
include(CheckCSourceCompiles)
|
||||||
|
include(CheckCSourceRuns)
|
||||||
|
include(CheckCXXSourceCompiles)
|
||||||
|
include(CheckCXXSourceRuns)
|
||||||
|
include(CheckFunctionExists)
|
||||||
|
include(CheckIncludeFiles)
|
||||||
|
include(CheckLibraryExists)
|
||||||
|
include(CheckPrototypeDefinition)
|
||||||
|
include(CheckStructHasMember)
|
||||||
|
include(CheckSymbolExists)
|
||||||
|
include(CheckTypeSize)
|
||||||
|
include(TestBigEndian)
|
||||||
|
|
||||||
|
set(include_files_list
|
||||||
|
dlfcn.h
|
||||||
|
inttypes.h
|
||||||
|
memory.h
|
||||||
|
stdint.h
|
||||||
|
stdlib.h
|
||||||
|
strings.h
|
||||||
|
string.h
|
||||||
|
sys/stat.h
|
||||||
|
sys/types.h
|
||||||
|
unistd.h
|
||||||
|
|
||||||
|
openjpeg-2.0/openjpeg.h
|
||||||
|
openjpeg-2.1/openjpeg.h
|
||||||
|
openjpeg-2.2/openjpeg.h
|
||||||
|
)
|
||||||
|
check_includes(include_files_list)
|
||||||
|
|
||||||
|
set(functions_list
|
||||||
|
fmemopen
|
||||||
|
)
|
||||||
|
check_functions(functions_list)
|
||||||
|
|
||||||
|
test_big_endian(WORDS_BIGENDIAN)
|
||||||
|
|
||||||
|
set(STDC_HEADERS 1)
|
||||||
|
|
||||||
|
if (GIF_FOUND)
|
||||||
|
set(HAVE_LIBGIF 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (JPEG_FOUND)
|
||||||
|
set(HAVE_LIBJPEG 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (PNG_FOUND)
|
||||||
|
set(HAVE_LIBPNG 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (TIFF_FOUND)
|
||||||
|
set(HAVE_LIBTIFF 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (ZLIB_FOUND)
|
||||||
|
set(HAVE_LIBZ 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
file(APPEND ${AUTOCONFIG_SRC} "
|
||||||
|
/* Define to 1 if you have the ANSI C header files. */
|
||||||
|
#cmakedefine STDC_HEADERS 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have giflib. */
|
||||||
|
#cmakedefine HAVE_LIBGIF 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have libopenjp2. */
|
||||||
|
#cmakedefine HAVE_LIBJP2K 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have jpeg. */
|
||||||
|
#cmakedefine HAVE_LIBJPEG 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have libpng. */
|
||||||
|
#cmakedefine HAVE_LIBPNG 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have libtiff. */
|
||||||
|
#cmakedefine HAVE_LIBTIFF 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have libwebp. */
|
||||||
|
#cmakedefine HAVE_LIBWEBP 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have zlib. */
|
||||||
|
#cmakedefine HAVE_LIBZ 1
|
||||||
|
|
||||||
|
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
|
||||||
|
significant byte first (like Motorola and SPARC, unlike Intel). */
|
||||||
|
#cmakedefine WORDS_BIGENDIAN 1
|
||||||
|
")
|
||||||
|
|
||||||
|
########################################
|
||||||
|
|
||||||
|
################################################################################
|
14
cmake/templates/TesseractConfig-version.cmake.in
Normal file
14
cmake/templates/TesseractConfig-version.cmake.in
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
set(Tesseract_VERSION @VERSION_PLAIN@)
|
||||||
|
set(PACKAGE_VERSION ${Tesseract_VERSION})
|
||||||
|
|
||||||
|
set(PACKAGE_VERSION_EXACT False)
|
||||||
|
set(PACKAGE_VERSION_COMPATIBLE False)
|
||||||
|
|
||||||
|
if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
|
||||||
|
set(PACKAGE_VERSION_EXACT True)
|
||||||
|
set(PACKAGE_VERSION_COMPATIBLE True)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(PACKAGE_FIND_VERSION VERSION_LESS PACKAGE_VERSION)
|
||||||
|
set(PACKAGE_VERSION_COMPATIBLE True)
|
||||||
|
endif()
|
43
cmake/templates/TesseractConfig.cmake.in
Normal file
43
cmake/templates/TesseractConfig.cmake.in
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# ===================================================================================
|
||||||
|
# The Tesseract CMake configuration file
|
||||||
|
#
|
||||||
|
# ** File generated automatically, do not modify **
|
||||||
|
#
|
||||||
|
# Usage from an external project:
|
||||||
|
# In your CMakeLists.txt, add these lines:
|
||||||
|
#
|
||||||
|
# find_package(Tesseract REQUIRED)
|
||||||
|
# include_directories(${Tesseract_INCLUDE_DIRS})
|
||||||
|
# target_link_libraries(MY_TARGET_NAME ${Tesseract_LIBRARIES})
|
||||||
|
#
|
||||||
|
# This file will define the following variables:
|
||||||
|
# - Tesseract_LIBRARIES : The list of all imported targets for OpenCV modules.
|
||||||
|
# - Tesseract_INCLUDE_DIRS : The Tesseract include directories.
|
||||||
|
# - Tesseract_VERSION : The version of this Tesseract build: "@VERSION_PLAIN@"
|
||||||
|
# - Tesseract_VERSION_MAJOR : Major version part of Tesseract_VERSION: "@VERSION_MAJOR@"
|
||||||
|
# - Tesseract_VERSION_MINOR : Minor version part of Tesseract_VERSION: "@VERSION_MINOR@"
|
||||||
|
#
|
||||||
|
# ===================================================================================
|
||||||
|
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/TesseractTargets.cmake)
|
||||||
|
|
||||||
|
# ======================================================
|
||||||
|
# Version variables:
|
||||||
|
# ======================================================
|
||||||
|
|
||||||
|
SET(Tesseract_VERSION @VERSION_PLAIN@)
|
||||||
|
SET(Tesseract_VERSION_MAJOR @VERSION_MAJOR@)
|
||||||
|
SET(Tesseract_VERSION_MINOR @VERSION_MINOR@)
|
||||||
|
|
||||||
|
# ======================================================
|
||||||
|
# Include directories to add to the user project:
|
||||||
|
# ======================================================
|
||||||
|
|
||||||
|
# Provide the include directories to the caller
|
||||||
|
set(Tesseract_INCLUDE_DIRS @INCLUDE_DIR@)
|
||||||
|
|
||||||
|
# ====================================================================
|
||||||
|
# Link libraries:
|
||||||
|
# ====================================================================
|
||||||
|
|
||||||
|
set(Tesseract_LIBRARIES tesseract)
|
Loading…
Reference in New Issue
Block a user