|
| 1 | +# |
| 2 | +# tesseract |
| 3 | +# |
| 4 | + |
| 5 | +############################################################################### |
| 6 | +# |
| 7 | +# cmake settings |
| 8 | +# |
| 9 | +############################################################################### |
| 10 | + |
| 11 | +cmake_minimum_required(VERSION 2.8.12) |
| 12 | + |
| 13 | +# In-source builds are disabled. |
| 14 | +if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) |
| 15 | + message(FATAL_ERROR |
| 16 | + "CMake generation is not possible within the source directory!" |
| 17 | + "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:" |
| 18 | + "\n " |
| 19 | + "\n rm CMakeCache.txt" |
| 20 | + "\n mkdir build" |
| 21 | + "\n cd build" |
| 22 | + "\n cmake .." |
| 23 | + ) |
| 24 | +endif() |
| 25 | + |
| 26 | +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake") |
| 27 | + |
| 28 | +set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin") |
| 29 | +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}") |
| 30 | + |
| 31 | +# Use solution folders. |
| 32 | +set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 33 | +set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake Targets") |
| 34 | + |
| 35 | +############################################################################### |
| 36 | +# |
| 37 | +# project settings |
| 38 | +# |
| 39 | +############################################################################### |
| 40 | + |
| 41 | +project(tesseract C CXX) |
| 42 | + |
| 43 | +set(VERSION_MAJOR 3) |
| 44 | +set(VERSION_MINOR 05) |
| 45 | +set(VERSION_PLAIN ${VERSION_MAJOR}.${VERSION_MINOR}) |
| 46 | + |
| 47 | +find_package(Leptonica 1.72 REQUIRED) |
| 48 | + |
| 49 | +############################################################################### |
| 50 | +# |
| 51 | +# compiler and linker |
| 52 | +# |
| 53 | +############################################################################### |
| 54 | + |
| 55 | +set(LIBRARY_TYPE SHARED) |
| 56 | +if (STATIC) |
| 57 | + set(LIBRARY_TYPE) |
| 58 | +endif() |
| 59 | + |
| 60 | +if (WIN32) |
| 61 | + if (MSVC) |
| 62 | + add_definitions(-D_SCL_SECURE_NO_WARNINGS) |
| 63 | + add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
| 64 | + |
| 65 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") |
| 66 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0") |
| 67 | + endif() |
| 68 | +endif() |
| 69 | + |
| 70 | +############################################################################### |
| 71 | +# |
| 72 | +# configure |
| 73 | +# |
| 74 | +############################################################################### |
| 75 | + |
| 76 | +set(AUTOCONFIG_SRC ${CMAKE_BINARY_DIR}/config_auto.h.in) |
| 77 | +set(AUTOCONFIG ${CMAKE_BINARY_DIR}/src/config_auto.h) |
| 78 | + |
| 79 | +include(Configure) |
| 80 | + |
| 81 | +configure_file(${AUTOCONFIG_SRC} ${AUTOCONFIG} @ONLY) |
| 82 | + |
| 83 | +set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/api) |
| 84 | + |
| 85 | +configure_file( |
| 86 | + ${CMAKE_SOURCE_DIR}/cmake/templates/TesseractConfig-version.cmake.in |
| 87 | + ${CMAKE_BINARY_DIR}/TesseractConfig-version.cmake @ONLY) |
| 88 | +configure_file( |
| 89 | + ${CMAKE_SOURCE_DIR}/cmake/templates/TesseractConfig.cmake.in |
| 90 | + ${CMAKE_BINARY_DIR}/TesseractConfig.cmake @ONLY) |
| 91 | + |
| 92 | +############################################################################### |
| 93 | +# |
| 94 | +# build |
| 95 | +# |
| 96 | +############################################################################### |
| 97 | + |
| 98 | +######################################## |
| 99 | +# FUNCTION build_dir |
| 100 | +######################################## |
| 101 | +function(build_dir target_name) |
| 102 | + if (${ARGC} GREATER 1) |
| 103 | + set(dir ${ARGV1}) |
| 104 | + else() |
| 105 | + set(dir ${target_name}) |
| 106 | + endif() |
| 107 | + file(GLOB ${dir}_src "${dir}/*.cpp") |
| 108 | + file(GLOB ${dir}_hdr "${dir}/*.h") |
| 109 | + add_library(${target_name} ${${dir}_src} ${${dir}_hdr}) |
| 110 | +endfunction(build_dir) |
| 111 | +######################################## |
| 112 | + |
| 113 | +add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1) |
| 114 | +add_definitions(-DUSE_STD_NAMESPACE=1) |
| 115 | +add_definitions(-DWINDLLNAME="libtesseract${VERSION_MAJOR}${VERSION_MINOR}.dll") |
| 116 | +add_definitions(-DTESS_EXPORTS) |
| 117 | + |
| 118 | +include_directories(${Leptonica_INCLUDE_DIRS}) |
| 119 | + |
| 120 | +include_directories(ccmain) |
| 121 | +include_directories(ccstruct) |
| 122 | +include_directories(ccutil) |
| 123 | +include_directories(classify) |
| 124 | +include_directories(cube) |
| 125 | +include_directories(cutil) |
| 126 | +include_directories(dict) |
| 127 | +include_directories(neural_networks/runtime) |
| 128 | +include_directories(opencl) |
| 129 | +include_directories(textord) |
| 130 | +include_directories(vs2010/port) |
| 131 | +include_directories(viewer) |
| 132 | +include_directories(wordrec) |
| 133 | + |
| 134 | +######################################## |
| 135 | +# LIBRARY api |
| 136 | +######################################## |
| 137 | + |
| 138 | +set(api_src |
| 139 | + api/baseapi.cpp |
| 140 | + api/capi.cpp |
| 141 | + api/renderer.cpp |
| 142 | + api/pdfrenderer.cpp |
| 143 | +) |
| 144 | +file(GLOB api_hdr "api/*.h") |
| 145 | +add_library(api ${api_src} ${api_hdr}) |
| 146 | + |
| 147 | + |
| 148 | +######################################## |
| 149 | + |
| 150 | +######################################## |
| 151 | +# LIBRARIES tesseract |
| 152 | +######################################## |
| 153 | + |
| 154 | +build_dir(main ccmain) |
| 155 | +build_dir(struct ccstruct) |
| 156 | +build_dir(ccutil) |
| 157 | +build_dir(classify) |
| 158 | +build_dir(cube) |
| 159 | +build_dir(cutil) |
| 160 | +build_dir(dict) |
| 161 | +build_dir(neural neural_networks/runtime) |
| 162 | +build_dir(opencl) |
| 163 | +build_dir(textord) |
| 164 | +build_dir(viewer) |
| 165 | +build_dir(port vs2010/port) |
| 166 | +build_dir(wordrec) |
| 167 | + |
| 168 | + |
| 169 | +######################################## |
| 170 | +# LIBRARY tesseract |
| 171 | +######################################## |
| 172 | + |
| 173 | +add_library (tesseract ${LIBRARY_TYPE} ${tesseract_src} ${tesseract_hdr}) |
| 174 | +target_link_libraries (tesseract |
| 175 | + PRIVATE |
| 176 | + main |
| 177 | + struct |
| 178 | + ccutil |
| 179 | + classify |
| 180 | + cube |
| 181 | + cutil |
| 182 | + dict |
| 183 | + neural |
| 184 | + opencl |
| 185 | + textord |
| 186 | + viewer |
| 187 | + port |
| 188 | + wordrec |
| 189 | + |
| 190 | + PUBLIC |
| 191 | + ${Leptonica_LIBRARIES} |
| 192 | + Ws2_32 |
| 193 | +) |
| 194 | +set_target_properties (tesseract PROPERTIES OUTPUT_NAME libtesseract${VERSION_MAJOR}${VERSION_MINOR}) |
| 195 | +set_target_properties (tesseract PROPERTIES DEBUG_OUTPUT_NAME libtesseract${VERSION_MAJOR}${VERSION_MINOR}d) |
| 196 | +export(TARGETS tesseract FILE ${CMAKE_BINARY_DIR}/TesseractTargets.cmake) |
| 197 | + |
| 198 | + |
| 199 | +######################################## |
| 200 | +# EXECUTABLE tesseractmain |
| 201 | +######################################## |
| 202 | + |
| 203 | +set(tesseractmain_src |
| 204 | + api/tesseractmain.cpp |
| 205 | + vs2010/tesseract/resource.h |
| 206 | + vs2010/tesseract/tesseract.rc |
| 207 | +) |
| 208 | +add_executable (tesseractmain ${tesseractmain_src}) |
| 209 | +target_link_libraries (tesseractmain tesseract) |
| 210 | + |
| 211 | +############################################################################### |
0 commit comments