diff --git a/lite/api/CMakeLists.txt b/lite/api/CMakeLists.txt index f80b6e8c9335a77bd31866341080d5ef73de907a..bb8ce4b5baafcbbfaac28414da677cfd7b0ccfe9 100644 --- a/lite/api/CMakeLists.txt +++ b/lite/api/CMakeLists.txt @@ -46,7 +46,14 @@ if ((NOT LITE_ON_TINY_PUBLISH) AND (LITE_WITH_CUDA OR LITE_WITH_X86 OR LITE_WITH target_link_libraries(paddle_light_api_shared shlwapi.lib) endif() target_link_libraries(paddle_light_api_shared ${light_lib_DEPS} ${arm_kernels} ${npu_kernels} ${rknpu_kernels} ${apu_kernels}) - if(NOT APPLE AND NOT WIN32) + if(APPLE) + set(LINK_MAP_FILE "${PADDLE_SOURCE_DIR}/lite/core/exported_symbols.lds") + set(LINK_FLAGS "-Wl,-exported_symbols_list, ${LINK_MAP_FILE}") + add_custom_command(OUTPUT ${LINK_MAP_FILE} COMMAND ...) + add_custom_target(custom_linker_map DEPENDS ${LINK_MAP_FILE}) + set_target_properties(paddle_full_api_shared PROPERTIES LINK_FLAGS ${LINK_FLAGS}) + add_dependencies(paddle_full_api_shared custom_linker_map) + elseif(NOT WIN32) set(LINK_MAP_FILE "${PADDLE_SOURCE_DIR}/lite/core/lite.map") set(LINK_FLAGS "-Wl,--version-script ${LINK_MAP_FILE}") add_custom_command(OUTPUT ${LINK_MAP_FILE} COMMAND ...) diff --git a/lite/api/python/pybind/CMakeLists.txt b/lite/api/python/pybind/CMakeLists.txt index fe4cdb5a73d62afa98fb8c343e8a6a20388e293b..b78ee13ec2a9728bc3edb1b1c4660d119a045fb9 100644 --- a/lite/api/python/pybind/CMakeLists.txt +++ b/lite/api/python/pybind/CMakeLists.txt @@ -7,8 +7,21 @@ if(WIN32) lite_cc_library(lite_pybind SHARED SRCS pybind.cc DEPS ${PYBIND_DEPS}) get_property (os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES) target_link_libraries(lite_pybind ${os_dependency_modules}) +elseif(APPLE) + lite_cc_library(lite_pybind SHARED SRCS pybind.cc DEPS ${PYBIND_DEPS}) + set(LINK_MAP_FILE "${PADDLE_SOURCE_DIR}/lite/core/exported_symbols.lds") + set(LINK_FLAGS "-Wl,-exported_symbols_list, ${LINK_MAP_FILE}") + add_custom_command(OUTPUT ${LINK_MAP_FILE} COMMAND ...) + set_target_properties(lite_pybind PROPERTIES LINK_FLAGS ${LINK_FLAGS}) + add_dependencies(lite_pybind custom_linker_map) else() lite_cc_library(lite_pybind SHARED SRCS pybind.cc DEPS ${PYBIND_DEPS}) + set(LINK_MAP_FILE "${PADDLE_SOURCE_DIR}/lite/core/lite.map") + set(LINK_FLAGS "-Wl,--version-script ${LINK_MAP_FILE}") + add_custom_command(OUTPUT ${LINK_MAP_FILE} COMMAND ...) + set_target_properties(lite_pybind PROPERTIES LINK_FLAGS ${LINK_FLAGS}) + add_dependencies(lite_pybind custom_linker_map) +endif(APPLE) endif(WIN32) if (LITE_ON_TINY_PUBLISH) diff --git a/lite/core/exported_symbols.lds b/lite/core/exported_symbols.lds new file mode 100644 index 0000000000000000000000000000000000000000..f5e53027bdcfb3db1f1f452c150758894847cd00 --- /dev/null +++ b/lite/core/exported_symbols.lds @@ -0,0 +1,4 @@ +*paddle*lite* +*touch_* +*mir_pass_* +*PyInit_lite* diff --git a/lite/core/lite.map b/lite/core/lite.map index 406f578fab545709b90939cdfe475a8620be6841..bc76ef04e9d0eb58b2e702207b526f3a2911e8c5 100644 --- a/lite/core/lite.map +++ b/lite/core/lite.map @@ -3,6 +3,7 @@ *paddle*lite*; *touch_*; *mir_pass_*; + *PyInit_lite*; local: *; };