@ -1,8 +1,16 @@
project ( ocr_system CXX C )
option ( WITH_MKL "Compile demo with MKL/OpenBlas support, default use MKL." ON )
option ( WITH_MKL "Compile demo with MKL/OpenBlas support, default use MKL." OFF )
option ( WITH_GPU "Compile demo with GPU/CPU, default use CPU." OFF )
option ( WITH_STATIC_LIB "Compile demo with static/shared library, default use static." ON )
option ( USE_TENSORRT "Compile demo with TensorRT." OFF )
SET ( PADDLE_LIB "" CACHE PATH "Location of libraries" )
SET ( OPENCV_DIR "" CACHE PATH "Location of libraries" )
SET ( CUDA_LIB "" CACHE PATH "Location of libraries" )
SET ( CUDNN_LIB "" CACHE PATH "Location of libraries" )
SET ( TENSORRT_DIR "" CACHE PATH "Compile demo with TensorRT" )
set ( DEMO_NAME "ocr_system" )
macro ( safe_set_static_flag )
@ -15,24 +23,60 @@ macro(safe_set_static_flag)
endforeach ( flag_var )
endmacro ( )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g -fpermissive" )
set ( CMAKE_STATIC_LIBRARY_PREFIX "" )
message ( "flags" ${ CMAKE_CXX_FLAGS } )
set ( CMAKE_CXX_FLAGS_RELEASE "-O3" )
if ( WITH_MKL )
ADD_DEFINITIONS ( -DUSE_MKL )
endif ( )
if ( NOT DEFINED PADDLE_LIB )
message ( FATAL_ERROR "please set PADDLE_LIB with -DPADDLE_LIB=/path/paddle/lib" )
endif ( )
if ( NOT DEFINED DEMO_NAME )
message ( FATAL_ERROR "please set DEMO_NAME with -DDEMO_NAME=demo_name" )
if ( NOT DEFINED OPENCV_DIR )
message ( FATAL_ERROR "please set OPENCV_DIR with -DOPENCV_DIR=/path/opencv" )
endif ( )
set ( OPENCV_DIR ${ OPENCV_DIR } )
find_package ( OpenCV REQUIRED PATHS ${ OPENCV_DIR } /share/OpenCV NO_DEFAULT_PATH )
if ( WIN32 )
include_directories ( "${PADDLE_LIB}/paddle/fluid/inference" )
include_directories ( "${PADDLE_LIB}/paddle/include" )
link_directories ( "${PADDLE_LIB}/paddle/fluid/inference" )
find_package ( OpenCV REQUIRED PATHS ${ OPENCV_DIR } /build/ NO_DEFAULT_PATH )
else ( )
find_package ( OpenCV REQUIRED PATHS ${ OPENCV_DIR } /share/OpenCV NO_DEFAULT_PATH )
include_directories ( "${PADDLE_LIB}/paddle/include" )
link_directories ( "${PADDLE_LIB}/paddle/lib" )
endif ( )
include_directories ( ${ OpenCV_INCLUDE_DIRS } )
include_directories ( "${PADDLE_LIB}/paddle/include" )
if ( WIN32 )
add_definitions ( "/DGOOGLE_GLOG_DLL_DECL=" )
set ( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /bigobj /MTd" )
set ( CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /bigobj /MT" )
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj /MTd" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /bigobj /MT" )
if ( WITH_STATIC_LIB )
safe_set_static_flag ( )
add_definitions ( -DSTATIC_LIB )
endif ( )
else ( )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -o3 -std=c++11" )
set ( CMAKE_STATIC_LIBRARY_PREFIX "" )
endif ( )
message ( "flags" ${ CMAKE_CXX_FLAGS } )
if ( WITH_GPU )
if ( NOT DEFINED CUDA_LIB OR ${ CUDA_LIB } STREQUAL "" )
message ( FATAL_ERROR "please set CUDA_LIB with -DCUDA_LIB=/path/cuda-8.0/lib64" )
endif ( )
if ( NOT WIN32 )
if ( NOT DEFINED CUDNN_LIB )
message ( FATAL_ERROR "please set CUDNN_LIB with -DCUDNN_LIB=/path/cudnn_v7.4/cuda/lib64" )
endif ( )
endif ( NOT WIN32 )
endif ( )
include_directories ( "${PADDLE_LIB}/third_party/install/protobuf/include" )
include_directories ( "${PADDLE_LIB}/third_party/install/glog/include" )
include_directories ( "${PADDLE_LIB}/third_party/install/gflags/include" )
@ -43,10 +87,12 @@ include_directories("${PADDLE_LIB}/third_party/eigen3")
include_directories ( "${CMAKE_SOURCE_DIR}/" )
if ( USE_TENSORRT AND WITH_GPU )
include_directories ( "${TENSORRT_ROOT}/include" )
link_directories ( "${TENSORRT_ROOT}/lib" )
endif ( )
if ( NOT WIN32 )
if ( WITH_TENSORRT AND WITH_GPU )
include_directories ( "${TENSORRT_DIR}/include" )
link_directories ( "${TENSORRT_DIR}/lib" )
endif ( )
endif ( NOT WIN32 )
link_directories ( "${PADDLE_LIB}/third_party/install/zlib/lib" )
@ -57,17 +103,24 @@ link_directories("${PADDLE_LIB}/third_party/install/xxhash/lib")
link_directories ( "${PADDLE_LIB}/paddle/lib" )
AUX_SOURCE_DIRECTORY ( ./src SRCS )
add_executable ( ${ DEMO_NAME } ${ SRCS } )
if ( WITH_MKL )
include_directories ( "${PADDLE_LIB}/third_party/install/mklml/include" )
set ( MATH_LIB ${ PADDLE_LIB } /third_party/install/mklml/lib/libmklml_intel ${ CMAKE_SHARED_LIBRARY_SUFFIX }
$ { P A D D L E _ L I B } / t h i r d _ p a r t y / i n s t a l l / m k l m l / l i b / l i b i o m p 5 $ { C M A K E _ S H A R E D _ L I B R A R Y _ S U F F I X } )
if ( WIN32 )
set ( MATH_LIB ${ PADDLE_LIB } /third_party/install/mklml/lib/mklml.lib
$ { P A D D L E _ L I B } / t h i r d _ p a r t y / i n s t a l l / m k l m l / l i b / l i b i o m p 5 m d . l i b )
else ( )
set ( MATH_LIB ${ PADDLE_LIB } /third_party/install/mklml/lib/libmklml_intel ${ CMAKE_SHARED_LIBRARY_SUFFIX }
$ { P A D D L E _ L I B } / t h i r d _ p a r t y / i n s t a l l / m k l m l / l i b / l i b i o m p 5 $ { C M A K E _ S H A R E D _ L I B R A R Y _ S U F F I X } )
execute_process ( COMMAND cp -r ${ PADDLE_LIB } /third_party/install/mklml/lib/libmklml_intel ${ CMAKE_SHARED_LIBRARY_SUFFIX } /usr/lib )
endif ( )
set ( MKLDNN_PATH "${PADDLE_LIB}/third_party/install/mkldnn" )
if ( EXISTS ${ MKLDNN_PATH } )
include_directories ( "${MKLDNN_PATH}/include" )
set ( MKLDNN_LIB ${ MKLDNN_PATH } /lib/libmkldnn.so.0 )
if ( WIN32 )
set ( MKLDNN_LIB ${ MKLDNN_PATH } /lib/mkldnn.lib )
else ( )
set ( MKLDNN_LIB ${ MKLDNN_PATH } /lib/libmkldnn.so.0 )
endif ( )
endif ( )
else ( )
set ( MATH_LIB ${ PADDLE_LIB } /third_party/install/openblas/lib/libopenblas ${ CMAKE_STATIC_LIBRARY_SUFFIX } )
@ -82,24 +135,66 @@ else()
$ { P A D D L E _ L I B } / p a d d l e / l i b / l i b p a d d l e _ f l u i d $ { C M A K E _ S H A R E D _ L I B R A R Y _ S U F F I X } )
endif ( )
set ( EXTERNAL_LIB "-lrt -ldl -lpthread -lm" )
if ( NOT WIN32 )
set ( DEPS ${ DEPS }
$ { M A T H _ L I B } $ { M K L D N N _ L I B }
g l o g g f l a g s p r o t o b u f z x x h a s h
)
if ( EXISTS "${PADDLE_LIB}/third_party/install/snappystream/lib" )
set ( DEPS ${ DEPS } snappystream )
endif ( )
if ( EXISTS "${PADDLE_LIB}/third_party/install/snappy/lib" )
set ( DEPS ${ DEPS } snappy )
endif ( )
else ( )
set ( DEPS ${ DEPS }
$ { M A T H _ L I B } $ { M K L D N N _ L I B }
g l o g g f l a g s _ s t a t i c l i b p r o t o b u f x x h a s h )
set ( DEPS ${ DEPS } libcmt shlwapi )
if ( EXISTS "${PADDLE_LIB}/third_party/install/snappy/lib" )
set ( DEPS ${ DEPS } snappy )
endif ( )
if ( EXISTS "${PADDLE_LIB}/third_party/install/snappystream/lib" )
set ( DEPS ${ DEPS } snappystream )
endif ( )
endif ( NOT WIN32 )
set ( DEPS ${ DEPS }
$ { M A T H _ L I B } $ { M K L D N N _ L I B }
g l o g g f l a g s p r o t o b u f z x x h a s h
$ { E X T E R N A L _ L I B } $ { O p e n C V _ L I B S } )
if ( WITH_GPU )
if ( USE_TENSORRT )
set ( DEPS ${ DEPS }
$ { T E N S O R R T _ R O O T } / l i b / l i b n v i n f e r $ { C M A K E _ S H A R E D _ L I B R A R Y _ S U F F I X } )
set ( DEPS ${ DEPS }
$ { T E N S O R R T _ R O O T } / l i b / l i b n v i n f e r _ p l u g i n $ { C M A K E _ S H A R E D _ L I B R A R Y _ S U F F I X } )
if ( NOT WIN32 )
if ( WITH_TENSORRT )
set ( DEPS ${ DEPS } ${ TENSORRT_DIR } /lib/libnvinfer ${ CMAKE_SHARED_LIBRARY_SUFFIX } )
set ( DEPS ${ DEPS } ${ TENSORRT_DIR } /lib/libnvinfer_plugin ${ CMAKE_SHARED_LIBRARY_SUFFIX } )
endif ( )
set ( DEPS ${ DEPS } ${ CUDA_LIB } /libcudart ${ CMAKE_SHARED_LIBRARY_SUFFIX } )
set ( DEPS ${ DEPS } ${ CUDNN_LIB } /libcudnn ${ CMAKE_SHARED_LIBRARY_SUFFIX } )
else ( )
set ( DEPS ${ DEPS } ${ CUDA_LIB } /cudart ${ CMAKE_STATIC_LIBRARY_SUFFIX } )
set ( DEPS ${ DEPS } ${ CUDA_LIB } /cublas ${ CMAKE_STATIC_LIBRARY_SUFFIX } )
set ( DEPS ${ DEPS } ${ CUDNN_LIB } /cudnn ${ CMAKE_STATIC_LIBRARY_SUFFIX } )
endif ( )
set ( DEPS ${ DEPS } ${ CUDA_LIB } /libcudart ${ CMAKE_SHARED_LIBRARY_SUFFIX } )
set ( DEPS ${ DEPS } ${ CUDA_LIB } /libcudart ${ CMAKE_SHARED_LIBRARY_SUFFIX } )
set ( DEPS ${ DEPS } ${ CUDA_LIB } /libcublas ${ CMAKE_SHARED_LIBRARY_SUFFIX } )
set ( DEPS ${ DEPS } ${ CUDNN_LIB } /libcudnn ${ CMAKE_SHARED_LIBRARY_SUFFIX } )
endif ( )
if ( NOT WIN32 )
set ( EXTERNAL_LIB "-ldl -lrt -lgomp -lz -lm -lpthread" )
set ( DEPS ${ DEPS } ${ EXTERNAL_LIB } )
endif ( )
set ( DEPS ${ DEPS } ${ OpenCV_LIBS } )
AUX_SOURCE_DIRECTORY ( ./src SRCS )
add_executable ( ${ DEMO_NAME } ${ SRCS } )
target_link_libraries ( ${ DEMO_NAME } ${ DEPS } )
if ( WIN32 AND WITH_MKL )
add_custom_command ( TARGET ${ DEMO_NAME } POST_BUILD
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t $ { P A D D L E _ L I B } / t h i r d _ p a r t y / i n s t a l l / m k l m l / l i b / m k l m l . d l l . / m k l m l . d l l
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t $ { P A D D L E _ L I B } / t h i r d _ p a r t y / i n s t a l l / m k l m l / l i b / l i b i o m p 5 m d . d l l . / l i b i o m p 5 m d . d l l
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t $ { P A D D L E _ L I B } / t h i r d _ p a r t y / i n s t a l l / m k l d n n / l i b / m k l d n n . d l l . / m k l d n n . d l l
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t $ { P A D D L E _ L I B } / t h i r d _ p a r t y / i n s t a l l / m k l m l / l i b / m k l m l . d l l . / r e l e a s e / m k l m l . d l l
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t $ { P A D D L E _ L I B } / t h i r d _ p a r t y / i n s t a l l / m k l m l / l i b / l i b i o m p 5 m d . d l l . / r e l e a s e / l i b i o m p 5 m d . d l l
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t $ { P A D D L E _ L I B } / t h i r d _ p a r t y / i n s t a l l / m k l d n n / l i b / m k l d n n . d l l . / r e l e a s e / m k l d n n . d l l
)
endif ( )