CMakeLists.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. # compile flags
  10. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
  11. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g")
  12. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_REENTRANT -fPIC -Wno-deprecated-declarations -Wall -Werror")
  13. set(CMAKE_MODULE_PATH ${CNSTREAM_ROOT_DIR}/cmake)
  14. # ---[ neuware
  15. find_package(Neuware)
  16. include_directories(${NEUWARE_INCLUDE_DIR})
  17. # ---[ pybind11
  18. set(PYBIND11_PYTHON_VERSION 3.5)
  19. add_subdirectory(${CNSTREAM_ROOT_DIR}/3rdparty/pybind11 ${CMAKE_CURRENT_BINARY_DIR}/pybind11)
  20. # ---[ rapidjson
  21. include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/rapidjson/include)
  22. # ---[ opencv
  23. set(OpenCV_FIND_QUIETLY true)
  24. #find_package(OpenCV REQUIRED) //this will include opencv_ts which result in crash on centos
  25. find_package(OpenCV REQUIRED core imgproc highgui features2d)
  26. if(OpenCV_FOUND)
  27. include_directories(${OpenCV_INCLUDE_DIRS})
  28. message(STATUS "opencv include: ${OpenCV_INCLUDE_DIRS}")
  29. message(STATUS "opencv libraries: ${OpenCV_LIBS}")
  30. else()
  31. message(FATAL_ERROR "opencv not found!")
  32. endif()
  33. set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib/)
  34. include_directories(${CNSTREAM_ROOT_DIR}/modules)
  35. include_directories(${CNSTREAM_ROOT_DIR}/framework/core/include)
  36. include_directories(${CNSTREAM_ROOT_DIR}/samples/common)
  37. include_directories(${CNSTREAM_ROOT_DIR}/modules/core/include)
  38. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  39. list(APPEND module_list source inference inference2 util)
  40. foreach(module ${module_list})
  41. include_directories(${CNSTREAM_ROOT_DIR}/modules/${module}/include)
  42. endforeach()
  43. aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/ cnstream_pyapi_srcs)
  44. aux_source_directory(${CNSTREAM_ROOT_DIR}/samples/common/ sample_common_srcs)
  45. aux_source_directory(${CNSTREAM_ROOT_DIR}/samples/common/preprocess postprocess_srcs)
  46. aux_source_directory(${CNSTREAM_ROOT_DIR}/samples/common/postprocess preprocess_srcs)
  47. include_directories(${CNSTREAM_ROOT_DIR}/3rdparty/pybind11/include)
  48. include(${CNSTREAM_ROOT_DIR}/cmake/have_cnstream_target.cmake)
  49. have_framework_target(${CNSTREAM_ROOT_DIR})
  50. have_easydk_target(${CNSTREAM_ROOT_DIR})
  51. have_modules_target(${CNSTREAM_ROOT_DIR})
  52. have_modules_contrib_target(${CNSTREAM_ROOT_DIR})
  53. pybind11_add_module(cnstream SHARED ${cnstream_pyapi_srcs} ${preprocess_srcs} ${postprocess_srcs} ${sample_common_srcs})
  54. find_package(PythonLibs REQUIRED)
  55. include_directories(${PYTHON_INCLUDE_DIR})
  56. # message(${PYTHON_INCLUDE_DIR})
  57. # message(${PYTHON_LIBRARY})
  58. if(HAVE_FRAMEWORK_TARGET)
  59. add_dependencies(cnstream cnstream_core)
  60. endif()
  61. if(HAVE_EASYDK_TARGET)
  62. add_dependencies(cnstream easydk cnis)
  63. endif()
  64. if(HAVE_MODULES_TARGET)
  65. add_dependencies(cnstream cnstream_va)
  66. endif()
  67. if(HAVE_MODULES_CONTRIB_TARGET)
  68. add_dependencies(cnstream cnstream_contrib)
  69. endif()
  70. target_link_libraries(cnstream PRIVATE cnstream_va cnstream_core ${OpenCV_LIBS})
  71. if(HAVE_MODULES_CONTRIB)
  72. set(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed")
  73. target_link_libraries(cnstream PRIVATE cnstream_contrib)
  74. endif()
  75. if(build_tests)
  76. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
  77. aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/test cnstream_pyapi_cpptest_srcs)
  78. pybind11_add_module(cnstream_cpptest MODULE ${cnstream_pyapi_cpptest_srcs})
  79. add_dependencies(cnstream_cpptest cnstream)
  80. target_link_libraries(cnstream_cpptest PRIVATE cnstream)
  81. endif()