diff --git a/CMakeLists.txt b/CMakeLists.txt index fe221560..6ea534fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,25 +2,25 @@ # tesseract # -############################################################################### +# ############################################################################## # # cmake settings # -############################################################################### +# ############################################################################## cmake_minimum_required(VERSION 3.7 FATAL_ERROR) # In-source builds are disabled. -if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_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 .." - ) +if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_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_CURRENT_SOURCE_DIR}/cmake") @@ -33,32 +33,34 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake Targets") if(NOT ${CMAKE_VERSION} VERSION_LESS "3.15.0") - if (WIN32) - cmake_policy(SET CMP0091 NEW) - message(STATUS "Setting policy CMP0091 to NEW") - endif() + if(WIN32) + cmake_policy(SET CMP0091 NEW) + message(STATUS "Setting policy CMP0091 to NEW") + endif() endif() -############################################################################### +# ############################################################################## # # project settings # -############################################################################### +# ############################################################################## project(tesseract C CXX) # Get version with components from VERSION file. file(STRINGS "VERSION" VERSION_PLAIN) string(REGEX REPLACE "^([^.]*)\\..*" "\\1" VERSION_MAJOR ${VERSION_PLAIN}) -string(REGEX REPLACE "^[^.]*\\.([^.]*)\\..*" "\\1" VERSION_MINOR ${VERSION_PLAIN}) -string(REGEX REPLACE "^[^.]*\\.[^.]*\\.([0-9]*).*" "\\1" VERSION_PATCH ${VERSION_PLAIN}) +string(REGEX REPLACE "^[^.]*\\.([^.]*)\\..*" "\\1" VERSION_MINOR + ${VERSION_PLAIN}) +string(REGEX REPLACE "^[^.]*\\.[^.]*\\.([0-9]*).*" "\\1" VERSION_PATCH + ${VERSION_PLAIN}) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git) - execute_process(COMMAND git --git-dir ${CMAKE_CURRENT_SOURCE_DIR}/.git describe --abbrev=4 - OUTPUT_VARIABLE GIT_REV) - string(REGEX REPLACE "\n$" "" PACKAGE_VERSION "${GIT_REV}") + execute_process(COMMAND git --git-dir ${CMAKE_CURRENT_SOURCE_DIR}/.git + describe --abbrev=4 OUTPUT_VARIABLE GIT_REV) + string(REGEX REPLACE "\n$" "" PACKAGE_VERSION "${GIT_REV}") endif() if(NOT PACKAGE_VERSION) - set(PACKAGE_VERSION ${VERSION_PLAIN}) + set(PACKAGE_VERSION ${VERSION_PLAIN}) endif() # Provide also same macro names as autoconf (see configure.ac). @@ -68,20 +70,20 @@ set(GENERIC_MICRO_VERSION ${VERSION_PATCH}) set(MINIMUM_LEPTONICA_VERSION 1.74) -############################################################################### +# ############################################################################## # # options # -############################################################################### +# ############################################################################## -message( "Configuring tesseract version ${PACKAGE_VERSION}...") +message("Configuring tesseract version ${PACKAGE_VERSION}...") -if (WIN32) - option(SW_BUILD "Build with sw" ON) +if(WIN32) + option(SW_BUILD "Build with sw" ON) else() - option(SW_BUILD "Build with sw" OFF) + option(SW_BUILD "Build with sw" OFF) endif() -option(OPENMP_BUILD "Build with openmp support" OFF) # see issue #1662 +option(OPENMP_BUILD "Build with openmp support" OFF) # see issue #1662 option(GRAPHICS_DISABLED "Disable disable graphics (ScrollView)" OFF) option(DISABLED_LEGACY_ENGINE "Disable the legacy OCR engine" OFF) option(ENABLE_LTO "Enable link-time optimization" OFF) @@ -93,38 +95,40 @@ option(DISABLE_ARCHIVE "Disable build with libarchive (if available)" OFF) option(DISABLE_CURL "Disable build with libcurl (if available)" OFF) if(NOT ${CMAKE_VERSION} VERSION_LESS "3.15.0") - if(WIN32 AND MSVC) - option(WIN32_MT_BUILD "Build with MT flag for MSVC" OFF) - endif() + if(WIN32 AND MSVC) + option(WIN32_MT_BUILD "Build with MT flag for MSVC" OFF) + endif() endif() -############################################################################### +# ############################################################################## # # compiler and linker # -############################################################################### +# ############################################################################## if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CLANG 1) + set(CLANG 1) endif() if(NOT CMAKE_BUILD_TYPE) - 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_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") + 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_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release") endif() include(CheckCXXCompilerFlag) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # cygwin gnu c++ needs to use -std=gnu++17 instead of -std=c++17 - set(CMAKE_CXX_EXTENSIONS OFF) -endif () +if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # cygwin gnu c++ needs to use -std=gnu++17 instead of -std=c++17 + set(CMAKE_CXX_EXTENSIONS OFF) +endif() -if (BUILD_SHARED_LIBS) - set(CMAKE_CXX_VISIBILITY_PRESET hidden) +if(BUILD_SHARED_LIBS) + set(CMAKE_CXX_VISIBILITY_PRESET hidden) endif() # LTO @@ -132,279 +136,280 @@ cmake_policy(SET CMP0069 NEW) include(CheckIPOSupported) check_ipo_supported(RESULT LTO_SUPPORTED OUTPUT error) if(LTO_SUPPORTED) - message(STATUS "IPO / LTO supported") + message(STATUS "IPO / LTO supported") else() - message(STATUS "IPO / LTO not supported: <${error}>") + message(STATUS "IPO / LTO not supported: <${error}>") 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) - set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -march=native") - if(NOT CLANG AND MSVC) - # clang-cl does not know this argument - set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -mtune=native") - endif() - set(MARCH_NATIVE_OPT ON) + set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -march=native") + if(NOT CLANG AND MSVC) + # clang-cl does not know this argument + set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -mtune=native") + endif() + set(MARCH_NATIVE_OPT ON) endif() message("CMAKE_SYSTEM_PROCESSOR=<${CMAKE_SYSTEM_PROCESSOR}>") 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) -if(HAVE_AVX) + check_cxx_compiler_flag("-mavx" HAVE_AVX) + if(HAVE_AVX) set(AVX_COMPILE_FLAGS "-mavx") add_definitions("-DHAVE_AVX") -endif(HAVE_AVX) + endif(HAVE_AVX) -CHECK_CXX_COMPILER_FLAG("-mavx2" HAVE_AVX2) -if(HAVE_AVX2) + check_cxx_compiler_flag("-mavx2" HAVE_AVX2) + if(HAVE_AVX2) set(AVX2_COMPILE_FLAGS "-mavx2") add_definitions("-DHAVE_AVX2") -endif() + endif() -CHECK_CXX_COMPILER_FLAG("-mfma" HAVE_FMA) -if(HAVE_FMA) + check_cxx_compiler_flag("-mfma" HAVE_FMA) + if(HAVE_FMA) set(FMA_COMPILE_FLAGS "-mfma") add_definitions("-DHAVE_FMA") -endif() + endif() -CHECK_CXX_COMPILER_FLAG("-msse4.1" HAVE_SSE4_1) -if(HAVE_SSE4_1) + check_cxx_compiler_flag("-msse4.1" HAVE_SSE4_1) + if(HAVE_SSE4_1) set(SSE4_1_COMPILE_FLAGS "-msse4.1") add_definitions("-DHAVE_SSE4_1") -endif() + endif() -if(MSVC) + if(MSVC) if(NOT HAVE_AVX) - set(AVX_COMPILE_FLAGS "/arch:AVX") - set(HAVE_AVX ON) - add_definitions("-DHAVE_AVX") + set(AVX_COMPILE_FLAGS "/arch:AVX") + set(HAVE_AVX ON) + add_definitions("-DHAVE_AVX") endif() if(NOT HAVE_AVX2) - set(AVX2_COMPILE_FLAGS "/arch:AVX2") - set(HAVE_AVX2 ON) - add_definitions("-DHAVE_AVX2") - set(FMA_COMPILE_FLAGS "-D__FMA__") - set(HAVE_FMA ON) - add_definitions("-DHAVE_FMA") + set(AVX2_COMPILE_FLAGS "/arch:AVX2") + set(HAVE_AVX2 ON) + add_definitions("-DHAVE_AVX2") + set(FMA_COMPILE_FLAGS "-D__FMA__") + set(HAVE_FMA ON) + add_definitions("-DHAVE_FMA") endif() if(NOT HAVE_SSE4_1) - set(SSE4_1_COMPILE_FLAGS "-D__SSE4_1__") - set(HAVE_SSE4_1 ON) - add_definitions("-DHAVE_SSE4_1") + set(SSE4_1_COMPILE_FLAGS "-D__SSE4_1__") + set(HAVE_SSE4_1 ON) + add_definitions("-DHAVE_SSE4_1") endif() # clang with MSVC compatibility if(CLANG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-microsoft-unqualified-friend") - if(HAVE_FMA) - set(FMA_COMPILE_FLAGS "-mfma ${FMA_COMPILE_FLAGS}") - endif(HAVE_FMA) - if(HAVE_SSE4_1) - set(SSE4_1_COMPILE_FLAGS "-msse4.1 ${SSE4_1_COMPILE_FLAGS}") - endif(HAVE_SSE4_1) + set(CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -Wno-microsoft-unqualified-friend") + if(HAVE_FMA) + set(FMA_COMPILE_FLAGS "-mfma ${FMA_COMPILE_FLAGS}") + endif(HAVE_FMA) + if(HAVE_SSE4_1) + set(SSE4_1_COMPILE_FLAGS "-msse4.1 ${SSE4_1_COMPILE_FLAGS}") + endif(HAVE_SSE4_1) endif(CLANG) -endif(MSVC) + endif(MSVC) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64.*|AARCH64.*") -set(HAVE_AVX FALSE) -set(HAVE_AVX2 FALSE) -set(HAVE_FMA FALSE) -set(HAVE_SSE4_1 FALSE) + set(HAVE_AVX FALSE) + set(HAVE_AVX2 FALSE) + set(HAVE_FMA FALSE) + set(HAVE_SSE4_1 FALSE) -add_definitions("-DHAVE_NEON") -set(HAVE_NEON TRUE) + add_definitions("-DHAVE_NEON") + set(HAVE_NEON TRUE) else() -set(HAVE_AVX FALSE) -set(HAVE_AVX2 FALSE) -set(HAVE_FMA FALSE) -set(HAVE_SSE4_1 FALSE) + set(HAVE_AVX FALSE) + set(HAVE_AVX2 FALSE) + set(HAVE_FMA FALSE) + set(HAVE_SSE4_1 FALSE) -CHECK_CXX_COMPILER_FLAG("-mfpu=neon" HAVE_NEON) -if(HAVE_NEON) + check_cxx_compiler_flag("-mfpu=neon" HAVE_NEON) + if(HAVE_NEON) set(NEON_COMPILE_FLAGS "-mfpu=neon") add_definitions("-DHAVE_NEON") -endif() + endif() endif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86|x86_64|AMD64|amd64|i386|i686") # Compiler specific environments 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) - add_definitions(-D_CRT_SECURE_NO_WARNINGS) - add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) # strdup - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") - if (NOT CLANG) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") - endif() - # Hide some warnings for release target - # wd4244 'argument': conversion from 'uint64_t' to 'unsigned int', possible loss of data - # wd4251 needs to have dll-interface - # wd4267 return': conversion from 'size_t' to 'int', possible loss of data - # wd4275 non dll-interface class - # wd4305 ...truncation from 'double' to 'float' - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /wd4244 /wd4305 /wd4267 /wd4251 /wd4275") - # Don't use /Wall because it generates too many warnings. - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W0 /bigobj") - # MT flag - if(WIN32_MT_BUILD) - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - message (STATUS "Building with static CRT.") - endif() + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) # strdup + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") + if(NOT CLANG) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") + endif() + # Hide some warnings for release target wd4244 'argument': conversion from + # 'uint64_t' to 'unsigned int', possible loss of data wd4251 needs to have + # dll-interface wd4267 return': conversion from 'size_t' to 'int', possible + # loss of data wd4275 non dll-interface class wd4305 ...truncation from + # 'double' to 'float' + set(CMAKE_CXX_FLAGS_RELEASE + "${CMAKE_CXX_FLAGS_RELEASE} /wd4244 /wd4305 /wd4267 /wd4251 /wd4275") + # Don't use /Wall because it generates too many warnings. + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W0 /bigobj") + # MT flag + if(WIN32_MT_BUILD) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + message(STATUS "Building with static CRT.") + endif() endif() -if(CLANG) # clang all platforms - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-unused-command-line-argument") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -DDEBUG -pedantic -O0") +if(CLANG) # clang all platforms + set(CMAKE_CXX_FLAGS_RELEASE + "${CMAKE_CXX_FLAGS_RELEASE} -Wno-unused-command-line-argument") + set(CMAKE_CXX_FLAGS_DEBUG + "${CMAKE_CXX_FLAGS_DEBUG} -Wall -DDEBUG -pedantic -O0") endif() -if (OPENMP_BUILD AND MSVC AND "${MSVC_VERSION}" LESS 1929) - set(OPENMP_BUILD OFF) +if(OPENMP_BUILD + AND MSVC + AND "${MSVC_VERSION}" LESS 1929) + set(OPENMP_BUILD OFF) endif() -if (OPENMP_BUILD) - find_package(OpenMP QUIET) - if (OpenMP_FOUND) - message(">> ${OpenMP_FOUND} ${OpenMP_VERSION}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - if(${CMAKE_VERSION} VERSION_LESS "3.9.0") - add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE) - endif() +if(OPENMP_BUILD) + find_package(OpenMP QUIET) + if(OpenMP_FOUND) + message(">> OpenMP_FOUND ${OpenMP_FOUND} ${OpenMP_VERSION}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + if(${CMAKE_VERSION} VERSION_LESS "3.9.0") + add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE) endif() - # https://stackoverflow.com/questions/12399422/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 - # https://gitlab.kitware.com/cmake/cmake/issues/19404 - check_include_file_cxx(omp.h HAVE_OMP_H_INCLUDE) - find_library(OpenMP_LIBRARY NAMES omp libomp.lib) - message(">> OpenMP_LIBRARY: ${OpenMP_LIBRARY}") - if (MSVC) - set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS} /openmp") - else() - set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS} -fopenmp") - endif() - set(OpenMP_FOUND 1) - add_definitions(-D_OPENMP=201107) # 3.1 version is supported from Clang 3.8.0 - endif() - if (MSVC) - string(REPLACE "/openmp" "/openmp:llvm" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) - string(REPLACE "-openmp" "/openmp:llvm" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + endif() + # https://stackoverflow.com/questions/12399422 + # 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 + # https://gitlab.kitware.com/cmake/cmake/issues/19404 + check_include_file_cxx(omp.h HAVE_OMP_H_INCLUDE) + find_library(OpenMP_LIBRARY NAMES omp libomp.lib) + message(">> OpenMP_LIBRARY: ${OpenMP_LIBRARY}") + if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp") + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") endif() + set(OpenMP_FOUND 1) + # OpenMP 3.1 is fully supported from Clang 3.8.0 + add_definitions(-D_OPENMP=201107) + endif() + if(MSVC) + string(REPLACE "/openmp" "/openmp:llvm" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + string(REPLACE "-openmp" "/openmp:llvm" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + endif() endif() -if (CYGWIN) - add_definitions(-D__CYGWIN__) +if(CYGWIN) + add_definitions(-D__CYGWIN__) elseif(UNIX) - if (NOT ANDROID) - set(LIB_pthread pthread) - endif() + if(NOT ANDROID) + set(LIB_pthread pthread) + endif() elseif(WIN32) - set(LIB_Ws2_32 Ws2_32) + set(LIB_Ws2_32 Ws2_32) endif() add_definitions("-DCMAKE_BUILD") -############################################################################### +# ############################################################################## # # packages # -############################################################################### +# ############################################################################## -if (SW_BUILD) - find_package(SW REQUIRED) - if (BUILD_SHARED_LIBS) - set(SW_BUILD_SHARED_LIBS 1) - else() - set(SW_BUILD_SHARED_LIBS 0) - endif() - sw_add_package( - org.sw.demo.danbloomberg.leptonica - org.sw.demo.libarchive.libarchive - ) - if (BUILD_TRAINING_TOOLS) - sw_add_package( - org.sw.demo.gnome.pango.pangocairo - org.sw.demo.unicode.icu.i18n - ) - endif() - sw_execute() +if(SW_BUILD) + find_package(SW REQUIRED) + if(BUILD_SHARED_LIBS) + set(SW_BUILD_SHARED_LIBS 1) + else() + set(SW_BUILD_SHARED_LIBS 0) + endif() + sw_add_package(org.sw.demo.danbloomberg.leptonica + org.sw.demo.libarchive.libarchive) + if(BUILD_TRAINING_TOOLS) + sw_add_package(org.sw.demo.gnome.pango.pangocairo + org.sw.demo.unicode.icu.i18n) + endif() + sw_execute() else() - find_package(PkgConfig) - if(BUILD_TRAINING_TOOLS) - message(WARNING "Building of Training Tools requires PkgConfig") - 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) - if (NOT Leptonica_FOUND AND PKG_CONFIG_EXECUTABLE) - pkg_check_modules(Leptonica lept>=${MINIMUM_LEPTONICA_VERSION}) - link_directories(${Leptonica_LIBRARY_DIRS}) - endif() - if (NOT Leptonica_FOUND) - message(FATAL_ERROR "Cannot find required library Leptonica. Quitting!") - endif(NOT Leptonica_FOUND) - include_directories(${Leptonica_INCLUDE_DIRS}) + find_package(PkgConfig) + # Check for required library. option -DLeptonica_DIR=path => cmake hint where + # to find leptonica + find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} CONFIG) + if(NOT Leptonica_FOUND AND PKG_CONFIG_EXECUTABLE) + pkg_check_modules(Leptonica lept>=${MINIMUM_LEPTONICA_VERSION}) + link_directories(${Leptonica_LIBRARY_DIRS}) + endif() + if(NOT Leptonica_FOUND) + message(FATAL_ERROR "Cannot find required library Leptonica. Quitting!") + endif(NOT Leptonica_FOUND) + include_directories(${Leptonica_INCLUDE_DIRS}) - # Check for optional libraries. - find_package(TIFF) # for tesseract - if(NOT TIFF_FOUND AND PKG_CONFIG_EXECUTABLE) - # try PKG_CONFIG to find libtiff if cmake failed - pkg_check_modules(TIFF libtiff-4) + # Check for optional libraries. + find_package(TIFF) # for tesseract + if(NOT TIFF_FOUND AND PKG_CONFIG_EXECUTABLE) + # try PKG_CONFIG to find libtiff if cmake failed + pkg_check_modules(TIFF libtiff-4) + endif() + if(TIFF_FOUND) + set(HAVE_TIFFIO_H ON) + include_directories(${TIFF_INCLUDE_DIRS}) + endif(TIFF_FOUND) + if(DISABLE_ARCHIVE) + set(HAVE_LIBARCHIVE OFF) + else(DISABLE_ARCHIVE) + find_package(LibArchive) + if(NOT LibArchive_FOUND AND PKG_CONFIG_EXECUTABLE) + # try PKG_CONFIG to find libarchive if cmake failed + pkg_check_modules(LibArchive libarchive) endif() - if(TIFF_FOUND) - set(HAVE_TIFFIO_H ON) - include_directories(${TIFF_INCLUDE_DIRS}) - endif(TIFF_FOUND) - if(DISABLE_ARCHIVE) - set(HAVE_LIBARCHIVE OFF) - else(DISABLE_ARCHIVE) - find_package(LibArchive) - if(NOT LibArchive_FOUND AND PKG_CONFIG_EXECUTABLE) - # try PKG_CONFIG to find libarchive if cmake failed - pkg_check_modules(LibArchive libarchive) - endif() - if(LibArchive_FOUND) - set(HAVE_LIBARCHIVE ON) - include_directories(${LibArchive_INCLUDE_DIRS}) - endif(LibArchive_FOUND) - endif(DISABLE_ARCHIVE) - if (DISABLE_CURL) - set(HAVE_LIBCURL OFF) - else(DISABLE_CURL) - find_package(CURL) - if(NOT CURL_FOUND AND PKG_CONFIG_EXECUTABLE) - # try PKG_CONFIG to find libcurl if cmake failed - pkg_check_modules(CURL libcurl) - endif() - if(CURL_FOUND) - set(HAVE_LIBCURL ON) - include_directories(${CURL_INCLUDE_DIRS}) - endif(CURL_FOUND) - endif(DISABLE_CURL) + if(LibArchive_FOUND) + set(HAVE_LIBARCHIVE ON) + include_directories(${LibArchive_INCLUDE_DIRS}) + endif(LibArchive_FOUND) + endif(DISABLE_ARCHIVE) + if(DISABLE_CURL) + set(HAVE_LIBCURL OFF) + else(DISABLE_CURL) + find_package(CURL) + if(NOT CURL_FOUND AND PKG_CONFIG_EXECUTABLE) + # try PKG_CONFIG to find libcurl if cmake failed + pkg_check_modules(CURL libcurl) + endif() + if(CURL_FOUND) + set(HAVE_LIBCURL ON) + include_directories(${CURL_INCLUDE_DIRS}) + endif(CURL_FOUND) + endif(DISABLE_CURL) endif() find_package(OpenCL QUIET) - -############################################################################### +# ############################################################################## # # configure # -############################################################################### +# ############################################################################## -if (NOT MSVC) - set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -O3 -ffast-math") +if(NOT MSVC) + set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -O3 -ffast-math") endif() if(NOT DEFINED CMAKE_INSTALL_LIBDIR) - set(CMAKE_INSTALL_LIBDIR lib) + set(CMAKE_INSTALL_LIBDIR lib) endif(NOT DEFINED CMAKE_INSTALL_LIBDIR) set(AUTOCONFIG_SRC ${CMAKE_CURRENT_BINARY_DIR}/config_auto.h.in) @@ -412,9 +417,11 @@ set(AUTOCONFIG ${CMAKE_CURRENT_BINARY_DIR}/config_auto.h) add_definitions(-DHAVE_CONFIG_H) if(GRAPHICS_DISABLED) - message("ScrollView debugging disabled.") + message("ScrollView debugging disabled.") 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) configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY) @@ -422,61 +429,65 @@ configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY) set(INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include") set(LIBRARY_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/include/tesseract/version.h.in - ${CMAKE_CURRENT_BINARY_DIR}/include/tesseract/version.h @ONLY) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/tesseract/version.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/tesseract/version.h @ONLY) include(CMakePackageConfigHelpers) include(GenerateExportHeader) # show summary of configuration if(${CMAKE_BUILD_TYPE} MATCHES Debug) - set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") + set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}") elseif(${CMAKE_BUILD_TYPE} MATCHES Release) - set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") - if (LTO_SUPPORTED AND ENABLE_LTO) - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) - else() - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE) - endif() # LTO_SUPPORTED + set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}") + if(LTO_SUPPORTED AND ENABLE_LTO) + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) + else() + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE) + endif() # LTO_SUPPORTED endif() -message( STATUS ) -message( STATUS "General configuration for Tesseract ${PACKAGE_VERSION}") -message( STATUS "--------------------------------------------------------") -message( STATUS "Build type: ${CMAKE_BUILD_TYPE}") -message( STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}") -message( STATUS "Used standard: C++${CMAKE_CXX_STANDARD}") -message( STATUS "CXX compiler options: ${COMPILER_FLAGS}") -get_directory_property( DirCompDefs COMPILE_DEFINITIONS) -message( STATUS "Compile definitions = ${DirCompDefs}") -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 "HAVE_AVX: ${HAVE_AVX}") -message( STATUS "HAVE_AVX2: ${HAVE_AVX2}") -message( STATUS "HAVE_FMA: ${HAVE_FMA}") -message( STATUS "HAVE_SSE4_1: ${HAVE_SSE4_1}") -message( STATUS "MARCH_NATIVE_OPT: ${MARCH_NATIVE_OPT}") -message( STATUS "HAVE_NEON: ${HAVE_NEON}") -message( STATUS "Link-time optimization: ${CMAKE_INTERPROCEDURAL_OPTIMIZATION}") -message( STATUS "--------------------------------------------------------") -message( STATUS "Build with sw [SW_BUILD]: ${SW_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 libcurl support [HAVE_LIBCURL]: ${HAVE_LIBCURL}") -message( STATUS "Enable float for LSTM [FAST_FLOAT]: ${FAST_FLOAT}") -message( STATUS "Disable disable graphics (ScrollView) [GRAPHICS_DISABLED]: ${GRAPHICS_DISABLED}") -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 "Use system ICU Library [USE_SYSTEM_ICU]: ${USE_SYSTEM_ICU}") -message( STATUS "--------------------------------------------------------") -message( STATUS ) +message(STATUS) +message(STATUS "General configuration for Tesseract ${PACKAGE_VERSION}") +message(STATUS "--------------------------------------------------------") +message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") +message(STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}") +message(STATUS "Used standard: C++${CMAKE_CXX_STANDARD}") +message(STATUS "CXX compiler options: ${COMPILER_FLAGS}") +get_directory_property(DirCompDefs COMPILE_DEFINITIONS) +message(STATUS "Compile definitions = ${DirCompDefs}") +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 "HAVE_AVX: ${HAVE_AVX}") +message(STATUS "HAVE_AVX2: ${HAVE_AVX2}") +message(STATUS "HAVE_FMA: ${HAVE_FMA}") +message(STATUS "HAVE_SSE4_1: ${HAVE_SSE4_1}") +message(STATUS "MARCH_NATIVE_OPT: ${MARCH_NATIVE_OPT}") +message(STATUS "HAVE_NEON: ${HAVE_NEON}") +message(STATUS "Link-time optimization: ${CMAKE_INTERPROCEDURAL_OPTIMIZATION}") +message(STATUS "--------------------------------------------------------") +message(STATUS "Build with sw [SW_BUILD]: ${SW_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 libcurl support [HAVE_LIBCURL]: ${HAVE_LIBCURL}") +message(STATUS "Enable float for LSTM [FAST_FLOAT]: ${FAST_FLOAT}") +message(STATUS "Disable disable graphics (ScrollView) [GRAPHICS_DISABLED]: " + "${GRAPHICS_DISABLED}") +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 "Use system ICU Library [USE_SYSTEM_ICU]: ${USE_SYSTEM_ICU}") +message(STATUS "--------------------------------------------------------") +message(STATUS) -############################################################################### +# ############################################################################## # # build # -############################################################################### +# ############################################################################## include(BuildFunctions) include(SourceGroups) @@ -486,160 +497,167 @@ add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1) include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) if(ANDROID_TOOLCHAIN) - include_directories(${ANDROID_TOOLCHAIN}/sysroot/usr/include) - add_compile_definitions(__ANDROID_API_FUTURE__) + include_directories(${ANDROID_TOOLCHAIN}/sysroot/usr/include) + add_compile_definitions(__ANDROID_API_FUTURE__) endif() -######################################## +# ############################################################################## # LIBRARY tesseract -######################################## +# ############################################################################## -file(GLOB tesseract_src - src/ccmain/*.cpp - src/ccstruct/*.cpp - src/ccutil/*.cpp - src/classify/*.cpp - src/cutil/*.cpp - src/dict/*.cpp - src/lstm/*.cpp - src/opencl/*.cpp - src/textord/*.cpp - src/viewer/*.cpp - src/wordrec/*.cpp -) +file( + GLOB + TESSERACT_SRC + src/ccmain/*.cpp + src/ccstruct/*.cpp + src/ccutil/*.cpp + src/classify/*.cpp + src/cutil/*.cpp + src/dict/*.cpp + src/lstm/*.cpp + src/opencl/*.cpp + src/textord/*.cpp + src/viewer/*.cpp + src/wordrec/*.cpp) -if (DISABLED_LEGACY_ENGINE) - function(prepend_path srcs path) - set(tmp, "") - foreach(src IN LISTS ${srcs}) - list(APPEND tmp ${path}/${src}) - endforeach(src ${srcs}) - set(${srcs} ${tmp} PARENT_SCOPE) - endfunction() +if(DISABLED_LEGACY_ENGINE) + # prepend path to list of source files + function(prepend_path srcs path) + set(tmp, "") + foreach(src IN LISTS ${srcs}) + list(APPEND tmp ${path}/${src}) + endforeach(src ${srcs}) + set(${srcs} + ${tmp} + PARENT_SCOPE) + endfunction() - SET(tesseract_src_legacy - src/ccmain/adaptions.cpp - src/ccmain/docqual.cpp - src/ccmain/equationdetect.cpp - src/ccmain/fixspace.cpp - src/ccmain/fixxht.cpp - src/ccmain/osdetect.cpp - src/ccmain/par_control.cpp - src/ccmain/recogtraining.cpp - src/ccmain/superscript.cpp - src/ccmain/tessbox.cpp - src/ccmain/tfacepp.cpp - src/ccstruct/fontinfo.cpp - src/ccstruct/params_training_featdef.cpp - src/ccutil/ambigs.cpp - src/ccutil/bitvector.cpp - src/ccutil/indexmapbidi.cpp - src/classify/adaptive.cpp - src/classify/adaptmatch.cpp - src/classify/blobclass.cpp - src/classify/cluster.cpp - src/classify/clusttool.cpp - src/classify/cutoffs.cpp - src/classify/featdefs.cpp - src/classify/float2int.cpp - src/classify/fpoint.cpp - src/classify/intfeaturespace.cpp - src/classify/intfx.cpp - src/classify/intmatcher.cpp - src/classify/intproto.cpp - src/classify/kdtree.cpp - src/classify/mf.cpp - src/classify/mfoutline.cpp - src/classify/mfx.cpp - src/classify/normfeat.cpp - src/classify/normmatch.cpp - src/classify/ocrfeatures.cpp - src/classify/outfeat.cpp - src/classify/picofeat.cpp - src/classify/protos.cpp - src/classify/shapeclassifier.cpp - src/classify/shapetable.cpp - src/classify/tessclassifier.cpp - src/classify/trainingsample.cpp - src/dict/permdawg.cpp - src/dict/hyphen.cpp - src/wordrec/associate.cpp - src/wordrec/chop.cpp - src/wordrec/chopper.cpp - src/wordrec/drawfx.cpp - src/wordrec/findseam.cpp - src/wordrec/gradechop.cpp - src/wordrec/language_model.cpp - src/wordrec/lm_consistency.cpp - src/wordrec/lm_pain_points.cpp - src/wordrec/lm_state.cpp - src/wordrec/outlines.cpp - src/wordrec/params_model.cpp - src/wordrec/pieces.cpp - src/wordrec/plotedges.cpp - src/wordrec/render.cpp - src/wordrec/segsearch.cpp - src/wordrec/wordclass.cpp - ) - prepend_path(tesseract_src_legacy "${CMAKE_CURRENT_SOURCE_DIR}") - list(REMOVE_ITEM tesseract_src ${tesseract_src_legacy}) +set(TESSERACT_SRC_LEGACY + src/ccmain/adaptions.cpp + src/ccmain/docqual.cpp + src/ccmain/equationdetect.cpp + src/ccmain/fixspace.cpp + src/ccmain/fixxht.cpp + src/ccmain/osdetect.cpp + src/ccmain/par_control.cpp + src/ccmain/recogtraining.cpp + src/ccmain/superscript.cpp + src/ccmain/tessbox.cpp + src/ccmain/tfacepp.cpp + src/ccstruct/fontinfo.cpp + src/ccstruct/params_training_featdef.cpp + src/ccutil/ambigs.cpp + src/ccutil/bitvector.cpp + src/ccutil/indexmapbidi.cpp + src/classify/adaptive.cpp + src/classify/adaptmatch.cpp + src/classify/blobclass.cpp + src/classify/cluster.cpp + src/classify/clusttool.cpp + src/classify/cutoffs.cpp + src/classify/featdefs.cpp + src/classify/float2int.cpp + src/classify/fpoint.cpp + src/classify/intfeaturespace.cpp + src/classify/intfx.cpp + src/classify/intmatcher.cpp + src/classify/intproto.cpp + src/classify/kdtree.cpp + src/classify/mf.cpp + src/classify/mfoutline.cpp + src/classify/mfx.cpp + src/classify/normfeat.cpp + src/classify/normmatch.cpp + src/classify/ocrfeatures.cpp + src/classify/outfeat.cpp + src/classify/picofeat.cpp + src/classify/protos.cpp + src/classify/shapeclassifier.cpp + src/classify/shapetable.cpp + src/classify/tessclassifier.cpp + src/classify/trainingsample.cpp + src/dict/permdawg.cpp + src/dict/hyphen.cpp + src/wordrec/associate.cpp + src/wordrec/chop.cpp + src/wordrec/chopper.cpp + src/wordrec/drawfx.cpp + src/wordrec/findseam.cpp + src/wordrec/gradechop.cpp + src/wordrec/language_model.cpp + src/wordrec/lm_consistency.cpp + src/wordrec/lm_pain_points.cpp + src/wordrec/lm_state.cpp + src/wordrec/outlines.cpp + src/wordrec/params_model.cpp + src/wordrec/pieces.cpp + src/wordrec/plotedges.cpp + src/wordrec/render.cpp + src/wordrec/segsearch.cpp + src/wordrec/wordclass.cpp) + prepend_path(TESSERACT_SRC_LEGACY "${CMAKE_CURRENT_SOURCE_DIR}") + list(REMOVE_ITEM TESSERACT_SRC ${TESSERACT_SRC_LEGACY}) endif(DISABLED_LEGACY_ENGINE) -list(APPEND arch_files - src/arch/dotproduct.cpp - src/arch/simddetect.cpp - src/arch/intsimdmatrix.cpp -) +list(APPEND arch_files src/arch/dotproduct.cpp src/arch/simddetect.cpp + src/arch/intsimdmatrix.cpp) if(MARCH_NATIVE_FLAGS) - set_source_files_properties(src/arch/dotproduct.cpp - PROPERTIES COMPILE_FLAGS ${MARCH_NATIVE_FLAGS}) + set_source_files_properties(src/arch/dotproduct.cpp + PROPERTIES COMPILE_FLAGS ${MARCH_NATIVE_FLAGS}) endif(MARCH_NATIVE_FLAGS) if(HAVE_AVX) - list(APPEND arch_files_opt src/arch/dotproductavx.cpp) - set_source_files_properties(src/arch/dotproductavx.cpp - PROPERTIES COMPILE_FLAGS ${AVX_COMPILE_FLAGS}) + list(APPEND arch_files_opt src/arch/dotproductavx.cpp) + set_source_files_properties(src/arch/dotproductavx.cpp + PROPERTIES COMPILE_FLAGS ${AVX_COMPILE_FLAGS}) endif(HAVE_AVX) if(HAVE_AVX2) - list(APPEND arch_files_opt src/arch/intsimdmatrixavx2.cpp src/arch/dotproductavx.cpp) - set_source_files_properties(src/arch/intsimdmatrixavx2.cpp - PROPERTIES COMPILE_FLAGS ${AVX2_COMPILE_FLAGS}) + list(APPEND arch_files_opt src/arch/intsimdmatrixavx2.cpp + src/arch/dotproductavx.cpp) + set_source_files_properties(src/arch/intsimdmatrixavx2.cpp + PROPERTIES COMPILE_FLAGS ${AVX2_COMPILE_FLAGS}) endif(HAVE_AVX2) if(HAVE_FMA) - list(APPEND arch_files_opt src/arch/dotproductfma.cpp) - set_source_files_properties(src/arch/dotproductfma.cpp - PROPERTIES COMPILE_FLAGS ${FMA_COMPILE_FLAGS}) + list(APPEND arch_files_opt src/arch/dotproductfma.cpp) + set_source_files_properties(src/arch/dotproductfma.cpp + PROPERTIES COMPILE_FLAGS ${FMA_COMPILE_FLAGS}) endif(HAVE_FMA) if(HAVE_SSE4_1) - list(APPEND arch_files_opt src/arch/dotproductsse.cpp src/arch/intsimdmatrixsse.cpp) - set_source_files_properties(src/arch/dotproductsse.cpp src/arch/intsimdmatrixsse.cpp - PROPERTIES COMPILE_FLAGS ${SSE4_1_COMPILE_FLAGS}) + list(APPEND arch_files_opt src/arch/dotproductsse.cpp + src/arch/intsimdmatrixsse.cpp) + set_source_files_properties( + src/arch/dotproductsse.cpp src/arch/intsimdmatrixsse.cpp + PROPERTIES COMPILE_FLAGS ${SSE4_1_COMPILE_FLAGS}) endif(HAVE_SSE4_1) if(HAVE_NEON) - list(APPEND arch_files_opt src/arch/dotproductneon.cpp src/arch/intsimdmatrixneon.cpp) - if(NEON_COMPILE_FLAGS) - set_source_files_properties(src/arch/dotproductneon.cpp src/arch/intsimdmatrixneon.cpp - PROPERTIES COMPILE_FLAGS ${NEON_COMPILE_FLAGS}) - endif() + list(APPEND arch_files_opt src/arch/dotproductneon.cpp + src/arch/intsimdmatrixneon.cpp) + if(NEON_COMPILE_FLAGS) + set_source_files_properties( + src/arch/dotproductneon.cpp src/arch/intsimdmatrixneon.cpp + PROPERTIES COMPILE_FLAGS ${NEON_COMPILE_FLAGS}) + endif() endif(HAVE_NEON) -file(GLOB_RECURSE tesseract_hdr - include/* - src/arch/*.h - src/ccmain/*.h - src/ccstruct/*.h - src/ccutil/*.h - src/classify/*.h - src/cutil/*.h - src/dict/*.h - src/lstm/*.h - src/opencl/*.h - src/textord/*.h - src/viewer/*.h - src/wordrec/*.h -) +file( + GLOB_RECURSE + tesseract_hdr + include/* + src/arch/*.h + src/ccmain/*.h + src/ccstruct/*.h + src/ccutil/*.h + src/classify/*.h + src/cutil/*.h + src/dict/*.h + src/lstm/*.h + src/opencl/*.h + src/textord/*.h + src/viewer/*.h + src/wordrec/*.h) -set(tesseract_src ${tesseract_src} +set(TESSERACT_SRC + ${TESSERACT_SRC} src/api/baseapi.cpp src/api/capi.cpp src/api/renderer.cpp @@ -647,159 +665,181 @@ set(tesseract_src ${tesseract_src} src/api/hocrrenderer.cpp src/api/lstmboxrenderer.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}) -target_include_directories (libtesseract - PUBLIC $ - PRIVATE src - - PUBLIC $ - PUBLIC $ - PUBLIC $ - PUBLIC $ - PUBLIC $ - PUBLIC $ - PUBLIC $ - PUBLIC $ - PUBLIC $ - PUBLIC $ - PUBLIC $ - PUBLIC $ - PUBLIC $ -) -if (BUILD_SHARED_LIBS) -target_compile_definitions (libtesseract +add_library(libtesseract ${LIBTESSFILES}) +target_include_directories( + libtesseract + PRIVATE src + PUBLIC $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $) +if(BUILD_SHARED_LIBS) + target_compile_definitions( + libtesseract PRIVATE -DTESS_EXPORTS - INTERFACE -DTESS_IMPORTS -) -#generate_export_header (libtesseract EXPORT_MACRO_NAME TESS_API) + INTERFACE -DTESS_IMPORTS) + # generate_export_header (libtesseract EXPORT_MACRO_NAME TESS_API) endif() -target_link_libraries (libtesseract PRIVATE ${LIB_Ws2_32} ${LIB_pthread}) +target_link_libraries(libtesseract PRIVATE ${LIB_Ws2_32} ${LIB_pthread}) if(OpenMP_CXX_FOUND) - target_link_libraries(libtesseract PUBLIC OpenMP::OpenMP_CXX) + target_link_libraries(libtesseract PUBLIC OpenMP::OpenMP_CXX) endif() if(LibArchive_FOUND) - target_link_libraries(libtesseract PUBLIC ${LibArchive_LIBRARIES}) + target_link_libraries(libtesseract PUBLIC ${LibArchive_LIBRARIES}) endif(LibArchive_FOUND) if(CURL_FOUND) - if(NOT "${CURL_LIBRARIES}") - target_link_libraries(libtesseract PUBLIC CURL::libcurl) - else() - target_link_libraries(libtesseract PUBLIC ${CURL_LIBRARIES}) - endif() + if(NOT "${CURL_LIBRARIES}") + target_link_libraries(libtesseract PUBLIC CURL::libcurl) + else() + target_link_libraries(libtesseract PUBLIC ${CURL_LIBRARIES}) + endif() 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}) -if (WIN32) - 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) + +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) + 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) + set_target_properties(libtesseract PROPERTIES OUTPUT_NAME tesseract) endif() -if (SW_BUILD) - target_link_libraries (libtesseract PUBLIC - org.sw.demo.danbloomberg.leptonica - org.sw.demo.libarchive.libarchive - ) - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake "include(${CMAKE_CURRENT_BINARY_DIR}/cppan.cmake)\n") - export(TARGETS libtesseract APPEND FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake NAMESPACE Tesseract::) +if(SW_BUILD) + target_link_libraries(libtesseract PUBLIC org.sw.demo.danbloomberg.leptonica + org.sw.demo.libarchive.libarchive) + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake + "include(${CMAKE_CURRENT_BINARY_DIR}/cppan.cmake)\n") + export( + TARGETS libtesseract + APPEND + FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake + NAMESPACE Tesseract::) else() - target_link_libraries (libtesseract PUBLIC ${Leptonica_LIBRARIES}) - export(TARGETS libtesseract FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake NAMESPACE Tesseract::) + target_link_libraries(libtesseract PUBLIC ${Leptonica_LIBRARIES}) + export( + TARGETS libtesseract + FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake + NAMESPACE Tesseract::) endif() -if (WIN32 AND CLANG 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}) +if(WIN32 + AND CLANG + 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}) endif() -######################################## +# ############################################################################## # EXECUTABLE tesseract -######################################## +# ############################################################################## -add_executable (tesseract src/tesseract.cpp) -target_link_libraries (tesseract libtesseract) -if (HAVE_TIFFIO_H AND WIN32) - target_link_libraries (tesseract ${TIFF_LIBRARIES}) +add_executable(tesseract src/tesseract.cpp) +target_link_libraries(tesseract libtesseract) +if(HAVE_TIFFIO_H AND WIN32) + target_link_libraries(tesseract ${TIFF_LIBRARIES}) endif() -if (OPENMP_BUILD AND UNIX) - target_link_libraries (tesseract pthread) +if(OPENMP_BUILD AND UNIX) + target_link_libraries(tesseract pthread) endif() -######################################## +# ############################################################################## -if (BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/unittest/third_party/googletest/CMakeLists.txt) - add_subdirectory(unittest/third_party/googletest) +if(BUILD_TESTS AND EXISTS + ${CMAKE_CURRENT_SOURCE_DIR}/unittest/third_party/googletest/CMakeLists.txt +) + add_subdirectory(unittest/third_party/googletest) endif() -if (BUILD_TRAINING_TOOLS) - add_subdirectory(src/training) +if(BUILD_TRAINING_TOOLS) + add_subdirectory(src/training) endif() 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) +configure_file(tesseract.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc + @ONLY) configure_package_config_file( - cmake/templates/TesseractConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/cmake/tesseract/TesseractConfig.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tesseract - PATH_VARS INCLUDE_DIR LIBRARY_DIRS) + cmake/templates/TesseractConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/cmake/tesseract/TesseractConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tesseract + PATH_VARS INCLUDE_DIR LIBRARY_DIRS) write_basic_package_version_file( - ${CMAKE_CURRENT_BINARY_DIR}/cmake/tesseract/TesseractConfigVersion.cmake - VERSION ${PACKAGE_VERSION} - COMPATIBILITY SameMajorVersion) + ${CMAKE_CURRENT_BINARY_DIR}/cmake/tesseract/TesseractConfigVersion.cmake + VERSION ${PACKAGE_VERSION} + 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 libtesseract EXPORT TesseractTargets RUNTIME DESTINATION bin LIBRARY - DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install(EXPORT TesseractTargets NAMESPACE Tesseract:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tesseract) -install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install( + TARGETS libtesseract + EXPORT TesseractTargets + RUNTIME DESTINATION bin + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install( + EXPORT TesseractTargets + NAMESPACE Tesseract:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/tesseract) +install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install(FILES - include/tesseract/baseapi.h - include/tesseract/capi.h - include/tesseract/renderer.h - ${CMAKE_CURRENT_BINARY_DIR}/include/tesseract/version.h +install( + FILES include/tesseract/baseapi.h + include/tesseract/capi.h + include/tesseract/renderer.h + ${CMAKE_CURRENT_BINARY_DIR}/include/tesseract/version.h + include/tesseract/ltrresultiterator.h + include/tesseract/pageiterator.h + include/tesseract/resultiterator.h + include/tesseract/osdetect.h + include/tesseract/publictypes.h + include/tesseract/ocrclass.h + include/tesseract/export.h + include/tesseract/unichar.h + # ${CMAKE_CURRENT_BINARY_DIR}/src/endianness.h + DESTINATION include/tesseract) - include/tesseract/ltrresultiterator.h - include/tesseract/pageiterator.h - include/tesseract/resultiterator.h - include/tesseract/osdetect.h - - include/tesseract/publictypes.h - - include/tesseract/ocrclass.h - include/tesseract/export.h - include/tesseract/unichar.h - - #${CMAKE_CURRENT_BINARY_DIR}/src/endianness.h - DESTINATION include/tesseract) - -######################################## +# ############################################################################## # uninstall target -######################################## +# ############################################################################## if(NOT TARGET uninstall) - configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/cmake_uninstall.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" - IMMEDIATE @ONLY) + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) - add_custom_target(uninstall - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) + add_custom_target( + uninstall + COMMENT "Uninstall installed files" + COMMAND ${CMAKE_COMMAND} -P + ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) endif() -############################################################################### +# ############################################################################## diff --git a/src/training/CMakeLists.txt b/src/training/CMakeLists.txt index d5ec214e..e75e7c02 100644 --- a/src/training/CMakeLists.txt +++ b/src/training/CMakeLists.txt @@ -3,73 +3,82 @@ # cmake_policy(SET CMP0074 NEW) -if (UNIX AND NOT ANDROID) - set(LIB_pthread pthread) +if(UNIX AND NOT ANDROID) + set(LIB_pthread pthread) endif() -if (SW_BUILD) - set(ICU_FOUND 1) +if(SW_BUILD) + set(ICU_FOUND 1) +else() # NOT SW_BUILD + find_package(PkgConfig) endif() # experimental -if (MSVC AND NOT SW_BUILD AND NOT USE_SYSTEM_ICU) - include(CheckTypeSize) - check_type_size("void *" SIZEOF_VOID_P) +# 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) + check_type_size("void *" SIZEOF_VOID_P) - if (SIZEOF_VOID_P EQUAL 8) - set(X64 1) - set(ARCH_DIR_NAME 64) - elseif (SIZEOF_VOID_P EQUAL 4) - set(X86 1) - set(ARCH_DIR_NAME 32) - else() - message(FATAL_ERROR "Cannot determine target architecture") - endif() + if(SIZEOF_VOID_P EQUAL 8) + set(X64 1) + set(ARCH_NAME 64) + elseif(SIZEOF_VOID_P EQUAL 4) + set(X86 1) + set(ARCH_NAME 32) + else() + message(FATAL_ERROR "Cannot determine target architecture") + endif() - set(icu_dir "${CMAKE_CURRENT_BINARY_DIR}/icu") - set(icu_archive "${icu_dir}/icu${ARCH_DIR_NAME}.zip") + set(ICU_DIR "${CMAKE_CURRENT_BINARY_DIR}/icu") + set(ICU_ARCHIVE "${ICU_DIR}/icu${ARCH_NAME}.zip") - if (X86) - set(icu_hash 45167a240b60e36b59a87eda23490ce4) - else() - set(icu_hash 480c72491576c048de1218c3c5519399) - endif() + if(X86) + set(ICU_HASH 45167a240b60e36b59a87eda23490ce4) + else() + set(ICU_HASH 480c72491576c048de1218c3c5519399) + endif() - message(STATUS "Downloading latest ICU binaries") + message(STATUS "Downloading latest ICU binaries") + set(COMPILER "msvc10") + set(ICU_URL "https://github.com/unicode-org/icu/releases/download") + SET(ICU_R "56-1") + SET(ICU_V "56_1") + file( + DOWNLOAD + "${ICU_URL}/release-${ICU_R}/icu4c-${ICU_V}-Win${ARCH_NAME}-${COMPILER}.zip" + "${ICU_ARCHIVE}" + SHOW_PROGRESS + INACTIVITY_TIMEOUT 300 # seconds + EXPECTED_HASH MD5=${ICU_HASH}) + execute_process( + COMMAND ${CMAKE_COMMAND} -E tar xz "${ICU_ARCHIVE}" + WORKING_DIRECTORY "${ICU_DIR}" + RESULT_VARIABLE __result) + if(NOT __result EQUAL 0) + message(FATAL_ERROR "error ${__result}") + endif() - file(DOWNLOAD - "https://github.com/unicode-org/icu/releases/download/release-56-1/icu4c-56_1-Win${ARCH_DIR_NAME}-msvc10.zip" - "${icu_archive}" - SHOW_PROGRESS - INACTIVITY_TIMEOUT 300 # seconds - EXPECTED_HASH MD5=${icu_hash} - ) - execute_process(COMMAND ${CMAKE_COMMAND} -E tar xz "${icu_archive}" - WORKING_DIRECTORY "${icu_dir}" - RESULT_VARIABLE __result - ) - if(NOT __result EQUAL 0) - message(FATAL_ERROR "error ${__result}") - endif() - - set(ICU_ROOT ${icu_dir}/icu) + set(ICU_ROOT ${ICU_DIR}/icu) endif() # experimental -if (NOT SW_BUILD) - if (PKG_CONFIG_FOUND) - pkg_check_modules(ICU REQUIRED icu-uc icu-i18n) - else() - find_package(ICU 52.1 COMPONENTS uc i18n) - endif() +if(NOT SW_BUILD) + if(PKG_CONFIG_FOUND) + pkg_check_modules(ICU REQUIRED icu-uc icu-i18n) + else() + find_package(ICU 52.1 COMPONENTS uc i18n) + endif() endif() - -######################################## +# ############################################################################## # LIBRARY common_training -######################################## +# ############################################################################## -set(common_training_src +set(COMMON_TRAINING_SRC common/commandlineflags.cpp common/commandlineflags.h common/commontraining.cpp @@ -77,11 +86,12 @@ set(common_training_src common/ctc.cpp common/ctc.h common/networkbuilder.cpp - common/networkbuilder.h -) + common/networkbuilder.h) -if (NOT DISABLED_LEGACY_ENGINE) -list(APPEND common_training_src +if(NOT DISABLED_LEGACY_ENGINE) + list( + APPEND + COMMON_TRAINING_SRC common/errorcounter.cpp common/errorcounter.h common/intfeaturedist.cpp @@ -93,254 +103,293 @@ list(APPEND common_training_src common/sampleiterator.cpp common/sampleiterator.h common/trainingsampleset.cpp - common/trainingsampleset.h -) + common/trainingsampleset.h) endif() -add_library (common_training ${common_training_src}) -target_include_directories (common_training PUBLIC common ${CMAKE_CURRENT_BINARY_DIR}) -target_link_libraries (common_training PUBLIC libtesseract) -generate_export_header (common_training EXPORT_MACRO_NAME TESS_COMMON_TRAINING_API) -project_group (common_training "Training Tools") +add_library(common_training ${COMMON_TRAINING_SRC}) +target_include_directories(common_training PUBLIC common + ${CMAKE_CURRENT_BINARY_DIR}) +target_link_libraries(common_training PUBLIC libtesseract) +generate_export_header(common_training EXPORT_MACRO_NAME + TESS_COMMON_TRAINING_API) +project_group(common_training "Training Tools") -######################################## +# ############################################################################## # EXECUTABLE ambiguous_words -######################################## +# ############################################################################## -if (NOT DISABLED_LEGACY_ENGINE) -add_executable (ambiguous_words ambiguous_words.cpp) -target_link_libraries (ambiguous_words common_training) -project_group (ambiguous_words "Training Tools") -install (TARGETS ambiguous_words RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +if(NOT DISABLED_LEGACY_ENGINE) + add_executable(ambiguous_words ambiguous_words.cpp) + target_link_libraries(ambiguous_words common_training) + project_group(ambiguous_words "Training Tools") + install( + TARGETS ambiguous_words + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) endif() - -######################################## +# ############################################################################## # EXECUTABLE classifier_tester -######################################## +# ############################################################################## -if (NOT DISABLED_LEGACY_ENGINE) -add_executable (classifier_tester classifier_tester.cpp) -target_link_libraries (classifier_tester common_training) -project_group (classifier_tester "Training Tools") -install (TARGETS classifier_tester RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +if(NOT DISABLED_LEGACY_ENGINE) + add_executable(classifier_tester classifier_tester.cpp) + target_link_libraries(classifier_tester common_training) + project_group(classifier_tester "Training Tools") + install( + TARGETS classifier_tester + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) endif() - -######################################## +# ############################################################################## # EXECUTABLE combine_tessdata -######################################## +# ############################################################################## -add_executable (combine_tessdata combine_tessdata.cpp) -target_link_libraries (combine_tessdata common_training) -project_group (combine_tessdata "Training Tools") -install (TARGETS combine_tessdata RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +add_executable(combine_tessdata combine_tessdata.cpp) +target_link_libraries(combine_tessdata common_training) +project_group(combine_tessdata "Training Tools") +install( + TARGETS combine_tessdata + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) - -######################################## +# ############################################################################## # EXECUTABLE cntraining -######################################## +# ############################################################################## -if (NOT DISABLED_LEGACY_ENGINE) -add_executable (cntraining cntraining.cpp) -target_link_libraries (cntraining common_training) -project_group (cntraining "Training Tools") -install (TARGETS cntraining RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +if(NOT DISABLED_LEGACY_ENGINE) + add_executable(cntraining cntraining.cpp) + target_link_libraries(cntraining common_training) + project_group(cntraining "Training Tools") + install( + TARGETS cntraining + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) endif() - -######################################## +# ############################################################################## # EXECUTABLE dawg2wordlist -######################################## +# ############################################################################## -add_executable (dawg2wordlist dawg2wordlist.cpp) -target_link_libraries (dawg2wordlist common_training) -project_group (dawg2wordlist "Training Tools") -install (TARGETS dawg2wordlist RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +add_executable(dawg2wordlist dawg2wordlist.cpp) +target_link_libraries(dawg2wordlist common_training) +project_group(dawg2wordlist "Training Tools") +install( + TARGETS dawg2wordlist + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) - -######################################## +# ############################################################################## # EXECUTABLE mftraining -######################################## +# ############################################################################## -if (NOT DISABLED_LEGACY_ENGINE) -add_executable (mftraining mftraining.cpp mergenf.cpp mergenf.h) -target_link_libraries (mftraining common_training) -project_group (mftraining "Training Tools") -install (TARGETS mftraining RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +if(NOT DISABLED_LEGACY_ENGINE) + add_executable(mftraining mftraining.cpp mergenf.cpp mergenf.h) + target_link_libraries(mftraining common_training) + project_group(mftraining "Training Tools") + install( + TARGETS mftraining + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) endif() - -######################################## +# ############################################################################## # EXECUTABLE shapeclustering -######################################## +# ############################################################################## -if (NOT DISABLED_LEGACY_ENGINE) -add_executable (shapeclustering shapeclustering.cpp) -target_link_libraries (shapeclustering common_training) -project_group (shapeclustering "Training Tools") -install (TARGETS shapeclustering RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +if(NOT DISABLED_LEGACY_ENGINE) + add_executable(shapeclustering shapeclustering.cpp) + target_link_libraries(shapeclustering common_training) + project_group(shapeclustering "Training Tools") + install( + TARGETS shapeclustering + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) endif() - -######################################## +# ############################################################################## # EXECUTABLE wordlist2dawg -######################################## +# ############################################################################## -add_executable (wordlist2dawg wordlist2dawg.cpp) -target_link_libraries (wordlist2dawg common_training) -project_group (wordlist2dawg "Training Tools") -install (TARGETS wordlist2dawg RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) +add_executable(wordlist2dawg wordlist2dawg.cpp) +target_link_libraries(wordlist2dawg common_training) +project_group(wordlist2dawg "Training Tools") +install( + TARGETS wordlist2dawg + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) +if(ICU_FOUND) -if (ICU_FOUND) - -if (NOT SW_BUILD) + if(NOT SW_BUILD) include_directories(${ICU_INCLUDE_DIRS}) -endif() + endif() -######################################## -# LIBRARY unicharset_training -######################################## + # ############################################################################ + # LIBRARY unicharset_training + # ############################################################################ -file(GLOB unicharset_training_src - unicharset/* -) + file(GLOB unicharset_training_src unicharset/*) -add_library (unicharset_training ${unicharset_training_src}) -if (SW_BUILD) -target_link_libraries (unicharset_training PUBLIC common_training org.sw.demo.unicode.icu.i18n) -else() -target_link_libraries (unicharset_training PUBLIC common_training ${ICU_LINK_LIBRARIES}) -endif() -target_include_directories (unicharset_training PUBLIC unicharset ${CMAKE_CURRENT_BINARY_DIR}) -generate_export_header (unicharset_training EXPORT_MACRO_NAME TESS_UNICHARSET_TRAINING_API) -project_group (unicharset_training "Training Tools") + add_library(unicharset_training ${unicharset_training_src}) + if(SW_BUILD) + target_link_libraries(unicharset_training + PUBLIC common_training org.sw.demo.unicode.icu.i18n) + else() + target_link_libraries(unicharset_training PUBLIC common_training + ${ICU_LINK_LIBRARIES}) + endif() + target_include_directories(unicharset_training + PUBLIC unicharset ${CMAKE_CURRENT_BINARY_DIR}) + generate_export_header(unicharset_training EXPORT_MACRO_NAME + TESS_UNICHARSET_TRAINING_API) + project_group(unicharset_training "Training Tools") + # ############################################################################ + # EXECUTABLE combine_lang_model + # ############################################################################ -######################################## -# EXECUTABLE combine_lang_model -######################################## + add_executable(combine_lang_model combine_lang_model.cpp) + target_link_libraries(combine_lang_model unicharset_training) + project_group(combine_lang_model "Training Tools") + install( + TARGETS combine_lang_model + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) -add_executable (combine_lang_model combine_lang_model.cpp) -target_link_libraries (combine_lang_model unicharset_training) -project_group (combine_lang_model "Training Tools") -install (TARGETS combine_lang_model RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + # ############################################################################ + # EXECUTABLE lstmeval + # ############################################################################ + add_executable(lstmeval lstmeval.cpp) + target_link_libraries(lstmeval unicharset_training ${LIB_pthread}) + project_group(lstmeval "Training Tools") + install( + TARGETS lstmeval + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) -######################################## -# EXECUTABLE lstmeval -######################################## + # ############################################################################ + # EXECUTABLE lstmtraining + # ############################################################################ -add_executable (lstmeval lstmeval.cpp) -target_link_libraries (lstmeval unicharset_training ${LIB_pthread}) -project_group (lstmeval "Training Tools") -install (TARGETS lstmeval RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + add_executable(lstmtraining lstmtraining.cpp) + target_link_libraries(lstmtraining unicharset_training ${LIB_pthread}) + project_group(lstmtraining "Training Tools") + install( + TARGETS lstmtraining + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + # ############################################################################ + # EXECUTABLE merge_unicharsets + # ############################################################################ -######################################## -# EXECUTABLE lstmtraining -######################################## + add_executable(merge_unicharsets merge_unicharsets.cpp) + target_link_libraries(merge_unicharsets common_training) + project_group(merge_unicharsets "Training Tools") + install( + TARGETS merge_unicharsets + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) -add_executable (lstmtraining lstmtraining.cpp) -target_link_libraries (lstmtraining unicharset_training ${LIB_pthread}) -project_group (lstmtraining "Training Tools") -install (TARGETS lstmtraining RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + # ############################################################################ + # EXECUTABLE set_unicharset_properties + # ############################################################################ + add_executable(set_unicharset_properties set_unicharset_properties.cpp) + target_link_libraries(set_unicharset_properties unicharset_training) + project_group(set_unicharset_properties "Training Tools") + install( + TARGETS set_unicharset_properties + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) -######################################## -# EXECUTABLE merge_unicharsets -######################################## + # ############################################################################ + # EXECUTABLE unicharset_extractor + # ############################################################################ -add_executable (merge_unicharsets merge_unicharsets.cpp) -target_link_libraries (merge_unicharsets common_training) -project_group (merge_unicharsets "Training Tools") -install (TARGETS merge_unicharsets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + add_executable(unicharset_extractor unicharset_extractor.cpp) + target_link_libraries(unicharset_extractor unicharset_training) + project_group(unicharset_extractor "Training Tools") + install( + TARGETS unicharset_extractor + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + # ############################################################################ -######################################## -# EXECUTABLE set_unicharset_properties -######################################## + if(PKG_CONFIG_FOUND OR SW_BUILD) -add_executable (set_unicharset_properties set_unicharset_properties.cpp) -target_link_libraries (set_unicharset_properties unicharset_training) -project_group (set_unicharset_properties "Training Tools") -install (TARGETS set_unicharset_properties RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + if(PKG_CONFIG_FOUND) + pkg_check_modules(Pango REQUIRED pango>=1.38.0) + pkg_check_modules(Cairo REQUIRED cairo) + pkg_check_modules(PangoFt2 REQUIRED pangoft2) + pkg_check_modules(PangoCairo REQUIRED pangocairo) + pkg_check_modules(FontConfig REQUIRED fontconfig) + endif() + # ########################################################################## + # LIBRARY pango_training + # ########################################################################## -######################################## -# EXECUTABLE unicharset_extractor -######################################## + file(GLOB pango_training_src pango/*) -add_executable (unicharset_extractor unicharset_extractor.cpp) -target_link_libraries (unicharset_extractor unicharset_training) -project_group (unicharset_extractor "Training Tools") -install (TARGETS unicharset_extractor RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + add_library(pango_training ${pango_training_src}) + target_link_libraries(pango_training PUBLIC unicharset_training) + if(SW_BUILD) + target_link_libraries(pango_training + PUBLIC org.sw.demo.gnome.pango.pangocairo) + else() + if(PKG_CONFIG_FOUND) + target_include_directories( + pango_training BEFORE PUBLIC ${Cairo_INCLUDE_DIRS} + ${Pango_INCLUDE_DIRS}) + target_compile_definitions(pango_training PUBLIC -DPANGO_ENABLE_ENGINE) + target_link_libraries( + pango_training + PUBLIC ${Pango_LINK_LIBRARIES} ${Cairo_LINK_LIBRARIES} + ${PangoCairo_LINK_LIBRARIES} ${PangoFt2_LINK_LIBRARIES} + ${FontConfig_LINK_LIBRARIES}) + endif() + endif() + target_include_directories(pango_training + PUBLIC pango ${CMAKE_CURRENT_BINARY_DIR}) + generate_export_header(pango_training EXPORT_MACRO_NAME + TESS_PANGO_TRAINING_API) + project_group(pango_training "Training Tools") + # ########################################################################## + # EXECUTABLE text2image + # ########################################################################## -######################################## + set(TEXT2IMAGE_SRC text2image.cpp degradeimage.cpp degradeimage.h) -if (NOT SW_BUILD) - find_package(PkgConfig) -endif() + add_executable(text2image ${TEXT2IMAGE_SRC}) + target_link_libraries(text2image pango_training) + project_group(text2image "Training Tools") + install( + TARGETS text2image + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) -if (PKG_CONFIG_FOUND OR SW_BUILD) - -if (PKG_CONFIG_FOUND) -pkg_check_modules(Pango REQUIRED pango>=1.38.0) -pkg_check_modules(Cairo REQUIRED cairo) -pkg_check_modules(PangoFt2 REQUIRED pangoft2) -pkg_check_modules(PangoCairo REQUIRED pangocairo) -pkg_check_modules(FontConfig REQUIRED fontconfig) -endif() - - -######################################## -# LIBRARY pango_training -######################################## - -file(GLOB pango_training_src - pango/* -) - -add_library (pango_training ${pango_training_src}) -target_link_libraries (pango_training PUBLIC unicharset_training) -if (SW_BUILD) -target_link_libraries (pango_training PUBLIC org.sw.demo.gnome.pango.pangocairo) -else() -if (PKG_CONFIG_FOUND) -target_include_directories (pango_training BEFORE PUBLIC ${Cairo_INCLUDE_DIRS} ${Pango_INCLUDE_DIRS}) -target_compile_definitions (pango_training PUBLIC -DPANGO_ENABLE_ENGINE) -target_link_libraries (pango_training PUBLIC - ${Pango_LINK_LIBRARIES} - ${Cairo_LINK_LIBRARIES} - ${PangoCairo_LINK_LIBRARIES} - ${PangoFt2_LINK_LIBRARIES} - ${FontConfig_LINK_LIBRARIES} -) -endif() -endif() -target_include_directories (pango_training PUBLIC pango ${CMAKE_CURRENT_BINARY_DIR}) -generate_export_header (pango_training EXPORT_MACRO_NAME TESS_PANGO_TRAINING_API) -project_group (pango_training "Training Tools") - - -######################################## -# EXECUTABLE text2image -######################################## - -set(text2image_src - text2image.cpp - degradeimage.cpp - degradeimage.h -) - -add_executable (text2image ${text2image_src}) -target_link_libraries (text2image pango_training) -project_group (text2image "Training Tools") -install (TARGETS text2image RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) - -endif() + endif() endif(ICU_FOUND) -############################################################################### +# ##############################################################################