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

[Fix] Export mmdeploy only in monolithic build #1798

Merged
merged 2 commits into from
Mar 21, 2023
Merged
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
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