cmake_minimum_required(VERSION 2.8.7) if(POLICY CMP0046) cmake_policy(SET CMP0046 NEW) endif() if(POLICY CMP0054) cmake_policy(SET CMP0054 NEW) endif() set(CNSTREAM_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..) include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) if(NOT COMPILER_SUPPORTS_CXX11) message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") endif() if(USE_libstdcpp) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++") message("-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)") endif() # compile flags set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_REENTRANT -fPIC -Wall -Werror") set(VERSION_HEAD_FILE ${CNSTREAM_ROOT_DIR}/framework/core/include/cnstream_version.hpp) execute_process(COMMAND awk /CNSTREAM_MAJOR_VERSION/ ${VERSION_HEAD_FILE} OUTPUT_VARIABLE VERSION_STR) string(REGEX MATCH "[0-9]+" MAJOR_VERSION ${VERSION_STR}) execute_process(COMMAND awk /CNSTREAM_MINOR_VERSION/ ${VERSION_HEAD_FILE} OUTPUT_VARIABLE VERSION_STR) string(REGEX MATCH "[0-9]+" MINOR_VERSION ${VERSION_STR}) execute_process(COMMAND awk /CNSTREAM_PATCH_VERSION/ ${VERSION_HEAD_FILE} OUTPUT_VARIABLE VERSION_STR) string(REGEX MATCH "[0-9]+" PATCH_VERSION ${VERSION_STR}) set(CNSTREAM_TARGET_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}") # ---[ Options option(build_display "build module display" ON) option(build_encode "build module encode" ON) option(build_inference "build module inference" ON) option(build_inference2 "build module inference2" ON) option(build_osd "build module osd" ON) option(build_rtsp_sink "build module rtsp sink" ON) option(build_source "build module source" ON) option(build_track "build module track" ON) option(build_kafka "build module kafka" ON) option(build_Base64 "build module build_Base64" ON) option(build_recorder "build module build_recorder" ON) option(build_udp "build module build_udp" ON) option(build_locus "build_locus" ON) option(build_InfineFilter "build_InfineFilter" ON) option(WITH_RTSP "with rtsp" ON) option(WITH_FFMPEG "with ffmpeg" ON) option(WITH_FFMPEG_AVDEVICE "with ffmpeg avdevice" OFF) option(WITH_FREETYPE "with freetype" OFF) if(build_tests) add_definitions(-DUNIT_TEST) endif() # ---[ 3rdparty set(3RDPARTY_LIBS "") set(DEPENDENCIES "") set(CMAKE_MODULE_PATH ${CNSTREAM_ROOT_DIR}/cmake) # ---[ neuware find_package(Neuware) include_directories(${NEUWARE_INCLUDE_DIR}) list(APPEND 3RDPARTY_LIBS ${CNRT_LIBS} ${CNCODEC_LIBS}) if (CNCODECV3_LIBS) add_definitions(-DENABLE_MLU300_CODEC) list(APPEND 3RDPARTY_LIBS ${CNCODECV3_LIBS}) endif() if (CNCV_LIBS AND build_encode) list(APPEND 3RDPARTY_LIBS ${CNCV_LIBS}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_CNCV") message(STATUS "CNCV libraries: ${CNCV_LIBS}") endif() include(${CNSTREAM_ROOT_DIR}/cmake/have_cnstream_target.cmake) # ---[ framework have_framework_target(${CNSTREAM_ROOT_DIR}) list(APPEND 3RDPARTY_LIBS cnstream_core) if(HAVE_FRAMEWORK_TARGET) list(APPEND DEPENDENCIES cnstream_core) endif() # ---[ easydk have_easydk_target(${CNSTREAM_ROOT_DIR}) list(APPEND 3RDPARTY_LIBS easydk cnis) if(HAVE_EASYDK_TARGET) list(APPEND DEPENDENCIES easydk cnis) endif() # ---[ rapidjson include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/rapidjson/include) # ---[ libyuv list(APPEND ADDITIONAL_MAKE_CLEAN_FILES_LIST "${CNSTREAM_ROOT_DIR}/3rdparty/libyuv") add_custom_target(cnstream_libyuv sh ${CNSTREAM_ROOT_DIR}/tools/build_libyuv.sh ${CMAKE_C_COMPILER} ${CMAKE_CXX_COMPILER}) list(APPEND DEPENDENCIES cnstream_libyuv) include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/libyuv/include) link_directories(${CNSTREAM_ROOT_DIR}/3rdparty/libyuv/lib) list(APPEND 3RDPARTY_LIBS ${CNSTREAM_ROOT_DIR}/3rdparty/libyuv/lib/libyuv.a) # ---[ opencv set(OpenCV_FIND_QUIETLY true) #find_package(OpenCV REQUIRED) //this will include opencv_ts which result in crash on centos find_package(OpenCV OPTIONAL_COMPONENTS imgcodecs) find_package(OpenCV OPTIONAL_COMPONENTS videoio) set(optional_opencv_libs ${OpenCV_LIBS}) find_package(OpenCV REQUIRED core imgproc highgui features2d) if(OpenCV_FOUND) if(imgcodecs_FOUND) list(APPEND OpenCV_LIBS optional_opencv_libs) endif() include_directories(${OpenCV_INCLUDE_DIRS}) list(APPEND 3RDPARTY_LIBS ${OpenCV_LIBS}) message(STATUS "opencv include: ${OpenCV_INCLUDE_DIRS}") message(STATUS "opencv libraries: ${OpenCV_LIBS}") else() message(FATAL_ERROR "opencv not found!") endif() # ---[ ffmpeg if(WITH_FFMPEG AND (build_source OR build_encode OR build_rtsp_sink)) find_package(FFmpeg REQUIRED) if (FFMPEG_FOUND) include_directories(${FFMPEG_INCLUDE_DIR}) list(APPEND 3RDPARTY_LIBS ${FFMPEG_LIBRARIES}) set(HAVE_FFMPEG true) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_FFMPEG") if (WITH_FFMPEG_AVDEVICE) add_definitions(-DHAVE_FFMPEG_AVDEVICE) endif () message(STATUS "ffmpeg include: ${FFMPEG_INCLUDE_DIR}") message(STATUS "ffmpeg libraries: ${FFMPEG_LIBRARIES}") else () message(FATAL_ERROR "ffmpeg not found!") endif () endif() # ---[ freetype if(WITH_FREETYPE AND build_osd) find_package(Freetype REQUIRED) if (FREETYPE_FOUND) include_directories(${FREETYPE_INCLUDE_DIR_ft2build}) list(APPEND 3RDPARTY_LIBS ${FREETYPE_LIBRARIES}) message(STATUS "freetype include: ${FREETYPE_INCLUDE_DIR_ft2build}") message(STATUS "freetype libraries: ${FREETYPE_LIBRARIES}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_FREETYPE") else (FREETYPE_FOUND) message(FATAL_ERROR "freetype not found!") endif (FREETYPE_FOUND) endif() # ---[ live555 if(WITH_RTSP AND (build_source OR build_rtsp_sink)) list(APPEND ADDITIONAL_MAKE_CLEAN_FILES_LIST "${CNSTREAM_ROOT_DIR}/3rdparty/live555") add_custom_target(live555 sh ${CNSTREAM_ROOT_DIR}/tools/build_live555.sh ${CMAKE_C_COMPILER} ${CMAKE_CXX_COMPILER}) list(APPEND DEPENDENCIES live555) include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/live555/include/BasicUsageEnvironment) include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/live555/include/groupsock) include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/live555/include/liveMedia) include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/live555/include/UsageEnvironment) set(Live555_LIBS ${CNSTREAM_ROOT_DIR}/3rdparty/live555/lib/libliveMedia.so ${CNSTREAM_ROOT_DIR}/3rdparty/live555/lib/libUsageEnvironment.so ${CNSTREAM_ROOT_DIR}/3rdparty/live555/lib/libBasicUsageEnvironment.so ${CNSTREAM_ROOT_DIR}/3rdparty/live555/lib/libgroupsock.so) list(APPEND 3RDPARTY_LIBS ${Live555_LIBS}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_LIVE555 -DNO_OPENSSL") endif() # ---[ sdl2 if(build_display) find_package(SDL2 REQUIRED sdl2) if(SDL2_FOUND) string(STRIP ${SDL2_LIBRARIES} SDL2_LIBRARIES) include_directories(${SDL2_INCLUDE_DIRS}) list(APPEND 3RDPARTY_LIBS ${SDL2_LIBRARIES}) message(STATUS "sdl2 include: ${SDL2_INCLUDE_DIRS}") message(STATUS "sdl2 libraries: ${SDL2_LIBRARIES}") else() message(FATAL_ERROR "sdl2 not found") endif() endif() # ---[ kafka if(build_kafka) find_package(LibRDKafka) if(LIBRDKAFKA_FOUND) include_directories(${LibRDKafka_INCLUDE_DIR}) list(APPEND 3RDPARTY_LIBS ${LibRDKafka_C_LIBRARIES}) message(STATUS "LibRDKafka include: ${LibRDKafka_INCLUDE_DIR}") message(STATUS "LibRDKafka libraries: ${LibRDKafka_C_LIBRARIES}") else() message(FATAL_ERROR "rdkafka not found!") endif() endif() set(module_list "") if(build_encode) list(APPEND module_list encode) include_directories(${PROJECT_SOURCE_DIR}/modules/encode/src) install(DIRECTORY encode/include/ DESTINATION include) endif() if(build_inference) list(APPEND module_list inference) install(DIRECTORY inference/include/ DESTINATION include) endif() if(build_inference2) list(APPEND module_list inference2) install(DIRECTORY inference2/include/ DESTINATION include) endif() if(build_osd) list(APPEND module_list osd) install(DIRECTORY osd/include/ DESTINATION include) endif() if(build_rtsp_sink) list(APPEND module_list rtsp_sink) install(DIRECTORY rtsp_sink/include/ DESTINATION include) endif() if(build_source) list(APPEND module_list source) install(DIRECTORY source/include/ DESTINATION include) endif() if(build_track) list(APPEND module_list track) install(DIRECTORY track/include/ DESTINATION include) endif() if(build_display) list(APPEND module_list display) install(DIRECTORY display/include/ DESTINATION include) endif() if(build_kafka) list(APPEND module_list kafka) install(DIRECTORY kafka/include/ DESTINATION include) endif() if(build_Base64) list(APPEND module_list Base64) install(DIRECTORY Base64/include/ DESTINATION include) endif() if(build_recorder) list(APPEND module_list recorder) install(DIRECTORY recorder/include/ DESTINATION include) endif() if(build_locus) list(APPEND module_list locus) install(DIRECTORY locus/include/ DESTINATION include) endif() if(build_udp) list(APPEND module_list udp) install(DIRECTORY udp/include/ DESTINATION include) endif() if(build_InfineFilter) list(APPEND module_list InfineFilter) install(DIRECTORY InfineFilter/include/ DESTINATION include) endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/util/include) file(GLOB srcs ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) foreach(module ${module_list}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/${module}/include) file(GLOB_RECURSE module_src ${CMAKE_CURRENT_SOURCE_DIR}/${module}/*.cpp) list(APPEND srcs ${module_src}) endforeach() set(LIBRARY_OUTPUT_PATH ${CNSTREAM_ROOT_DIR}/lib) add_library(cnstream_va SHARED ${srcs}) add_dependencies(cnstream_va ${DEPENDENCIES}) set_target_properties(cnstream_va PROPERTIES LINK_FLAGS_RELEASE -s) install(TARGETS cnstream_va LIBRARY DESTINATION lib) target_link_libraries(cnstream_va ${3RDPARTY_LIBS} rt dl pthread ZLToolKit) set_target_properties(cnstream_va PROPERTIES VERSION ${CNSTREAM_TARGET_VERSION}) # remove related files while make clean set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${ADDITIONAL_MAKE_CLEAN_FILES_LIST}) if(build_tests) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/) add_subdirectory(unitest) endif()