Jan Eilers | a96489a | 2021-12-08 10:05:47 +0000 | [diff] [blame] | 1 | # |
Teresa Charlin | ad1b3d7 | 2023-03-14 12:10:28 +0000 | [diff] [blame] | 2 | # Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. |
Jan Eilers | a96489a | 2021-12-08 10:05:47 +0000 | [diff] [blame] | 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | |
| 6 | cmake_minimum_required(VERSION 3.7.0) |
| 7 | |
| 8 | project("armnn_delegate_jni") |
| 9 | |
| 10 | # JNI is needed for jni calls |
| 11 | find_package(JNI) |
| 12 | |
| 13 | list(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 |
| 20 | include(${ARMNN_SOURCE_DIR}/src/backends/backends.cmake) |
| 21 | foreach(lib ${armnnLibraries}) |
| 22 | message(STATUS "Adding object library dependency to armnn_delegate_jni: ${lib}") |
| 23 | list(APPEND jni_delegate_sources $<TARGET_OBJECTS:${lib}>) |
| 24 | endforeach() |
| 25 | |
| 26 | if (JNI_FOUND) |
| 27 | message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}") |
| 28 | message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}") |
| 29 | else() |
| 30 | message (FATAL_ERROR "JNI library could not be found") |
| 31 | endif() |
| 32 | include_directories(${JNI_INCLUDE_DIRS}) |
| 33 | |
| 34 | add_library(armnn_delegate_jni SHARED ${jni_delegate_sources}) |
| 35 | |
Teresa Charlin | ad1b3d7 | 2023-03-14 12:10:28 +0000 | [diff] [blame] | 36 | target_link_libraries(armnn_delegate_jni |
Jan Eilers | a96489a | 2021-12-08 10:05:47 +0000 | [diff] [blame] | 37 | PRIVATE |
Teresa Charlin | ad1b3d7 | 2023-03-14 12:10:28 +0000 | [diff] [blame] | 38 | Armnn::Armnn |
| 39 | ArmnnDelegate::ArmnnDelegate |
Jan Eilers | a96489a | 2021-12-08 10:05:47 +0000 | [diff] [blame] | 40 | ) |
| 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 |
| 47 | set(version_script "${CMAKE_CURRENT_SOURCE_DIR}/version_script") |
| 48 | |
| 49 | # Generate a map file for debug mode only |
| 50 | set_property(TARGET armnn_delegate_jni APPEND_STRING PROPERTY |
| 51 | LINK_FLAGS " -Wl,--version-script=${version_script},-Map=mapfile.map") |
| 52 | |
| 53 | set_target_properties(armnn_delegate_jni PROPERTIES LINK_DEPENDS ${version_script}) |