tesseract/CMakeLists.txt

361 lines
10 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)
2017-02-07 22:50:30 +08:00
set(VERSION_MAJOR 4)
set(VERSION_MINOR 00)
2015-09-06 05:47:32 +08:00
set(VERSION_PLAIN ${VERSION_MAJOR}.${VERSION_MINOR})
set(MINIMUM_LEPTONICA_VERSION 1.74)
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.cppan)
if (NOT Leptonica_DIR AND NOT MSVC)
find_package(PkgConfig REQUIRED)
pkg_check_modules(Leptonica REQUIRED lept>=${MINIMUM_LEPTONICA_VERSION})
link_directories(${Leptonica_LIBRARY_DIRS})
else()
find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
endif()
else()
if (STATIC)
set(CPPAN_BUILD_SHARED_LIBS 0)
else()
set(CPPAN_BUILD_SHARED_LIBS 1)
endif()
add_subdirectory(.cppan)
endif()
2015-09-06 05:47:32 +08:00
2015-09-07 07:49:18 +08:00
find_package(OpenCL QUIET)
2015-09-07 01:43:28 +08:00
option(BUILD_TRAINING_TOOLS "Build training tools" ON)
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)
2015-11-30 16:52:21 +08:00
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
2016-02-04 18:44:07 +08:00
2015-09-06 05:47:32 +08:00
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()
2016-02-04 18:44:07 +08:00
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")
2016-02-04 18:44:07 +08:00
2015-09-07 01:43:28 +08:00
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_INSTALL_PREFIX}/include" "${CMAKE_INSTALL_PREFIX}/include/tesseract")
2015-09-06 05:47:32 +08:00
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
2016-02-04 18:44:07 +08:00
${CMAKE_BINARY_DIR}/TesseractConfig.cmake @ONLY)
2015-09-06 05:47:32 +08:00
###############################################################################
#
# 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)
include_directories(arch)
2015-09-06 05:47:32 +08:00
include_directories(ccmain)
include_directories(ccstruct)
include_directories(ccutil)
include_directories(classify)
include_directories(cutil)
include_directories(dict)
include_directories(lstm)
2015-09-06 05:47:32 +08:00
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
arch/*.cpp
2016-07-04 04:34:14 +08:00
ccmain/*.cpp
ccstruct/*.cpp
ccutil/*.cpp
classify/*.cpp
cutil/*.cpp
dict/*.cpp
lstm/*.cpp
2016-07-04 04:34:14 +08:00
opencl/*.cpp
textord/*.cpp
viewer/*.cpp
wordrec/*.cpp
2015-09-06 18:47:30 +08:00
)
file(GLOB tesseract_hdr
2016-07-04 04:34:14 +08:00
api/*.h
arch/*.h
2016-07-04 04:34:14 +08:00
ccmain/*.h
ccstruct/*.h
ccutil/*.h
classify/*.h
cutil/*.h
dict/*.h
lstm/*.h
2016-07-04 04:34:14 +08:00
opencl/*.h
textord/*.h
viewer/*.h
wordrec/*.h
2015-09-06 18:47:30 +08:00
)
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
)
2017-02-24 00:29:48 +08:00
if (WIN32)
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/arch/dotproductsse.cpp
PROPERTIES COMPILE_DEFINITIONS __SSE4_1__)
if (MSVC)
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/arch/dotproductavx.cpp
PROPERTIES COMPILE_FLAGS "/arch:AVX")
endif()
else()
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/arch/dotproductsse.cpp
PROPERTIES COMPILE_FLAGS "-msse4.1")
set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/arch/dotproductavx.cpp
PROPERTIES COMPILE_FLAGS "-mavx")
2017-02-24 00:29:48 +08:00
endif()
2017-02-23 20:39:58 +08:00
add_library (libtesseract ${LIBRARY_TYPE} ${tesseract_src} ${tesseract_hdr})
if (NOT STATIC)
2017-02-23 20:39:58 +08:00
target_compile_definitions (libtesseract
PRIVATE -DTESS_EXPORTS
INTERFACE -DTESS_IMPORTS
)
2017-02-23 20:39:58 +08:00
set_target_properties (libtesseract PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS True)
endif()
2017-02-23 20:39:58 +08:00
target_link_libraries (libtesseract ${LIB_Ws2_32} ${LIB_pthread})
set_target_properties (libtesseract PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR_0}.${VERSION_MINOR_1})
set_target_properties (libtesseract PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR_0}.${VERSION_MINOR_1})
if (WIN32)
2017-02-23 20:39:58 +08:00
set_target_properties (libtesseract PROPERTIES OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR})
set_target_properties (libtesseract PROPERTIES DEBUG_OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR}d)
else()
set_target_properties (libtesseract PROPERTIES OUTPUT_NAME tesseract)
endif()
2015-09-06 05:47:32 +08:00
2016-09-05 23:10:56 +08:00
if (NOT CPPAN_BUILD)
2017-02-23 20:39:58 +08:00
target_link_libraries (libtesseract ${Leptonica_LIBRARIES})
export(TARGETS libtesseract FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake)
else()
2017-02-23 20:39:58 +08:00
target_link_libraries (libtesseract pvt.cppan.demo.danbloomberg.leptonica)
file(WRITE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake "include(${CMAKE_BINARY_DIR}/cppan.cmake)\n")
2017-02-23 20:39:58 +08:00
export(TARGETS libtesseract APPEND FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake)
endif()
2015-09-06 05:47:32 +08:00
########################################
# EXECUTABLE tesseractmain
########################################
set(tesseractmain_src
api/tesseractmain.cpp
vs2010/tesseract/resource.h
vs2010/tesseract/tesseract.rc
)
2017-02-23 20:39:58 +08:00
add_executable (tesseract ${tesseractmain_src})
target_link_libraries (tesseract libtesseract)
2015-09-06 05:47:32 +08:00
2015-09-06 18:47:30 +08:00
########################################
if (EXISTS ${PROJECT_SOURCE_DIR}/googletest/CMakeLists.txt)
add_subdirectory(googletest)
add_executable(tesseract_tests tests/tesseracttests.cpp)
target_link_libraries(tesseract_tests gtest_main)
endif()
if (BUILD_TRAINING_TOOLS)
2015-09-06 18:47:30 +08:00
add_subdirectory(training)
endif()
2015-09-06 18:47:30 +08:00
2017-04-20 19:50:53 +08:00
get_target_property(tesseract_NAME libtesseract NAME)
get_target_property(tesseract_VERSION libtesseract VERSION)
get_target_property(tesseract_OUTPUT_NAME libtesseract OUTPUT_NAME)
configure_file(tesseract.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc DESTINATION lib/pkgconfig)
install(TARGETS tesseract RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
install(TARGETS libtesseract EXPORT TesseractTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
install(EXPORT TesseractTargets DESTINATION cmake)
install(FILES
${CMAKE_BINARY_DIR}/TesseractConfig.cmake
${CMAKE_BINARY_DIR}/TesseractConfig-version.cmake
DESTINATION cmake)
install(FILES
# from api/makefile.am
api/apitypes.h
api/baseapi.h
api/capi.h
api/renderer.h
#from arch/makefile.am
arch/dotproductavx.h
arch/dotproductsse.h
arch/simddetect.h
#from ccmain/makefile.am
ccmain/thresholder.h
ccmain/ltrresultiterator.h
ccmain/pageiterator.h
ccmain/resultiterator.h
ccmain/osdetect.h
#from ccstruct/makefile.am
ccstruct/publictypes.h
#from ccutil/makefile.am
ccutil/basedir.h
ccutil/errcode.h
ccutil/fileerr.h
ccutil/genericvector.h
ccutil/helpers.h
ccutil/host.h
ccutil/memry.h
ccutil/ndminx.h
ccutil/params.h
ccutil/ocrclass.h
ccutil/platform.h
ccutil/serialis.h
ccutil/strngs.h
ccutil/tesscallback.h
ccutil/unichar.h
ccutil/unicharcompress.h
ccutil/unicharmap.h
ccutil/unicharset.h
2017-08-30 05:14:54 +08:00
ccutil/version.h
2017-04-20 19:50:53 +08:00
#from lstm/makefile.am
lstm/convolve.h
lstm/ctc.h
lstm/fullyconnected.h
lstm/functions.h
lstm/input.h
lstm/lstm.h
lstm/lstmrecognizer.h
lstm/lstmtrainer.h
lstm/maxpool.h
lstm/networkbuilder.h
lstm/network.h
lstm/networkio.h
lstm/networkscratch.h
lstm/parallel.h
lstm/plumbing.h
lstm/recodebeam.h
lstm/reconfig.h
lstm/reversed.h
lstm/series.h
lstm/static_shape.h
lstm/stridemap.h
lstm/tfnetwork.h
lstm/weightmatrix.h
#${CMAKE_BINARY_DIR}/src/endianness.h
DESTINATION include/tesseract)
2015-09-06 05:47:32 +08:00
###############################################################################