cmake: reformat with cmake-format and check with cmake-lint

This commit is contained in:
Zdenko Podobný 2021-12-20 13:18:01 +01:00
parent b565cfee9b
commit 8f02255294
2 changed files with 856 additions and 767 deletions

View File

@ -12,15 +12,15 @@ cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
# In-source builds are disabled. # In-source builds are disabled.
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
message(FATAL_ERROR message(
FATAL_ERROR
"CMake generation is not possible within the source directory!" "CMake generation is not possible within the source directory!"
"\n Remove the CMakeCache.txt file and try again from another folder, e.g.:" "\n Remove the CMakeCache.txt file and try again from another folder, "
"\n " "e.g.:\n "
"\n rm CMakeCache.txt" "\n rm CMakeCache.txt"
"\n mkdir build" "\n mkdir build"
"\n cd build" "\n cd build"
"\n cmake .." "\n cmake ..")
)
endif() endif()
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
@ -50,11 +50,13 @@ project(tesseract C CXX)
# Get version with components from VERSION file. # Get version with components from VERSION file.
file(STRINGS "VERSION" VERSION_PLAIN) file(STRINGS "VERSION" VERSION_PLAIN)
string(REGEX REPLACE "^([^.]*)\\..*" "\\1" VERSION_MAJOR ${VERSION_PLAIN}) string(REGEX REPLACE "^([^.]*)\\..*" "\\1" VERSION_MAJOR ${VERSION_PLAIN})
string(REGEX REPLACE "^[^.]*\\.([^.]*)\\..*" "\\1" VERSION_MINOR ${VERSION_PLAIN}) string(REGEX REPLACE "^[^.]*\\.([^.]*)\\..*" "\\1" VERSION_MINOR
string(REGEX REPLACE "^[^.]*\\.[^.]*\\.([0-9]*).*" "\\1" VERSION_PATCH ${VERSION_PLAIN}) ${VERSION_PLAIN})
string(REGEX REPLACE "^[^.]*\\.[^.]*\\.([0-9]*).*" "\\1" VERSION_PATCH
${VERSION_PLAIN})
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
execute_process(COMMAND git --git-dir ${CMAKE_CURRENT_SOURCE_DIR}/.git describe --abbrev=4 execute_process(COMMAND git --git-dir ${CMAKE_CURRENT_SOURCE_DIR}/.git
OUTPUT_VARIABLE GIT_REV) describe --abbrev=4 OUTPUT_VARIABLE GIT_REV)
string(REGEX REPLACE "\n$" "" PACKAGE_VERSION "${GIT_REV}") string(REGEX REPLACE "\n$" "" PACKAGE_VERSION "${GIT_REV}")
endif() endif()
if(NOT PACKAGE_VERSION) if(NOT PACKAGE_VERSION)
@ -110,7 +112,9 @@ endif()
if(NOT CMAKE_BUILD_TYPE) if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.") message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) set(CMAKE_BUILD_TYPE
Release
CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
endif() endif()
@ -137,7 +141,7 @@ else()
message(STATUS "IPO / LTO not supported: <${error}>") message(STATUS "IPO / LTO not supported: <${error}>")
endif() endif()
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
if(COMPILER_SUPPORTS_MARCH_NATIVE) if(COMPILER_SUPPORTS_MARCH_NATIVE)
set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -march=native") set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -march=native")
if(NOT CLANG AND MSVC) if(NOT CLANG AND MSVC)
@ -153,25 +157,25 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86|x86_64|AMD64|amd64|i386|i686")
set(HAVE_NEON FALSE) set(HAVE_NEON FALSE)
CHECK_CXX_COMPILER_FLAG("-mavx" HAVE_AVX) check_cxx_compiler_flag("-mavx" HAVE_AVX)
if(HAVE_AVX) if(HAVE_AVX)
set(AVX_COMPILE_FLAGS "-mavx") set(AVX_COMPILE_FLAGS "-mavx")
add_definitions("-DHAVE_AVX") add_definitions("-DHAVE_AVX")
endif(HAVE_AVX) endif(HAVE_AVX)
CHECK_CXX_COMPILER_FLAG("-mavx2" HAVE_AVX2) check_cxx_compiler_flag("-mavx2" HAVE_AVX2)
if(HAVE_AVX2) if(HAVE_AVX2)
set(AVX2_COMPILE_FLAGS "-mavx2") set(AVX2_COMPILE_FLAGS "-mavx2")
add_definitions("-DHAVE_AVX2") add_definitions("-DHAVE_AVX2")
endif() endif()
CHECK_CXX_COMPILER_FLAG("-mfma" HAVE_FMA) check_cxx_compiler_flag("-mfma" HAVE_FMA)
if(HAVE_FMA) if(HAVE_FMA)
set(FMA_COMPILE_FLAGS "-mfma") set(FMA_COMPILE_FLAGS "-mfma")
add_definitions("-DHAVE_FMA") add_definitions("-DHAVE_FMA")
endif() endif()
CHECK_CXX_COMPILER_FLAG("-msse4.1" HAVE_SSE4_1) check_cxx_compiler_flag("-msse4.1" HAVE_SSE4_1)
if(HAVE_SSE4_1) if(HAVE_SSE4_1)
set(SSE4_1_COMPILE_FLAGS "-msse4.1") set(SSE4_1_COMPILE_FLAGS "-msse4.1")
add_definitions("-DHAVE_SSE4_1") add_definitions("-DHAVE_SSE4_1")
@ -200,7 +204,8 @@ if(MSVC)
endif() endif()
# clang with MSVC compatibility # clang with MSVC compatibility
if(CLANG) if(CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-microsoft-unqualified-friend") set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wno-microsoft-unqualified-friend")
if(HAVE_FMA) if(HAVE_FMA)
set(FMA_COMPILE_FLAGS "-mfma ${FMA_COMPILE_FLAGS}") set(FMA_COMPILE_FLAGS "-mfma ${FMA_COMPILE_FLAGS}")
endif(HAVE_FMA) endif(HAVE_FMA)
@ -227,7 +232,7 @@ set(HAVE_AVX2 FALSE)
set(HAVE_FMA FALSE) set(HAVE_FMA FALSE)
set(HAVE_SSE4_1 FALSE) set(HAVE_SSE4_1 FALSE)
CHECK_CXX_COMPILER_FLAG("-mfpu=neon" HAVE_NEON) check_cxx_compiler_flag("-mfpu=neon" HAVE_NEON)
if(HAVE_NEON) if(HAVE_NEON)
set(NEON_COMPILE_FLAGS "-mfpu=neon") set(NEON_COMPILE_FLAGS "-mfpu=neon")
add_definitions("-DHAVE_NEON") add_definitions("-DHAVE_NEON")
@ -237,7 +242,8 @@ endif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86|x86_64|AMD64|amd64|i386|i686")
# Compiler specific environments # Compiler specific environments
if(CMAKE_COMPILER_IS_GNUCXX OR MINGW) if(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -DDEBUG -pedantic -Og") set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -Wall -DDEBUG -pedantic -Og")
elseif(MSVC) elseif(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) # strdup add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) # strdup
@ -245,13 +251,13 @@ elseif(MSVC)
if(NOT CLANG) if(NOT CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif() endif()
# Hide some warnings for release target # Hide some warnings for release target wd4244 'argument': conversion from
# wd4244 'argument': conversion from 'uint64_t' to 'unsigned int', possible loss of data # 'uint64_t' to 'unsigned int', possible loss of data wd4251 needs to have
# wd4251 needs to have dll-interface # dll-interface wd4267 return': conversion from 'size_t' to 'int', possible
# wd4267 return': conversion from 'size_t' to 'int', possible loss of data # loss of data wd4275 non dll-interface class wd4305 ...truncation from
# wd4275 non dll-interface class # 'double' to 'float'
# wd4305 ...truncation from 'double' to 'float' set(CMAKE_CXX_FLAGS_RELEASE
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /wd4244 /wd4305 /wd4267 /wd4251 /wd4275") "${CMAKE_CXX_FLAGS_RELEASE} /wd4244 /wd4305 /wd4267 /wd4251 /wd4275")
# Don't use /Wall because it generates too many warnings. # Don't use /Wall because it generates too many warnings.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W0 /bigobj") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W0 /bigobj")
# MT flag # MT flag
@ -261,36 +267,44 @@ elseif(MSVC)
endif() endif()
endif() endif()
if(CLANG) # clang all platforms if(CLANG) # clang all platforms
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-unused-command-line-argument") set(CMAKE_CXX_FLAGS_RELEASE
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -DDEBUG -pedantic -O0") "${CMAKE_CXX_FLAGS_RELEASE} -Wno-unused-command-line-argument")
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -Wall -DDEBUG -pedantic -O0")
endif() endif()
if (OPENMP_BUILD AND MSVC AND "${MSVC_VERSION}" LESS 1929) if(OPENMP_BUILD
AND MSVC
AND "${MSVC_VERSION}" LESS 1929)
set(OPENMP_BUILD OFF) set(OPENMP_BUILD OFF)
endif() endif()
if(OPENMP_BUILD) if(OPENMP_BUILD)
find_package(OpenMP QUIET) find_package(OpenMP QUIET)
if(OpenMP_FOUND) if(OpenMP_FOUND)
message(">> ${OpenMP_FOUND} ${OpenMP_VERSION}") message(">> OpenMP_FOUND ${OpenMP_FOUND} ${OpenMP_VERSION}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
if(${CMAKE_VERSION} VERSION_LESS "3.9.0") if(${CMAKE_VERSION} VERSION_LESS "3.9.0")
add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE) add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE)
endif() endif()
endif() endif()
# https://stackoverflow.com/questions/12399422/how-to-set-linker-flags-for-openmp-in-cmakes-try-compile-function # https://stackoverflow.com/questions/12399422
if (NOT OpenMP_FOUND AND CLANG AND WIN32) # how-to-set-linker-flags-for-openmp-in-cmakes-try-compile-function
if(NOT OpenMP_FOUND
AND CLANG
AND WIN32)
# workaroung because find_package(OpenMP) does not work for clang-cl # workaroung because find_package(OpenMP) does not work for clang-cl
# https://gitlab.kitware.com/cmake/cmake/issues/19404 # https://gitlab.kitware.com/cmake/cmake/issues/19404
check_include_file_cxx(omp.h HAVE_OMP_H_INCLUDE) check_include_file_cxx(omp.h HAVE_OMP_H_INCLUDE)
find_library(OpenMP_LIBRARY NAMES omp libomp.lib) find_library(OpenMP_LIBRARY NAMES omp libomp.lib)
message(">> OpenMP_LIBRARY: ${OpenMP_LIBRARY}") message(">> OpenMP_LIBRARY: ${OpenMP_LIBRARY}")
if(MSVC) if(MSVC)
set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS} /openmp") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
else() else()
set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS} -fopenmp") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
endif() endif()
set(OpenMP_FOUND 1) set(OpenMP_FOUND 1)
add_definitions(-D_OPENMP=201107) # 3.1 version is supported from Clang 3.8.0 # OpenMP 3.1 is fully supported from Clang 3.8.0
add_definitions(-D_OPENMP=201107)
endif() endif()
if(MSVC) if(MSVC)
string(REPLACE "/openmp" "/openmp:llvm" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) string(REPLACE "/openmp" "/openmp:llvm" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
@ -323,25 +337,17 @@ if (SW_BUILD)
else() else()
set(SW_BUILD_SHARED_LIBS 0) set(SW_BUILD_SHARED_LIBS 0)
endif() endif()
sw_add_package( sw_add_package(org.sw.demo.danbloomberg.leptonica
org.sw.demo.danbloomberg.leptonica org.sw.demo.libarchive.libarchive)
org.sw.demo.libarchive.libarchive
)
if(BUILD_TRAINING_TOOLS) if(BUILD_TRAINING_TOOLS)
sw_add_package( sw_add_package(org.sw.demo.gnome.pango.pangocairo
org.sw.demo.gnome.pango.pangocairo org.sw.demo.unicode.icu.i18n)
org.sw.demo.unicode.icu.i18n
)
endif() endif()
sw_execute() sw_execute()
else() else()
find_package(PkgConfig) find_package(PkgConfig)
if(BUILD_TRAINING_TOOLS) # Check for required library. option -DLeptonica_DIR=path => cmake hint where
message(WARNING "Building of Training Tools requires PkgConfig") # to find leptonica
set(BUILD_TRAINING_TOOLS OFF)
endif(BUILD_TRAINING_TOOLS)
# Check for required library.
# option -DLeptonica_DIR=path => cmake hint where to find leptonica
find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} CONFIG) find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} CONFIG)
if(NOT Leptonica_FOUND AND PKG_CONFIG_EXECUTABLE) if(NOT Leptonica_FOUND AND PKG_CONFIG_EXECUTABLE)
pkg_check_modules(Leptonica lept>=${MINIMUM_LEPTONICA_VERSION}) pkg_check_modules(Leptonica lept>=${MINIMUM_LEPTONICA_VERSION})
@ -392,7 +398,6 @@ endif()
find_package(OpenCL QUIET) find_package(OpenCL QUIET)
# ############################################################################## # ##############################################################################
# #
# configure # configure
@ -414,7 +419,9 @@ add_definitions(-DHAVE_CONFIG_H)
if(GRAPHICS_DISABLED) if(GRAPHICS_DISABLED)
message("ScrollView debugging disabled.") message("ScrollView debugging disabled.")
endif() endif()
set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${CMAKE_PREFIX_PATH}/include" "${CMAKE_INSTALL_PREFIX}/include") set(CMAKE_REQUIRED_INCLUDES
${CMAKE_REQUIRED_INCLUDES} "${CMAKE_PREFIX_PATH}/include"
"${CMAKE_INSTALL_PREFIX}/include")
include(Configure) include(Configure)
configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY) configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY)
@ -422,8 +429,7 @@ configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY)
set(INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include") set(INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include")
set(LIBRARY_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") set(LIBRARY_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
configure_file( configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/tesseract/version.h.in
${CMAKE_CURRENT_SOURCE_DIR}/include/tesseract/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/tesseract/version.h @ONLY) ${CMAKE_CURRENT_BINARY_DIR}/include/tesseract/version.h @ONLY)
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
@ -449,7 +455,8 @@ message( STATUS "Used standard: C++${CMAKE_CXX_STANDARD}")
message(STATUS "CXX compiler options: ${COMPILER_FLAGS}") message(STATUS "CXX compiler options: ${COMPILER_FLAGS}")
get_directory_property(DirCompDefs COMPILE_DEFINITIONS) get_directory_property(DirCompDefs COMPILE_DEFINITIONS)
message(STATUS "Compile definitions = ${DirCompDefs}") message(STATUS "Compile definitions = ${DirCompDefs}")
message( STATUS "Linker options: ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UP}}") message(STATUS "Linker options: ${CMAKE_EXE_LINKER_FLAGS} "
"${CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UP}}")
message(STATUS "Install directory: ${CMAKE_INSTALL_PREFIX}") message(STATUS "Install directory: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "HAVE_AVX: ${HAVE_AVX}") message(STATUS "HAVE_AVX: ${HAVE_AVX}")
message(STATUS "HAVE_AVX2: ${HAVE_AVX2}") message(STATUS "HAVE_AVX2: ${HAVE_AVX2}")
@ -461,12 +468,16 @@ message( STATUS "Link-time optimization: ${CMAKE_INTERPROCEDURAL_OPTIMIZATION}")
message(STATUS "--------------------------------------------------------") message(STATUS "--------------------------------------------------------")
message(STATUS "Build with sw [SW_BUILD]: ${SW_BUILD}") message(STATUS "Build with sw [SW_BUILD]: ${SW_BUILD}")
message(STATUS "Build with openmp support [OPENMP_BUILD]: ${OPENMP_BUILD}") message(STATUS "Build with openmp support [OPENMP_BUILD]: ${OPENMP_BUILD}")
message( STATUS "Build with libarchive support [HAVE_LIBARCHIVE]: ${HAVE_LIBARCHIVE}") message(STATUS "Build with libarchive support [HAVE_LIBARCHIVE]: "
"${HAVE_LIBARCHIVE}")
message(STATUS "Build with libcurl support [HAVE_LIBCURL]: ${HAVE_LIBCURL}") message(STATUS "Build with libcurl support [HAVE_LIBCURL]: ${HAVE_LIBCURL}")
message(STATUS "Enable float for LSTM [FAST_FLOAT]: ${FAST_FLOAT}") message(STATUS "Enable float for LSTM [FAST_FLOAT]: ${FAST_FLOAT}")
message( STATUS "Disable disable graphics (ScrollView) [GRAPHICS_DISABLED]: ${GRAPHICS_DISABLED}") message(STATUS "Disable disable graphics (ScrollView) [GRAPHICS_DISABLED]: "
message( STATUS "Disable the legacy OCR engine [DISABLED_LEGACY_ENGINE]: ${DISABLED_LEGACY_ENGINE}") "${GRAPHICS_DISABLED}")
message( STATUS "Build training tools [BUILD_TRAINING_TOOLS]: ${BUILD_TRAINING_TOOLS}") message(STATUS "Disable the legacy OCR engine [DISABLED_LEGACY_ENGINE]: "
"${DISABLED_LEGACY_ENGINE}")
message(STATUS "Build training tools [BUILD_TRAINING_TOOLS]: "
"${BUILD_TRAINING_TOOLS}")
message(STATUS "Build tests [BUILD_TESTS]: ${BUILD_TESTS}") message(STATUS "Build tests [BUILD_TESTS]: ${BUILD_TESTS}")
message(STATUS "Use system ICU Library [USE_SYSTEM_ICU]: ${USE_SYSTEM_ICU}") message(STATUS "Use system ICU Library [USE_SYSTEM_ICU]: ${USE_SYSTEM_ICU}")
message(STATUS "--------------------------------------------------------") message(STATUS "--------------------------------------------------------")
@ -490,11 +501,13 @@ if(ANDROID_TOOLCHAIN)
add_compile_definitions(__ANDROID_API_FUTURE__) add_compile_definitions(__ANDROID_API_FUTURE__)
endif() endif()
######################################## # ##############################################################################
# LIBRARY tesseract # LIBRARY tesseract
######################################## # ##############################################################################
file(GLOB tesseract_src file(
GLOB
TESSERACT_SRC
src/ccmain/*.cpp src/ccmain/*.cpp
src/ccstruct/*.cpp src/ccstruct/*.cpp
src/ccutil/*.cpp src/ccutil/*.cpp
@ -505,19 +518,21 @@ file(GLOB tesseract_src
src/opencl/*.cpp src/opencl/*.cpp
src/textord/*.cpp src/textord/*.cpp
src/viewer/*.cpp src/viewer/*.cpp
src/wordrec/*.cpp src/wordrec/*.cpp)
)
if(DISABLED_LEGACY_ENGINE) if(DISABLED_LEGACY_ENGINE)
# prepend path to list of source files
function(prepend_path srcs path) function(prepend_path srcs path)
set(tmp, "") set(tmp, "")
foreach(src IN LISTS ${srcs}) foreach(src IN LISTS ${srcs})
list(APPEND tmp ${path}/${src}) list(APPEND tmp ${path}/${src})
endforeach(src ${srcs}) endforeach(src ${srcs})
set(${srcs} ${tmp} PARENT_SCOPE) set(${srcs}
${tmp}
PARENT_SCOPE)
endfunction() endfunction()
SET(tesseract_src_legacy set(TESSERACT_SRC_LEGACY
src/ccmain/adaptions.cpp src/ccmain/adaptions.cpp
src/ccmain/docqual.cpp src/ccmain/docqual.cpp
src/ccmain/equationdetect.cpp src/ccmain/equationdetect.cpp
@ -579,17 +594,13 @@ if (DISABLED_LEGACY_ENGINE)
src/wordrec/plotedges.cpp src/wordrec/plotedges.cpp
src/wordrec/render.cpp src/wordrec/render.cpp
src/wordrec/segsearch.cpp src/wordrec/segsearch.cpp
src/wordrec/wordclass.cpp src/wordrec/wordclass.cpp)
) prepend_path(TESSERACT_SRC_LEGACY "${CMAKE_CURRENT_SOURCE_DIR}")
prepend_path(tesseract_src_legacy "${CMAKE_CURRENT_SOURCE_DIR}") list(REMOVE_ITEM TESSERACT_SRC ${TESSERACT_SRC_LEGACY})
list(REMOVE_ITEM tesseract_src ${tesseract_src_legacy})
endif(DISABLED_LEGACY_ENGINE) endif(DISABLED_LEGACY_ENGINE)
list(APPEND arch_files list(APPEND arch_files src/arch/dotproduct.cpp src/arch/simddetect.cpp
src/arch/dotproduct.cpp src/arch/intsimdmatrix.cpp)
src/arch/simddetect.cpp
src/arch/intsimdmatrix.cpp
)
if(MARCH_NATIVE_FLAGS) if(MARCH_NATIVE_FLAGS)
set_source_files_properties(src/arch/dotproduct.cpp set_source_files_properties(src/arch/dotproduct.cpp
@ -601,7 +612,8 @@ if(HAVE_AVX)
PROPERTIES COMPILE_FLAGS ${AVX_COMPILE_FLAGS}) PROPERTIES COMPILE_FLAGS ${AVX_COMPILE_FLAGS})
endif(HAVE_AVX) endif(HAVE_AVX)
if(HAVE_AVX2) if(HAVE_AVX2)
list(APPEND arch_files_opt src/arch/intsimdmatrixavx2.cpp src/arch/dotproductavx.cpp) list(APPEND arch_files_opt src/arch/intsimdmatrixavx2.cpp
src/arch/dotproductavx.cpp)
set_source_files_properties(src/arch/intsimdmatrixavx2.cpp set_source_files_properties(src/arch/intsimdmatrixavx2.cpp
PROPERTIES COMPILE_FLAGS ${AVX2_COMPILE_FLAGS}) PROPERTIES COMPILE_FLAGS ${AVX2_COMPILE_FLAGS})
endif(HAVE_AVX2) endif(HAVE_AVX2)
@ -611,19 +623,25 @@ if(HAVE_FMA)
PROPERTIES COMPILE_FLAGS ${FMA_COMPILE_FLAGS}) PROPERTIES COMPILE_FLAGS ${FMA_COMPILE_FLAGS})
endif(HAVE_FMA) endif(HAVE_FMA)
if(HAVE_SSE4_1) if(HAVE_SSE4_1)
list(APPEND arch_files_opt src/arch/dotproductsse.cpp src/arch/intsimdmatrixsse.cpp) list(APPEND arch_files_opt src/arch/dotproductsse.cpp
set_source_files_properties(src/arch/dotproductsse.cpp src/arch/intsimdmatrixsse.cpp src/arch/intsimdmatrixsse.cpp)
set_source_files_properties(
src/arch/dotproductsse.cpp src/arch/intsimdmatrixsse.cpp
PROPERTIES COMPILE_FLAGS ${SSE4_1_COMPILE_FLAGS}) PROPERTIES COMPILE_FLAGS ${SSE4_1_COMPILE_FLAGS})
endif(HAVE_SSE4_1) endif(HAVE_SSE4_1)
if(HAVE_NEON) if(HAVE_NEON)
list(APPEND arch_files_opt src/arch/dotproductneon.cpp src/arch/intsimdmatrixneon.cpp) list(APPEND arch_files_opt src/arch/dotproductneon.cpp
src/arch/intsimdmatrixneon.cpp)
if(NEON_COMPILE_FLAGS) if(NEON_COMPILE_FLAGS)
set_source_files_properties(src/arch/dotproductneon.cpp src/arch/intsimdmatrixneon.cpp set_source_files_properties(
src/arch/dotproductneon.cpp src/arch/intsimdmatrixneon.cpp
PROPERTIES COMPILE_FLAGS ${NEON_COMPILE_FLAGS}) PROPERTIES COMPILE_FLAGS ${NEON_COMPILE_FLAGS})
endif() endif()
endif(HAVE_NEON) endif(HAVE_NEON)
file(GLOB_RECURSE tesseract_hdr file(
GLOB_RECURSE
tesseract_hdr
include/* include/*
src/arch/*.h src/arch/*.h
src/ccmain/*.h src/ccmain/*.h
@ -636,10 +654,10 @@ file(GLOB_RECURSE tesseract_hdr
src/opencl/*.h src/opencl/*.h
src/textord/*.h src/textord/*.h
src/viewer/*.h src/viewer/*.h
src/wordrec/*.h src/wordrec/*.h)
)
set(tesseract_src ${tesseract_src} set(TESSERACT_SRC
${TESSERACT_SRC}
src/api/baseapi.cpp src/api/baseapi.cpp
src/api/capi.cpp src/api/capi.cpp
src/api/renderer.cpp src/api/renderer.cpp
@ -647,37 +665,36 @@ set(tesseract_src ${tesseract_src}
src/api/hocrrenderer.cpp src/api/hocrrenderer.cpp
src/api/lstmboxrenderer.cpp src/api/lstmboxrenderer.cpp
src/api/pdfrenderer.cpp src/api/pdfrenderer.cpp
src/api/wordstrboxrenderer.cpp src/api/wordstrboxrenderer.cpp)
)
set(libtessfiles ${tesseract_src} ${arch_files} ${arch_files_opt} ${tesseract_hdr}) set(LIBTESSFILES ${TESSERACT_SRC} ${arch_files} ${arch_files_opt}
${tesseract_hdr})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${libtessfiles}) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${LIBTESSFILES})
add_library (libtesseract ${libtessfiles}) add_library(libtesseract ${LIBTESSFILES})
target_include_directories (libtesseract target_include_directories(
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> libtesseract
PRIVATE src PRIVATE src
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/arch> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/arch>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/ccmain> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/ccmain>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/ccstruct> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/ccstruct>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/ccutil> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/ccutil>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/classify> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/classify>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/cutil> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/cutil>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/dict> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/dict>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/lstm> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/lstm>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/opencl> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/opencl>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/textord> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/textord>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/viewer> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/viewer>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/wordrec> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/wordrec>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/training> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/training>)
)
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
target_compile_definitions (libtesseract target_compile_definitions(
libtesseract
PRIVATE -DTESS_EXPORTS PRIVATE -DTESS_EXPORTS
INTERFACE -DTESS_IMPORTS INTERFACE -DTESS_IMPORTS)
)
# generate_export_header (libtesseract EXPORT_MACRO_NAME TESS_API) # generate_export_header (libtesseract EXPORT_MACRO_NAME TESS_API)
endif() endif()
target_link_libraries(libtesseract PRIVATE ${LIB_Ws2_32} ${LIB_pthread}) target_link_libraries(libtesseract PRIVATE ${LIB_Ws2_32} ${LIB_pthread})
@ -694,36 +711,50 @@ if(CURL_FOUND)
target_link_libraries(libtesseract PUBLIC ${CURL_LIBRARIES}) target_link_libraries(libtesseract PUBLIC ${CURL_LIBRARIES})
endif() endif()
endif(CURL_FOUND) endif(CURL_FOUND)
set_target_properties (libtesseract PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set_target_properties (libtesseract PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) set_target_properties(libtesseract
PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set_target_properties(libtesseract
PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
if(WIN32) if(WIN32)
set_target_properties (libtesseract PROPERTIES OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR}) set_target_properties(libtesseract
set_target_properties (libtesseract PROPERTIES DEBUG_OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR}d) PROPERTIES OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR})
set_target_properties(libtesseract
PROPERTIES DEBUG_OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR}d)
else() else()
set_target_properties(libtesseract PROPERTIES OUTPUT_NAME tesseract) set_target_properties(libtesseract PROPERTIES OUTPUT_NAME tesseract)
endif() endif()
if(SW_BUILD) if(SW_BUILD)
target_link_libraries (libtesseract PUBLIC target_link_libraries(libtesseract PUBLIC org.sw.demo.danbloomberg.leptonica
org.sw.demo.danbloomberg.leptonica org.sw.demo.libarchive.libarchive)
org.sw.demo.libarchive.libarchive file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake
) "include(${CMAKE_CURRENT_BINARY_DIR}/cppan.cmake)\n")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake "include(${CMAKE_CURRENT_BINARY_DIR}/cppan.cmake)\n") export(
export(TARGETS libtesseract APPEND FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake NAMESPACE Tesseract::) TARGETS libtesseract
APPEND
FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake
NAMESPACE Tesseract::)
else() else()
target_link_libraries(libtesseract PUBLIC ${Leptonica_LIBRARIES}) target_link_libraries(libtesseract PUBLIC ${Leptonica_LIBRARIES})
export(TARGETS libtesseract FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake NAMESPACE Tesseract::) export(
TARGETS libtesseract
FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake
NAMESPACE Tesseract::)
endif() endif()
if (WIN32 AND CLANG AND OPENMP_BUILD) if(WIN32
# Workaround for "libomp.lib is not automatically added on Windows" AND CLANG
# see: http://lists.llvm.org/pipermail/openmp-dev/2015-August/000857.html AND OPENMP_BUILD)
# Workaround for "libomp.lib is not automatically added on Windows" see:
# http://lists.llvm.org/pipermail/openmp-dev/2015-August/000857.html
target_link_libraries(libtesseract PRIVATE ${OpenMP_LIBRARY}) target_link_libraries(libtesseract PRIVATE ${OpenMP_LIBRARY})
endif() endif()
######################################## # ##############################################################################
# EXECUTABLE tesseract # EXECUTABLE tesseract
######################################## # ##############################################################################
add_executable(tesseract src/tesseract.cpp) add_executable(tesseract src/tesseract.cpp)
target_link_libraries(tesseract libtesseract) target_link_libraries(tesseract libtesseract)
@ -735,9 +766,11 @@ if (OPENMP_BUILD AND UNIX)
target_link_libraries(tesseract pthread) target_link_libraries(tesseract pthread)
endif() endif()
######################################## # ##############################################################################
if (BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/unittest/third_party/googletest/CMakeLists.txt) if(BUILD_TESTS AND EXISTS
${CMAKE_CURRENT_SOURCE_DIR}/unittest/third_party/googletest/CMakeLists.txt
)
add_subdirectory(unittest/third_party/googletest) add_subdirectory(unittest/third_party/googletest)
endif() endif()
@ -749,7 +782,8 @@ get_target_property(tesseract_NAME libtesseract NAME)
get_target_property(tesseract_VERSION libtesseract VERSION) get_target_property(tesseract_VERSION libtesseract VERSION)
get_target_property(tesseract_OUTPUT_NAME libtesseract OUTPUT_NAME) get_target_property(tesseract_OUTPUT_NAME libtesseract OUTPUT_NAME)
configure_file(tesseract.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc @ONLY) configure_file(tesseract.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc
@ONLY)
configure_package_config_file( configure_package_config_file(
cmake/templates/TesseractConfig.cmake.in cmake/templates/TesseractConfig.cmake.in
@ -761,45 +795,51 @@ write_basic_package_version_file(
VERSION ${PACKAGE_VERSION} VERSION ${PACKAGE_VERSION}
COMPATIBILITY SameMajorVersion) COMPATIBILITY SameMajorVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(TARGETS tesseract DESTINATION bin) install(TARGETS tesseract DESTINATION bin)
install(TARGETS libtesseract EXPORT TesseractTargets RUNTIME DESTINATION bin LIBRARY install(
DESTINATION ${CMAKE_INSTALL_LIBDIR} TARGETS libtesseract
EXPORT TesseractTargets
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(EXPORT TesseractTargets NAMESPACE Tesseract:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tesseract) install(
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}) EXPORT TesseractTargets
NAMESPACE Tesseract::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tesseract)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES install(
include/tesseract/baseapi.h FILES include/tesseract/baseapi.h
include/tesseract/capi.h include/tesseract/capi.h
include/tesseract/renderer.h include/tesseract/renderer.h
${CMAKE_CURRENT_BINARY_DIR}/include/tesseract/version.h ${CMAKE_CURRENT_BINARY_DIR}/include/tesseract/version.h
include/tesseract/ltrresultiterator.h include/tesseract/ltrresultiterator.h
include/tesseract/pageiterator.h include/tesseract/pageiterator.h
include/tesseract/resultiterator.h include/tesseract/resultiterator.h
include/tesseract/osdetect.h include/tesseract/osdetect.h
include/tesseract/publictypes.h include/tesseract/publictypes.h
include/tesseract/ocrclass.h include/tesseract/ocrclass.h
include/tesseract/export.h include/tesseract/export.h
include/tesseract/unichar.h include/tesseract/unichar.h
# ${CMAKE_CURRENT_BINARY_DIR}/src/endianness.h # ${CMAKE_CURRENT_BINARY_DIR}/src/endianness.h
DESTINATION include/tesseract) DESTINATION include/tesseract)
######################################## # ##############################################################################
# uninstall target # uninstall target
######################################## # ##############################################################################
if(NOT TARGET uninstall) if(NOT TARGET uninstall)
configure_file( configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
IMMEDIATE @ONLY)
add_custom_target(uninstall add_custom_target(
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) uninstall
COMMENT "Uninstall installed files"
COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif() endif()
# ############################################################################## # ##############################################################################

View File

@ -9,50 +9,60 @@ endif()
if(SW_BUILD) if(SW_BUILD)
set(ICU_FOUND 1) set(ICU_FOUND 1)
else() # NOT SW_BUILD
find_package(PkgConfig)
endif() endif()
# experimental # experimental
if (MSVC AND NOT SW_BUILD AND NOT USE_SYSTEM_ICU) # If PkgConfig is not present training tools will not be build,
# so it does not make sense to set ICU
if(MSVC
AND PKG_CONFIG_FOUND
AND NOT SW_BUILD
AND NOT USE_SYSTEM_ICU)
include(CheckTypeSize) include(CheckTypeSize)
check_type_size("void *" SIZEOF_VOID_P) check_type_size("void *" SIZEOF_VOID_P)
if(SIZEOF_VOID_P EQUAL 8) if(SIZEOF_VOID_P EQUAL 8)
set(X64 1) set(X64 1)
set(ARCH_DIR_NAME 64) set(ARCH_NAME 64)
elseif(SIZEOF_VOID_P EQUAL 4) elseif(SIZEOF_VOID_P EQUAL 4)
set(X86 1) set(X86 1)
set(ARCH_DIR_NAME 32) set(ARCH_NAME 32)
else() else()
message(FATAL_ERROR "Cannot determine target architecture") message(FATAL_ERROR "Cannot determine target architecture")
endif() endif()
set(icu_dir "${CMAKE_CURRENT_BINARY_DIR}/icu") set(ICU_DIR "${CMAKE_CURRENT_BINARY_DIR}/icu")
set(icu_archive "${icu_dir}/icu${ARCH_DIR_NAME}.zip") set(ICU_ARCHIVE "${ICU_DIR}/icu${ARCH_NAME}.zip")
if(X86) if(X86)
set(icu_hash 45167a240b60e36b59a87eda23490ce4) set(ICU_HASH 45167a240b60e36b59a87eda23490ce4)
else() else()
set(icu_hash 480c72491576c048de1218c3c5519399) set(ICU_HASH 480c72491576c048de1218c3c5519399)
endif() endif()
message(STATUS "Downloading latest ICU binaries") message(STATUS "Downloading latest ICU binaries")
set(COMPILER "msvc10")
file(DOWNLOAD set(ICU_URL "https://github.com/unicode-org/icu/releases/download")
"https://github.com/unicode-org/icu/releases/download/release-56-1/icu4c-56_1-Win${ARCH_DIR_NAME}-msvc10.zip" SET(ICU_R "56-1")
"${icu_archive}" SET(ICU_V "56_1")
file(
DOWNLOAD
"${ICU_URL}/release-${ICU_R}/icu4c-${ICU_V}-Win${ARCH_NAME}-${COMPILER}.zip"
"${ICU_ARCHIVE}"
SHOW_PROGRESS SHOW_PROGRESS
INACTIVITY_TIMEOUT 300 # seconds INACTIVITY_TIMEOUT 300 # seconds
EXPECTED_HASH MD5=${icu_hash} EXPECTED_HASH MD5=${ICU_HASH})
) execute_process(
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xz "${icu_archive}" COMMAND ${CMAKE_COMMAND} -E tar xz "${ICU_ARCHIVE}"
WORKING_DIRECTORY "${icu_dir}" WORKING_DIRECTORY "${ICU_DIR}"
RESULT_VARIABLE __result RESULT_VARIABLE __result)
)
if(NOT __result EQUAL 0) if(NOT __result EQUAL 0)
message(FATAL_ERROR "error ${__result}") message(FATAL_ERROR "error ${__result}")
endif() endif()
set(ICU_ROOT ${icu_dir}/icu) set(ICU_ROOT ${ICU_DIR}/icu)
endif() endif()
# experimental # experimental
@ -64,12 +74,11 @@ if (NOT SW_BUILD)
endif() endif()
endif() endif()
# ##############################################################################
########################################
# LIBRARY common_training # LIBRARY common_training
######################################## # ##############################################################################
set(common_training_src set(COMMON_TRAINING_SRC
common/commandlineflags.cpp common/commandlineflags.cpp
common/commandlineflags.h common/commandlineflags.h
common/commontraining.cpp common/commontraining.cpp
@ -77,11 +86,12 @@ set(common_training_src
common/ctc.cpp common/ctc.cpp
common/ctc.h common/ctc.h
common/networkbuilder.cpp common/networkbuilder.cpp
common/networkbuilder.h common/networkbuilder.h)
)
if(NOT DISABLED_LEGACY_ENGINE) if(NOT DISABLED_LEGACY_ENGINE)
list(APPEND common_training_src list(
APPEND
COMMON_TRAINING_SRC
common/errorcounter.cpp common/errorcounter.cpp
common/errorcounter.h common/errorcounter.h
common/intfeaturedist.cpp common/intfeaturedist.cpp
@ -93,105 +103,130 @@ list(APPEND common_training_src
common/sampleiterator.cpp common/sampleiterator.cpp
common/sampleiterator.h common/sampleiterator.h
common/trainingsampleset.cpp common/trainingsampleset.cpp
common/trainingsampleset.h common/trainingsampleset.h)
)
endif() endif()
add_library (common_training ${common_training_src}) add_library(common_training ${COMMON_TRAINING_SRC})
target_include_directories (common_training PUBLIC common ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(common_training PUBLIC common
${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(common_training PUBLIC libtesseract) target_link_libraries(common_training PUBLIC libtesseract)
generate_export_header (common_training EXPORT_MACRO_NAME TESS_COMMON_TRAINING_API) generate_export_header(common_training EXPORT_MACRO_NAME
TESS_COMMON_TRAINING_API)
project_group(common_training "Training Tools") project_group(common_training "Training Tools")
######################################## # ##############################################################################
# EXECUTABLE ambiguous_words # EXECUTABLE ambiguous_words
######################################## # ##############################################################################
if(NOT DISABLED_LEGACY_ENGINE) if(NOT DISABLED_LEGACY_ENGINE)
add_executable(ambiguous_words ambiguous_words.cpp) add_executable(ambiguous_words ambiguous_words.cpp)
target_link_libraries(ambiguous_words common_training) target_link_libraries(ambiguous_words common_training)
project_group(ambiguous_words "Training Tools") project_group(ambiguous_words "Training Tools")
install (TARGETS ambiguous_words RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS ambiguous_words
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif() endif()
# ##############################################################################
########################################
# EXECUTABLE classifier_tester # EXECUTABLE classifier_tester
######################################## # ##############################################################################
if(NOT DISABLED_LEGACY_ENGINE) if(NOT DISABLED_LEGACY_ENGINE)
add_executable(classifier_tester classifier_tester.cpp) add_executable(classifier_tester classifier_tester.cpp)
target_link_libraries(classifier_tester common_training) target_link_libraries(classifier_tester common_training)
project_group(classifier_tester "Training Tools") project_group(classifier_tester "Training Tools")
install (TARGETS classifier_tester RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS classifier_tester
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif() endif()
# ##############################################################################
########################################
# EXECUTABLE combine_tessdata # EXECUTABLE combine_tessdata
######################################## # ##############################################################################
add_executable(combine_tessdata combine_tessdata.cpp) add_executable(combine_tessdata combine_tessdata.cpp)
target_link_libraries(combine_tessdata common_training) target_link_libraries(combine_tessdata common_training)
project_group(combine_tessdata "Training Tools") project_group(combine_tessdata "Training Tools")
install (TARGETS combine_tessdata RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS combine_tessdata
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
# ##############################################################################
########################################
# EXECUTABLE cntraining # EXECUTABLE cntraining
######################################## # ##############################################################################
if(NOT DISABLED_LEGACY_ENGINE) if(NOT DISABLED_LEGACY_ENGINE)
add_executable(cntraining cntraining.cpp) add_executable(cntraining cntraining.cpp)
target_link_libraries(cntraining common_training) target_link_libraries(cntraining common_training)
project_group(cntraining "Training Tools") project_group(cntraining "Training Tools")
install (TARGETS cntraining RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS cntraining
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif() endif()
# ##############################################################################
########################################
# EXECUTABLE dawg2wordlist # EXECUTABLE dawg2wordlist
######################################## # ##############################################################################
add_executable(dawg2wordlist dawg2wordlist.cpp) add_executable(dawg2wordlist dawg2wordlist.cpp)
target_link_libraries(dawg2wordlist common_training) target_link_libraries(dawg2wordlist common_training)
project_group(dawg2wordlist "Training Tools") project_group(dawg2wordlist "Training Tools")
install (TARGETS dawg2wordlist RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS dawg2wordlist
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
# ##############################################################################
########################################
# EXECUTABLE mftraining # EXECUTABLE mftraining
######################################## # ##############################################################################
if(NOT DISABLED_LEGACY_ENGINE) if(NOT DISABLED_LEGACY_ENGINE)
add_executable(mftraining mftraining.cpp mergenf.cpp mergenf.h) add_executable(mftraining mftraining.cpp mergenf.cpp mergenf.h)
target_link_libraries(mftraining common_training) target_link_libraries(mftraining common_training)
project_group(mftraining "Training Tools") project_group(mftraining "Training Tools")
install (TARGETS mftraining RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS mftraining
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif() endif()
# ##############################################################################
########################################
# EXECUTABLE shapeclustering # EXECUTABLE shapeclustering
######################################## # ##############################################################################
if(NOT DISABLED_LEGACY_ENGINE) if(NOT DISABLED_LEGACY_ENGINE)
add_executable(shapeclustering shapeclustering.cpp) add_executable(shapeclustering shapeclustering.cpp)
target_link_libraries(shapeclustering common_training) target_link_libraries(shapeclustering common_training)
project_group(shapeclustering "Training Tools") project_group(shapeclustering "Training Tools")
install (TARGETS shapeclustering RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS shapeclustering
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif() endif()
# ##############################################################################
########################################
# EXECUTABLE wordlist2dawg # EXECUTABLE wordlist2dawg
######################################## # ##############################################################################
add_executable(wordlist2dawg wordlist2dawg.cpp) add_executable(wordlist2dawg wordlist2dawg.cpp)
target_link_libraries(wordlist2dawg common_training) target_link_libraries(wordlist2dawg common_training)
project_group(wordlist2dawg "Training Tools") project_group(wordlist2dawg "Training Tools")
install (TARGETS wordlist2dawg RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS wordlist2dawg
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
if(ICU_FOUND) if(ICU_FOUND)
@ -199,90 +234,105 @@ if (NOT SW_BUILD)
include_directories(${ICU_INCLUDE_DIRS}) include_directories(${ICU_INCLUDE_DIRS})
endif() endif()
######################################## # ############################################################################
# LIBRARY unicharset_training # LIBRARY unicharset_training
######################################## # ############################################################################
file(GLOB unicharset_training_src file(GLOB unicharset_training_src unicharset/*)
unicharset/*
)
add_library(unicharset_training ${unicharset_training_src}) add_library(unicharset_training ${unicharset_training_src})
if(SW_BUILD) if(SW_BUILD)
target_link_libraries (unicharset_training PUBLIC common_training org.sw.demo.unicode.icu.i18n) target_link_libraries(unicharset_training
PUBLIC common_training org.sw.demo.unicode.icu.i18n)
else() else()
target_link_libraries (unicharset_training PUBLIC common_training ${ICU_LINK_LIBRARIES}) target_link_libraries(unicharset_training PUBLIC common_training
${ICU_LINK_LIBRARIES})
endif() endif()
target_include_directories (unicharset_training PUBLIC unicharset ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(unicharset_training
generate_export_header (unicharset_training EXPORT_MACRO_NAME TESS_UNICHARSET_TRAINING_API) PUBLIC unicharset ${CMAKE_CURRENT_BINARY_DIR})
generate_export_header(unicharset_training EXPORT_MACRO_NAME
TESS_UNICHARSET_TRAINING_API)
project_group(unicharset_training "Training Tools") project_group(unicharset_training "Training Tools")
# ############################################################################
########################################
# EXECUTABLE combine_lang_model # EXECUTABLE combine_lang_model
######################################## # ############################################################################
add_executable(combine_lang_model combine_lang_model.cpp) add_executable(combine_lang_model combine_lang_model.cpp)
target_link_libraries(combine_lang_model unicharset_training) target_link_libraries(combine_lang_model unicharset_training)
project_group(combine_lang_model "Training Tools") project_group(combine_lang_model "Training Tools")
install (TARGETS combine_lang_model RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS combine_lang_model
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
# ############################################################################
########################################
# EXECUTABLE lstmeval # EXECUTABLE lstmeval
######################################## # ############################################################################
add_executable(lstmeval lstmeval.cpp) add_executable(lstmeval lstmeval.cpp)
target_link_libraries(lstmeval unicharset_training ${LIB_pthread}) target_link_libraries(lstmeval unicharset_training ${LIB_pthread})
project_group(lstmeval "Training Tools") project_group(lstmeval "Training Tools")
install (TARGETS lstmeval RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS lstmeval
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
# ############################################################################
########################################
# EXECUTABLE lstmtraining # EXECUTABLE lstmtraining
######################################## # ############################################################################
add_executable(lstmtraining lstmtraining.cpp) add_executable(lstmtraining lstmtraining.cpp)
target_link_libraries(lstmtraining unicharset_training ${LIB_pthread}) target_link_libraries(lstmtraining unicharset_training ${LIB_pthread})
project_group(lstmtraining "Training Tools") project_group(lstmtraining "Training Tools")
install (TARGETS lstmtraining RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS lstmtraining
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
# ############################################################################
########################################
# EXECUTABLE merge_unicharsets # EXECUTABLE merge_unicharsets
######################################## # ############################################################################
add_executable(merge_unicharsets merge_unicharsets.cpp) add_executable(merge_unicharsets merge_unicharsets.cpp)
target_link_libraries(merge_unicharsets common_training) target_link_libraries(merge_unicharsets common_training)
project_group(merge_unicharsets "Training Tools") project_group(merge_unicharsets "Training Tools")
install (TARGETS merge_unicharsets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS merge_unicharsets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
# ############################################################################
########################################
# EXECUTABLE set_unicharset_properties # EXECUTABLE set_unicharset_properties
######################################## # ############################################################################
add_executable(set_unicharset_properties set_unicharset_properties.cpp) add_executable(set_unicharset_properties set_unicharset_properties.cpp)
target_link_libraries(set_unicharset_properties unicharset_training) target_link_libraries(set_unicharset_properties unicharset_training)
project_group(set_unicharset_properties "Training Tools") project_group(set_unicharset_properties "Training Tools")
install (TARGETS set_unicharset_properties RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS set_unicharset_properties
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
# ############################################################################
########################################
# EXECUTABLE unicharset_extractor # EXECUTABLE unicharset_extractor
######################################## # ############################################################################
add_executable(unicharset_extractor unicharset_extractor.cpp) add_executable(unicharset_extractor unicharset_extractor.cpp)
target_link_libraries(unicharset_extractor unicharset_training) target_link_libraries(unicharset_extractor unicharset_training)
project_group(unicharset_extractor "Training Tools") project_group(unicharset_extractor "Training Tools")
install (TARGETS unicharset_extractor RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS unicharset_extractor
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
# ############################################################################
########################################
if (NOT SW_BUILD)
find_package(PkgConfig)
endif()
if(PKG_CONFIG_FOUND OR SW_BUILD) if(PKG_CONFIG_FOUND OR SW_BUILD)
@ -294,51 +344,50 @@ pkg_check_modules(PangoCairo REQUIRED pangocairo)
pkg_check_modules(FontConfig REQUIRED fontconfig) pkg_check_modules(FontConfig REQUIRED fontconfig)
endif() endif()
# ##########################################################################
########################################
# LIBRARY pango_training # LIBRARY pango_training
######################################## # ##########################################################################
file(GLOB pango_training_src file(GLOB pango_training_src pango/*)
pango/*
)
add_library(pango_training ${pango_training_src}) add_library(pango_training ${pango_training_src})
target_link_libraries(pango_training PUBLIC unicharset_training) target_link_libraries(pango_training PUBLIC unicharset_training)
if(SW_BUILD) if(SW_BUILD)
target_link_libraries (pango_training PUBLIC org.sw.demo.gnome.pango.pangocairo) target_link_libraries(pango_training
PUBLIC org.sw.demo.gnome.pango.pangocairo)
else() else()
if(PKG_CONFIG_FOUND) if(PKG_CONFIG_FOUND)
target_include_directories (pango_training BEFORE PUBLIC ${Cairo_INCLUDE_DIRS} ${Pango_INCLUDE_DIRS}) target_include_directories(
pango_training BEFORE PUBLIC ${Cairo_INCLUDE_DIRS}
${Pango_INCLUDE_DIRS})
target_compile_definitions(pango_training PUBLIC -DPANGO_ENABLE_ENGINE) target_compile_definitions(pango_training PUBLIC -DPANGO_ENABLE_ENGINE)
target_link_libraries (pango_training PUBLIC target_link_libraries(
${Pango_LINK_LIBRARIES} pango_training
${Cairo_LINK_LIBRARIES} PUBLIC ${Pango_LINK_LIBRARIES} ${Cairo_LINK_LIBRARIES}
${PangoCairo_LINK_LIBRARIES} ${PangoCairo_LINK_LIBRARIES} ${PangoFt2_LINK_LIBRARIES}
${PangoFt2_LINK_LIBRARIES} ${FontConfig_LINK_LIBRARIES})
${FontConfig_LINK_LIBRARIES}
)
endif() endif()
endif() endif()
target_include_directories (pango_training PUBLIC pango ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(pango_training
generate_export_header (pango_training EXPORT_MACRO_NAME TESS_PANGO_TRAINING_API) PUBLIC pango ${CMAKE_CURRENT_BINARY_DIR})
generate_export_header(pango_training EXPORT_MACRO_NAME
TESS_PANGO_TRAINING_API)
project_group(pango_training "Training Tools") project_group(pango_training "Training Tools")
# ##########################################################################
########################################
# EXECUTABLE text2image # EXECUTABLE text2image
######################################## # ##########################################################################
set(text2image_src set(TEXT2IMAGE_SRC text2image.cpp degradeimage.cpp degradeimage.h)
text2image.cpp
degradeimage.cpp
degradeimage.h
)
add_executable (text2image ${text2image_src}) add_executable(text2image ${TEXT2IMAGE_SRC})
target_link_libraries(text2image pango_training) target_link_libraries(text2image pango_training)
project_group(text2image "Training Tools") project_group(text2image "Training Tools")
install (TARGETS text2image RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(
TARGETS text2image
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif() endif()
endif(ICU_FOUND) endif(ICU_FOUND)