diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0ac4849..35949b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,45 +13,37 @@ add_definitions( -DOPENALPR_MAJOR_VERSION=${OPENALPR_MAJOR_VERSION}) add_definitions( -DOPENALPR_MINOR_VERSION=${OPENALPR_MINOR_VERSION}) add_definitions( -DOPENALPR_PATCH_VERSION=${OPENALPR_PATCH_VERSION}) - -SET(OpenCV_DIR "${CMAKE_SOURCE_DIR}/../libraries/opencv/") -#SET(Tesseract_DIR "${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr") - -include_directories( - ${Tesseract_DIR}/api - ${Tesseract_DIR}/ccutil/ - ${Tesseract_DIR}/ccstruct/ - ${Tesseract_DIR}/ccmain/ -) - -IF (WIN32) - add_definitions( -DWINDOWS) - add_definitions( -DNOMINMAX) - - link_directories( ${Tesseract_DIR}/lib/ ) - include_directories(${Tesseract_DIR}/include/ ) - - # Extra linker dependencies for Windows - SET(Tesseract_LIBS - libtesseract303-static - liblept170 - ws2_32.lib) -ELSE() - - link_directories( ${Tesseract_DIR}/api/.libs/ ) - - SET(Tesseract_LIBS tesseract) -ENDIF() +SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/") +FIND_PACKAGE( Tesseract REQUIRED ) + +include_directories(${Tesseract_INCLUDE_DIRS}) + +# Discover OpenCV directory automatically +find_path(OpenCV_DIR + NAMES OpenCVConfig.cmake + HINTS ${CMAKE_SOURCE_DIR}/../libraries/opencv/) + # Opencv Package FIND_PACKAGE( OpenCV REQUIRED ) IF (${OpenCV_VERSION} VERSION_LESS 2.4.8) MESSAGE(FATAL_ERROR "OpenCV version is not compatible : ${OpenCV_VERSION}") ENDIF() +include_directories(./openalpr ) -include_directories(./openalpr ) +IF (WIN32) + add_definitions( -DWINDOWS) + add_definitions( -DNOMINMAX) + + # Extra linker dependencies for Windows + SET (Tesseract_LIBRARIES + ${Tesseract_LIBRARIES} + ws2_32.lib + ) + +ENDIF() set(CMAKE_CSS_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall ") @@ -60,9 +52,9 @@ ADD_EXECUTABLE( alpr main.cpp ) TARGET_LINK_LIBRARIES(alpr openalpr-static support - video + video ${OpenCV_LIBS} - ${Tesseract_LIBS} + ${Tesseract_LIBRARIES} ) # Compile the alprd library on Unix-based OS @@ -72,13 +64,16 @@ IF (NOT WIN32) TARGET_LINK_LIBRARIES(alprd openalpr support - video + video uuid curl log4cplus ${OpenCV_LIBS} - ${Tesseract_LIBS} + ${Tesseract_LIBRARIES} ) + + # Don't include misc utilities for Windows + add_subdirectory(misc_utilities) ENDIF() @@ -87,12 +82,6 @@ ENDIF() add_subdirectory(openalpr) add_subdirectory(video) -IF (NOT WIN32) - # Don't include misc utilities for Windows - add_subdirectory(misc_utilities) -ENDIF() - - install (TARGETS alpr DESTINATION bin) install (FILES ${CMAKE_SOURCE_DIR}/../doc/man/alpr.1 DESTINATION share/man/man1 COMPONENT doc) diff --git a/src/cmake_modules/FindTesseract.cmake b/src/cmake_modules/FindTesseract.cmake new file mode 100644 index 0000000..6b7da2f --- /dev/null +++ b/src/cmake_modules/FindTesseract.cmake @@ -0,0 +1,72 @@ +# - Try to find Tesseract-OCR +# Once done, this will define +# +# Tesseract_FOUND - system has Tesseract +# Tesseract_INCLUDE_DIRS - the Tesseract include directories +# Tesseract_LIBRARIES - link these to use Tesseract + +include(LibFindMacros) + +# Use pkg-config to get hints about paths +#libfind_pkg_check_modules(Tesseract_PKGCONF Tesseract) + +# Include dir +find_path(Tesseract_INCLUDE_BASEAPI_DIR + NAMES tesseract/baseapi.h + HINTS "/usr/include" + "/usr/local/include" + ${Tesseract_PKGCONF_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/api/ +) +find_path(Tesseract_INCLUDE_CCSTRUCT_DIR + NAMES publictypes.h + HINTS "/usr/include" + "/usr/local/include" + ${Tesseract_PKGCONF_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/ccstruct/ +) +find_path(Tesseract_INCLUDE_CCMAIN_DIR + NAMES thresholder.h + HINTS "/usr/include" + "/usr/local/include" + ${Tesseract_PKGCONF_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/ccmain/ +) +find_path(Tesseract_INCLUDE_CCUTIL_DIR + NAMES platform.h + HINTS "/usr/include" + "/usr/local/include" + ${Tesseract_PKGCONF_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/ccutil/ +) + + +# Finally the library itself +find_library(Tesseract_LIB + NAMES tesseract tesseract-static libtesseract303-static + HINTS "/usr/lib" + "/usr/local/lib" + ${Tesseract_PKGCONF_LIBRARY_DIRS} + ${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/api/.libs + ${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/vs2010/LIB_Release +) + +find_library(Leptonica_LIB + NAMES liblept170 liblept + HINTS "/usr/lib" + "/usr/local/lib" + ${Tesseract_PKGCONF_LIBRARY_DIRS} + ${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/api/.libs + ${CMAKE_SOURCE_DIR}/../libraries/tesseract-ocr/vs2010/LIB_Release +) + +# Set the include dir variables and the libraries and let libfind_process do the rest. +# NOTE: Singular variables for this library, plural for libraries this this lib depends on. +set(Tesseract_PROCESS_INCLUDES + Tesseract_INCLUDE_BASEAPI_DIR + Tesseract_INCLUDE_CCSTRUCT_DIR + Tesseract_INCLUDE_CCMAIN_DIR + Tesseract_INCLUDE_CCUTIL_DIR + Tesseract_INCLUDE_DIRS) +set(Tesseract_PROCESS_LIBS Tesseract_LIB Leptonica_LIB Tesseract_LIBRARIES) +libfind_process(Tesseract) \ No newline at end of file diff --git a/src/cmake_modules/LibFindMacros.cmake b/src/cmake_modules/LibFindMacros.cmake new file mode 100644 index 0000000..92b8397 --- /dev/null +++ b/src/cmake_modules/LibFindMacros.cmake @@ -0,0 +1,98 @@ +# Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments +# used for the current package. For this to work, the first parameter must be the +# prefix of the current package, then the prefix of the new package etc, which are +# passed to find_package. +macro (libfind_package PREFIX) + set (LIBFIND_PACKAGE_ARGS ${ARGN}) + if (${PREFIX}_FIND_QUIETLY) + set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) + endif (${PREFIX}_FIND_QUIETLY) + if (${PREFIX}_FIND_REQUIRED) + set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) + endif (${PREFIX}_FIND_REQUIRED) + find_package(${LIBFIND_PACKAGE_ARGS}) +endmacro (libfind_package) + +# CMake developers made the UsePkgConfig system deprecated in the same release (2.6) +# where they added pkg_check_modules. Consequently I need to support both in my scripts +# to avoid those deprecated warnings. Here's a helper that does just that. +# Works identically to pkg_check_modules, except that no checks are needed prior to use. +macro (libfind_pkg_check_modules PREFIX PKGNAME) + if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + include(UsePkgConfig) + pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) + else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) + find_package(PkgConfig) + if (PKG_CONFIG_FOUND) + pkg_check_modules(${PREFIX} ${PKGNAME}) + endif (PKG_CONFIG_FOUND) + endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) +endmacro (libfind_pkg_check_modules) + +# Do the final processing once the paths have been detected. +# If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain +# all the variables, each of which contain one include directory. +# Ditto for ${PREFIX}_PROCESS_LIBS and library files. +# Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. +# Also handles errors in case library detection was required, etc. +macro (libfind_process PREFIX) + # Skip processing if already processed during this run + if (NOT ${PREFIX}_FOUND) + # Start with the assumption that the library was found + set (${PREFIX}_FOUND TRUE) + + # Process all includes and set _FOUND to false if any are missing + foreach (i ${${PREFIX}_PROCESS_INCLUDES}) + if (${i}) + set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) + mark_as_advanced(${i}) + else (${i}) + set (${PREFIX}_FOUND FALSE) + endif (${i}) + endforeach (i) + + # Process all libraries and set _FOUND to false if any are missing + foreach (i ${${PREFIX}_PROCESS_LIBS}) + if (${i}) + set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) + mark_as_advanced(${i}) + else (${i}) + set (${PREFIX}_FOUND FALSE) + endif (${i}) + endforeach (i) + + # Print message and/or exit on fatal error + if (${PREFIX}_FOUND) + if (NOT ${PREFIX}_FIND_QUIETLY) + message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") + endif (NOT ${PREFIX}_FIND_QUIETLY) + else (${PREFIX}_FOUND) + if (${PREFIX}_FIND_REQUIRED) + foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) + message("${i}=${${i}}") + endforeach (i) + message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") + endif (${PREFIX}_FIND_REQUIRED) + endif (${PREFIX}_FOUND) + endif (NOT ${PREFIX}_FOUND) +endmacro (libfind_process) + +macro(libfind_library PREFIX basename) + set(TMP "") + if(MSVC80) + set(TMP -vc80) + endif(MSVC80) + if(MSVC90) + set(TMP -vc90) + endif(MSVC90) + set(${PREFIX}_LIBNAMES ${basename}${TMP}) + if(${ARGC} GREATER 2) + set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) + string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) + set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) + endif(${ARGC} GREATER 2) + find_library(${PREFIX}_LIBRARY + NAMES ${${PREFIX}_LIBNAMES} + PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} + ) +endmacro(libfind_library) \ No newline at end of file diff --git a/src/misc_utilities/CMakeLists.txt b/src/misc_utilities/CMakeLists.txt index 210fcfc..46d38ed 100644 --- a/src/misc_utilities/CMakeLists.txt +++ b/src/misc_utilities/CMakeLists.txt @@ -8,7 +8,7 @@ TARGET_LINK_LIBRARIES(sortstate openalpr-static support ${OpenCV_LIBS} - ${Tesseract_LIBS} + ${Tesseract_LIBRARIES} ) ADD_EXECUTABLE( classifychars EXCLUDE_FROM_ALL classifychars.cpp ) @@ -16,7 +16,7 @@ TARGET_LINK_LIBRARIES(classifychars openalpr-static support ${OpenCV_LIBS} - ${Tesseract_LIBS} + ${Tesseract_LIBRARIES} ) @@ -30,7 +30,7 @@ TARGET_LINK_LIBRARIES(benchmark support pthread ${OpenCV_LIBS} - ${Tesseract_LIBS} + ${Tesseract_LIBRARIES} ) diff --git a/src/openalpr/CMakeLists.txt b/src/openalpr/CMakeLists.txt index b5e2056..288c4a6 100644 --- a/src/openalpr/CMakeLists.txt +++ b/src/openalpr/CMakeLists.txt @@ -40,13 +40,12 @@ set_target_properties(openalpr PROPERTIES SOVERSION ${OPENALPR_MAJOR_VERSION}) TARGET_LINK_LIBRARIES(openalpr support ${OpenCV_LIBS} - ${Tesseract_LIBS} + ${Tesseract_LIBRARIES} ) install (FILES alpr.h DESTINATION include) install (TARGETS openalpr DESTINATION lib) -# Add definition for default runtime dir -#add_definitions(-DDEFAULT_RUNTIME_DIR="/usr/share/openalpr/runtime_data") +# Add definition for default config file add_definitions(-DDEFAULT_CONFIG_FILE="/etc/openalpr/openalpr.conf")