blob: 06eb3bf8e378b05c2bea0b591e471cc6ceefb241 [file] [log] [blame]
Jan Eilersa96489a2021-12-08 10:05:47 +00001#
2# Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3# 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
36target_include_directories(
37 armnn_delegate_jni
38 PUBLIC
39 ${ARMNN_INCLUDE_DIR}
40 ${ARMNN_DELEGATE_INCLUDE_DIR}
41 ${ARMCOMPUTE_INCLUDE}
42 )
43
44target_link_libraries(
45 armnn_delegate_jni
46 PRIVATE
47 Armnn::Armnn
48 ArmnnDelegate::ArmnnDelegate
49 )
50
51# A version script is used to hide all symbols that are not required to use the jni interface
52# This is mostly required to avoid symbol conflicts between libc++_shared used to compile armnn
53# and an eventual other version used somewhere else: https://developer.android.com/ndk/guides/cpp-support
54# This also requires to tell the compiler to link to the static version of libc++_shared. This can be accomplished
55# by adding -DCMAKE_ANDROID_STL_TYPE=c++_static to the cmake command when building for android
56set(version_script "${CMAKE_CURRENT_SOURCE_DIR}/version_script")
57
58# Generate a map file for debug mode only
59set_property(TARGET armnn_delegate_jni APPEND_STRING PROPERTY
60 LINK_FLAGS " -Wl,--version-script=${version_script},-Map=mapfile.map")
61
62set_target_properties(armnn_delegate_jni PROPERTIES LINK_DEPENDS ${version_script})