未验证 提交 f6b3e784 编写于 作者: H hong19860320 提交者: GitHub

[Core] Support Clang toolchains for Android (#3107)

* [CORE] Support Clang compiling for Android
test=develop

* fix lto for jni so
test=develop

* disable assembly code
test=develop

* disable layout.cc
test=develop

* refine
test=develop

* Enable LTO on Clang
test=develop

* Disable LTO when clang is used.
test=develop

* Remove space
test=develop

* [Core] enable clang in build.sh
test=develop

* [Core] Remove the workaround for clang compiling
test=develop
上级 64cbe711
......@@ -60,16 +60,11 @@ endfunction()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if (LITE_ON_TINY_PUBLISH)
if(NOT LITE_WITH_PYTHON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
endif()
if(ARM_TARGET_LANG STREQUAL "clang")
# TODO(ysh329): add options for clang like gcc branch below
else() # ARM_TARGET_LANG STREQUAL "gcc"
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math -Ofast -Os -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -ffunction-sections")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden -ffunction-sections")
check_linker_flag(-Wl,--gc-sections)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math -Ofast -Os -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -ffunction-sections")
check_linker_flag(-Wl,--gc-sections)
endif()
if(LITE_WITH_OPENMP)
......
......@@ -5,13 +5,8 @@ else()
endif(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
if (LITE_ON_TINY_PUBLISH)
if(ARM_TARGET_LANG STREQUAL "clang")
set(CMAKE_CXX_FLAGS_RELEASE " -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE " -DNDEBUG")
else() # gcc
set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
endif()
set(light_lib_DEPS light_api paddle_api paddle_api_light optimizer)
if ((NOT LITE_ON_TINY_PUBLISH) AND (LITE_WITH_CUDA OR LITE_WITH_X86 OR ARM_TARGET_OS STREQUAL "android" OR ARM_TARGET_OS STREQUAL "armlinux"))
......@@ -50,11 +45,11 @@ else()
if ((ARM_TARGET_OS STREQUAL "android") OR (ARM_TARGET_OS STREQUAL "armlinux"))
add_library(paddle_light_api_shared SHARED "")
target_sources(paddle_light_api_shared PUBLIC ${__lite_cc_files} paddle_api.cc light_api.cc light_api_impl.cc)
if(ARM_TARGET_LANG STREQUAL "clang")
set_target_properties(paddle_light_api_shared PROPERTIES COMPILE_FLAGS "")
else() # ARM_TARGET_LANG STREQUAL "gcc"
set_target_properties(paddle_light_api_shared PROPERTIES COMPILE_FLAGS "-flto -fdata-sections")
set(TARGET_COMIPILE_FLAGS "-fdata-sections")
if (NOT (ARM_TARGET_LANG STREQUAL "clang")) #gcc
set(TARGET_COMIPILE_FLAGS "${TARGET_COMIPILE_FLAGS} -flto")
endif()
set_target_properties(paddle_light_api_shared PROPERTIES COMPILE_FLAGS "${TARGET_COMIPILE_FLAGS}")
add_dependencies(paddle_light_api_shared op_list_h kernel_list_h)
if (LITE_WITH_NPU)
# Need to add HIAI runtime libs (libhiai.so) dependency
......
# Generate paddle_lite_jni.so
if (LITE_ON_TINY_PUBLISH)
if(ARM_TARGET_LANG STREQUAL "clang")
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG")
else() # ARM_TARGET_LANG STREQUAL "gcc"
set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
set(lib_DEPS light_api paddle_api paddle_api_light)
else()
set(lib_DEPS light_api cxx_api paddle_api_full paddle_api paddle_api_light)
......@@ -30,11 +25,11 @@ if (NOT LITE_ON_TINY_PUBLISH)
endif()
else()
add_library(paddle_lite_jni SHARED "")
if(ARM_TARGET_LANG STREQUAL "clang")
set_target_properties(paddle_lite_jni PROPERTIES COMPILE_FLAGS "")
else() # ARM_TARGET_LANG STREQUAL "gcc"
set_target_properties(paddle_lite_jni PROPERTIES COMPILE_FLAGS "-flto -fdata-sections")
set(TARGET_COMIPILE_FLAGS "-fdata-sections")
if (NOT (ARM_TARGET_LANG STREQUAL "clang")) #gcc
set(TARGET_COMIPILE_FLAGS "${TARGET_COMIPILE_FLAGS} -flto")
endif()
set_target_properties(paddle_lite_jni PROPERTIES COMPILE_FLAGS ${TARGET_COMIPILE_FLAGS})
target_sources(paddle_lite_jni PUBLIC ${__lite_cc_files} paddle_lite_jni.cc tensor_jni.cc)
add_dependencies(paddle_lite_jni op_list_h kernel_list_h)
if (LITE_WITH_NPU)
......
......@@ -390,13 +390,6 @@ function main {
;;
--arm_lang=*)
ARM_LANG="${i#*=}"
if [ ${ARM_LANG} == "clang" ]; then
set +x
echo
echo -e "error: only support gcc now, clang will be supported in future."
echo
# exit 1
fi
shift
;;
--android_stl=*)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册