blob: fea07b37ec6afdb06393a7055f8a74d0c35000bf [file] [log] [blame]
Sadik Armagan3c24f432020-10-19 17:35:30 +01001#
2# Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3# SPDX-License-Identifier: MIT
4#
5
Jan Eilersb968a4f2020-11-15 14:44:43 +00006cmake_minimum_required (VERSION 3.7.0)
Sadik Armagan3c24f432020-10-19 17:35:30 +01007project(armnnDelegate)
8
Finn Williams6f9f9902020-11-13 13:23:15 +00009set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Werror -Wold-style-cast -Wno-missing-braces -Wconversion -Wsign-conversion")
Sadik Armagan3c24f432020-10-19 17:35:30 +010010
Finn Williamsbbbefec2020-11-25 14:32:42 +000011set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules/")
Sadik Armagan3c24f432020-10-19 17:35:30 +010012
13set(armnnDelegate_sources)
14list(APPEND armnnDelegate_sources
15 include/armnn_delegate.hpp
16 include/DelegateOptions.hpp
Matthew Sloyanac001ee2021-02-03 10:43:04 +000017 include/Version.hpp
Sadik Armagan3c24f432020-10-19 17:35:30 +010018 src/armnn_delegate.cpp
Jan Eilers2cd18472020-12-15 10:42:38 +000019 src/armnn_external_delegate.cpp
Sadik Armagan62483be2020-10-23 17:14:43 +010020 src/DelegateOptions.cpp
21 src/Activation.hpp
22 src/ArgMinMax.hpp
23 src/BatchSpace.hpp
24 src/Comparison.hpp
25 src/Convolution.hpp
26 src/Control.hpp
27 src/DelegateUtils.hpp
28 src/ElementwiseBinary.hpp
29 src/ElementwiseUnary.hpp
30 src/Fill.hpp
31 src/FullyConnected.hpp
32 src/Gather.hpp
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000033 src/LogicalBinary.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010034 src/Lstm.hpp
35 src/Normalization.hpp
36 src/Pad.hpp
37 src/Pooling.hpp
38 src/Quantization.hpp
39 src/Redefine.hpp
Sadik Armagana2747482021-02-09 10:28:54 +000040 src/Reduce.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010041 src/Resize.hpp
42 src/Round.hpp
43 src/Slice.hpp
44 src/Softmax.hpp
45 src/SpaceDepth.hpp
Sadik Armagan34fa1bd2020-11-27 12:40:52 +000046 src/Split.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010047 src/Transpose.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +010048
49add_library(armnnDelegate SHARED ${armnnDelegate_sources})
50
51target_include_directories(armnnDelegate
52 PUBLIC
53 $<INSTALL_INTERFACE:include>
54 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
55 PRIVATE
56 ${CMAKE_CURRENT_SOURCE_DIR}/src)
57
58include(GNUInstallDirs)
59
60## Add Armnn as a Dependency
Finn Williamsbbbefec2020-11-25 14:32:42 +000061if(NOT ARMNN_SUB_PROJECT)
62 find_package(Armnn REQUIRED CONFIG HINTS ${Armnn_DIR})
63endif()
64target_link_libraries(armnnDelegate PUBLIC Armnn::Armnn)
Sadik Armagan3c24f432020-10-19 17:35:30 +010065
66## Add TfLite v2.3.1 dependency
67find_package(TfLite REQUIRED MODULE)
68
Finn Williamsbbbefec2020-11-25 14:32:42 +000069target_link_libraries(armnnDelegate PUBLIC ${TfLite_LIB})
Sadik Armagan3c24f432020-10-19 17:35:30 +010070
Finn Williams6f9f9902020-11-13 13:23:15 +000071# Various tflite header files are not warning clean
72# We can't change compilation flags on header files directly, so we need to add them to an interface library first
73add_library(tflite_headers INTERFACE)
74target_include_directories(tflite_headers INTERFACE $<BUILD_INTERFACE:${TfLite_INCLUDE_DIR}>
75 $<INSTALL_INTERFACE:include/tflite_headers>)
76
Finn Williams019840d2020-11-30 17:43:28 +000077target_compile_options(tflite_headers INTERFACE -Wno-conversion
78 -Wno-sign-conversion
79 -Wno-unused-parameter
80 -Wno-unused-function)
Finn Williams6f9f9902020-11-13 13:23:15 +000081
Finn Williamsbbbefec2020-11-25 14:32:42 +000082target_link_libraries(armnnDelegate PUBLIC tflite_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +010083
Sadik Armagan3c24f432020-10-19 17:35:30 +010084## Add Flatbuffers dependency
85find_package(Flatbuffers REQUIRED MODULE)
86
Finn Williamsbbbefec2020-11-25 14:32:42 +000087target_link_libraries(armnnDelegate PRIVATE
Sadik Armagan3c24f432020-10-19 17:35:30 +010088 ${Flatbuffers_LIB})
89
Finn Williams6f9f9902020-11-13 13:23:15 +000090# include/flatbuffers/flatbuffers.h is not warning clean
91# We can't change compilation flags on header files directly, so we need to add them to an interface library first
92add_library(flatbuffer_headers INTERFACE)
93target_include_directories(flatbuffer_headers INTERFACE $<BUILD_INTERFACE:${Flatbuffers_INCLUDE_DIR}>
94 $<INSTALL_INTERFACE:include/flatbuffer_headers>)
Finn Williams019840d2020-11-30 17:43:28 +000095target_compile_options(flatbuffer_headers INTERFACE -Wno-sign-conversion)
Finn Williams6f9f9902020-11-13 13:23:15 +000096
Finn Williamsbbbefec2020-11-25 14:32:42 +000097target_link_libraries(armnnDelegate PUBLIC flatbuffer_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +010098
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +000099# Add libraries from armnn third-party libraries
100# Third-party header files are not warning clean
101# We can't change compilation flags on header files directly, so we need to add them to an interface library first
102add_library(thirdparty_headers INTERFACE)
103target_include_directories(thirdparty_headers INTERFACE $<BUILD_INTERFACE:${ARMNN_SOURCE_DIR}/third-party>
104 $<INSTALL_INTERFACE:include/thirdparty_headers>)
105
106target_compile_options(thirdparty_headers INTERFACE -Wno-old-style-cast)
107
Matthew Sloyanac001ee2021-02-03 10:43:04 +0000108set_target_properties(armnnDelegate PROPERTIES VERSION ${DELEGATE_LIB_VERSION} SOVERSION ${DELEGATE_LIB_SOVERSION})
109
Sadik Armagan4189cc52020-11-11 18:01:48 +0000110option(BUILD_UNIT_TESTS "Build unit tests" ON)
111if(BUILD_UNIT_TESTS)
112 set(armnnDelegate_unittest_sources)
113 list(APPEND armnnDelegate_unittest_sources
David Monahan0cf84422020-11-16 15:53:03 +0000114 src/test/ActivationTest.cpp
115 src/test/ActivationTestHelper.hpp
Sadik Armagandc032fc2021-01-19 17:24:21 +0000116 src/test/ArgMinMaxTest.cpp
117 src/test/ArgMinMaxTestHelper.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +0100118 src/test/ArmnnDelegateTest.cpp
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000119 src/test/BatchSpaceTest.cpp
120 src/test/BatchSpaceTestHelper.hpp
Sadik Armagan937565b2021-04-21 14:03:28 +0100121 src/test/CastTest.cpp
122 src/test/CastTestHelper.hpp
Sadik Armagan8b9858d2020-11-09 08:26:22 +0000123 src/test/ComparisonTest.cpp
124 src/test/ComparisonTestHelper.hpp
Matthew Sloyan91c41712020-11-13 09:47:35 +0000125 src/test/ControlTest.cpp
126 src/test/ControlTestHelper.hpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000127 src/test/Convolution2dTest.cpp
128 src/test/ConvolutionTestHelper.hpp
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000129 src/test/DelegateOptionsTest.cpp
130 src/test/DelegateOptionsTestHelper.hpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000131 src/test/DepthwiseConvolution2dTest.cpp
Sadik Armagan67e95f22020-10-29 16:14:54 +0000132 src/test/ElementwiseBinaryTest.cpp
133 src/test/ElementwiseBinaryTestHelper.hpp
Sadik Armagan0534e032020-10-27 17:30:18 +0000134 src/test/ElementwiseUnaryTest.cpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000135 src/test/ElementwiseUnaryTestHelper.hpp
Sadik Armagan29b49cf2021-02-22 18:09:07 +0000136 src/test/FillTest.cpp
137 src/test/FillTestHelper.hpp
Sadik Armagan6e36a642020-11-10 21:18:41 +0000138 src/test/FullyConnectedTest.cpp
139 src/test/FullyConnectedTestHelper.hpp
Teresa Charlin98427a12020-11-25 18:22:57 +0000140 src/test/GatherTest.cpp
141 src/test/GatherTestHelper.hpp
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000142 src/test/LogicalTest.cpp
143 src/test/LogicalTestHelper.hpp
Mike Kelly8ae17b32021-02-17 13:45:50 +0000144 src/test/LstmTest.cpp
145 src/test/LstmTestHelper.hpp
Sadik Armagan4b227bb2021-01-22 10:53:38 +0000146 src/test/NormalizationTest.cpp
147 src/test/NormalizationTestHelper.hpp
Narumol Prangnawarat958024b2020-12-17 12:17:58 +0000148 src/test/PadTest.cpp
149 src/test/PadTestHelper.hpp
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000150 src/test/Pooling2dTest.cpp
151 src/test/Pooling2dTestHelper.hpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000152 src/test/QuantizationTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000153 src/test/QuantizationTestHelper.hpp
David Monahan1670b0c2020-11-18 14:40:27 +0000154 src/test/RedefineTestHelper.hpp
Sadik Armagana2747482021-02-09 10:28:54 +0000155 src/test/ReduceTest.cpp
156 src/test/ReduceTestHelper.hpp
David Monahan1670b0c2020-11-18 14:40:27 +0000157 src/test/ReshapeTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000158 src/test/ResizeTest.cpp
159 src/test/ResizeTestHelper.hpp
Sadik Armagan788e2c62021-02-10 16:26:44 +0000160 src/test/RoundTest.cpp
161 src/test/RoundTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000162 src/test/SoftmaxTest.cpp
163 src/test/SoftmaxTestHelper.hpp
Sadik Armagan89c5a9e2021-01-20 17:48:07 +0000164 src/test/SpaceDepthTest.cpp
165 src/test/SpaceDepthTestHelper.hpp
Jan Eilers2ffddda2021-02-03 09:14:30 +0000166 src/test/SliceTest.cpp
167 src/test/SliceTestHelper.hpp
Sadik Armagan34fa1bd2020-11-27 12:40:52 +0000168 src/test/SplitTest.cpp
169 src/test/SplitTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000170 src/test/TestUtils.hpp
Jan Eilers3812fbc2020-11-17 19:06:35 +0000171 src/test/TestUtils.cpp
James Wardf89964e2020-11-09 11:57:47 +0000172 src/test/TransposeTest.cpp
James Warda8578102020-11-13 18:05:04 +0000173 src/test/TransposeTestHelper.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100174
Keith Davis7c67fab2021-04-08 11:47:23 +0100175 # There's a known Android NDK bug which causes a subset of NeonLayerTests to
176 # fail. We'll exclude these tests in NeonLayerTests_NDK_Bug.cpp if we're doing
177 # a debug build and NDK is less than r21.
178 # https://github.com/android/ndk/issues/1135
179
180 # Default to always including these tests.
181 set(INCLUDE_NDK_BUG_TESTS "ON")
182 # Reconsider if we in a debug build.
183 string( TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE_LOWERCASE )
184 if ( NOT BUILD_TYPE_LOWERCASE STREQUAL "release" )
185 message("CMAKE:: BUILD TYPE IS ${CMAKE_BUILD_TYPE}")
186 # And NDK_VERSION has been set.
187 if ( DEFINED NDK_VERSION )
188 message("CMAKE:: NDK DEFINED")
189 # And the version is less than r21.
190 if ( ${NDK_VERSION} STRLESS "r21" )
191 message("CMAKE:: BUG TESTS OFF")
192 set(INCLUDE_NDK_BUG_TESTS "OFF")
193 endif()
194 endif()
195 endif()
196
197 if ( INCLUDE_NDK_BUG_TESTS STREQUAL "ON" )
198 list(APPEND armnnDelegate_unittest_sources
199 src/test/NeonDelegateTests_NDK_Issue.cpp
200 )
201 else()
202
203 endif()
204
Sadik Armagan4189cc52020-11-11 18:01:48 +0000205 add_executable(DelegateUnitTests ${armnnDelegate_unittest_sources})
206 target_include_directories(DelegateUnitTests PRIVATE third-party)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100207
Sadik Armagan4189cc52020-11-11 18:01:48 +0000208 # Add half library from armnn third-party libraries
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000209 target_link_libraries(DelegateUnitTests PRIVATE thirdparty_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100210
Finn Williamsbbbefec2020-11-25 14:32:42 +0000211 target_link_libraries(DelegateUnitTests PRIVATE armnnDelegate)
212 target_link_libraries(DelegateUnitTests PRIVATE Armnn::armnnUtils)
Sadik Armagan4189cc52020-11-11 18:01:48 +0000213
Finn Williamsbbbefec2020-11-25 14:32:42 +0000214 target_link_libraries(DelegateUnitTests PRIVATE tflite_headers)
215 target_link_libraries(DelegateUnitTests PRIVATE flatbuffer_headers)
Finn Williams6f9f9902020-11-13 13:23:15 +0000216
Sadik Armagan4189cc52020-11-11 18:01:48 +0000217endif()
Sadik Armagan3c24f432020-10-19 17:35:30 +0100218
219####################################################
220## Export targets
221set(armnn_delegate_export_targets)
222list(APPEND armnn_delegate_export_targets
Finn Williams6f9f9902020-11-13 13:23:15 +0000223 armnnDelegate
224 tflite_headers
225 flatbuffer_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100226
227install(
228 TARGETS ${armnn_delegate_export_targets}
229 EXPORT armnn-delegate-targets
230 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
231 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
232 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
233
234## Set export alias
235set_target_properties(armnnDelegate
236 PROPERTIES
237 EXPORT_NAME ArmnnDelegate)
238
239## Export target scrips
240install(
241 EXPORT armnn-delegate-targets
242 FILE ArmnnDelegateTargets.cmake
243 NAMESPACE ArmnnDelegate::
244 DESTINATION ${CMAKE_INSTALL_LIBDIR})
245
246## Create ArmnnDelegateConfig.cmake
247include(CMakePackageConfigHelpers)
248set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR})
249message(STATUS "CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}" )
250message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}" )
Finn Williamsbbbefec2020-11-25 14:32:42 +0000251SET(Armnn_DIR "${Armnn_DIR}")
252
Sadik Armagan3c24f432020-10-19 17:35:30 +0100253configure_package_config_file(
254 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/ArmnnDelegateConfig.cmake.in
255 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
Finn Williamsbbbefec2020-11-25 14:32:42 +0000256 INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
257 PATH_VARS Armnn_DIR)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100258
259## Install ArmNN Delegate config file
260install(
261 FILES
262 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
263 DESTINATION ${INSTALL_CONFIGDIR})
264
265## Export from build tree
266export(
267 EXPORT armnn-delegate-targets
268 FILE ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateTargets.cmake
269 NAMESPACE ArmnnDelegate::)
Sadik Armagan5d03e312020-11-17 16:43:56 +0000270add_library(ArmnnDelegate::ArmnnDelegate ALIAS armnnDelegate)
271
Sadik Armagan3c24f432020-10-19 17:35:30 +0100272
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000273####################################################