blob: f16238c826f0a3429c0a0a6cba3539cb03741d3f [file] [log] [blame]
Jan Eilersa96489a2021-12-08 10:05:47 +00001#
Teresa Charlinad1b3d72023-03-14 12:10:28 +00002# Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
Jan Eilersa96489a2021-12-08 10:05:47 +00003# SPDX-License-Identifier: MIT
4#
5
6cmake_minimum_required(VERSION 3.7.0)
7
8project("armnn_delegate_jni")
9
10# JNI is needed for jni calls
11find_package(JNI)
12
13list(APPEND jni_delegate_sources
14 src/armnn_delegate_jni.cpp)
15
16# the backends under src/backends extend the list of
17# object libs armnn to include in the build
18# If armnn is a static library (which it should be to make armnn_delegate_jni a stand alone library) then
19# the object libraries of the backends need to be linked manually
20include(${ARMNN_SOURCE_DIR}/src/backends/backends.cmake)
21foreach(lib ${armnnLibraries})
22 message(STATUS "Adding object library dependency to armnn_delegate_jni: ${lib}")
23 list(APPEND jni_delegate_sources $<TARGET_OBJECTS:${lib}>)
24endforeach()
25
26if (JNI_FOUND)
27 message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
28 message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
29else()
30 message (FATAL_ERROR "JNI library could not be found")
31endif()
32include_directories(${JNI_INCLUDE_DIRS})
33
34add_library(armnn_delegate_jni SHARED ${jni_delegate_sources})
35
Teresa Charlinad1b3d72023-03-14 12:10:28 +000036target_link_libraries(armnn_delegate_jni
Jan Eilersa96489a2021-12-08 10:05:47 +000037 PRIVATE
Teresa Charlinad1b3d72023-03-14 12:10:28 +000038 Armnn::Armnn
39 ArmnnDelegate::ArmnnDelegate
Jan Eilersa96489a2021-12-08 10:05:47 +000040 )
41
42# A version script is used to hide all symbols that are not required to use the jni interface
43# This is mostly required to avoid symbol conflicts between libc++_shared used to compile armnn
44# and an eventual other version used somewhere else: https://developer.android.com/ndk/guides/cpp-support
45# This also requires to tell the compiler to link to the static version of libc++_shared. This can be accomplished
46# by adding -DCMAKE_ANDROID_STL_TYPE=c++_static to the cmake command when building for android
47set(version_script "${CMAKE_CURRENT_SOURCE_DIR}/version_script")
48
49# Generate a map file for debug mode only
50set_property(TARGET armnn_delegate_jni APPEND_STRING PROPERTY
51 LINK_FLAGS " -Wl,--version-script=${version_script},-Map=mapfile.map")
52
53set_target_properties(armnn_delegate_jni PROPERTIES LINK_DEPENDS ${version_script})