From 93d1c66e4eb9cdc34e287c1e75472ef37eb98c74 Mon Sep 17 00:00:00 2001 From: Egor Pugin Date: Mon, 5 Oct 2015 22:33:10 +0300 Subject: [PATCH 1/4] Add FindLeptonica.cmake module to find installed liblept on *nix systems. --- CMakeLists.txt | 2 +- cmake/FindLeptonica.cmake | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 cmake/FindLeptonica.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4acdb14ca..065830044 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ set(VERSION_MAJOR 3) set(VERSION_MINOR 05) set(VERSION_PLAIN ${VERSION_MAJOR}.${VERSION_MINOR}) -find_package(Leptonica 1.72 REQUIRED) +find_package(Leptonica 1.71 REQUIRED) find_package(ICU COMPONENTS uc i18n) find_package(PkgConfig QUIET) diff --git a/cmake/FindLeptonica.cmake b/cmake/FindLeptonica.cmake new file mode 100644 index 000000000..0ff55b768 --- /dev/null +++ b/cmake/FindLeptonica.cmake @@ -0,0 +1,49 @@ +# +# Find Leptonica +# +# Exported variables: +# Leptonica_FOUND +# Leptonica_INCLUDE_DIRS +# Leptonica_LIBRARIES +# +# Leptonica_VERSION +# Leptonica_MAJOR_VERSION +# Leptonica_MINOR_VERSION +# + +find_path(Leptonica_INCLUDE_DIR leptonica/allheaders.h + HINTS + /usr/include + /usr/local/include + /opt/include + /opt/local/include +) +if(NOT Leptonica_INCLUDE_DIR-NOTFOUND) + set(Leptonica_INCLUDE_DIRS ${Leptonica_INCLUDE_DIR}/leptonica) + file(STRINGS ${Leptonica_INCLUDE_DIRS}/allheaders.h Leptonica_MAJOR_VERSION REGEX "LIBLEPT_MAJOR_VERSION") + file(STRINGS ${Leptonica_INCLUDE_DIRS}/allheaders.h Leptonica_MINOR_VERSION REGEX "LIBLEPT_MINOR_VERSION") + string(REGEX MATCH "[0-9]+" Leptonica_MAJOR_VERSION ${Leptonica_MAJOR_VERSION}) + string(REGEX MATCH "[0-9]+" Leptonica_MINOR_VERSION ${Leptonica_MINOR_VERSION}) + set(Leptonica_VERSION ${Leptonica_MAJOR_VERSION}.${Leptonica_MINOR_VERSION}) +endif() + +find_library(Leptonica_LIBRARY NAMES lept liblept + HINTS + /usr/lib + /usr/local/lib + /opt/lib + /opt/local/lib +) +set(Leptonica_LIBRARIES ${Leptonica_LIBRARY}) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(Leptonica + REQUIRED_VARS + Leptonica_INCLUDE_DIRS + Leptonica_LIBRARIES + VERSION_VAR Leptonica_VERSION +) + +mark_as_advanced(Leptonica_INCLUDE_DIRS Leptonica_LIBRARIES) + From dfb5aa5c347d61bd0179eea4efcfa8af91ca54db Mon Sep 17 00:00:00 2001 From: Egor Pugin Date: Fri, 9 Oct 2015 18:12:02 +0300 Subject: [PATCH 2/4] Add Leptonica_BUILD_DIR option for CMake find_package in Config mode. Set correct .so name on Linux. --- .travis.yml | 2 +- CMakeLists.txt | 14 +++++++++++++- appveyor.yml | 2 +- cmake/FindLeptonica.cmake | 5 ++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8875cfba4..1538614ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,5 +41,5 @@ install: script: - mkdir build - cd build - - cmake .. -DLeptonica_DIR=leptonica-master/build + - cmake .. -DLeptonica_BUILD_DIR=leptonica-master/build - make diff --git a/CMakeLists.txt b/CMakeLists.txt index 73d4a8379..bd0a59381 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,13 @@ set(VERSION_MAJOR 3) set(VERSION_MINOR 05) set(VERSION_PLAIN ${VERSION_MAJOR}.${VERSION_MINOR}) -find_package(Leptonica 1.71 REQUIRED) +set(MINIMUM_LEPTONICA_VERSION 1.71) + +if (NOT Leptonica_BUILD_DIR) +find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED) +else() +find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG) +endif() find_package(ICU COMPONENTS uc i18n) find_package(OpenCL QUIET) @@ -142,6 +148,8 @@ include_directories(wordrec) # LIBRARY tesseract ######################################## +string(SUBSTRING ${VERSION_MINOR} 0 1 VERSION_MINOR_0) +string(SUBSTRING ${VERSION_MINOR} 1 1 VERSION_MINOR_1) file(GLOB tesseract_src "ccmain/*.cpp" @@ -191,8 +199,12 @@ if (NOT STATIC) target_compile_definitions (tesseract PUBLIC -DTESS_EXPORTS) endif() target_link_libraries (tesseract ${Leptonica_LIBRARIES} ${LIB_Ws2_32} ${LIB_pthread}) +set_target_properties (tesseract PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR_0}.${VERSION_MINOR_1}) +set_target_properties (tesseract PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR_0}.${VERSION_MINOR_1}) +if (WIN32) set_target_properties (tesseract PROPERTIES OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR}) set_target_properties (tesseract PROPERTIES DEBUG_OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR}d) +endif() export(TARGETS tesseract FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake) diff --git a/appveyor.yml b/appveyor.yml index f9318fd0c..3f54f976e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,5 +20,5 @@ before_build: build_script: - mkdir build - cd build - - cmake .. -G "%generator%" -DLeptonica_DIR=leptonica-master/build -DSTATIC=1 + - cmake .. -G "%generator%" -DLeptonica_BUILD_DIR=leptonica-master/build -DSTATIC=1 - msbuild tesseract.sln /p:Platform=%vcplatform% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" diff --git a/cmake/FindLeptonica.cmake b/cmake/FindLeptonica.cmake index 0ff55b768..5ceb76463 100644 --- a/cmake/FindLeptonica.cmake +++ b/cmake/FindLeptonica.cmake @@ -17,8 +17,9 @@ find_path(Leptonica_INCLUDE_DIR leptonica/allheaders.h /usr/local/include /opt/include /opt/local/include + ${Leptonica_DIR}/include ) -if(NOT Leptonica_INCLUDE_DIR-NOTFOUND) +if("${Leptonica_INCLUDE_DIR}" EQUAL "Leptonica_INCLUDE_DIR-NOTFOUND") set(Leptonica_INCLUDE_DIRS ${Leptonica_INCLUDE_DIR}/leptonica) file(STRINGS ${Leptonica_INCLUDE_DIRS}/allheaders.h Leptonica_MAJOR_VERSION REGEX "LIBLEPT_MAJOR_VERSION") file(STRINGS ${Leptonica_INCLUDE_DIRS}/allheaders.h Leptonica_MINOR_VERSION REGEX "LIBLEPT_MINOR_VERSION") @@ -33,6 +34,7 @@ find_library(Leptonica_LIBRARY NAMES lept liblept /usr/local/lib /opt/lib /opt/local/lib + ${Leptonica_DIR}/lib ) set(Leptonica_LIBRARIES ${Leptonica_LIBRARY}) @@ -43,6 +45,7 @@ find_package_handle_standard_args(Leptonica Leptonica_INCLUDE_DIRS Leptonica_LIBRARIES VERSION_VAR Leptonica_VERSION + FAIL_MESSAGE "Try to set Leptonica_DIR or Leptonica_ROOT" ) mark_as_advanced(Leptonica_INCLUDE_DIRS Leptonica_LIBRARIES) From 8e157dbb7ea2d9b8a1d49c6fa3a26400cc379cf8 Mon Sep 17 00:00:00 2001 From: Egor Pugin Date: Fri, 9 Oct 2015 18:18:02 +0300 Subject: [PATCH 3/4] Fix build. --- cmake/FindLeptonica.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/FindLeptonica.cmake b/cmake/FindLeptonica.cmake index 5ceb76463..59723ed2e 100644 --- a/cmake/FindLeptonica.cmake +++ b/cmake/FindLeptonica.cmake @@ -19,7 +19,7 @@ find_path(Leptonica_INCLUDE_DIR leptonica/allheaders.h /opt/local/include ${Leptonica_DIR}/include ) -if("${Leptonica_INCLUDE_DIR}" EQUAL "Leptonica_INCLUDE_DIR-NOTFOUND") +if(NOT "${Leptonica_INCLUDE_DIR}" EQUAL "Leptonica_INCLUDE_DIR-NOTFOUND") set(Leptonica_INCLUDE_DIRS ${Leptonica_INCLUDE_DIR}/leptonica) file(STRINGS ${Leptonica_INCLUDE_DIRS}/allheaders.h Leptonica_MAJOR_VERSION REGEX "LIBLEPT_MAJOR_VERSION") file(STRINGS ${Leptonica_INCLUDE_DIRS}/allheaders.h Leptonica_MINOR_VERSION REGEX "LIBLEPT_MINOR_VERSION") From 0788098b8020dfa8c24194ec60f6d07e1675d205 Mon Sep 17 00:00:00 2001 From: Egor Pugin Date: Fri, 9 Oct 2015 18:22:04 +0300 Subject: [PATCH 4/4] Fix Linux build with Leptonica_BUILD_DIR. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd0a59381..44b4ac5dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ set(MINIMUM_LEPTONICA_VERSION 1.71) if (NOT Leptonica_BUILD_DIR) find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED) else() +set(Leptonica_DIR ${Leptonica_BUILD_DIR}) find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG) endif()