CMakeLists.txt 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. include(CheckCXXCompilerFlag)
  9. CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
  10. if(NOT COMPILER_SUPPORTS_CXX11)
  11. message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
  12. endif()
  13. if(USE_libstdcpp)
  14. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
  15. message("-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)")
  16. endif()
  17. set(CNSTREAM_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../..)
  18. set(SOURCE_ROOT_DIR ${CNSTREAM_ROOT_DIR}/source)
  19. # compile flags
  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(CMAKE_MODULE_PATH ${CNSTREAM_ROOT_DIR}/cmake/sanitizers ${CNSTREAM_ROOT_DIR}/cmake)
  24. find_package(Sanitizers)
  25. # ---[ neuware
  26. find_package(Neuware)
  27. include_directories(${NEUWARE_INCLUDE_DIR})
  28. # ---[ rapidjson
  29. include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/rapidjson/include)
  30. # ---[ librdkafka
  31. if(build_kafka)
  32. find_package(LibRDKafka)
  33. if(LIBRDKAFKA_FOUND)
  34. include_directories(${LibRDKafka_INCLUDE_DIR})
  35. list(APPEND 3RDPARTY_LIBS ${LibRDKafka_C_LIBRARIES})
  36. message(STATUS "LibRDKafka include: ${LibRDKafka_INCLUDE_DIR}")
  37. message(STATUS "LibRDKafka libraries: ${LibRDKafka_C_LIBRARIES}")
  38. else()
  39. message(FATAL_ERROR "rdkafka not found!")
  40. endif()
  41. endif()
  42. # ---[ opencv
  43. set(OpenCV_FIND_QUIETLY true)
  44. #find_package(OpenCV REQUIRED) //this will include opencv_ts which result in crash on centos
  45. find_package(OpenCV REQUIRED core imgproc highgui features2d)
  46. if(OpenCV_FOUND)
  47. include_directories(${OpenCV_INCLUDE_DIRS})
  48. message(STATUS "opencv include: ${OpenCV_INCLUDE_DIRS}")
  49. message(STATUS "opencv libraries: ${OpenCV_LIBS}")
  50. else()
  51. message(FATAL_ERROR "opencv not found!")
  52. endif()
  53. # ---[ gflags
  54. include(${CNSTREAM_ROOT_DIR}/cmake/FindGFlags.cmake)
  55. include_directories(${GFLAGS_INCLUDE_DIRS})
  56. # ---[ modules include dirs
  57. include_directories(${CNSTREAM_ROOT_DIR}/modules)
  58. include_directories(${CNSTREAM_ROOT_DIR}/modules/util/include)
  59. include_directories(${CNSTREAM_ROOT_DIR}/modules/inference/include)
  60. include_directories(${CNSTREAM_ROOT_DIR}/modules/inference2/include)
  61. include_directories(${CNSTREAM_ROOT_DIR}/modules/osd/include)
  62. include_directories(${CNSTREAM_ROOT_DIR}/modules/source/include)
  63. include_directories(${CNSTREAM_ROOT_DIR}/modules/encode/include)
  64. include_directories(${CNSTREAM_ROOT_DIR}/modules/track/include)
  65. include_directories(${CNSTREAM_ROOT_DIR}/modules/kafka/include)
  66. include_directories(${CNSTREAM_ROOT_DIR}/modules/Base64/include)
  67. if(build_display)
  68. include_directories(${CNSTREAM_ROOT_DIR}/modules/display/include)
  69. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_DISPLAY")
  70. message(STATUS "Samples build with display module.")
  71. endif()
  72. include_directories(${CNSTREAM_ROOT_DIR}/modules/rtsp_sink/include)
  73. # ---[ current include dirs
  74. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  75. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common)
  76. # ---[ sources
  77. aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} srcs)
  78. aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../common common_srcs)
  79. aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../common/preprocess preprocess_srcs)
  80. aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../common/postprocess postprocess_srcs)
  81. aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../common/obj_filter obj_filter_srcs)
  82. aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../common/cns_openpose cns_openpose_srcs)
  83. if(build_kafka)
  84. aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/../common/kafka_handler kafka_handler_srcs)
  85. endif()
  86. # ---[ dependencies
  87. set(SAMPLES_DEPENDENCIES "")
  88. include(${CNSTREAM_ROOT_DIR}/cmake/have_cnstream_target.cmake)
  89. have_framework_target(${CNSTREAM_ROOT_DIR})
  90. have_easydk_target(${CNSTREAM_ROOT_DIR})
  91. have_modules_target(${CNSTREAM_ROOT_DIR})
  92. have_modules_contrib_target(${CNSTREAM_ROOT_DIR})
  93. if(HAVE_FRAMEWORK_TARGET)
  94. list(APPEND SAMPLES_DEPENDENCIES cnstream_core)
  95. endif()
  96. if(HAVE_EASYDK_TARGET)
  97. list(APPEND SAMPLES_DEPENDENCIES easydk cnis)
  98. endif()
  99. if(HAVE_MODULES_TARGET)
  100. list(APPEND SAMPLES_DEPENDENCIES cnstream_va)
  101. endif()
  102. if(HAVE_MODULES_CONTRIB_TARGET)
  103. list(APPEND SAMPLES_DEPENDENCIES cnstream_contrib)
  104. endif()
  105. # ---[ add targets
  106. set(EXECUTABLE_OUTPUT_PATH ${SOURCE_ROOT_DIR}/bin)
  107. add_executable(main ${srcs} ${common_srcs} ${preprocess_srcs} ${postprocess_srcs} ${obj_filter_srcs} ${cns_openpose_srcs} ${kafka_handler_srcs})
  108. add_sanitizers(main)
  109. if(NOT "${SAMPLES_DEPENDENCIES} " STREQUAL " ")
  110. add_dependencies(main ${SAMPLES_DEPENDENCIES})
  111. endif()
  112. target_link_libraries(main cnstream_va cnstream_core easydk cnis ${OpenCV_LIBS} ${GFLAGS_LIBRARIES} pthread dl)
  113. if(HAVE_MODULES_CONTRIB)
  114. set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed")
  115. target_link_libraries(main cnstream_contrib)
  116. endif()