Skip to content

Commit

Permalink
refactor cmake build (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
irexyc authored Mar 31, 2022
1 parent 06dd5c9 commit c404a0b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ if (MMDEPLOY_BUILD_SDK)
FILE MMDeployTargets.cmake
DESTINATION lib/cmake/MMDeploy)

# append backend deps
mmdeploy_add_deps(trt BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS TENSORRT CUDNN)
mmdeploy_add_deps(ort BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS ONNXRUNTIME)
mmdeploy_add_deps(ncnn BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS ncnn)
mmdeploy_add_deps(openvino BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS InferenceEngine)
mmdeploy_add_deps(pplnn BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS pplnn)

include(CMakePackageConfigHelpers)
# generate the config file that is includes the exports
configure_package_config_file(${CMAKE_SOURCE_DIR}/cmake/MMDeployConfig.cmake.in
Expand Down
11 changes: 11 additions & 0 deletions cmake/MMDeploy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,14 @@ function (mmdeploy_load_dynamic NAME)
-Wl,--as-needed)
endif ()
endfunction ()

macro(mmdeploy_add_deps backend)
set(multiValueArgs BACKENDS DEPS)
cmake_parse_arguments(INFO "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
set(has_backend OFF)
if (${backend} IN_LIST INFO_BACKENDS)
foreach(pkg IN LISTS INFO_DEPS)
set(${pkg}_DEPENDENCY "find_package(${pkg} REQUIRED)")
endforeach()
endif()
endmacro()
18 changes: 7 additions & 11 deletions cmake/MMDeployConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@ endif ()

set(MMDEPLOY_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/modules")
list(APPEND CMAKE_MODULE_PATH ${MMDEPLOY_MODULE_PATH})
if ("trt" IN_LIST MMDEPLOY_TARGET_BACKENDS)
find_package(CUDNN)
find_package(TENSORRT)
endif()
if ("ort" IN_LIST MMDEPLOY_TARGET_BACKENDS)
find_package(ONNXRUNTIME)
endif()
if ("ncnn" IN_LIST MMDEPLOY_TARGET_BACKENDS)
find_package(ncnn REQUIRED)
endif()
list(POP_BACK CMAKE_MODULE_PATH)
@TENSORRT_DEPENDENCY@
@CUDNN_DEPENDENCY@
@ONNXRUNTIME_DEPENDENCY@
@ncnn_DEPENDENCY@
@InferenceEngine_DEPENDENCY@
@pplnn_DEPENDENCY@
list(REMOVE_ITEM CMAKE_MODULE_PATH ${MMDEPLOY_MODULE_PATH})

find_package(spdlog REQUIRED)
find_package(OpenCV REQUIRED)
Expand Down

0 comments on commit c404a0b

Please sign in to comment.