tesseract/CMakeLists.txt

229 lines
6.3 KiB
CMake
Raw Normal View History

2015-09-06 05:47:32 +08:00
#
# tesseract
#
###############################################################################
#
# cmake settings
#
###############################################################################
2015-09-07 07:49:18 +08:00
cmake_minimum_required(VERSION 2.8.11)
2015-09-06 05:47:32 +08:00
# 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})
set(MINIMUM_LEPTONICA_VERSION 1.71)
if (NOT Leptonica_BUILD_DIR)
find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED)
else()
set(Leptonica_DIR ${Leptonica_BUILD_DIR})
find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
endif()
2015-09-06 05:47:32 +08:00
2015-09-07 01:43:28 +08:00
find_package(ICU COMPONENTS uc i18n)
2015-09-07 07:49:18 +08:00
find_package(OpenCL QUIET)
2015-09-07 02:42:47 +08:00
find_package(PkgConfig)
2015-09-07 01:43:28 +08:00
2015-09-06 05:47:32 +08:00
###############################################################################
#
# 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()
2015-09-07 01:43:28 +08:00
set(LIB_Ws2_32 Ws2_32)
endif()
2015-09-07 07:49:18 +08:00
if (CYGWIN)
add_definitions(-D__CYGWIN__)
endif()
2015-09-07 01:43:28 +08:00
if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11")
set(LIB_pthread pthread)
2015-09-06 05:47:32 +08:00
endif()
###############################################################################
#
# configure
#
###############################################################################
set(AUTOCONFIG_SRC ${CMAKE_BINARY_DIR}/config_auto.h.in)
2015-09-07 01:43:28 +08:00
set(AUTOCONFIG ${CMAKE_BINARY_DIR}/config_auto.h)
2015-09-06 05:47:32 +08:00
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
#
###############################################################################
2015-09-06 18:47:30 +08:00
include(BuildFunctions)
include(SourceGroups)
2015-09-06 05:47:32 +08:00
2015-09-07 01:43:28 +08:00
add_definitions(-DHAVE_CONFIG_H)
2015-09-06 05:47:32 +08:00
add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1)
add_definitions(-DUSE_STD_NAMESPACE=1)
add_definitions(-DWINDLLNAME="libtesseract${VERSION_MAJOR}${VERSION_MINOR}.dll")
include_directories(${Leptonica_INCLUDE_DIRS})
2015-09-07 01:43:28 +08:00
include_directories(${CMAKE_BINARY_DIR})
2015-09-06 18:47:30 +08:00
include_directories(api)
2015-09-06 05:47:32 +08:00
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)
########################################
2015-09-06 18:47:30 +08:00
# LIBRARY tesseract
2015-09-06 05:47:32 +08:00
########################################
string(SUBSTRING ${VERSION_MINOR} 0 1 VERSION_MINOR_0)
string(SUBSTRING ${VERSION_MINOR} 1 1 VERSION_MINOR_1)
2015-09-06 18:47:30 +08:00
file(GLOB tesseract_src
"ccmain/*.cpp"
"ccstruct/*.cpp"
"ccutil/*.cpp"
"classify/*.cpp"
"cube/*.cpp"
"cutil/*.cpp"
"dict/*.cpp"
"neural_networks/runtime/*.cpp"
"opencl/*.cpp"
"textord/*.cpp"
"viewer/*.cpp"
"wordrec/*.cpp"
)
file(GLOB tesseract_hdr
"api/*.h"
"ccmain/*.h"
"ccstruct/*.h"
"ccutil/*.h"
"classify/*.h"
"cube/*.h"
"cutil/*.h"
"dict/*.h"
"neural_networks/runtime/*.h"
"opencl/*.h"
"textord/*.h"
"viewer/*.h"
"wordrec/*.h"
)
2015-09-07 01:43:28 +08:00
if (WIN32)
file(GLOB tesseract_win32_src "vs2010/port/*.cpp")
file(GLOB tesseract_win32_hdr "vs2010/port/*.h")
set(tesseract_src ${tesseract_src} ${tesseract_win32_src})
set(tesseract_hdr ${tesseract_hdr} ${tesseract_win32_hdr})
endif()
2015-09-06 18:47:30 +08:00
set(tesseract_src ${tesseract_src}
2015-09-06 05:47:32 +08:00
api/baseapi.cpp
api/capi.cpp
api/renderer.cpp
api/pdfrenderer.cpp
)
add_library (tesseract ${LIBRARY_TYPE} ${tesseract_src} ${tesseract_hdr})
if (NOT STATIC)
2015-09-06 18:47:30 +08:00
target_compile_definitions (tesseract PUBLIC -DTESS_EXPORTS)
endif()
2015-09-07 01:43:28 +08:00
target_link_libraries (tesseract ${Leptonica_LIBRARIES} ${LIB_Ws2_32} ${LIB_pthread})
set_target_properties (tesseract PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR_0}.${VERSION_MINOR_1})
set_target_properties (tesseract PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR_0}.${VERSION_MINOR_1})
if (WIN32)
2015-09-07 01:43:28 +08:00
set_target_properties (tesseract PROPERTIES OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR})
set_target_properties (tesseract PROPERTIES DEBUG_OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR}d)
endif()
2015-09-06 05:47:32 +08:00
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)
2015-09-06 18:47:30 +08:00
########################################
add_subdirectory(training)
2015-09-06 05:47:32 +08:00
###############################################################################