Skip to content

Commit 739e6b7

Browse files
lzhangzzirexyc
authored andcommitted
[Fix] Export mmdeploy only in monolithic build (#1798)
* export only `mmdeploy` in monolithic build * export dynamic backends
1 parent c96967f commit 739e6b7

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ include(cmake/MMDeploy.cmake)
9999
add_subdirectory(csrc/mmdeploy)
100100

101101
if (MMDEPLOY_BUILD_SDK)
102-
install(TARGETS MMDeployStaticModules
103-
MMDeployDynamicModules
104-
MMDeployLibs
105-
EXPORT MMDeployTargets)
102+
if (NOT MMDEPLOY_BUILD_SDK_MONOLITHIC)
103+
install(TARGETS MMDeployStaticModules
104+
MMDeployDynamicModules
105+
MMDeployLibs
106+
EXPORT MMDeployTargets)
107+
endif ()
106108

107109
if (MMDEPLOY_BUILD_TEST)
108110
add_subdirectory(tests/test_csrc)

cmake/MMDeploy.cmake

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) OpenMMLab. All rights reserved.
22

3-
function (mmdeploy_export NAME)
3+
function (mmdeploy_export_impl NAME)
44
set(_LIB_DIR lib)
55
if (MSVC)
66
set(_LIB_DIR bin)
@@ -15,13 +15,22 @@ endfunction ()
1515
macro(mmdeploy_add_net NAME)
1616
if (MMDEPLOY_DYNAMIC_BACKEND)
1717
mmdeploy_add_library(${NAME} SHARED ${ARGN})
18+
# DYNAMIC_BACKEND implies BUILD_SDK_MONOLITHIC
19+
mmdeploy_export_impl(${NAME})
1820
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy)
1921
set(BACKEND_LIB_NAMES ${BACKEND_LIB_NAMES} ${PROJECT_NAME} PARENT_SCOPE)
2022
else ()
2123
mmdeploy_add_module(${NAME} ${ARGN})
2224
endif ()
2325
endmacro()
2426

27+
function (mmdeploy_export NAME)
28+
if (NOT MMDEPLOY_BUILD_SDK_MONOLITHIC)
29+
mmdeploy_export_impl(${NAME})
30+
endif ()
31+
endfunction ()
32+
33+
2534
function (mmdeploy_add_library NAME)
2635
# EXCLUDE: exclude from registering & exporting
2736
cmake_parse_arguments(_MMDEPLOY "EXCLUDE" "" "" ${ARGN})

csrc/mmdeploy/apis/c/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ if (MMDEPLOY_BUILD_SDK_CSHARP_API OR MMDEPLOY_BUILD_SDK_MONOLITHIC)
8989
INSTALL_RPATH "\$ORIGIN"
9090
BUILD_RPATH "\$ORIGIN")
9191
endif ()
92-
mmdeploy_export(mmdeploy)
92+
mmdeploy_export_impl(mmdeploy)
9393
endif ()

csrc/mmdeploy/apis/cxx/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if (TARGET mmdeploy)
3434
else ()
3535
target_link_libraries(${PROJECT_NAME} INTERFACE mmdeploy::core)
3636
endif ()
37-
mmdeploy_export(${PROJECT_NAME})
37+
mmdeploy_export_impl(${PROJECT_NAME})
3838
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/common.hpp
3939
DESTINATION include/mmdeploy)
4040
install(DIRECTORY ${CMAKE_SOURCE_DIR}/demo/csrc/ DESTINATION example/cpp

demo/csrc/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ if (NOT (${CMAKE_PROJECT_NAME} STREQUAL "MMDeploy"))
77
endif ()
88

99

10-
function(add_example dep folder name)
11-
if (NOT dep OR TARGET mmdeploy_${dep})
10+
function(add_example task folder name)
11+
if ((NOT task) OR (task IN_LIST MMDEPLOY_TASKS))
1212
# Search for c/cpp sources
1313
file(GLOB _SRCS ${folder}/${name}.c*)
1414
add_executable(${name} ${_SRCS})

0 commit comments

Comments
 (0)