Skip to content

Commit

Permalink
Fix building of training tools in shared configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
egorpugin committed Dec 17, 2016
1 parent fc13f96 commit 442b5b7
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 59 deletions.
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.cppan)
find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
endif()
else()
if (STATIC)
set(CPPAN_BUILD_SHARED_LIBS 0)
else()
set(CPPAN_BUILD_SHARED_LIBS 1)
endif()
add_subdirectory(.cppan)
endif()

find_package(OpenCL QUIET)
find_package(PkgConfig)

###############################################################################
#
Expand Down Expand Up @@ -203,7 +207,11 @@ set(tesseract_src ${tesseract_src}

add_library (tesseract ${LIBRARY_TYPE} ${tesseract_src} ${tesseract_hdr})
if (NOT STATIC)
target_compile_definitions (tesseract PUBLIC -DTESS_EXPORTS)
target_compile_definitions (tesseract
PRIVATE -DTESS_EXPORTS
INTERFACE -DTESS_IMPORTS
)
set_target_properties (tesseract PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS True)
endif()
target_link_libraries (tesseract ${LIB_Ws2_32} ${LIB_pthread})
set_target_properties (tesseract PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR_0}.${VERSION_MINOR_1})
Expand All @@ -217,7 +225,8 @@ if (NOT CPPAN_BUILD)
target_link_libraries (tesseract ${Leptonica_LIBRARIES})
export(TARGETS tesseract FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake)
else()
target_link_libraries (tesseract cppan)
target_link_libraries (tesseract pvt.cppan.demo.leptonica)
add_dependencies (tesseract cppan)
file(WRITE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake "include(${CMAKE_BINARY_DIR}/cppan.cmake)\n")
export(TARGETS tesseract APPEND FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake)
endif()
Expand Down
2 changes: 1 addition & 1 deletion ccutil/unicharset.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class UNICHARSET {
// Custom list of characters and their ligature forms (UTF8)
// These map to unicode values in the private use area (PUC) and are supported
// by only few font families (eg. Wyld, Adobe Caslon Pro).
static const char* kCustomLigatures[][2];
static TESS_API const char* kCustomLigatures[][2];

// List of strings for the SpecialUnicharCodes. Keep in sync with the enum.
static const char* kSpecialUnicharCodes[SPECIAL_UNICHAR_CODES_COUNT];
Expand Down
2 changes: 1 addition & 1 deletion classify/featdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int ShortNameToFeatureType(const FEATURE_DEFS_STRUCT &FeatureDefs,
Global Data Definitions and Declarations
----------------------------------------------------------------------------**/
extern const FEATURE_DESC_STRUCT MicroFeatureDesc;
extern const FEATURE_DESC_STRUCT PicoFeatDesc;
extern TESS_API const FEATURE_DESC_STRUCT PicoFeatDesc;
extern const FEATURE_DESC_STRUCT CharNormDesc;
extern const FEATURE_DESC_STRUCT OutlineFeatDesc;
extern const FEATURE_DESC_STRUCT IntFeatDesc;
Expand Down
2 changes: 1 addition & 1 deletion classify/picofeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ extern double_VAR_H(classify_pico_feature_length, 0.05, "Pico Feature Length");
/**----------------------------------------------------------------------------
Global Data Definitions and Declarations
----------------------------------------------------------------------------**/
extern FLOAT32 PicoFeatureLength;
extern TESS_API FLOAT32 PicoFeatureLength;
#endif
14 changes: 9 additions & 5 deletions cppan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ options:
- WINDLLNAME="tesseract"
shared:
definitions:
public: TESS_EXPORTS
private:
- TESS_EXPORTS
interface:
- TESS_IMPORTS

dependencies:
private:
# tesseract uses leptonica only internally
# and does not expose its interface to users
pvt.cppan.demo.leptonica: master
private:
pvt.cppan.demo.leptonica: master
# only for training tools, move to them later
pvt.cppan.demo.unicode.icu.i18n: "*"

2 changes: 1 addition & 1 deletion dict/trie.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class Trie : public Dawg {
EDGE_VECTOR* backward_edges,
NODE_MARKER reduced_nodes);

/**
/**
* Order num_edges of consequtive EDGE_RECORDS in the given EDGE_VECTOR in
* increasing order of unichar ids. This function is normally called
* for all edges in a single node, and since number of edges in each node
Expand Down
103 changes: 59 additions & 44 deletions training/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,62 @@
# tesseract
#

if (STATIC OR NOT (WIN32 OR CYGWIN))

# experimental
if (MSVC)

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")
if (NOT CPPAN_BUILD AND NOT (WIN32 OR CYGWIN))
return()

This comment has been minimized.

Copy link
@stweil

stweil Jun 22, 2019

Member

@egorpugin, Travis CI currently does not compile the training code. Nor does a local CMake build on Linux. Should this return statement be modified or removed?

This comment has been minimized.

Copy link
@egorpugin

egorpugin Jun 22, 2019

Author Contributor

I did not test training tools on linux.
If it works for you, then return should be removed.

endif()

set(icu_dir "${CMAKE_CURRENT_BINARY_DIR}/icu")
set(icu_archive "${icu_dir}/icu${ARCH_DIR_NAME}.zip")

if (X86)
set(icu_hash 45167a240b60e36b59a87eda23490ce4)
else()
set(icu_hash 480c72491576c048de1218c3c5519399)
if (CPPAN_BUILD)
set(ICU_FOUND 1)
endif()

message(STATUS "Downloading latest ICU binaries")

file(DOWNLOAD
"http://download.icu-project.org/files/icu4c/56.1/icu4c-56_1-Win${ARCH_DIR_NAME}-msvc10.zip"
"${icu_archive}"
SHOW_PROGRESS
INACTIVITY_TIMEOUT 60 # 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}")
# experimental
if (MSVC AND NOT CPPAN_BUILD)
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()

set(icu_dir "${CMAKE_CURRENT_BINARY_DIR}/icu")
set(icu_archive "${icu_dir}/icu${ARCH_DIR_NAME}.zip")

if (X86)
set(icu_hash 45167a240b60e36b59a87eda23490ce4)
else()
set(icu_hash 480c72491576c048de1218c3c5519399)
endif()

message(STATUS "Downloading latest ICU binaries")

file(DOWNLOAD
"http://download.icu-project.org/files/icu4c/56.1/icu4c-56_1-Win${ARCH_DIR_NAME}-msvc10.zip"
"${icu_archive}"
SHOW_PROGRESS
INACTIVITY_TIMEOUT 60 # 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)
endif()

set(ICU_ROOT ${icu_dir}/icu)

endif(MSVC)
# experimental

if (NOT CPPAN_BUILD)
find_package(ICU COMPONENTS uc i18n)
endif()

########################################
# LIBRARY tessopt
Expand Down Expand Up @@ -159,7 +165,9 @@ project_group (wordlist2dawg "Training Tools")

if (ICU_FOUND)

if (NOT CPPAN_BUILD)
include_directories(${ICU_INCLUDE_DIRS})
endif()

########################################
# LIBRARY unicharset_training
Expand All @@ -177,7 +185,11 @@ set(unicharset_training_src
unicharset_training_utils.h
)
add_library (unicharset_training ${unicharset_training_src})
if (NOT CPPAN_BUILD)
target_link_libraries (unicharset_training common_training ${ICU_LIBRARIES})
else()
target_link_libraries (unicharset_training common_training pvt.cppan.demo.unicode.icu.i18n)
endif()
project_group (unicharset_training "Training Tools")


Expand All @@ -198,6 +210,7 @@ add_executable (lstmtraining lstmtraining.cpp)
target_link_libraries (lstmtraining unicharset_training)
project_group (lstmtraining "Training Tools")


########################################
# EXECUTABLE set_unicharset_properties
########################################
Expand All @@ -211,6 +224,10 @@ project_group (set_unicharset_properties "Training Tools")
# EXECUTABLE text2image
########################################

if (NOT CPPAN_BUILD)
find_package(PkgConfig)
endif()

if (PKG_CONFIG_FOUND)

pkg_check_modules(Pango REQUIRED pango)
Expand Down Expand Up @@ -246,7 +263,6 @@ add_executable (text2image ${text2image_src})
target_include_directories (text2image BEFORE PRIVATE ${Cairo_INCLUDE_DIRS} ${Pango_INCLUDE_DIRS})
target_compile_definitions (text2image PRIVATE -DPANGO_ENABLE_ENGINE)
target_link_libraries (text2image tesseract unicharset_training
${ICU_LIBRARIES}
${Pango_LIBRARIES}
${Cairo_LIBRARIES}
${PangoCairo_LIBRARIES}
Expand All @@ -257,6 +273,5 @@ project_group (text2image "Training Tools")

endif(PKG_CONFIG_FOUND)
endif(ICU_FOUND)
endif(STATIC OR NOT (WIN32 OR CYGWIN))

###############################################################################
5 changes: 2 additions & 3 deletions training/mergenf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <string.h>
#include <math.h>


/*-------------------once in subfeat---------------------------------*/
double_VAR(training_angle_match_scale, 1.0, "Angle Match Scale ...");

Expand Down Expand Up @@ -199,9 +198,9 @@ int FindClosestExistingProto(CLASS_TYPE Class, int NumMerged[],
*
* @param New new proto to be filled in
* @param Old old proto to be converted
*
*
* Globals: none
*
*
* Exceptions: none
* History: Mon Nov 26 09:45:39 1990, DSJ, Created.
*/
Expand Down

0 comments on commit 442b5b7

Please sign in to comment.