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

Link necessary libraries when building runtime for Android #5496

Merged
merged 1 commit into from
May 1, 2020
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
26 changes: 25 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,35 @@ else(MSVC)
if(BUILD_FOR_HEXAGON)
message(STATUS "Building for Hexagon")
endif()

# Detect if we're compiling for Android.
set(TEST_FOR_ANDROID_CXX
"#ifndef __ANDROID__"
"#error"
"#endif"
"int main() {}")
set(TEST_FOR_ANDROID_DIR
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp")
set(TEST_FOR_ANDROID_FILE "${TEST_FOR_ANDROID_DIR}/test_for_android.cc")
string(REPLACE ";" "\n" TEST_FOR_ANDROID_CXX_TEXT "${TEST_FOR_ANDROID_CXX}")
file(WRITE "${TEST_FOR_ANDROID_FILE}" "${TEST_FOR_ANDROID_CXX_TEXT}")
try_compile(BUILD_FOR_ANDROID "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}"
"${TEST_FOR_ANDROID_FILE}")
file(REMOVE "${TEST_FOR_ANDROID_FILE}")
if(BUILD_FOR_ANDROID)
message(STATUS "Building for Android")
endif()
endif(MSVC)

# Hexagon has dlopen built into QuRT (no need for static library).
if(NOT BUILD_FOR_HEXAGON)
string(APPEND TVM_RUNTIME_LINKER_LIBS ${CMAKE_DL_LIBS})
list(APPEND TVM_RUNTIME_LINKER_LIBS ${CMAKE_DL_LIBS})
endif()

if(BUILD_FOR_ANDROID)
# EmuTLS on Android is in libgcc. Without it linked in, libtvm_runtime.so
# won't load on Android due to missing __emutls_XXX symbols.
list(APPEND TVM_RUNTIME_LINKER_LIBS "gcc")
endif()

# add source group
Expand Down
6 changes: 5 additions & 1 deletion cmake/modules/Hexagon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ elseif(USE_HEXAGON_DEVICE STREQUAL "${PICK_HW}")
include_directories(
"${HEXAGON_SDK_ROOT}/libs/common/remote/ship/android_Release_aarch64")
include_directories("${HEXAGON_TOOLCHAIN}/include/iss")
list(APPEND TVM_RUNTIME_LINKER_LIBS "-ldl")
list(APPEND TVM_RUNTIME_LINKER_LIBS "dl")
if(BUILD_FOR_ANDROID)
# Hexagon runtime uses __android_log_print, which is in liblog.
list(APPEND TVM_RUNTIME_LINKER_LIBS "log")
endif()
endif()

file(GLOB RUNTIME_HEXAGON_SRCS src/runtime/hexagon/*.cc)
Expand Down