Skip to content

Commit

Permalink
[Fix] Export mmdeploy only in monolithic build (open-mmlab#1798)
Browse files Browse the repository at this point in the history
* export only `mmdeploy` in monolithic build

* export dynamic backends
  • Loading branch information
lzhangzz authored and irexyc committed Mar 29, 2023
1 parent c96967f commit 739e6b7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ include(cmake/MMDeploy.cmake)
add_subdirectory(csrc/mmdeploy)

if (MMDEPLOY_BUILD_SDK)
install(TARGETS MMDeployStaticModules
MMDeployDynamicModules
MMDeployLibs
EXPORT MMDeployTargets)
if (NOT MMDEPLOY_BUILD_SDK_MONOLITHIC)
install(TARGETS MMDeployStaticModules
MMDeployDynamicModules
MMDeployLibs
EXPORT MMDeployTargets)
endif ()

if (MMDEPLOY_BUILD_TEST)
add_subdirectory(tests/test_csrc)
Expand Down
11 changes: 10 additions & 1 deletion cmake/MMDeploy.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) OpenMMLab. All rights reserved.

function (mmdeploy_export NAME)
function (mmdeploy_export_impl NAME)
set(_LIB_DIR lib)
if (MSVC)
set(_LIB_DIR bin)
Expand All @@ -15,13 +15,22 @@ endfunction ()
macro(mmdeploy_add_net NAME)
if (MMDEPLOY_DYNAMIC_BACKEND)
mmdeploy_add_library(${NAME} SHARED ${ARGN})
# DYNAMIC_BACKEND implies BUILD_SDK_MONOLITHIC
mmdeploy_export_impl(${NAME})
target_link_libraries(${PROJECT_NAME} PRIVATE mmdeploy)
set(BACKEND_LIB_NAMES ${BACKEND_LIB_NAMES} ${PROJECT_NAME} PARENT_SCOPE)
else ()
mmdeploy_add_module(${NAME} ${ARGN})
endif ()
endmacro()

function (mmdeploy_export NAME)
if (NOT MMDEPLOY_BUILD_SDK_MONOLITHIC)
mmdeploy_export_impl(${NAME})
endif ()
endfunction ()


function (mmdeploy_add_library NAME)
# EXCLUDE: exclude from registering & exporting
cmake_parse_arguments(_MMDEPLOY "EXCLUDE" "" "" ${ARGN})
Expand Down
2 changes: 1 addition & 1 deletion csrc/mmdeploy/apis/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ if (MMDEPLOY_BUILD_SDK_CSHARP_API OR MMDEPLOY_BUILD_SDK_MONOLITHIC)
INSTALL_RPATH "\$ORIGIN"
BUILD_RPATH "\$ORIGIN")
endif ()
mmdeploy_export(mmdeploy)
mmdeploy_export_impl(mmdeploy)
endif ()
2 changes: 1 addition & 1 deletion csrc/mmdeploy/apis/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if (TARGET mmdeploy)
else ()
target_link_libraries(${PROJECT_NAME} INTERFACE mmdeploy::core)
endif ()
mmdeploy_export(${PROJECT_NAME})
mmdeploy_export_impl(${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mmdeploy/common.hpp
DESTINATION include/mmdeploy)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/demo/csrc/ DESTINATION example/cpp
Expand Down
4 changes: 2 additions & 2 deletions demo/csrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ if (NOT (${CMAKE_PROJECT_NAME} STREQUAL "MMDeploy"))
endif ()


function(add_example dep folder name)
if (NOT dep OR TARGET mmdeploy_${dep})
function(add_example task folder name)
if ((NOT task) OR (task IN_LIST MMDEPLOY_TASKS))
# Search for c/cpp sources
file(GLOB _SRCS ${folder}/${name}.c*)
add_executable(${name} ${_SRCS})
Expand Down

0 comments on commit 739e6b7

Please sign in to comment.