Skip to content

Commit

Permalink
Fix linux build.
Browse files Browse the repository at this point in the history
  • Loading branch information
egorpugin committed Sep 6, 2015
1 parent 5e3b8d3 commit 03531ba
Show file tree
Hide file tree
Showing 4 changed files with 402 additions and 54 deletions.
38 changes: 32 additions & 6 deletions CMakeLists.txt
Expand Up @@ -46,6 +46,17 @@ set(VERSION_PLAIN ${VERSION_MAJOR}.${VERSION_MINOR})

find_package(Leptonica 1.72 REQUIRED)

find_package(ICU COMPONENTS uc i18n)
find_package(PkgConfig QUIET)
pkg_check_modules(Pango pango)
pkg_check_modules(Cairo cairo)
pkg_check_modules(PangoFt2 pangoft2)
pkg_check_modules(PangoCairo pangocairo)
pkg_check_modules(FontConfig fontconfig)

include_directories(${Pango_INCLUDE_DIRS})
include_directories(${Cairo_INCLUDE_DIRS})

###############################################################################
#
# compiler and linker
Expand All @@ -65,6 +76,14 @@ if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0")
endif()

set(LIB_Ws2_32 Ws2_32)
endif()

if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11")

set(LIB_pthread pthread)
endif()

###############################################################################
Expand All @@ -74,7 +93,7 @@ endif()
###############################################################################

set(AUTOCONFIG_SRC ${CMAKE_BINARY_DIR}/config_auto.h.in)
set(AUTOCONFIG ${CMAKE_BINARY_DIR}/src/config_auto.h)
set(AUTOCONFIG ${CMAKE_BINARY_DIR}/config_auto.h)

include(Configure)

Expand All @@ -98,12 +117,15 @@ configure_file(
include(BuildFunctions)
include(SourceGroups)

add_definitions(-DHAVE_CONFIG_H)
add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1)
add_definitions(-DUSE_STD_NAMESPACE=1)
add_definitions(-DWINDLLNAME="libtesseract${VERSION_MAJOR}${VERSION_MINOR}.dll")

include_directories(${Leptonica_INCLUDE_DIRS})

include_directories(${CMAKE_BINARY_DIR})

include_directories(api)
include_directories(ccmain)
include_directories(ccstruct)
Expand Down Expand Up @@ -136,7 +158,6 @@ file(GLOB tesseract_src
"opencl/*.cpp"
"textord/*.cpp"
"viewer/*.cpp"
"vs2010/port/*.cpp"
"wordrec/*.cpp"
)
file(GLOB tesseract_hdr
Expand All @@ -152,9 +173,14 @@ file(GLOB tesseract_hdr
"opencl/*.h"
"textord/*.h"
"viewer/*.h"
"vs2010/port/*.h"
"wordrec/*.h"
)
if (WIN32)
file(GLOB tesseract_win32_src "vs2010/port/*.cpp")
file(GLOB tesseract_win32_hdr "vs2010/port/*.h")
set(tesseract_src ${tesseract_src} ${tesseract_win32_src})
set(tesseract_hdr ${tesseract_hdr} ${tesseract_win32_hdr})
endif()

set(tesseract_src ${tesseract_src}
api/baseapi.cpp
Expand All @@ -165,9 +191,9 @@ set(tesseract_src ${tesseract_src}

add_library (tesseract ${LIBRARY_TYPE} ${tesseract_src} ${tesseract_hdr})
target_compile_definitions (tesseract PUBLIC -DTESS_EXPORTS)
target_link_libraries (tesseract ${Leptonica_LIBRARIES} Ws2_32)
set_target_properties (tesseract PROPERTIES OUTPUT_NAME libtesseract${VERSION_MAJOR}${VERSION_MINOR})
set_target_properties (tesseract PROPERTIES DEBUG_OUTPUT_NAME libtesseract${VERSION_MAJOR}${VERSION_MINOR}d)
target_link_libraries (tesseract ${Leptonica_LIBRARIES} ${LIB_Ws2_32} ${LIB_pthread})
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)
export(TARGETS tesseract FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake)


Expand Down
90 changes: 45 additions & 45 deletions cmake/Configure.cmake
Expand Up @@ -35,6 +35,24 @@ function(check_functions functions)
endforeach()
endfunction(check_functions)

########################################
# FUNCTION check_types
########################################
function(check_types types)
foreach(T ${${types}})
set(name ${T})
string(REPLACE " " "_" name ${name})
string(REPLACE "-" "_" name ${name})
string(REPLACE "." "_" name ${name})
string(REPLACE "/" "_" name ${name})
string(TOUPPER ${name} name)
check_type_size(${T} HAVE_${name})
file(APPEND ${AUTOCONFIG_SRC} "/* Define to 1 if the system has the type `${T}'. */\n")
file(APPEND ${AUTOCONFIG_SRC} "#cmakedefine HAVE_${name} 1\n")
file(APPEND ${AUTOCONFIG_SRC} "\n")
endforeach()
endfunction(check_types)

########################################

file(WRITE ${AUTOCONFIG_SRC})
Expand All @@ -55,78 +73,60 @@ include(TestBigEndian)
set(include_files_list
dlfcn.h
inttypes.h
limits.h
malloc.h
memory.h
stdbool.h
stdint.h
stdlib.h
strings.h
string.h
sys/ipc.h
sys/shm.h
sys/stat.h
sys/types.h
sys/wait.h
tiffio.h
unistd.h

openjpeg-2.0/openjpeg.h
openjpeg-2.1/openjpeg.h
openjpeg-2.2/openjpeg.h
cairo/cairo-version.h
CL/cl.h
OpenCL/cl.h
pango-1.0/pango/pango-features.h
unicode/uchar.h
)
check_includes(include_files_list)

set(functions_list
fmemopen
getline
snprintf
)
check_functions(functions_list)

test_big_endian(WORDS_BIGENDIAN)

set(STDC_HEADERS 1)

if (GIF_FOUND)
set(HAVE_LIBGIF 1)
endif()

if (JPEG_FOUND)
set(HAVE_LIBJPEG 1)
endif()
set(types_list
"long long int"
mbstate_t
wchar_t
_Bool
)
check_types(types_list)

if (PNG_FOUND)
set(HAVE_LIBPNG 1)
endif()
check_c_source_compiles("#include <sys/time.h>\n#include <time.h>\nmain(){}" TIME_WITH_SYS_TIME)

if (TIFF_FOUND)
set(HAVE_LIBTIFF 1)
endif()
test_big_endian(WORDS_BIGENDIAN)

if (ZLIB_FOUND)
set(HAVE_LIBZ 1)
endif()
set(STDC_HEADERS 1)

file(APPEND ${AUTOCONFIG_SRC} "
/* Define to 1 if you have the ANSI C header files. */
#cmakedefine STDC_HEADERS 1
/* Define to 1 if you have giflib. */
#cmakedefine HAVE_LIBGIF 1
/* Define to 1 if you have libopenjp2. */
#cmakedefine HAVE_LIBJP2K 1
/* Define to 1 if you have jpeg. */
#cmakedefine HAVE_LIBJPEG 1
/* Define to 1 if you have libpng. */
#cmakedefine HAVE_LIBPNG 1
/* Define to 1 if you have libtiff. */
#cmakedefine HAVE_LIBTIFF 1
/* Define to 1 if you have libwebp. */
#cmakedefine HAVE_LIBWEBP 1
/* Define to 1 if you have zlib. */
#cmakedefine HAVE_LIBZ 1
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
#cmakedefine WORDS_BIGENDIAN 1
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#cmakedefine TIME_WITH_SYS_TIME 1
")

########################################
Expand Down

0 comments on commit 03531ba

Please sign in to comment.