[cmake] Implement shared builds.

This commit is contained in:
Egor Pugin 2020-12-31 19:32:03 +03:00
parent 6464e3298a
commit 6306393c91
24 changed files with 142 additions and 110 deletions

View File

@ -144,10 +144,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(LIBRARY_TYPE SHARED)
if (STATIC)
set(LIBRARY_TYPE)
else()
if (BUILD_SHARED_LIBS)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
endif()
@ -247,7 +244,7 @@ elseif(MSVC)
endif()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /wd4244 /wd4305 /wd4267")
# Don't use /Wall because it generates too many warnings.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 /bigobj")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W0 /bigobj")
# MT flag
if(WIN32_MT_BUILD)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
@ -285,7 +282,6 @@ if (OPENMP_BUILD)
endif()
endif()
if (CYGWIN)
add_definitions(-D__CYGWIN__)
elseif(UNIX)
@ -296,6 +292,8 @@ elseif(WIN32)
set(LIB_Ws2_32 Ws2_32)
endif()
add_definitions("-DCMAKE_BUILD")
###############################################################################
#
# packages
@ -370,6 +368,7 @@ configure_file(
${CMAKE_CURRENT_BINARY_DIR}/include/tesseract/version.h @ONLY)
include(CMakePackageConfigHelpers)
include(GenerateExportHeader)
configure_package_config_file(
cmake/templates/TesseractConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/tesseract/TesseractConfig.cmake
@ -607,7 +606,7 @@ set(libtessfiles ${tesseract_src} ${arch_files} ${arch_files_opt} ${tesseract_hd
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${libtessfiles})
add_library (libtesseract ${LIBRARY_TYPE} ${libtessfiles})
add_library (libtesseract ${libtessfiles})
target_include_directories (libtesseract
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE src
@ -631,7 +630,7 @@ target_compile_definitions (libtesseract
PRIVATE -DTESS_EXPORTS
INTERFACE -DTESS_IMPORTS
)
set_target_properties (libtesseract PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS True)
generate_export_header (libtesseract EXPORT_MACRO_NAME TESS_API)
endif()
target_link_libraries (libtesseract PRIVATE ${LIB_Ws2_32} ${LIB_pthread})
if(OpenMP_CXX_FOUND)

View File

@ -72,35 +72,37 @@ project_group (tessopt "Training Tools")
########################################
set(common_training_src
commandlineflags.cpp
commandlineflags.h
commontraining.cpp
commontraining.h
ctc.cpp
ctc.h
networkbuilder.cpp
networkbuilder.h
common/commandlineflags.cpp
common/commandlineflags.h
common/commontraining.cpp
common/commontraining.h
common/ctc.cpp
common/ctc.h
common/networkbuilder.cpp
common/networkbuilder.h
)
if (NOT DISABLED_LEGACY_ENGINE)
list(APPEND common_training_src
errorcounter.cpp
errorcounter.h
intfeaturedist.cpp
intfeaturedist.h
intfeaturemap.cpp
intfeaturemap.h
mastertrainer.cpp
mastertrainer.h
sampleiterator.cpp
sampleiterator.h
trainingsampleset.cpp
trainingsampleset.h
common/errorcounter.cpp
common/errorcounter.h
common/intfeaturedist.cpp
common/intfeaturedist.h
common/intfeaturemap.cpp
common/intfeaturemap.h
common/mastertrainer.cpp
common/mastertrainer.h
common/sampleiterator.cpp
common/sampleiterator.h
common/trainingsampleset.cpp
common/trainingsampleset.h
)
endif()
add_library (common_training ${common_training_src})
target_link_libraries (common_training libtesseract tessopt)
target_include_directories (common_training PUBLIC common ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries (common_training PUBLIC libtesseract tessopt)
generate_export_header (common_training EXPORT_MACRO_NAME TESS_COMMON_TRAINING_API)
project_group (common_training "Training Tools")
########################################
@ -109,7 +111,7 @@ project_group (common_training "Training Tools")
if (NOT DISABLED_LEGACY_ENGINE)
add_executable (ambiguous_words ambiguous_words.cpp)
target_link_libraries (ambiguous_words libtesseract)
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()
@ -132,7 +134,7 @@ endif()
########################################
add_executable (combine_tessdata combine_tessdata.cpp)
target_link_libraries (combine_tessdata libtesseract)
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)
@ -154,7 +156,7 @@ endif()
########################################
add_executable (dawg2wordlist dawg2wordlist.cpp)
target_link_libraries (dawg2wordlist libtesseract)
target_link_libraries (dawg2wordlist common_training)
project_group (dawg2wordlist "Training Tools")
install (TARGETS dawg2wordlist RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
@ -188,7 +190,7 @@ endif()
########################################
add_executable (wordlist2dawg wordlist2dawg.cpp)
target_link_libraries (wordlist2dawg libtesseract)
target_link_libraries (wordlist2dawg common_training)
project_group (wordlist2dawg "Training Tools")
install (TARGETS wordlist2dawg RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
@ -203,34 +205,18 @@ endif()
# LIBRARY unicharset_training
########################################
set(unicharset_training_src
icuerrorcode.cpp
icuerrorcode.h
fileio.cpp
fileio.h
lang_model_helpers.cpp
lang_model_helpers.h
lstmtester.cpp
lstmtester.h
lstmtrainer.cpp
lstmtrainer.h
normstrngs.cpp
normstrngs.h
unicharset_training_utils.cpp
unicharset_training_utils.h
validate_grapheme.h validate_indic.h validate_khmer.h
validate_javanese.h validate_myanmar.h validator.h
validate_grapheme.cpp validate_indic.cpp validate_khmer.cpp
validate_javanese.cpp validate_myanmar.cpp validator.cpp
file(GLOB unicharset_training_src
unicharset/*
)
add_library (unicharset_training ${unicharset_training_src})
if (SW_BUILD)
target_link_libraries (unicharset_training common_training org.sw.demo.unicode.icu.i18n)
target_link_libraries (unicharset_training PUBLIC common_training org.sw.demo.unicode.icu.i18n)
else()
target_link_libraries (unicharset_training common_training ${ICU_LIBRARIES})
target_link_libraries (unicharset_training PUBLIC common_training ${ICU_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")
@ -269,7 +255,7 @@ install (TARGETS lstmtraining RUNTIME DESTINATION bin LIBRAR
########################################
add_executable (merge_unicharsets merge_unicharsets.cpp)
target_link_libraries (merge_unicharsets libtesseract tessopt)
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)
@ -289,13 +275,11 @@ install (TARGETS set_unicharset_properties RUNTIME DESTINATI
########################################
add_executable (unicharset_extractor unicharset_extractor.cpp)
target_link_libraries (unicharset_extractor libtesseract tessopt unicharset_training)
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 text2image
########################################
if (NOT SW_BUILD)
@ -312,34 +296,23 @@ pkg_check_modules(PangoCairo REQUIRED pangocairo)
pkg_check_modules(FontConfig REQUIRED fontconfig)
endif()
set(text2image_src
text2image.cpp
boxchar.cpp
boxchar.h
degradeimage.cpp
degradeimage.h
fileio.h
fileio.cpp
ligature_table.cpp
ligature_table.h
normstrngs.cpp
normstrngs.h
pango_font_info.cpp
pango_font_info.h
stringrenderer.cpp
stringrenderer.h
tlog.cpp
tlog.h
util.h
icuerrorcode.h
########################################
# LIBRARY pango_training
########################################
file(GLOB pango_training_src
pango/*
)
add_executable (text2image ${text2image_src})
target_link_libraries (text2image unicharset_training)
add_library (pango_training ${pango_training_src})
if (SW_BUILD)
target_link_libraries (pango_training unicharset_training org.sw.demo.gnome.pango.pangocairo)
else()
if (PKG_CONFIG_FOUND)
target_include_directories (text2image BEFORE PRIVATE ${Cairo_INCLUDE_DIRS} ${Pango_INCLUDE_DIRS})
target_compile_definitions (text2image PRIVATE -DPANGO_ENABLE_ENGINE)
target_link_libraries (text2image
target_include_directories (pango_training BEFORE PRIVATE ${Cairo_INCLUDE_DIRS} ${Pango_INCLUDE_DIRS})
target_compile_definitions (pango_training PRIVATE -DPANGO_ENABLE_ENGINE)
target_link_libraries (pango_training
${Pango_LIBRARIES}
${Cairo_LIBRARIES}
${PangoCairo_LIBRARIES}
@ -347,9 +320,24 @@ target_link_libraries (text2image
${FontConfig_LIBRARIES}
)
endif()
if (SW_BUILD)
target_link_libraries (text2image org.sw.demo.gnome.pango.pangocairo)
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)

View File

@ -18,6 +18,7 @@
#ifndef TESSERACT_TRAINING_COMMANDLINEFLAGS_H_
#define TESSERACT_TRAINING_COMMANDLINEFLAGS_H_
#include "export.h"
#include "params.h"
#include <cstdlib>

View File

@ -18,6 +18,7 @@
#include "config_auto.h"
#endif
#include "export.h"
#include "commandlineflags.h"
#include "tprintf.h"

View File

@ -19,6 +19,7 @@
#ifndef TESSERACT_LSTM_CTC_H_
#define TESSERACT_LSTM_CTC_H_
#include "export.h"
#include "genericvector.h"
#include "network.h"
#include "networkio.h"

View File

@ -0,0 +1,5 @@
#pragma once
#ifdef CMAKE_BUILD
#include <common_training_export.h>
#endif

View File

@ -21,6 +21,7 @@
#ifndef TESSERACT_CLASSIFY_INTFEATUREMAP_H_
#define TESSERACT_CLASSIFY_INTFEATUREMAP_H_
#include "export.h"
#include "intfeaturespace.h"
#include "indexmapbidi.h"
#include "intproto.h"

View File

@ -22,9 +22,8 @@
#ifndef TESSERACT_TRAINING_MASTERTRAINER_H_
#define TESSERACT_TRAINING_MASTERTRAINER_H_
/**----------------------------------------------------------------------------
Include Files and Type Defines
----------------------------------------------------------------------------**/
#include "export.h"
#include "classify.h"
#include "cluster.h"
#include "intfx.h"

View File

@ -17,6 +17,7 @@
///////////////////////////////////////////////////////////////////////
#include "networkbuilder.h"
#include "convolve.h"
#include "fullyconnected.h"
#include "input.h"

View File

@ -19,6 +19,7 @@
#ifndef TESSERACT_LSTM_NETWORKBUILDER_H_
#define TESSERACT_LSTM_NETWORKBUILDER_H_
#include "export.h"
#include "static_shape.h"
#include "stridemap.h"

View File

@ -0,0 +1,5 @@
#pragma once
#ifdef CMAKE_BUILD
#include <pango_training_export.h>
#endif

View File

@ -21,8 +21,6 @@
#include "ligature_table.h"
#include <utility>
#include "pango_font_info.h"
#include "tlog.h"
#include <tesseract/unichar.h>
@ -32,6 +30,8 @@
#include "unicode/unistr.h" // from libicu
#include "unicode/utypes.h" // from libicu
#include <utility>
namespace tesseract {
static std::string EncodeAsUTF8(const char32 ch32) {

View File

@ -22,12 +22,12 @@
#ifndef TRAININGDATA_LIGATURE_TABLE_H_
#define TRAININGDATA_LIGATURE_TABLE_H_
#include "export.h"
#include <memory>
#include <string>
#include <unordered_map>
#include "util.h"
namespace tesseract {
class PangoFontInfo; // defined in pango_font_info.h

View File

@ -20,10 +20,7 @@
#ifndef TESSERACT_TRAINING_PANGO_FONT_INFO_H_
#define TESSERACT_TRAINING_PANGO_FONT_INFO_H_
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include "export.h"
#include "commandlineflags.h"
#include "pango/pango-font.h"
@ -31,6 +28,11 @@
#include "pango/pangocairo.h"
#include "util.h"
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using char32 = signed int;
namespace tesseract {

View File

@ -28,14 +28,16 @@
#ifndef TESSERACT_TRAINING_STRINGRENDERER_H_
#define TESSERACT_TRAINING_STRINGRENDERER_H_
#include <string>
#include <unordered_map>
#include <vector>
#include "export.h"
#include "pango_font_info.h"
#include "pango/pango-layout.h"
#include "pango/pangocairo.h"
#include <string>
#include <unordered_map>
#include <vector>
struct Boxa;
struct Pix;

View File

@ -20,6 +20,8 @@
#ifndef TESSERACT_TRAINING_TLOG_H_
#define TESSERACT_TRAINING_TLOG_H_
#include "export.h"
#include "commandlineflags.h"
#include "errcode.h"
#include "tprintf.h"

View File

@ -0,0 +1,5 @@
#pragma once
#ifdef CMAKE_BUILD
#include <unicharset_training_export.h>
#endif

View File

@ -16,14 +16,17 @@
#ifndef TESSERACT_TRAINING_FILEIO_H_
#define TESSERACT_TRAINING_FILEIO_H_
#include "export.h"
#include "genericvector.h" // for GenericVector
#include "strngs.h" // for STRING
#include <tesseract/platform.h>
#include <cstddef>
#include <cstdio>
#include <string>
#include "genericvector.h" // for GenericVector
#include <tesseract/platform.h>
#include "strngs.h" // for STRING
namespace tesseract {
// Reads a file as a vector of STRING.

View File

@ -15,10 +15,13 @@
#ifndef TESSERACT_TRAINING_LANG_MODEL_HELPERS_H_
#define TESSERACT_TRAINING_LANG_MODEL_HELPERS_H_
#include "export.h"
#include "serialis.h"
#include "strngs.h"
#include "tessdatamanager.h"
#include "unicharset.h"
#include <string>
namespace tesseract {

View File

@ -18,8 +18,11 @@
#ifndef TESSERACT_TRAINING_LSTMTESTER_H_
#define TESSERACT_TRAINING_LSTMTESTER_H_
#include "export.h"
#include "lstmtrainer.h"
#include "strngs.h"
#include <mutex>
#include <vector>

View File

@ -18,11 +18,14 @@
#ifndef TESSERACT_LSTM_LSTMTRAINER_H_
#define TESSERACT_LSTM_LSTMTRAINER_H_
#include <functional> // for std::function
#include "export.h"
#include "imagedata.h"
#include "lstmrecognizer.h"
#include "rect.h"
#include <functional> // for std::function
namespace tesseract {
class LSTM;

View File

@ -21,11 +21,13 @@
#ifndef TESSERACT_CCUTIL_NORMSTRNGS_H_
#define TESSERACT_CCUTIL_NORMSTRNGS_H_
#include <string>
#include <vector>
#include "export.h"
#include "validator.h"
#include <string>
#include <vector>
namespace tesseract {
// The standard unicode normalizations.

View File

@ -20,10 +20,12 @@
#ifndef TESSERACT_TRAINING_UNICHARSET_TRAINING_UTILS_H_
#define TESSERACT_TRAINING_UNICHARSET_TRAINING_UTILS_H_
#include <string>
#include "export.h"
#include <tesseract/platform.h>
#include <string>
namespace tesseract {
class STATS;

View File

@ -20,9 +20,12 @@
#ifndef TESSERACT_TRAINING_VALIDATOR_H_
#define TESSERACT_TRAINING_VALIDATOR_H_
#include "export.h"
#include <tesseract/unichar.h>
#include <memory>
#include <vector>
#include <tesseract/unichar.h>
namespace tesseract {