CMakeLists.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. # 指定CMake版本
  2. cmake_minimum_required(VERSION 3.5)
  3. #使能c++11
  4. set(CMAKE_CXX_STANDARD 11)
  5. # 项目信息
  6. project(Demo C CXX)
  7. # 设置为调试版本
  8. set(CMAKE_BUILD_TYPE Debug)
  9. # 设置可执行文件路径
  10. set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/source/bin/)
  11. # ---[ Options
  12. option(build_inference "build module inference" ON)
  13. option(build_decoder "build module decoder" ON)
  14. option(build_inifile "build module inifile" ON)
  15. option(build_dataType "build module dataType" ON)
  16. option(build_HttpClient "build module HttpClient" ON)
  17. option(build_md5 "build module md5" ON)
  18. option(build_userApp "build module userApp" ON)
  19. option(build_TCPClient "build module TCPClient" ON)
  20. option(build_recorder "build module recorder" ON)
  21. option(WITH_FFMPEG "with ffmpeg" ON)
  22. option(WITH_OPENCV "with opencv" ON)
  23. option(WITH_ZLMediaKit "with ZLMediaKit" OFF)
  24. set(ENABLE_MYSQL ON CACHE BOOL "enable mysql")
  25. # ---[ Google-gflags
  26. if(CMAKE_TOOLCHAIN_FILE)
  27. set(GFLAGS_LIBRARIES gflags)
  28. else()
  29. include("${PROJECT_SOURCE_DIR}/cmake/FindGFlags.cmake")
  30. endif()
  31. list(APPEND 3RDPARTY_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIRS})
  32. list(APPEND 3RDPARTY_LIBS ${GFLAGS_LIBRARIES})
  33. # ---[ Google-glog
  34. if(CMAKE_TOOLCHAIN_FILE)
  35. set(GLOG_LIBRARIES glog)
  36. else()
  37. include("${PROJECT_SOURCE_DIR}/cmake/FindGlog.cmake")
  38. endif()
  39. list(APPEND 3RDPARTY_INCLUDE_DIRS ${GLOG_INCLUDE_DIRS})
  40. list(APPEND 3RDPARTY_LIBS ${GLOG_LIBRARIES})
  41. list(APPEND 3RDPARTY_LIBS mpeg mov flv mk_api zltoolkit zlmediakit)
  42. ##OpenCV
  43. if(WITH_OPENCV)
  44. if(CMAKE_TOOLCHAIN_FILE)
  45. if(EXISTS ${PROJECT_SOURCE_DIR}/include/opencv)
  46. set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_features2d opencv_flann)
  47. if(EXISTS ${PROJECT_SOURCE_DIR}/include/opencv2/imgcodecs)
  48. list(APPEND OpenCV_LIBS opencv_imgcodecs)
  49. endif()
  50. if(EXISTS ${PROJECT_SOURCE_DIR}/include/opencv2/videoio)
  51. list(APPEND OpenCV_LIBS opencv_videoio)
  52. endif()
  53. message(STATUS "HAVE_OPENCV enabled")
  54. message(STATUS "opencv libraries: ${OpenCV_LIBS}")
  55. set(HAVE_OPENCV true)
  56. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_OPENCV")
  57. else()
  58. set (HAVE_OPENCV false)
  59. endif()
  60. else()
  61. set(OpenCV_FIND_QUIETLY true)
  62. #find_package(OpenCV REQUIRED) //this will include opencv_ts which result in crash on centos
  63. find_package(OpenCV OPTIONAL_COMPONENTS imgcodecs)
  64. find_package(OpenCV OPTIONAL_COMPONENTS videoio)
  65. set(optional_opencv_libs ${OpenCV_LIBS})
  66. find_package(OpenCV REQUIRED core imgproc highgui features2d)
  67. if(OpenCV_FOUND)
  68. if(imgcodecs_FOUND)
  69. list(APPEND OpenCV_LIBS optional_opencv_libs)
  70. endif()
  71. message(STATUS "HAVE_OPENCV enabled")
  72. message(STATUS "opencv libraries: ${OpenCV_LIBS}")
  73. set(HAVE_OPENCV true)
  74. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_OPENCV")
  75. else()
  76. set (HAVE_OPENCV false)
  77. endif()
  78. endif()
  79. else()
  80. set (HAVE_OPENCV false)
  81. endif()
  82. ##FFmpeg
  83. if(WITH_FFMPEG)
  84. if(CMAKE_TOOLCHAIN_FILE)
  85. if(EXISTS ${PROJECT_SOURCE_DIR}/include/libavcodec)
  86. set(FFMPEG_LIBRARIES avformat avcodec avutil swscale swresample)
  87. if (WITH_FFMPEG_AVDEVICE)
  88. list(APPEND FFMPEG_LIBRARIES avdevice)
  89. endif ()
  90. set(HAVE_FFMPEG true)
  91. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_FFMPEG")
  92. message(STATUS "HAVE_FFMPEG enabled")
  93. message(STATUS "ffmpeg libraries: ${FFMPEG_LIBRARIES}")
  94. else()
  95. set (HAVE_FFMPEG false)
  96. endif()
  97. else()
  98. set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
  99. find_package(FFmpeg REQUIRED)
  100. if (FFMPEG_FOUND)
  101. include_directories(${FFMPEG_INCLUDE_DIR})
  102. set(HAVE_FFMPEG true)
  103. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_FFMPEG")
  104. message(STATUS "HAVE_FFMPEG enabled")
  105. message(STATUS "ffmpeg include: ${FFMPEG_INCLUDE_DIR}")
  106. message(STATUS "ffmpeg libraries: ${FFMPEG_LIBRARIES}")
  107. else ()
  108. message(FATAL_ERROR "Can't find FFmpeg libs!")
  109. set (HAVE_FFMPEG false)
  110. endif ()
  111. endif()
  112. else()
  113. set (HAVE_FFMPEG false)
  114. endif()
  115. # -- ZLMediaKit
  116. if(WITH_ZLMediaKit)
  117. add_subdirectory(${PROJECT_SOURCE_DIR}/3rdparty)
  118. endif()
  119. #查找mysql是否安装
  120. find_package(MYSQL QUIET)
  121. if(MYSQL_FOUND AND ENABLE_MYSQL)
  122. message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
  123. include_directories(${MYSQL_INCLUDE_DIR})
  124. include_directories(${MYSQL_INCLUDE_DIR}/mysql)
  125. add_definitions(-DENABLE_MYSQL)
  126. list(APPEND 3RDPARTY_LIBS ${MYSQL_LIBRARIES})
  127. endif()
  128. #设置工程源码根目录
  129. set(ToolKit_Root ${PROJECT_SOURCE_DIR}/3rdparty/ZLMediaKit/3rdpart/ZLToolKit/src)
  130. set(MediaKit_Root ${PROJECT_SOURCE_DIR}/3rdparty/ZLMediaKit/src)
  131. set(MediaServer_Root ${PROJECT_SOURCE_DIR}/3rdparty/ZLMediaKit/3rdpart/media-server)
  132. # -- include
  133. include_directories(${PROJECT_SOURCE_DIR}/3rdparty/rapidjson/include/)
  134. include_directories(${PROJECT_SOURCE_DIR}/modules/inference/include/)
  135. include_directories(${PROJECT_SOURCE_DIR}/modules/decoder/include/)
  136. include_directories(${PROJECT_SOURCE_DIR}/modules/userApp/include/)
  137. include_directories(${PROJECT_SOURCE_DIR}/modules/md5/include/)
  138. include_directories(${PROJECT_SOURCE_DIR}/modules/inifile/include/)
  139. include_directories(${PROJECT_SOURCE_DIR}/modules/TCPClient/include/)
  140. include_directories(${PROJECT_SOURCE_DIR}/modules/dataType/include/)
  141. include_directories(${PROJECT_SOURCE_DIR}/modules/HttpClient/include/)
  142. include_directories(${PROJECT_SOURCE_DIR}/modules/recorder/include/)
  143. include_directories(${ToolKit_Root})
  144. include_directories(${MediaKit_Root})
  145. include_directories(${PROJECT_SOURCE_DIR}/3rdparty/ZLMediaKit)
  146. # -- include gstreamer
  147. include_directories(/usr/include/gstreamer-1.0)
  148. include_directories(/usr/include/glib-2.0/)
  149. include_directories(/usr/lib/aarch64-linux-gnu/glib-2.0/include)
  150. include_directories(/opt/nvidia/deepstream/deepstream-5.0/sources/includes/)
  151. include_directories(/usr/local/cuda-10.2/include/)
  152. # 寻找当前目录下所有源文件
  153. aux_source_directory(./source/src DIR_SRCS)
  154. # 添加编译参数
  155. add_compile_options(-Wall -std=c++11 -O2 -g -DPLATFORM_TEGRA)
  156. link_directories(${PROJECT_SOURCE_DIR}/lib)
  157. link_directories(/opt/nvidia/deepstream/deepstream-5.0/lib/)
  158. list(APPEND Source_LINKER_LIBS mov flv mk_api mpeg zlmediakit ZLToolKit dl ${3RDPARTY_LIBS} ${OpenCV_LIBS} ${FFMPEG_LIBRARIES} pthread)
  159. list(APPEND ALL_LINKER_LIBS gstreamer-1.0 gobject-2.0 glib-2.0 nvdsgst_meta nvds_meta nvdsgst_helper nvbufsurface m ${Source_LINKER_LIBS})
  160. add_subdirectory(${PROJECT_SOURCE_DIR}/modules)
  161. # 指定生成的目标
  162. add_executable(main ${DIR_SRCS})
  163. # 链接
  164. target_link_libraries(main ${ALL_LINKER_LIBS} modules)