CMakeLists.txt 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. cmake_minimum_required(VERSION 2.8.12)
  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. # ---[ easydk project
  9. project(easydk C CXX)
  10. set(EDK_VERSION_MAJOR 2)
  11. set(EDK_VERSION_MINOR 6)
  12. set(EDK_VERSION_PATCH 0)
  13. set(EDK_VERSION "${EDK_VERSION_MAJOR}.${EDK_VERSION_MINOR}.${EDK_VERSION_PATCH}")
  14. #######################################################################
  15. # -- Build Flags
  16. option(BUILD_TESTS "Build all of modules' unit-tests" OFF)
  17. option(BUILD_SAMPLES "Build samples" ON)
  18. option(CODE_COVERAGE_TEST "Build code coverage test" OFF)
  19. option(WITH_CODEC "Build easy codec" ON)
  20. option(WITH_INFER "Build easy infer" ON)
  21. option(WITH_TRACKER "Build easy tracker" ON)
  22. option(WITH_BANG "Build easy Bang" ON)
  23. option(ENABLE_KCF "Build with KCF track" OFF)
  24. option(WITH_INFER_SERVER "Build infer server" ON)
  25. option(WITH_TURBOJPEG "Build Turbo Jpeg" OFF)
  26. option(SANITIZE_MEMORY "Enable MemorySanitizer for sanitized targets." OFF)
  27. option(SANITIZE_ADDRESS "Enable AddressSanitizer for sanitized targets." OFF)
  28. option(SANITIZE_THREAD "Enable ThreadSanitizer for sanitized targets." OFF)
  29. option(SANITIZE_UNDEFINED "Enable UndefinedBehaviorSanitizer for sanitized targets." OFF)
  30. set(CMAKE_CXX_FLAGS "-fPIC -Wall -Werror -std=c++11 -D_REENTRANT")
  31. set(CMAKE_CXX_FLAGS_DEBUG "-g")
  32. set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3")
  33. set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed")
  34. if(CODE_COVERAGE_TEST)
  35. message(STATUS "Build with code coverage test")
  36. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
  37. endif()
  38. set(CMAKE_INSTALL_DEFAULT_PREFIX "${PROJECT_SOURCE_DIR}/dist")
  39. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  40. set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_DEFAULT_PREFIX}" CACHE PATH
  41. "Directory into which to install ${CMAKE_PROJECT_NAME} (default: ${CMAKE_INSTALL_DEFAULT_PREFIX})"
  42. FORCE)
  43. endif()
  44. message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
  45. if (NOT CMAKE_BUILD_TYPE)
  46. set(CMAKE_BUILD_TYPE Release)
  47. endif()
  48. message(STATUS "!!!!! BUILD ${CMAKE_BUILD_TYPE} !!!!!")
  49. #######################################################################
  50. set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${PROJECT_SOURCE_DIR}/cmake/sanitizer)
  51. find_package(Sanitizers)
  52. # disable KCF
  53. if (WITH_TRACKER AND ENABLE_KCF)
  54. message(WARNING "disable KCF since it's not supported on MLU220EDGE for now")
  55. set(ENABLE_KCF OFF)
  56. endif()
  57. find_package(MLU)
  58. # set runtime path
  59. set(CMAKE_BUILD_RPATH "$ORIGIN;${NEUWARE_HOME}/lib64;")
  60. set(CMAKE_INSTALL_RPATH "$ORIGIN;${CMAKE_INSTALL_PREFIX}/lib;${NEUWARE_HOME}/lib64;")
  61. # ------------------- Sources -----------------------
  62. configure_file(${PROJECT_SOURCE_DIR}/config.h.in
  63. ${PROJECT_SOURCE_DIR}/include/device/config.h)
  64. file(GLOB cxxutil_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/cxxutil/*.cpp)
  65. file(GLOB device_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/device/*.cpp)
  66. install(DIRECTORY include/cxxutil DESTINATION include)
  67. install(DIRECTORY include/device DESTINATION include)
  68. if(WITH_INFER)
  69. message(STATUS "Build with EasyInfer")
  70. file(GLOB infer_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/easyinfer/*.cpp)
  71. install(DIRECTORY include/easyinfer DESTINATION include)
  72. endif()
  73. if(WITH_CODEC)
  74. message(STATUS "Build with EasyCodec")
  75. file(GLOB codec_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/easycodec/*.cpp)
  76. install(DIRECTORY include/easycodec DESTINATION include)
  77. endif()
  78. if(WITH_TRACKER)
  79. message(STATUS "Build with EasyTrack")
  80. file(GLOB_RECURSE track_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/easytrack/*.cpp)
  81. if(ENABLE_KCF)
  82. set(KCF_LIBS "${CMAKE_CURRENT_SOURCE_DIR}/src/easytrack/kcf/libkcf_mlu270.a")
  83. list(APPEND EDK_DEFINITIONS "ENABLE_KCF")
  84. endif()
  85. install(DIRECTORY include/easytrack DESTINATION include)
  86. endif()
  87. if(WITH_BANG)
  88. message(STATUS "Build with EasyBang")
  89. if ((CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64) OR (CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64))
  90. file(GLOB_RECURSE resize_and_convert_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/easybang/resize_and_convert/kernel_${CMAKE_SYSTEM_PROCESSOR}.o ${CMAKE_CURRENT_SOURCE_DIR}/src/easybang/resize_and_convert/*.cpp)
  91. if (CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
  92. file(GLOB_RECURSE resize_srcs ${CMAKE_CURRENT_SOURCE_DIR}/src/easybang/resize/kernel_x86_64_mlu270.o ${CMAKE_CURRENT_SOURCE_DIR}/src/easybang/resize/*.cpp)
  93. endif()
  94. install(DIRECTORY include/easybang DESTINATION include)
  95. else()
  96. message(FATAL_ERROR "error system processor !!!")
  97. endif()
  98. endif()
  99. message(STATUS "@@@@@@@@@@@ Target : easydk")
  100. add_library(easydk SHARED
  101. ${cxxutil_srcs}
  102. ${device_srcs}
  103. ${infer_srcs}
  104. ${codec_srcs}
  105. ${resize_srcs}
  106. ${resize_and_convert_srcs}
  107. ${track_srcs})
  108. target_include_directories(easydk PRIVATE
  109. ${NEUWARE_INCLUDE_DIR}
  110. ${CMAKE_CURRENT_SOURCE_DIR}/include)
  111. target_link_libraries(easydk PUBLIC
  112. ${CNRT_LIBS}
  113. ${CNDRV_LIBS}
  114. ${KCF_LIBS})
  115. if(WITH_CODEC)
  116. target_link_libraries(easydk PUBLIC ${CNCODEC_LIBS})
  117. # turbojpeg and libyuv
  118. if(WITH_TURBOJPEG)
  119. message("------------------- Turbo-JPEG and libyuv -----------------------")
  120. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -fvisibility=hidden")
  121. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
  122. add_subdirectory(3rdparty/libjpeg-turbo)
  123. add_subdirectory(3rdparty/libyuv)
  124. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=default")
  125. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default")
  126. message("------------------- Turbo-JPEG and libyuv END -----------------------")
  127. list(APPEND EDK_DEFINITIONS "ENABLE_TURBOJPEG")
  128. target_include_directories(easydk PRIVATE "${PROJECT_SOURCE_DIR}/3rdparty/libyuv/include"
  129. "${PROJECT_SOURCE_DIR}/3rdparty/libjpeg-turbo")
  130. target_link_libraries(easydk PRIVATE turbojpeg-static yuv)
  131. endif()
  132. endif()
  133. # backward
  134. include(${PROJECT_SOURCE_DIR}/3rdparty/backward/BackwardConfig.cmake)
  135. target_include_directories(easydk PRIVATE ${BACKWARD_INCLUDE_DIRS})
  136. target_link_libraries(easydk PUBLIC ${BACKWARD_LIBRARIES})
  137. target_compile_definitions(easydk PRIVATE ${EDK_DEFINITIONS} ${BACKWARD_DEFINITIONS})
  138. set_target_properties(easydk PROPERTIES VERSION ${EDK_VERSION})
  139. set_target_properties(easydk PROPERTIES SOVERSION ${EDK_VERSION_MAJOR})
  140. install(TARGETS easydk LIBRARY DESTINATION lib)
  141. if (WITH_INFER_SERVER)
  142. add_subdirectory(infer_server)
  143. endif()
  144. if(BUILD_SAMPLES AND WITH_INFER AND WITH_CODEC AND WITH_TRACKER AND WITH_BANG)
  145. message(STATUS "---------------- Build samples -----------------")
  146. add_subdirectory(samples)
  147. endif()
  148. if(BUILD_TESTS)
  149. message(STATUS "----------------- Build tests ------------------")
  150. add_subdirectory(3rdparty/googletest)
  151. add_subdirectory(tests)
  152. endif()