提交 03e0fa17 编写于 作者: Y Yuan Shuai 提交者: GitHub

[LITE][BUILD] Fix armv8-cpu clang compile (#3102)

* [LITE][CMAKE] support clang compile for armv8 cpu. test=develop

* add build for clang. test=develop

* fix cmake format. test=develop
上级 3bbab10d
...@@ -62,9 +62,14 @@ if (LITE_ON_TINY_PUBLISH) ...@@ -62,9 +62,14 @@ if (LITE_ON_TINY_PUBLISH)
if(NOT LITE_WITH_PYTHON) if(NOT LITE_WITH_PYTHON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
endif() 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} -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=hidden -fvisibility-inlines-hidden -ffunction-sections")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden -ffunction-sections")
check_linker_flag(-Wl,--gc-sections) check_linker_flag(-Wl,--gc-sections)
endif()
endif() endif()
if(LITE_WITH_OPENMP) if(LITE_WITH_OPENMP)
......
...@@ -5,8 +5,13 @@ else() ...@@ -5,8 +5,13 @@ else()
endif(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK) endif(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
if (LITE_ON_TINY_PUBLISH) 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_CXX_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG") set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
endif()
endif() endif()
set(light_lib_DEPS light_api paddle_api paddle_api_light optimizer) 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")) 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"))
...@@ -45,7 +50,11 @@ else() ...@@ -45,7 +50,11 @@ else()
if ((ARM_TARGET_OS STREQUAL "android") OR (ARM_TARGET_OS STREQUAL "armlinux")) if ((ARM_TARGET_OS STREQUAL "android") OR (ARM_TARGET_OS STREQUAL "armlinux"))
add_library(paddle_light_api_shared SHARED "") 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) 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_properties(paddle_light_api_shared PROPERTIES COMPILE_FLAGS "-flto -fdata-sections")
endif()
add_dependencies(paddle_light_api_shared op_list_h kernel_list_h) add_dependencies(paddle_light_api_shared op_list_h kernel_list_h)
if (LITE_WITH_NPU) if (LITE_WITH_NPU)
# Need to add HIAI runtime libs (libhiai.so) dependency # Need to add HIAI runtime libs (libhiai.so) dependency
......
# Generate paddle_lite_jni.so # Generate paddle_lite_jni.so
if (LITE_ON_TINY_PUBLISH) 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_CXX_FLAGS_RELEASE "-Os -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG") set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG")
endif()
set(lib_DEPS light_api paddle_api paddle_api_light) set(lib_DEPS light_api paddle_api paddle_api_light)
else() else()
set(lib_DEPS light_api cxx_api paddle_api_full paddle_api paddle_api_light) set(lib_DEPS light_api cxx_api paddle_api_full paddle_api paddle_api_light)
...@@ -25,7 +30,11 @@ if (NOT LITE_ON_TINY_PUBLISH) ...@@ -25,7 +30,11 @@ if (NOT LITE_ON_TINY_PUBLISH)
endif() endif()
else() else()
add_library(paddle_lite_jni SHARED "") 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_properties(paddle_lite_jni PROPERTIES COMPILE_FLAGS "-flto -fdata-sections")
endif()
target_sources(paddle_lite_jni PUBLIC ${__lite_cc_files} paddle_lite_jni.cc tensor_jni.cc) 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) add_dependencies(paddle_lite_jni op_list_h kernel_list_h)
if (LITE_WITH_NPU) if (LITE_WITH_NPU)
......
...@@ -395,7 +395,7 @@ function main { ...@@ -395,7 +395,7 @@ function main {
echo echo
echo -e "error: only support gcc now, clang will be supported in future." echo -e "error: only support gcc now, clang will be supported in future."
echo echo
exit 1 # exit 1
fi fi
shift shift
;; ;;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册