Skip to content

Commit ed0a9bb

Browse files
authored
[BUG FIX] Remove flto cmake flags on static lib to support Android10.0+ (#5808)
1 parent b3d2f63 commit ed0a9bb

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

lite/api/CMakeLists.txt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,15 @@ else()
8484
add_library(paddle_api_light_bundled STATIC $<TARGET_OBJECTS:PADDLELITE_OBJS>)
8585
else()
8686
# 1. enable -flto compiling flag if toochain==gcc
87-
set(TARGET_COMIPILE_FLAGS "-fdata-sections")
88-
if (NOT (ARM_TARGET_LANG STREQUAL "clang")) #gcc
89-
set(TARGET_COMIPILE_FLAGS "${TARGET_COMIPILE_FLAGS} -flto")
90-
# '-flto' is only supported by gcc-ar, while gcc-ar is not supported on MacOs
91-
if(NOT ${HOST_SYSTEM} MATCHES "macosx")
92-
SET(CMAKE_AR "gcc-ar")
93-
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>")
94-
SET(CMAKE_CXX_ARCHIVE_FINISH true)
95-
endif()
96-
# TODO (hong19860320): Disable lto temporarily since it causes fail to catch the exceptions in android when toolchain is gcc.
87+
# TODO (hong19860320): Disable lto temporarily since it causes fail to catch the exceptions in android when toolchain is gcc.
88+
if (NOT (ARM_TARGET_LANG STREQUAL "clang"))
9789
if (ARM_TARGET_OS STREQUAL "android" AND LITE_WITH_EXCEPTION)
9890
set(TARGET_COMIPILE_FLAGS "")
91+
else()
92+
set(TARGET_COMIPILE_FLAGS "-fdata-sections -flto")
9993
endif()
94+
else()
95+
set(TARGET_COMIPILE_FLAGS "-fdata-sections")
10096
endif()
10197
# 1.1 enable -flto on PADDLELITE_OBJS
10298
set_target_properties(PADDLELITE_OBJS PROPERTIES COMPILE_FLAGS "${TARGET_COMIPILE_FLAGS}")
@@ -130,11 +126,11 @@ else()
130126
endif()
131127

132128
# 4. produce static lib `libpaddle_api_light_bundled.a` from `PADDLELITE_OBJS`
133-
# '-flto' is only supported by gcc-ar, while gcc-ar is not supported on MacOs
134-
if(NOT ${HOST_SYSTEM} MATCHES "macosx")
135-
add_library(paddle_api_light_bundled STATIC $<TARGET_OBJECTS:PADDLELITE_OBJS>)
136-
else()
129+
# '-flto' is only supported by dynamic lib
130+
if(TARGET_COMIPILE_FLAGS MATCHES ".*-flto.*")
137131
add_library(paddle_api_light_bundled STATIC ${__lite_cc_files} paddle_api.cc light_api.cc light_api_impl.cc)
132+
else()
133+
add_library(paddle_api_light_bundled STATIC $<TARGET_OBJECTS:PADDLELITE_OBJS>)
138134
endif()
139135
endif()
140136
endif()

0 commit comments

Comments
 (0)