From 6e073f168652a551d8f29d19481ec67be3fccac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jack=C2=B7Boos=C2=B7Yu?= <47264268+JackBoosY@users.noreply.github.com> Date: Mon, 23 Nov 2020 16:20:30 -0800 Subject: [PATCH] [tesseract] Enable dynamic build, format portfile.cmake (#14650) * [tesseract] Enable dynamic build, format portfile.cmake * [tesseract] Remove wrongly deletions * [tesseract] Fix build training tools on dynamic --- ports/tesseract/CONTROL | 2 +- ports/tesseract/fix-training-tools.patch | 40 +++++++++++++++ ports/tesseract/portfile.cmake | 65 ++++++++---------------- 3 files changed, 61 insertions(+), 46 deletions(-) create mode 100644 ports/tesseract/fix-training-tools.patch diff --git a/ports/tesseract/CONTROL b/ports/tesseract/CONTROL index 0524821bf2..eb90d70e10 100644 --- a/ports/tesseract/CONTROL +++ b/ports/tesseract/CONTROL @@ -1,6 +1,6 @@ Source: tesseract Version: 4.1.1 -Port-Version: 2 +Port-Version: 3 Homepage: https://github.com/tesseract-ocr/tesseract Description: An OCR Engine that was developed at HP Labs between 1985 and 1995... and now at Google. Build-Depends: leptonica diff --git a/ports/tesseract/fix-training-tools.patch b/ports/tesseract/fix-training-tools.patch new file mode 100644 index 0000000000..fd5729cb8b --- /dev/null +++ b/ports/tesseract/fix-training-tools.patch @@ -0,0 +1,40 @@ +diff --git a/src/training/CMakeLists.txt b/src/training/CMakeLists.txt +index af291a5..f2e2ceb 100644 +--- a/src/training/CMakeLists.txt ++++ b/src/training/CMakeLists.txt +@@ -63,7 +63,7 @@ endif() + # LIBRARY tessopt + ######################################## + +-add_library (tessopt tessopt.cpp tessopt.h) ++add_library (tessopt STATIC tessopt.cpp tessopt.h) + project_group (tessopt "Training Tools") + + +@@ -81,7 +81,7 @@ set(common_training_src + mastertrainer.cpp + mastertrainer.h + ) +-add_library (common_training ${common_training_src}) ++add_library (common_training STATIC ${common_training_src}) + target_link_libraries (common_training libtesseract tessopt) + project_group (common_training "Training Tools") + +@@ -196,7 +196,7 @@ set(unicharset_training_src + validate_javanese.cpp validate_myanmar.cpp validator.cpp + + ) +-add_library (unicharset_training ${unicharset_training_src}) ++add_library (unicharset_training STATIC ${unicharset_training_src}) + if(UNIX) + list(APPEND ICU_LIBRARIES ${CMAKE_DL_LIBS}) + endif() +@@ -270,7 +270,7 @@ endif() + + find_package(unofficial-cairo CONFIG REQUIRED) + find_package(unofficial-glib CONFIG REQUIRED) +-find_package(Intl CONFIG REQUIRED) ++find_package(Intl REQUIRED) + find_package(Fontconfig REQUIRED) + find_package(Freetype REQUIRED) + if(UNIX OR BUILD_SHARED_LIBS) diff --git a/ports/tesseract/portfile.cmake b/ports/tesseract/portfile.cmake index 925b19afbc..d141625b62 100644 --- a/ports/tesseract/portfile.cmake +++ b/ports/tesseract/portfile.cmake @@ -1,5 +1,3 @@ -vcpkg_check_linkage(ONLY_STATIC_LIBRARY) - vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO tesseract-ocr/tesseract @@ -8,78 +6,55 @@ vcpkg_from_github( PATCHES fix-tiff-linkage.patch fix-text2image.patch + fix-training-tools.patch ) # The built-in cmake FindICU is better file(REMOVE ${SOURCE_PATH}/cmake/FindICU.cmake) -# Handle Static Library Output -if(VCPKG_LIBRARY_LINKAGE EQUAL "static") - list(APPEND OPTIONS_LIST -DSTATIC=ON) -endif() +string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC) + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS + training-tools BUILD_TRAINING_TOOLS +) -# Handle CONTROL -if("training-tools" IN_LIST FEATURES) - list(APPEND OPTIONS_LIST -DBUILD_TRAINING_TOOLS=ON) -else() - list(APPEND OPTIONS_LIST -DBUILD_TRAINING_TOOLS=OFF) -endif() if("cpu-independed" IN_LIST FEATURES) - list(APPEND OPTIONS_LIST -DTARGET_ARCHITECTURE=none) + set(TARGET_ARCHITECTURE none) else() - list(APPEND OPTIONS_LIST -DTARGET_ARCHITECTURE=auto) + set(TARGET_ARCHITECTURE auto) endif() vcpkg_configure_cmake( SOURCE_PATH ${SOURCE_PATH} PREFER_NINJA - OPTIONS - -DSTATIC=ON + OPTIONS ${FEATURE_OPTIONS} + -DSTATIC=${BUILD_STATIC} -DUSE_SYSTEM_ICU=True -DCMAKE_DISABLE_FIND_PACKAGE_LibArchive=ON -DCMAKE_DISABLE_FIND_PACKAGE_OpenCL=ON -DLeptonica_DIR=YES - ${OPTIONS_LIST} + -DTARGET_ARCHITECTURE=${TARGET_ARCHITECTURE} ) vcpkg_install_cmake() vcpkg_fixup_cmake_targets(CONFIG_PATH cmake) -# Install tool -file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/tools/tesseract) -set(EXTENSION) -if(WIN32) - set(EXTENSION ".exe") -endif() +vcpkg_copy_tools(TOOL_NAMES tesseract AUTO_CLEAN) -# copy training tools -set(TRAINING_TOOLS_DIR ${CURRENT_PACKAGES_DIR}/tools/tesseract/training) -if("training_tools" IN_LIST FEATURES) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/ambiguous_words${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/classifier_tester${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/combine_tessdata${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/cntraining${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/dawg2wordlist${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/mftraining${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/shapeclustering${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/wordlist2dawg${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/combine_lang_model${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/lstmeval${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/lstmtraining${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/set_unicharset_properties${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/unicharset_extractor${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) - file(COPY ${CURRENT_PACKAGES_DIR}/bin/text2image${EXTENSION} DESTINATION ${TRAINING_TOOLS_DIR}) +if("training-tools" IN_LIST FEATURES) + list(APPEND TRAINING_TOOLS + ambiguous_words classifier_tester combine_tessdata + cntraining dawg2wordlist mftraining shapeclustering + wordlist2dawg combine_lang_model lstmeval lstmtraining + set_unicharset_properties unicharset_extractor text2image + ) + vcpkg_copy_tools(TOOL_NAMES ${TRAINING_TOOLS} AUTO_CLEAN) endif() -file(COPY ${CURRENT_PACKAGES_DIR}/bin/tesseract${EXTENSION} DESTINATION ${CURRENT_PACKAGES_DIR}/tools/tesseract) -vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/tesseract) - vcpkg_copy_pdbs() file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) -file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin) -file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/bin) # Handle copyright file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)