blob: 6521e7c302db165647809422a8ec2eecfb6754c7 [file] [log] [blame]
Colm Donelan0aef6532023-10-02 17:01:37 +01001#
2# Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3# SPDX-License-Identifier: MIT
4#
5# Usage: cmake -DARMNN_ROOT=<path to armnn library and includes>
6
7cmake_minimum_required (VERSION 3.7.0)
8project(InterfaceTests)
9set(CMAKE_CXX_STANDARD 17)
10set(CMAKE_CXX_STANDARD_REQUIRED ON)
11
12# Reusing the TfLite cmake module from Arm NN. This module should have no
13# external dependencies on other parts of Arm NN. Its only required
14# parameter is TFLITE_LIB_ROOT
15set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/../../delegate/cmake/Modules/")
16
17# This is the base path for the Arm NN binary build. The root directory
18# contains the library files and also an include directory.
19option(ARMNN_ROOT "Location where the Arm NN libraries and 'include' directory can be found" Off)
20
21# TfLite needs flatbuffers.
22option(FLATBUFFERS_ROOT "Location where Flatbuffers include files can be found." Off)
23
24# To test both delegates we need TfLite.
25option(TFLITE_INCLUDE_ROOT "Location where the TfLite includes can be found." Off)
26option(TFLITE_LIB_ROOT "Location where the built TfLite libraries can be found." Off)
27
28
29# Locate the Arm NN libraries and includes.
30message(STATUS "Arm NN root is set to \"${ARMNN_ROOT}\"")
31# Exclude default paths to ensure only the specified path is used.
32find_path(ARMNN_LIB_INCLUDE armnn/ArmNN.hpp PATHS ${ARMNN_ROOT}/include NO_DEFAULT_PATH)
33message(STATUS "Arm NN library include directory located at: ${ARMNN_LIB_INCLUDE}")
34find_library(ARMNN_LIB
35 NAMES armnn
36 HINTS ${ARMNN_ROOT})
37message(STATUS "Arm NN library location set to ${ARMNN_LIB}")
38
39# Arm NN uses pthreads.
40find_package(Threads)
41
42# First test is the use of the Arm NN graph interface. We compile
43# SimpleSample into a binary based on the libraries and includes we have
44# found.
45add_executable(SimpleSample ../../samples/SimpleSample.cpp)
46# We're using BEFORE here to ensure no stray system libraries get used first.
47target_include_directories(SimpleSample BEFORE PUBLIC ${ARMNN_LIB_INCLUDE})
48target_link_libraries(SimpleSample ${ARMNN_LIB} ${CMAKE_THREAD_LIBS_INIT})
49
50# TfLite parser.
51find_library(ARMNN_TFLITE_LIB
52 NAMES armnnTfLiteParser
53 HINTS ${ARMNN_ROOT})
54add_executable(TfLiteParserTest ./TfLiteParserTest.cpp)
55target_include_directories(TfLiteParserTest BEFORE PUBLIC ${ARMNN_LIB_INCLUDE})
56target_link_libraries(TfLiteParserTest ${ARMNN_LIB} ${ARMNN_TFLITE_LIB} ${CMAKE_THREAD_LIBS_INIT})
57
58# Onnx parser
59find_library(ARMNN_ONNX_LIB
60 NAMES armnnOnnxParser
61 HINTS ${ARMNN_ROOT})
62add_executable(OnnxParserTest ./OnnxParserTest.cpp)
63target_include_directories(OnnxParserTest BEFORE PUBLIC ${ARMNN_LIB_INCLUDE})
64target_link_libraries(OnnxParserTest ${ARMNN_LIB} ${ARMNN_ONNX_LIB} ${CMAKE_THREAD_LIBS_INIT})
65
66
67# These next two targets are for our TfLite delegates. The machanism used to
68# compile and use them does not confirm to how Tf intends delegates to be
69# used. We include these tests to highlight potential missing, or awkwrd,
70# includes that could occur.
71
72# Find Flatbuffers dependency
73find_package(Flatbuffers REQUIRED MODULE)
74
75# Find TfLite libraries and includes.
76find_package(TfLite REQUIRED MODULE)
77find_path(TFLITE_INCLUDE tensorflow/c/c_api.h PATHS ${TFLITE_INCLUDE_ROOT} NO_DEFAULT_PATH)
78
79# Classic delegate
80find_library(ARMNN_CLASSIC_DELEGATE_LIB
81 NAMES armnnDelegate
82 HINTS ${ARMNN_ROOT})
83add_executable(ClassicDelegateTest ./ClassicDelegateTest.cpp)
84find_path(ARMNN_COMMON_DELEGATE_INCLUDE DelegateOptions.hpp PATHS ${ARMNN_ROOT}/include/armnnDelegate/armnn/delegate/common/include/ NO_DEFAULT_PATH)
85find_path(ARMNN_CLASSIC_DELEGATE_INCLUDE armnn_delegate.hpp PATHS ${ARMNN_ROOT}/include/armnnDelegate/armnn/delegate/classic/include/ NO_DEFAULT_PATH)
86target_include_directories(ClassicDelegateTest BEFORE PUBLIC ${ARMNN_LIB_INCLUDE}
87 ${Flatbuffers_INCLUDE_DIR}
88 ${TFLITE_INCLUDE}
89 ${ARMNN_COMMON_DELEGATE_INCLUDE}
90 ${ARMNN_CLASSIC_DELEGATE_INCLUDE})
91target_link_libraries(ClassicDelegateTest ${TfLite_LIB}
92 ${ARMNN_CLASSIC_DELEGATE_LIB}
93 ${ARMNN_LIB}
94 ${Flatbuffers_LIB}
95 ${CMAKE_THREAD_LIBS_INIT}
96 ${CMAKE_DL_LIBS})
97
98# Opaque delegate
99find_library(ARMNN_OPAQUE_DELEGATE_LIB
100 NAMES armnnOpaqueDelegate
101 HINTS ${ARMNN_ROOT})
102# Additional Absl Sync for Opaque Delegate
103find_package(TfLiteAbsl REQUIRED MODULE)
104
105add_executable(OpaqueDelegateTest ./OpaqueDelegateTest.cpp)
106find_path(ARMNN_OPAQUE_DELEGATE_INCLUDE armnn_delegate.hpp PATHS ${ARMNN_ROOT}/include/armnnDelegate/armnn/delegate/opaque/include/ NO_DEFAULT_PATH)
107# delegate_registry.h happens to use a ABSL mutex. We need to find and add its path too.
108find_path(TFLITE_ABSL_INCLUDE absl/synchronization/mutex.h PATHS ${TFLITE_LIB_ROOT}/abseil-cpp/ NO_DEFAULT_PATH)
109target_include_directories(OpaqueDelegateTest BEFORE PUBLIC ${ARMNN_LIB_INCLUDE}
110 ${Flatbuffers_INCLUDE_DIR}
111 ${TFLITE_INCLUDE}
112 ${TFLITE_ABSL_INCLUDE}
113 ${ARMNN_COMMON_DELEGATE_INCLUDE}
114 ${ARMNN_OPAQUE_DELEGATE_INCLUDE})
115target_link_libraries(OpaqueDelegateTest ${ARMNN_OPAQUE_DELEGATE_LIB}
116 ${ARMNN_LIB}
117 ${TfLite_Extra_Absl_LIB}
118 ${TfLite_LIB}
119 ${Flatbuffers_LIB}
120 ${CMAKE_THREAD_LIBS_INIT}
121 ${CMAKE_DL_LIBS})