CMakeLists.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. #
  2. # tesseract
  3. #
  4. ###############################################################################
  5. #
  6. # cmake settings
  7. #
  8. ###############################################################################
  9. cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
  10. # In-source builds are disabled.
  11. if ("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
  12. message(FATAL_ERROR
  13. "CMake generation is not possible within the source directory!"
  14. "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:"
  15. "\n "
  16. "\n rm CMakeCache.txt"
  17. "\n mkdir build"
  18. "\n cd build"
  19. "\n cmake .."
  20. )
  21. endif()
  22. set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  23. set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin")
  24. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}")
  25. # Use solution folders.
  26. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  27. set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake Targets")
  28. ###############################################################################
  29. #
  30. # project settings
  31. #
  32. ###############################################################################
  33. project(tesseract C CXX)
  34. # Get version with components from VERSION file.
  35. file(STRINGS "VERSION" VERSION_PLAIN)
  36. string(REGEX REPLACE "^([^.]*)\\..*" "\\1" VERSION_MAJOR ${VERSION_PLAIN})
  37. string(REGEX REPLACE "^[^.]*\\.([^.]*)\\..*" "\\1" VERSION_MINOR ${VERSION_PLAIN})
  38. string(REGEX REPLACE "^[^.]*\\.[^.]*\\.([0-9]*).*" "\\1" VERSION_PATCH ${VERSION_PLAIN})
  39. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
  40. execute_process(COMMAND git --git-dir ${CMAKE_CURRENT_SOURCE_DIR}/.git describe --abbrev=4
  41. OUTPUT_VARIABLE GIT_REV)
  42. string(REGEX REPLACE "\n$" "" PACKAGE_VERSION "${GIT_REV}")
  43. endif()
  44. if(NOT PACKAGE_VERSION)
  45. set(PACKAGE_VERSION ${VERSION_PLAIN})
  46. endif()
  47. # Provide also same macro names as autoconf (see configure.ac).
  48. set(GENERIC_MAJOR_VERSION ${VERSION_MAJOR})
  49. set(GENERIC_MINOR_VERSION ${VERSION_MINOR})
  50. set(GENERIC_MICRO_VERSION ${VERSION_PATCH})
  51. set(MINIMUM_LEPTONICA_VERSION 1.74)
  52. ###############################################################################
  53. #
  54. # options
  55. #
  56. ###############################################################################
  57. message( "Configuring tesseract version ${PACKAGE_VERSION}...")
  58. if (WIN32)
  59. option(SW_BUILD "Build with sw" ON)
  60. else()
  61. option(SW_BUILD "Build with sw" OFF)
  62. endif()
  63. option(OPENMP_BUILD "Build with openmp support" OFF) # see issue #1662
  64. option(AUTO_OPTIMIZE "Usage of cmake auto optimize macros (not suitable for portable build)" ON)
  65. option(GRAPHICS_DISABLED "Disable disable graphics (ScrollView)" OFF)
  66. option(DISABLED_LEGACY_ENGINE "Disable the legacy OCR engine" OFF)
  67. option(BUILD_TRAINING_TOOLS "Build training tools" ON)
  68. option(BUILD_TESTS "Build tests" OFF)
  69. option(USE_SYSTEM_ICU "Use system ICU" OFF)
  70. ###############################################################################
  71. #
  72. # compiler and linker
  73. #
  74. ###############################################################################
  75. if(NOT CMAKE_BUILD_TYPE)
  76. message(STATUS "Setting build type to 'Release' as none was specified.")
  77. set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
  78. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
  79. endif()
  80. include(CheckCXXCompilerFlag)
  81. # Check for C++ standard to use
  82. get_property(known_features GLOBAL PROPERTY CMAKE_CXX_KNOWN_FEATURES)
  83. if (cxx_std_17 IN_LIST known_features)
  84. set(CMAKE_CXX_STANDARD 17)
  85. elseif (cxx_std_14 IN_LIST known_features)
  86. set(CMAKE_CXX_STANDARD 14)
  87. else() # minimum required standard
  88. set(CMAKE_CXX_STANDARD 11)
  89. endif()
  90. # Avoid using experimental c++1y (c++1z) standard even if the compiler announces cxx14 (cxx17)
  91. # in CMAKE_CXX_KNOWN_FEATURES and CMAKE_CXX_COMPILE_FEATURES
  92. # It is the case of clang 3.9, 4.0 (announces c++1z) and gcc 4.8 (announces c++1y)
  93. if ("${CMAKE_CXX17_STANDARD_COMPILE_OPTION}" STREQUAL "-std=c++1z")
  94. set(CMAKE_CXX_STANDARD 14)
  95. endif()
  96. if ("${CMAKE_CXX14_STANDARD_COMPILE_OPTION}" STREQUAL "-std=c++1y")
  97. set(CMAKE_CXX_STANDARD 11)
  98. endif()
  99. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  100. set(CMAKE_CXX_EXTENSIONS OFF)
  101. set(LIBRARY_TYPE SHARED)
  102. if (STATIC)
  103. set(LIBRARY_TYPE)
  104. endif()
  105. # auto optimize
  106. if (AUTO_OPTIMIZE)
  107. include(OptimizeForArchitecture)
  108. AutodetectHostArchitecture()
  109. OptimizeForArchitecture()
  110. endif()
  111. # Compiler specific environments
  112. if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  113. set(CLANG 1)
  114. endif()
  115. if(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
  116. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -DDEBUG -pedantic -Og")
  117. elseif(MSVC)
  118. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  119. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
  120. if (NOT CLANG)
  121. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  122. endif()
  123. # Don't use /Wall because it generates too many warnings.
  124. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 /bigobj")
  125. endif()
  126. if(CLANG) # clang all platforms
  127. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-unused-command-line-argument")
  128. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -DDEBUG -pedantic -O0")
  129. endif()
  130. if (OPENMP_BUILD)
  131. find_package(OpenMP QUIET)
  132. if (OpenMP_FOUND)
  133. message(">> ${OpenMP_FOUND} ${OpenMP_VERSION}")
  134. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
  135. if(${CMAKE_VERSION} VERSION_LESS "3.9.0")
  136. add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE)
  137. endif()
  138. endif()
  139. # https://stackoverflow.com/questions/12399422/how-to-set-linker-flags-for-openmp-in-cmakes-try-compile-function
  140. if (NOT OpenMP_FOUND AND CLANG AND WIN32)
  141. # workaroung because find_package(OpenMP) does not work for clang-cl
  142. # https://gitlab.kitware.com/cmake/cmake/issues/19404
  143. check_include_file_cxx(omp.h HAVE_OMP_H_INCLUDE)
  144. find_library(OpenMP_LIBRARY NAMES omp libomp.lib)
  145. message(">> OpenMP_LIBRARY: ${OpenMP_LIBRARY}")
  146. if (MSVC)
  147. set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS} /openmp")
  148. else()
  149. set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS} -fopenmp")
  150. endif()
  151. set(OpenMP_FOUND 1)
  152. add_definitions(-D_OPENMP=201107) # 3.1 version is supported from Clang 3.8.0
  153. endif()
  154. endif()
  155. if (CYGWIN)
  156. add_definitions(-D__CYGWIN__)
  157. elseif(UNIX)
  158. if (NOT ANDROID)
  159. set(LIB_pthread pthread)
  160. endif()
  161. elseif(WIN32)
  162. set(LIB_Ws2_32 Ws2_32)
  163. endif()
  164. ###############################################################################
  165. #
  166. # packages
  167. #
  168. ###############################################################################
  169. if (SW_BUILD)
  170. find_package(SW REQUIRED)
  171. if (STATIC)
  172. set(SW_BUILD_SHARED_LIBS 0)
  173. else()
  174. set(SW_BUILD_SHARED_LIBS 1)
  175. endif()
  176. sw_add_package(
  177. org.sw.demo.danbloomberg.leptonica
  178. org.sw.demo.libarchive.libarchive
  179. )
  180. if (BUILD_TRAINING_TOOLS)
  181. sw_add_package(
  182. org.sw.demo.gnome.pango.pangocairo
  183. org.sw.demo.unicode.icu.i18n
  184. )
  185. endif()
  186. sw_execute()
  187. else()
  188. find_package(PkgConfig)
  189. if(PKG_CONFIG_EXECUTABLE AND NOT Leptonica_DIR)
  190. pkg_check_modules(Leptonica REQUIRED lept>=${MINIMUM_LEPTONICA_VERSION})
  191. link_directories(${Leptonica_LIBRARY_DIRS})
  192. else()
  193. find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
  194. endif()
  195. if (NOT Leptonica_FOUND)
  196. message(FATAL_ERROR "Cannot find required library Leptonica. Quitting!")
  197. endif(NOT Leptonica_FOUND)
  198. find_package(LibArchive)
  199. if(LibArchive_FOUND)
  200. set(HAVE_LIBARCHIVE ON)
  201. endif()
  202. endif()
  203. find_package(OpenCL QUIET)
  204. ###############################################################################
  205. #
  206. # configure
  207. #
  208. ###############################################################################
  209. foreach(flag ${Vc_ARCHITECTURE_FLAGS})
  210. set(Vc_CXX_FLAGS "${Vc_CXX_FLAGS} ${flag}")
  211. endforeach()
  212. # add definition as expected in src/arch/simddetect.cpp
  213. set(HAVE_AVX OFF)
  214. set(HAVE_AVX2 OFF)
  215. set(HAVE_FMA OFF)
  216. set(HAVE_SSE4_1 OFF)
  217. set(MARCH_NATIVE_OPT OFF)
  218. foreach(flag ${_enable_vector_unit_list}) # from OptimizeForArchitecture()
  219. string(TOUPPER "${flag}" flag)
  220. string(REPLACE "\." "_" flag "${flag}")
  221. if("${flag}" MATCHES "AVX|AVX2|FMA|SSE4_1")
  222. set(simd_flags "${simd_flags} -DHAVE_${flag}")
  223. set("HAVE_${flag}" ON)
  224. endif()
  225. endforeach(flag)
  226. if (NOT MSVC)
  227. set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -O3 -ffast-math")
  228. endif()
  229. CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE)
  230. if(COMPILER_SUPPORTS_MARCH_NATIVE)
  231. set(MARCH_NATIVE_FLAGS "${MARCH_NATIVE_FLAGS} -march=native -mtune=native")
  232. set(MARCH_NATIVE_OPT ON)
  233. endif()
  234. set(AUTOCONFIG_SRC ${CMAKE_CURRENT_BINARY_DIR}/config_auto.h.in)
  235. set(AUTOCONFIG ${CMAKE_CURRENT_BINARY_DIR}/config_auto.h)
  236. add_definitions(-DHAVE_CONFIG_H)
  237. if(GRAPHICS_DISABLED)
  238. message("ScrollView debugging disabled.")
  239. endif()
  240. set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${CMAKE_PREFIX_PATH}/include" "${CMAKE_INSTALL_PREFIX}/include")
  241. include(Configure)
  242. configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY)
  243. set(INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include" "${CMAKE_INSTALL_PREFIX}/include/tesseract")
  244. configure_file(
  245. ${CMAKE_CURRENT_SOURCE_DIR}/include/tesseract/version.h.in
  246. ${CMAKE_CURRENT_BINARY_DIR}/include/tesseract/version.h @ONLY)
  247. configure_file(
  248. ${CMAKE_CURRENT_SOURCE_DIR}/src/vs2010/tesseract/tesseract.rc.in
  249. ${CMAKE_CURRENT_BINARY_DIR}/vs2010/tesseract/tesseract.rc @ONLY)
  250. configure_file(
  251. ${CMAKE_CURRENT_SOURCE_DIR}/src/vs2010/tesseract/libtesseract.rc.in
  252. ${CMAKE_CURRENT_BINARY_DIR}/vs2010/tesseract/libtesseract.rc @ONLY)
  253. configure_file(
  254. ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/TesseractConfig-version.cmake.in
  255. ${CMAKE_CURRENT_BINARY_DIR}/TesseractConfig-version.cmake @ONLY)
  256. configure_file(
  257. ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/TesseractConfig.cmake.in
  258. ${CMAKE_CURRENT_BINARY_DIR}/TesseractConfig.cmake @ONLY)
  259. # show summary of configuration
  260. if(${CMAKE_BUILD_TYPE} MATCHES Debug)
  261. set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
  262. elseif(${CMAKE_BUILD_TYPE} MATCHES Release)
  263. set(COMPILER_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
  264. endif()
  265. message( STATUS )
  266. message( STATUS "General configuration for Tesseract ${PACKAGE_VERSION}")
  267. message( STATUS "--------------------------------------------------------")
  268. message( STATUS "Build type: ${CMAKE_BUILD_TYPE}")
  269. message( STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID}")
  270. message( STATUS "Used standard: C++${CMAKE_CXX_STANDARD}")
  271. message( STATUS "CXX compiler options: ${COMPILER_FLAGS}")
  272. message( STATUS "Linker options: ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UP}}")
  273. message( STATUS "Install directory: ${CMAKE_INSTALL_PREFIX}")
  274. message( STATUS "Architecture flags: ${Vc_ARCHITECTURE_FLAGS}")
  275. message( STATUS "Vector unit list: ${_enable_vector_unit_list}")
  276. message( STATUS "HAVE_AVX: ${HAVE_AVX}")
  277. message( STATUS "HAVE_AVX2: ${HAVE_AVX2}")
  278. message( STATUS "HAVE_FMA: ${HAVE_FMA}")
  279. message( STATUS "HAVE_SSE4_1: ${HAVE_SSE4_1}")
  280. message( STATUS "MARCH_NATIVE_OPT: ${MARCH_NATIVE_OPT}")
  281. message( STATUS "simd_flags: ${simd_flags}")
  282. message( STATUS "--------------------------------------------------------")
  283. message( STATUS "Build with sw [SW_BUILD]: ${SW_BUILD}")
  284. message( STATUS "Build with openmp support [OPENMP_BUILD]: ${OPENMP_BUILD}")
  285. message( STATUS "Disable disable graphics (ScrollView) [GRAPHICS_DISABLED]: ${GRAPHICS_DISABLED}")
  286. message( STATUS "Disable the legacy OCR engine [DISABLED_LEGACY_ENGINE]: ${DISABLED_LEGACY_ENGINE}")
  287. message( STATUS "Build training tools [BUILD_TRAINING_TOOLS]: ${BUILD_TRAINING_TOOLS}")
  288. message( STATUS "Build tests [BUILD_TESTS]: ${BUILD_TESTS}")
  289. message( STATUS "Use system ICU Library [USE_SYSTEM_ICU]: ${USE_SYSTEM_ICU}")
  290. message( STATUS "--------------------------------------------------------")
  291. message( STATUS )
  292. ###############################################################################
  293. #
  294. # build
  295. #
  296. ###############################################################################
  297. include(BuildFunctions)
  298. include(SourceGroups)
  299. add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1)
  300. include_directories(${Leptonica_INCLUDE_DIRS})
  301. include_directories(${LibArchive_INCLUDE_DIRS})
  302. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  303. include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
  304. include_directories(include)
  305. include_directories(src/arch)
  306. include_directories(src/ccmain)
  307. include_directories(src/ccstruct)
  308. include_directories(src/ccutil)
  309. include_directories(src/classify)
  310. include_directories(src/cutil)
  311. include_directories(src/dict)
  312. include_directories(src/lstm)
  313. include_directories(src/opencl)
  314. include_directories(src/textord)
  315. include_directories(src/viewer)
  316. include_directories(src/wordrec)
  317. include_directories(src/training)
  318. if(ANDROID_TOOLCHAIN)
  319. include_directories(${ANDROID_TOOLCHAIN}/sysroot/usr/include)
  320. add_compile_definitions(__ANDROID_API_FUTURE__)
  321. endif()
  322. ########################################
  323. # LIBRARY tesseract
  324. ########################################
  325. file(GLOB tesseract_src
  326. src/ccmain/*.cpp
  327. src/ccstruct/*.cpp
  328. src/ccutil/*.cpp
  329. src/classify/*.cpp
  330. src/cutil/*.cpp
  331. src/dict/*.cpp
  332. src/lstm/*.cpp
  333. src/opencl/*.cpp
  334. src/textord/*.cpp
  335. src/viewer/*.cpp
  336. src/wordrec/*.cpp
  337. )
  338. list(APPEND arch_files
  339. src/arch/dotproduct.cpp
  340. src/arch/simddetect.cpp
  341. src/arch/intsimdmatrix.cpp
  342. )
  343. set_source_files_properties(${arch_files} PROPERTIES COMPILE_FLAGS "${simd_flags}")
  344. set_source_files_properties(src/arch/dotproduct.cpp PROPERTIES COMPILE_FLAGS "${MARCH_NATIVE_FLAGS} ${Vc_CXX_FLAGS}")
  345. if(HAVE_AVX)
  346. list(APPEND arch_files_opt src/arch/dotproductavx.cpp)
  347. set_source_files_properties(src/arch/dotproductavx.cpp PROPERTIES COMPILE_FLAGS "-mavx")
  348. endif(HAVE_AVX)
  349. if(HAVE_AVX2)
  350. list(APPEND arch_files_opt src/arch/intsimdmatrixavx2.cpp)
  351. set_source_files_properties(src/arch/intsimdmatrixavx2.cpp PROPERTIES COMPILE_FLAGS "-mavx2")
  352. endif(HAVE_AVX2)
  353. if(HAVE_FMA)
  354. list(APPEND arch_files_opt src/arch/dotproductfma.cpp)
  355. set_source_files_properties(src/arch/dotproductfma.cpp PROPERTIES COMPILE_FLAGS "-mfma")
  356. endif(HAVE_FMA)
  357. if(HAVE_SSE4_1)
  358. list(APPEND arch_files_opt src/arch/dotproductsse.cpp src/arch/intsimdmatrixsse.cpp)
  359. set_source_files_properties(src/arch/dotproductsse.cpp src/arch/intsimdmatrixsse.cpp PROPERTIES COMPILE_FLAGS "-msse4.1")
  360. endif(HAVE_SSE4_1)
  361. set_source_files_properties(${arch_files_opt} PROPERTIES COMPILE_FLAGS "${Vc_CXX_FLAGS}")
  362. file(GLOB tesseract_hdr
  363. src/arch/*.h
  364. src/ccmain/*.h
  365. src/ccstruct/*.h
  366. src/ccutil/*.h
  367. src/classify/*.h
  368. src/cutil/*.h
  369. src/dict/*.h
  370. src/lstm/*.h
  371. src/opencl/*.h
  372. src/textord/*.h
  373. src/viewer/*.h
  374. src/wordrec/*.h
  375. )
  376. set(tesseract_src ${tesseract_src}
  377. src/api/baseapi.cpp
  378. src/api/capi.cpp
  379. src/api/renderer.cpp
  380. src/api/altorenderer.cpp
  381. src/api/hocrrenderer.cpp
  382. src/api/lstmboxrenderer.cpp
  383. src/api/pdfrenderer.cpp
  384. src/api/wordstrboxrenderer.cpp
  385. )
  386. if (WIN32)
  387. if (MSVC)
  388. include_directories(src/vs2010/tesseract)
  389. set(tesseract_hdr
  390. ${tesseract_hdr}
  391. ${CMAKE_CURRENT_SOURCE_DIR}/src/vs2010/tesseract/resource.h)
  392. set(tesseract_rsc ${CMAKE_CURRENT_BINARY_DIR}/vs2010/tesseract/libtesseract.rc)
  393. endif() # MSVC
  394. endif()
  395. add_library (libtesseract ${LIBRARY_TYPE} ${tesseract_src} ${arch_files}
  396. ${arch_files_opt} ${tesseract_hdr} ${tesseract_rsc}
  397. )
  398. if (NOT STATIC)
  399. target_compile_definitions (libtesseract
  400. PRIVATE -DTESS_EXPORTS
  401. INTERFACE -DTESS_IMPORTS
  402. )
  403. set_target_properties (libtesseract PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS True)
  404. endif()
  405. target_link_libraries (libtesseract PRIVATE ${LIB_Ws2_32} ${LIB_pthread})
  406. if(OpenMP_CXX_FOUND)
  407. target_link_libraries(libtesseract PUBLIC OpenMP::OpenMP_CXX)
  408. endif()
  409. set_target_properties (libtesseract PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
  410. set_target_properties (libtesseract PROPERTIES SOVERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
  411. if (WIN32)
  412. set_target_properties (libtesseract PROPERTIES OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR})
  413. set_target_properties (libtesseract PROPERTIES DEBUG_OUTPUT_NAME tesseract${VERSION_MAJOR}${VERSION_MINOR}d)
  414. else()
  415. set_target_properties (libtesseract PROPERTIES OUTPUT_NAME tesseract)
  416. endif()
  417. if (SW_BUILD)
  418. target_link_libraries (libtesseract PUBLIC
  419. org.sw.demo.danbloomberg.leptonica
  420. org.sw.demo.libarchive.libarchive
  421. )
  422. file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake "include(${CMAKE_CURRENT_BINARY_DIR}/cppan.cmake)\n")
  423. export(TARGETS libtesseract APPEND FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake)
  424. else()
  425. target_link_libraries (libtesseract PUBLIC
  426. ${Leptonica_LIBRARIES}
  427. ${LibArchive_LIBRARIES}
  428. )
  429. export(TARGETS libtesseract FILE ${CMAKE_CURRENT_BINARY_DIR}/TesseractTargets.cmake)
  430. endif()
  431. if (WIN32 AND CLANG AND OPENMP_BUILD)
  432. # Workaround for "libomp.lib is not automatically added on Windows"
  433. # see: http://lists.llvm.org/pipermail/openmp-dev/2015-August/000857.html
  434. target_link_libraries (libtesseract PRIVATE ${OpenMP_LIBRARY})
  435. endif()
  436. ########################################
  437. # EXECUTABLE tesseractmain
  438. ########################################
  439. set(tesseractmain_src src/api/tesseractmain.cpp)
  440. if (MSVC)
  441. set(tesseractmain_rsc ${CMAKE_CURRENT_BINARY_DIR}/vs2010/tesseract/tesseract.rc)
  442. endif()
  443. add_executable (tesseract ${tesseractmain_src} ${tesseractmain_rsc})
  444. target_link_libraries (tesseract libtesseract)
  445. if (HAVE_TIFFIO_H)
  446. target_link_libraries(tesseract tiff)
  447. endif()
  448. if (OPENMP_BUILD AND UNIX)
  449. target_link_libraries (tesseract pthread)
  450. endif()
  451. ########################################
  452. if (BUILD_TESTS AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt)
  453. add_subdirectory(googletest)
  454. endif()
  455. if (BUILD_TRAINING_TOOLS)
  456. add_subdirectory(src/training)
  457. endif()
  458. get_target_property(tesseract_NAME libtesseract NAME)
  459. get_target_property(tesseract_VERSION libtesseract VERSION)
  460. get_target_property(tesseract_OUTPUT_NAME libtesseract OUTPUT_NAME)
  461. configure_file(tesseract.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc @ONLY)
  462. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tesseract.pc DESTINATION lib/pkgconfig)
  463. install(TARGETS tesseract RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
  464. install(TARGETS libtesseract EXPORT TesseractTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
  465. install(EXPORT TesseractTargets DESTINATION cmake)
  466. install(FILES
  467. ${CMAKE_CURRENT_BINARY_DIR}/TesseractConfig.cmake
  468. ${CMAKE_CURRENT_BINARY_DIR}/TesseractConfig-version.cmake
  469. DESTINATION cmake)
  470. install(FILES
  471. # from api/makefile.am
  472. include/tesseract/apitypes.h
  473. include/tesseract/baseapi.h
  474. include/tesseract/capi.h
  475. include/tesseract/renderer.h
  476. ${CMAKE_CURRENT_BINARY_DIR}/include/tesseract/version.h
  477. #from ccmain/makefile.am
  478. include/tesseract/thresholder.h
  479. include/tesseract/ltrresultiterator.h
  480. include/tesseract/pageiterator.h
  481. include/tesseract/resultiterator.h
  482. include/tesseract/osdetect.h
  483. #from ccstruct/makefile.am
  484. include/tesseract/publictypes.h
  485. #from ccutil/makefile.am
  486. include/tesseract/genericvector.h
  487. include/tesseract/helpers.h
  488. include/tesseract/ocrclass.h
  489. include/tesseract/platform.h
  490. include/tesseract/serialis.h
  491. include/tesseract/strngs.h
  492. include/tesseract/unichar.h
  493. #${CMAKE_CURRENT_BINARY_DIR}/src/endianness.h
  494. DESTINATION include/tesseract)
  495. ########################################
  496. # uninstall target
  497. ########################################
  498. if(NOT TARGET uninstall)
  499. configure_file(
  500. "${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/cmake_uninstall.cmake.in"
  501. "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  502. IMMEDIATE @ONLY)
  503. add_custom_target(uninstall
  504. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
  505. endif()
  506. ###############################################################################
Tip!

Press p or to see the previous file or, n or to see the next file