Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Remove find backend dependencies when build dynamic lib #1988

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endif ()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# options
option(MMDEPLOY_SHARED_LIBS "build shared libs" OFF)
option(MMDEPLOY_SHARED_LIBS "build shared libs" ON)
option(MMDEPLOY_BUILD_SDK "build MMDeploy SDK" OFF)
option(MMDEPLOY_DYNAMIC_BACKEND "dynamic load backend" OFF)
option(MMDEPLOY_BUILD_SDK_MONOLITHIC "build single lib for SDK API" ON)
Expand All @@ -41,14 +41,24 @@ set(MMDEPLOY_TARGET_BACKENDS "" CACHE STRING "target inference engines to suppor
set(MMDEPLOY_CODEBASES "all" CACHE STRING "select OpenMMLab codebases")

if ((NOT MMDEPLOY_BUILD_SDK_MONOLITHIC) AND MMDEPLOY_DYNAMIC_BACKEND)
message(WARNING
"dynamic backend only supported with MMDEPLOY_BUILD_SDK_MONOLITHIC=ON\n"
"implicit set MMDEPLOY_DYNAMIC_BACKEND=OFF")
set(MMDEPLOY_DYNAMIC_BACKEND OFF)
endif ()

if (MMDEPLOY_BUILD_SDK_MONOLITHIC AND (NOT MMDEPLOY_SHARED_LIBS))
message(WARNING
"monolithic lib only supported with MMDEPLOY_SHARED_LIBS=ON\n"
"implicit set MMDEPLOY_BUILD_SDK_MONOLITHIC=OFF")
set(MMDEPLOY_BUILD_SDK_MONOLITHIC OFF)
endif ()

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "choose 'Release' as default build type" FORCE)
endif ()

if (MMDEPLOY_SHARED_LIBS)
if (MMDEPLOY_SHARED_LIBS AND (NOT MMDEPLOY_BUILD_SDK_MONOLITHIC))
set(MMDEPLOY_LIB_TYPE SHARED)
else ()
set(MMDEPLOY_LIB_TYPE STATIC)
Expand Down Expand Up @@ -124,16 +134,15 @@ if (MMDEPLOY_BUILD_SDK)
set(SPDLOG_DEPENDENCY "find_package(spdlog QUIET)")
endif ()
# 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)
if (NOT MMDEPLOY_SHARED_LIBS)
if (NOT (MMDEPLOY_SHARED_LIBS OR MMDEPLOY_BUILD_SDK_MONOLITHIC))
mmdeploy_add_deps(pplnn BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS pplnn)
mmdeploy_add_deps(ncnn BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS ncnn)
mmdeploy_add_deps(trt BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS TENSORRT CUDNN)
mmdeploy_add_deps(ort BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS ONNXRUNTIME)
mmdeploy_add_deps(openvino BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS InferenceEngine)
mmdeploy_add_deps(snpe BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS snpe)
mmdeploy_add_deps(rknn BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS rknn)
endif ()
mmdeploy_add_deps(snpe BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS snpe)
mmdeploy_add_deps(rknn BACKENDS ${MMDEPLOY_TARGET_BACKENDS} DEPS rknn)

include(CMakePackageConfigHelpers)
# generate the config file that is includes the exports
configure_package_config_file(${CMAKE_SOURCE_DIR}/cmake/MMDeployConfig.cmake.in
Expand Down
1 change: 1 addition & 0 deletions cmake/MMDeployConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(MMDEPLOY_VERSION_MINOR @MMDEPLOY_VERSION_MINOR@)
set(MMDEPLOY_VERSION_PATCH @MMDEPLOY_VERSION_PATCH@)

if (NOT MMDEPLOY_BUILD_SHARED AND NOT MMDEPLOY_BUILD_SDK_MONOLITHIC)
find_package(OpenCV REQUIRED)
if ("cuda" IN_LIST MMDEPLOY_TARGET_DEVICES)
find_package(CUDA REQUIRED)
if(MSVC)
Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/codebase/mmdet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(mmdeploy_mmdet)
file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
mmdeploy_add_module(${PROJECT_NAME} "${SRCS}")
target_link_libraries(${PROJECT_NAME}
PRIVATE mmdeploy_opencv_utils)
PRIVATE mmdeploy_opencv_utils mmdeploy_operation)

add_library(mmdeploy::mmdet ALIAS ${PROJECT_NAME})

Expand Down
3 changes: 1 addition & 2 deletions csrc/mmdeploy/codebase/mmpose/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ mmdeploy_add_module(${PROJECT_NAME} ${MMPOSE_SRCS} ${POSE_TRACKER_SRCS})
target_link_libraries(${PROJECT_NAME} PRIVATE
mmdeploy::transform
mmdeploy_operation
mmdeploy_opencv_utils
${OpenCV_LIBS})
mmdeploy_opencv_utils)
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../apis/c)
Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/net/ort/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ include(${CMAKE_SOURCE_DIR}/cmake/modules/FindONNXRUNTIME.cmake)
mmdeploy_add_net(${PROJECT_NAME} ort_net.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${ONNXRUNTIME_DIR}/include)
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy_onnxruntime_ops_obj)
target_link_libraries(${PROJECT_NAME} PUBLIC onnxruntime)
target_link_libraries(${PROJECT_NAME} PRIVATE onnxruntime)
add_library(mmdeploy::ort_net ALIAS ${PROJECT_NAME})
2 changes: 1 addition & 1 deletion csrc/mmdeploy/net/trt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ target_include_directories(${PROJECT_NAME} PRIVATE
target_include_directories(${PROJECT_NAME} PRIVATE ${CUDNN_DIR}/include)
target_include_directories(${PROJECT_NAME} PRIVATE ${CUDA_TOOLKIT_ROOT_DIR}/include)
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy_tensorrt_ops_obj)
target_link_libraries(${PROJECT_NAME} PUBLIC ${TENSORRT_LIBS} cudnn cuda)
target_link_libraries(${PROJECT_NAME} PRIVATE ${TENSORRT_LIBS} cudnn cuda)

add_library(mmdeploy::trt_net ALIAS ${PROJECT_NAME})
2 changes: 1 addition & 1 deletion csrc/mmdeploy/utils/opencv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mmdeploy_add_library(${PROJECT_NAME} opencv_utils.cpp)

target_link_libraries(${PROJECT_NAME}
PRIVATE mmdeploy::core
PUBLIC ${OpenCV_LIBS})
PUBLIC $<BUILD_INTERFACE:${OpenCV_LIBS}>)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What benefits it can bring in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove opencv deps

image


target_include_directories(${PROJECT_NAME}
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)