CMakeLists.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. cmake_minimum_required(VERSION 2.8.7)
  2. if(POLICY CMP0046)
  3. cmake_policy(SET CMP0046 NEW)
  4. endif()
  5. if(POLICY CMP0054)
  6. cmake_policy(SET CMP0054 NEW)
  7. endif()
  8. set(CNSTREAM_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
  9. include(CheckCXXCompilerFlag)
  10. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  11. if(NOT COMPILER_SUPPORTS_CXX11)
  12. message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  13. endif()
  14. if(USE_libstdcpp)
  15. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
  16. message("-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)")
  17. endif()
  18. # compile flags
  19. set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed")
  20. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
  21. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g")
  22. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_REENTRANT -fPIC -Wall -Werror")
  23. set(VERSION_HEAD_FILE ${CNSTREAM_ROOT_DIR}/framework/core/include/cnstream_version.hpp)
  24. execute_process(COMMAND awk /CNSTREAM_MAJOR_VERSION/ ${VERSION_HEAD_FILE} OUTPUT_VARIABLE VERSION_STR)
  25. string(REGEX MATCH "[0-9]+" MAJOR_VERSION ${VERSION_STR})
  26. execute_process(COMMAND awk /CNSTREAM_MINOR_VERSION/ ${VERSION_HEAD_FILE} OUTPUT_VARIABLE VERSION_STR)
  27. string(REGEX MATCH "[0-9]+" MINOR_VERSION ${VERSION_STR})
  28. execute_process(COMMAND awk /CNSTREAM_PATCH_VERSION/ ${VERSION_HEAD_FILE} OUTPUT_VARIABLE VERSION_STR)
  29. string(REGEX MATCH "[0-9]+" PATCH_VERSION ${VERSION_STR})
  30. set(CNSTREAM_TARGET_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")
  31. # ---[ Options
  32. option(build_display "build module display" ON)
  33. option(build_encode "build module encode" ON)
  34. option(build_inference "build module inference" ON)
  35. option(build_inference2 "build module inference2" ON)
  36. option(build_osd "build module osd" ON)
  37. option(build_rtsp_sink "build module rtsp sink" ON)
  38. option(build_source "build module source" ON)
  39. option(build_track "build module track" ON)
  40. option(build_kafka "build module kafka" ON)
  41. option(build_Base64 "build module build_Base64" ON)
  42. option(build_recorder "build module build_recorder" ON)
  43. option(build_udp "build module build_udp" ON)
  44. option(build_locus "build_locus" ON)
  45. option(build_InfineFilter "build_InfineFilter" ON)
  46. option(WITH_RTSP "with rtsp" ON)
  47. option(WITH_FFMPEG "with ffmpeg" ON)
  48. option(WITH_FFMPEG_AVDEVICE "with ffmpeg avdevice" OFF)
  49. option(WITH_FREETYPE "with freetype" OFF)
  50. if(build_tests)
  51. add_definitions(-DUNIT_TEST)
  52. endif()
  53. # ---[ 3rdparty
  54. set(3RDPARTY_LIBS "")
  55. set(DEPENDENCIES "")
  56. set(CMAKE_MODULE_PATH ${CNSTREAM_ROOT_DIR}/cmake)
  57. # ---[ neuware
  58. find_package(Neuware)
  59. include_directories(${NEUWARE_INCLUDE_DIR})
  60. list(APPEND 3RDPARTY_LIBS ${CNRT_LIBS} ${CNCODEC_LIBS})
  61. if (CNCODECV3_LIBS)
  62. add_definitions(-DENABLE_MLU300_CODEC)
  63. list(APPEND 3RDPARTY_LIBS ${CNCODECV3_LIBS})
  64. endif()
  65. if (CNCV_LIBS AND build_encode)
  66. list(APPEND 3RDPARTY_LIBS ${CNCV_LIBS})
  67. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_CNCV")
  68. message(STATUS "CNCV libraries: ${CNCV_LIBS}")
  69. endif()
  70. include(${CNSTREAM_ROOT_DIR}/cmake/have_cnstream_target.cmake)
  71. # ---[ framework
  72. have_framework_target(${CNSTREAM_ROOT_DIR})
  73. list(APPEND 3RDPARTY_LIBS cnstream_core)
  74. if(HAVE_FRAMEWORK_TARGET)
  75. list(APPEND DEPENDENCIES cnstream_core)
  76. endif()
  77. # ---[ easydk
  78. have_easydk_target(${CNSTREAM_ROOT_DIR})
  79. list(APPEND 3RDPARTY_LIBS easydk cnis)
  80. if(HAVE_EASYDK_TARGET)
  81. list(APPEND DEPENDENCIES easydk cnis)
  82. endif()
  83. # ---[ rapidjson
  84. include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/rapidjson/include)
  85. # ---[ libyuv
  86. list(APPEND ADDITIONAL_MAKE_CLEAN_FILES_LIST "${CNSTREAM_ROOT_DIR}/3rdparty/libyuv")
  87. add_custom_target(cnstream_libyuv sh ${CNSTREAM_ROOT_DIR}/tools/build_libyuv.sh ${CMAKE_C_COMPILER} ${CMAKE_CXX_COMPILER})
  88. list(APPEND DEPENDENCIES cnstream_libyuv)
  89. include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/libyuv/include)
  90. link_directories(${CNSTREAM_ROOT_DIR}/3rdparty/libyuv/lib)
  91. list(APPEND 3RDPARTY_LIBS ${CNSTREAM_ROOT_DIR}/3rdparty/libyuv/lib/libyuv.a)
  92. # ---[ opencv
  93. set(OpenCV_FIND_QUIETLY true)
  94. #find_package(OpenCV REQUIRED) //this will include opencv_ts which result in crash on centos
  95. find_package(OpenCV OPTIONAL_COMPONENTS imgcodecs)
  96. find_package(OpenCV OPTIONAL_COMPONENTS videoio)
  97. set(optional_opencv_libs ${OpenCV_LIBS})
  98. find_package(OpenCV REQUIRED core imgproc highgui features2d)
  99. if(OpenCV_FOUND)
  100. if(imgcodecs_FOUND)
  101. list(APPEND OpenCV_LIBS optional_opencv_libs)
  102. endif()
  103. include_directories(${OpenCV_INCLUDE_DIRS})
  104. list(APPEND 3RDPARTY_LIBS ${OpenCV_LIBS})
  105. message(STATUS "opencv include: ${OpenCV_INCLUDE_DIRS}")
  106. message(STATUS "opencv libraries: ${OpenCV_LIBS}")
  107. else()
  108. message(FATAL_ERROR "opencv not found!")
  109. endif()
  110. # ---[ ffmpeg
  111. if(WITH_FFMPEG AND (build_source OR build_encode OR build_rtsp_sink))
  112. find_package(FFmpeg REQUIRED)
  113. if (FFMPEG_FOUND)
  114. include_directories(${FFMPEG_INCLUDE_DIR})
  115. list(APPEND 3RDPARTY_LIBS ${FFMPEG_LIBRARIES})
  116. set(HAVE_FFMPEG true)
  117. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_FFMPEG")
  118. if (WITH_FFMPEG_AVDEVICE)
  119. add_definitions(-DHAVE_FFMPEG_AVDEVICE)
  120. endif ()
  121. message(STATUS "ffmpeg include: ${FFMPEG_INCLUDE_DIR}")
  122. message(STATUS "ffmpeg libraries: ${FFMPEG_LIBRARIES}")
  123. else ()
  124. message(FATAL_ERROR "ffmpeg not found!")
  125. endif ()
  126. endif()
  127. # ---[ freetype
  128. if(WITH_FREETYPE AND build_osd)
  129. find_package(Freetype REQUIRED)
  130. if (FREETYPE_FOUND)
  131. include_directories(${FREETYPE_INCLUDE_DIR_ft2build})
  132. list(APPEND 3RDPARTY_LIBS ${FREETYPE_LIBRARIES})
  133. message(STATUS "freetype include: ${FREETYPE_INCLUDE_DIR_ft2build}")
  134. message(STATUS "freetype libraries: ${FREETYPE_LIBRARIES}")
  135. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_FREETYPE")
  136. else (FREETYPE_FOUND)
  137. message(FATAL_ERROR "freetype not found!")
  138. endif (FREETYPE_FOUND)
  139. endif()
  140. # ---[ live555
  141. if(WITH_RTSP AND (build_source OR build_rtsp_sink))
  142. list(APPEND ADDITIONAL_MAKE_CLEAN_FILES_LIST "${CNSTREAM_ROOT_DIR}/3rdparty/live555")
  143. add_custom_target(live555 sh ${CNSTREAM_ROOT_DIR}/tools/build_live555.sh ${CMAKE_C_COMPILER} ${CMAKE_CXX_COMPILER})
  144. list(APPEND DEPENDENCIES live555)
  145. include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/live555/include/BasicUsageEnvironment)
  146. include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/live555/include/groupsock)
  147. include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/live555/include/liveMedia)
  148. include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/live555/include/UsageEnvironment)
  149. set(Live555_LIBS ${CNSTREAM_ROOT_DIR}/3rdparty/live555/lib/libliveMedia.so
  150. ${CNSTREAM_ROOT_DIR}/3rdparty/live555/lib/libUsageEnvironment.so
  151. ${CNSTREAM_ROOT_DIR}/3rdparty/live555/lib/libBasicUsageEnvironment.so
  152. ${CNSTREAM_ROOT_DIR}/3rdparty/live555/lib/libgroupsock.so)
  153. list(APPEND 3RDPARTY_LIBS ${Live555_LIBS})
  154. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_LIVE555 -DNO_OPENSSL")
  155. endif()
  156. # ---[ sdl2
  157. if(build_display)
  158. find_package(SDL2 REQUIRED sdl2)
  159. if(SDL2_FOUND)
  160. string(STRIP ${SDL2_LIBRARIES} SDL2_LIBRARIES)
  161. include_directories(${SDL2_INCLUDE_DIRS})
  162. list(APPEND 3RDPARTY_LIBS ${SDL2_LIBRARIES})
  163. message(STATUS "sdl2 include: ${SDL2_INCLUDE_DIRS}")
  164. message(STATUS "sdl2 libraries: ${SDL2_LIBRARIES}")
  165. else()
  166. message(FATAL_ERROR "sdl2 not found")
  167. endif()
  168. endif()
  169. # ---[ kafka
  170. if(build_kafka)
  171. find_package(LibRDKafka)
  172. if(LIBRDKAFKA_FOUND)
  173. include_directories(${LibRDKafka_INCLUDE_DIR})
  174. list(APPEND 3RDPARTY_LIBS ${LibRDKafka_C_LIBRARIES})
  175. message(STATUS "LibRDKafka include: ${LibRDKafka_INCLUDE_DIR}")
  176. message(STATUS "LibRDKafka libraries: ${LibRDKafka_C_LIBRARIES}")
  177. else()
  178. message(FATAL_ERROR "rdkafka not found!")
  179. endif()
  180. endif()
  181. set(module_list "")
  182. if(build_encode)
  183. list(APPEND module_list encode)
  184. include_directories(${PROJECT_SOURCE_DIR}/modules/encode/src)
  185. install(DIRECTORY encode/include/ DESTINATION include)
  186. endif()
  187. if(build_inference)
  188. list(APPEND module_list inference)
  189. install(DIRECTORY inference/include/ DESTINATION include)
  190. endif()
  191. if(build_inference2)
  192. list(APPEND module_list inference2)
  193. install(DIRECTORY inference2/include/ DESTINATION include)
  194. endif()
  195. if(build_osd)
  196. list(APPEND module_list osd)
  197. install(DIRECTORY osd/include/ DESTINATION include)
  198. endif()
  199. if(build_rtsp_sink)
  200. list(APPEND module_list rtsp_sink)
  201. install(DIRECTORY rtsp_sink/include/ DESTINATION include)
  202. endif()
  203. if(build_source)
  204. list(APPEND module_list source)
  205. install(DIRECTORY source/include/ DESTINATION include)
  206. endif()
  207. if(build_track)
  208. list(APPEND module_list track)
  209. install(DIRECTORY track/include/ DESTINATION include)
  210. endif()
  211. if(build_display)
  212. list(APPEND module_list display)
  213. install(DIRECTORY display/include/ DESTINATION include)
  214. endif()
  215. if(build_kafka)
  216. list(APPEND module_list kafka)
  217. install(DIRECTORY kafka/include/ DESTINATION include)
  218. endif()
  219. if(build_Base64)
  220. list(APPEND module_list Base64)
  221. install(DIRECTORY Base64/include/ DESTINATION include)
  222. endif()
  223. if(build_recorder)
  224. list(APPEND module_list recorder)
  225. install(DIRECTORY recorder/include/ DESTINATION include)
  226. endif()
  227. if(build_locus)
  228. list(APPEND module_list locus)
  229. install(DIRECTORY locus/include/ DESTINATION include)
  230. endif()
  231. if(build_udp)
  232. list(APPEND module_list udp)
  233. install(DIRECTORY udp/include/ DESTINATION include)
  234. endif()
  235. if(build_InfineFilter)
  236. list(APPEND module_list InfineFilter)
  237. install(DIRECTORY InfineFilter/include/ DESTINATION include)
  238. endif()
  239. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  240. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/util/include)
  241. file(GLOB srcs ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
  242. foreach(module ${module_list})
  243. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${module}/include)
  244. file(GLOB_RECURSE module_src ${CMAKE_CURRENT_SOURCE_DIR}/${module}/*.cpp)
  245. list(APPEND srcs ${module_src})
  246. endforeach()
  247. set(LIBRARY_OUTPUT_PATH ${CNSTREAM_ROOT_DIR}/lib)
  248. add_library(cnstream_va SHARED ${srcs})
  249. add_dependencies(cnstream_va ${DEPENDENCIES})
  250. set_target_properties(cnstream_va PROPERTIES LINK_FLAGS_RELEASE -s)
  251. install(TARGETS cnstream_va LIBRARY DESTINATION lib)
  252. target_link_libraries(cnstream_va ${3RDPARTY_LIBS} rt dl pthread ZLToolKit)
  253. set_target_properties(cnstream_va PROPERTIES VERSION ${CNSTREAM_TARGET_VERSION})
  254. # remove related files while make clean
  255. set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${ADDITIONAL_MAKE_CLEAN_FILES_LIST})
  256. if(build_tests)
  257. set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/)
  258. add_subdirectory(unitest)
  259. endif()