blob: dc65a1942e5a9bece056d00a702028101483f694 [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
Matthew Sloyana7a12f52021-05-06 10:05:28 +010036 src/Pack.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010037 src/Pad.hpp
38 src/Pooling.hpp
39 src/Quantization.hpp
40 src/Redefine.hpp
Sadik Armagana2747482021-02-09 10:28:54 +000041 src/Reduce.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010042 src/Resize.hpp
43 src/Round.hpp
44 src/Slice.hpp
45 src/Softmax.hpp
46 src/SpaceDepth.hpp
Sadik Armagan34fa1bd2020-11-27 12:40:52 +000047 src/Split.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010048 src/Transpose.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +010049
50add_library(armnnDelegate SHARED ${armnnDelegate_sources})
51
52target_include_directories(armnnDelegate
53 PUBLIC
54 $<INSTALL_INTERFACE:include>
55 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
56 PRIVATE
57 ${CMAKE_CURRENT_SOURCE_DIR}/src)
58
59include(GNUInstallDirs)
60
61## Add Armnn as a Dependency
Finn Williamsbbbefec2020-11-25 14:32:42 +000062if(NOT ARMNN_SUB_PROJECT)
63 find_package(Armnn REQUIRED CONFIG HINTS ${Armnn_DIR})
64endif()
65target_link_libraries(armnnDelegate PUBLIC Armnn::Armnn)
Sadik Armagan3c24f432020-10-19 17:35:30 +010066
67## Add TfLite v2.3.1 dependency
68find_package(TfLite REQUIRED MODULE)
69
Finn Williamsbbbefec2020-11-25 14:32:42 +000070target_link_libraries(armnnDelegate PUBLIC ${TfLite_LIB})
Sadik Armagan3c24f432020-10-19 17:35:30 +010071
Finn Williams6f9f9902020-11-13 13:23:15 +000072# Various tflite header files are not warning clean
73# We can't change compilation flags on header files directly, so we need to add them to an interface library first
74add_library(tflite_headers INTERFACE)
75target_include_directories(tflite_headers INTERFACE $<BUILD_INTERFACE:${TfLite_INCLUDE_DIR}>
76 $<INSTALL_INTERFACE:include/tflite_headers>)
77
Finn Williams019840d2020-11-30 17:43:28 +000078target_compile_options(tflite_headers INTERFACE -Wno-conversion
79 -Wno-sign-conversion
80 -Wno-unused-parameter
81 -Wno-unused-function)
Finn Williams6f9f9902020-11-13 13:23:15 +000082
Finn Williamsbbbefec2020-11-25 14:32:42 +000083target_link_libraries(armnnDelegate PUBLIC tflite_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +010084
Sadik Armagan3c24f432020-10-19 17:35:30 +010085## Add Flatbuffers dependency
86find_package(Flatbuffers REQUIRED MODULE)
87
Finn Williamsbbbefec2020-11-25 14:32:42 +000088target_link_libraries(armnnDelegate PRIVATE
Sadik Armagan3c24f432020-10-19 17:35:30 +010089 ${Flatbuffers_LIB})
90
Finn Williams6f9f9902020-11-13 13:23:15 +000091# include/flatbuffers/flatbuffers.h is not warning clean
92# We can't change compilation flags on header files directly, so we need to add them to an interface library first
93add_library(flatbuffer_headers INTERFACE)
94target_include_directories(flatbuffer_headers INTERFACE $<BUILD_INTERFACE:${Flatbuffers_INCLUDE_DIR}>
95 $<INSTALL_INTERFACE:include/flatbuffer_headers>)
Finn Williams019840d2020-11-30 17:43:28 +000096target_compile_options(flatbuffer_headers INTERFACE -Wno-sign-conversion)
Finn Williams6f9f9902020-11-13 13:23:15 +000097
Finn Williamsbbbefec2020-11-25 14:32:42 +000098target_link_libraries(armnnDelegate PUBLIC flatbuffer_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +010099
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000100# Add libraries from armnn third-party libraries
101# Third-party header files are not warning clean
102# We can't change compilation flags on header files directly, so we need to add them to an interface library first
103add_library(thirdparty_headers INTERFACE)
104target_include_directories(thirdparty_headers INTERFACE $<BUILD_INTERFACE:${ARMNN_SOURCE_DIR}/third-party>
105 $<INSTALL_INTERFACE:include/thirdparty_headers>)
106
107target_compile_options(thirdparty_headers INTERFACE -Wno-old-style-cast)
108
Matthew Sloyanac001ee2021-02-03 10:43:04 +0000109set_target_properties(armnnDelegate PROPERTIES VERSION ${DELEGATE_LIB_VERSION} SOVERSION ${DELEGATE_LIB_SOVERSION})
110
Sadik Armagan4189cc52020-11-11 18:01:48 +0000111option(BUILD_UNIT_TESTS "Build unit tests" ON)
112if(BUILD_UNIT_TESTS)
113 set(armnnDelegate_unittest_sources)
114 list(APPEND armnnDelegate_unittest_sources
David Monahan0cf84422020-11-16 15:53:03 +0000115 src/test/ActivationTest.cpp
116 src/test/ActivationTestHelper.hpp
Sadik Armagandc032fc2021-01-19 17:24:21 +0000117 src/test/ArgMinMaxTest.cpp
118 src/test/ArgMinMaxTestHelper.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +0100119 src/test/ArmnnDelegateTest.cpp
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000120 src/test/BatchSpaceTest.cpp
121 src/test/BatchSpaceTestHelper.hpp
Sadik Armagan937565b2021-04-21 14:03:28 +0100122 src/test/CastTest.cpp
123 src/test/CastTestHelper.hpp
Sadik Armagan8b9858d2020-11-09 08:26:22 +0000124 src/test/ComparisonTest.cpp
125 src/test/ComparisonTestHelper.hpp
Matthew Sloyan91c41712020-11-13 09:47:35 +0000126 src/test/ControlTest.cpp
127 src/test/ControlTestHelper.hpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000128 src/test/Convolution2dTest.cpp
129 src/test/ConvolutionTestHelper.hpp
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000130 src/test/DelegateOptionsTest.cpp
131 src/test/DelegateOptionsTestHelper.hpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000132 src/test/DepthwiseConvolution2dTest.cpp
Sadik Armagan67e95f22020-10-29 16:14:54 +0000133 src/test/ElementwiseBinaryTest.cpp
134 src/test/ElementwiseBinaryTestHelper.hpp
Sadik Armagan0534e032020-10-27 17:30:18 +0000135 src/test/ElementwiseUnaryTest.cpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000136 src/test/ElementwiseUnaryTestHelper.hpp
Sadik Armagan29b49cf2021-02-22 18:09:07 +0000137 src/test/FillTest.cpp
138 src/test/FillTestHelper.hpp
Sadik Armagan6e36a642020-11-10 21:18:41 +0000139 src/test/FullyConnectedTest.cpp
140 src/test/FullyConnectedTestHelper.hpp
Teresa Charlin98427a12020-11-25 18:22:57 +0000141 src/test/GatherTest.cpp
142 src/test/GatherTestHelper.hpp
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000143 src/test/LogicalTest.cpp
144 src/test/LogicalTestHelper.hpp
Mike Kelly8ae17b32021-02-17 13:45:50 +0000145 src/test/LstmTest.cpp
146 src/test/LstmTestHelper.hpp
Sadik Armagan4b227bb2021-01-22 10:53:38 +0000147 src/test/NormalizationTest.cpp
148 src/test/NormalizationTestHelper.hpp
Matthew Sloyana7a12f52021-05-06 10:05:28 +0100149 src/test/PackTest.cpp
150 src/test/PackTestHelper.hpp
Narumol Prangnawarat958024b2020-12-17 12:17:58 +0000151 src/test/PadTest.cpp
152 src/test/PadTestHelper.hpp
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000153 src/test/Pooling2dTest.cpp
154 src/test/Pooling2dTestHelper.hpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000155 src/test/QuantizationTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000156 src/test/QuantizationTestHelper.hpp
David Monahan1670b0c2020-11-18 14:40:27 +0000157 src/test/RedefineTestHelper.hpp
Sadik Armagana2747482021-02-09 10:28:54 +0000158 src/test/ReduceTest.cpp
159 src/test/ReduceTestHelper.hpp
David Monahan1670b0c2020-11-18 14:40:27 +0000160 src/test/ReshapeTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000161 src/test/ResizeTest.cpp
162 src/test/ResizeTestHelper.hpp
Sadik Armagan788e2c62021-02-10 16:26:44 +0000163 src/test/RoundTest.cpp
164 src/test/RoundTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000165 src/test/SoftmaxTest.cpp
166 src/test/SoftmaxTestHelper.hpp
Sadik Armagan89c5a9e2021-01-20 17:48:07 +0000167 src/test/SpaceDepthTest.cpp
168 src/test/SpaceDepthTestHelper.hpp
Jan Eilers2ffddda2021-02-03 09:14:30 +0000169 src/test/SliceTest.cpp
170 src/test/SliceTestHelper.hpp
Sadik Armagan34fa1bd2020-11-27 12:40:52 +0000171 src/test/SplitTest.cpp
172 src/test/SplitTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000173 src/test/TestUtils.hpp
Jan Eilers3812fbc2020-11-17 19:06:35 +0000174 src/test/TestUtils.cpp
James Wardf89964e2020-11-09 11:57:47 +0000175 src/test/TransposeTest.cpp
James Warda8578102020-11-13 18:05:04 +0000176 src/test/TransposeTestHelper.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100177
Keith Davis7c67fab2021-04-08 11:47:23 +0100178 # There's a known Android NDK bug which causes a subset of NeonLayerTests to
179 # fail. We'll exclude these tests in NeonLayerTests_NDK_Bug.cpp if we're doing
180 # a debug build and NDK is less than r21.
181 # https://github.com/android/ndk/issues/1135
182
183 # Default to always including these tests.
184 set(INCLUDE_NDK_BUG_TESTS "ON")
185 # Reconsider if we in a debug build.
186 string( TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE_LOWERCASE )
187 if ( NOT BUILD_TYPE_LOWERCASE STREQUAL "release" )
188 message("CMAKE:: BUILD TYPE IS ${CMAKE_BUILD_TYPE}")
189 # And NDK_VERSION has been set.
190 if ( DEFINED NDK_VERSION )
191 message("CMAKE:: NDK DEFINED")
192 # And the version is less than r21.
193 if ( ${NDK_VERSION} STRLESS "r21" )
194 message("CMAKE:: BUG TESTS OFF")
195 set(INCLUDE_NDK_BUG_TESTS "OFF")
196 endif()
197 endif()
198 endif()
199
200 if ( INCLUDE_NDK_BUG_TESTS STREQUAL "ON" )
201 list(APPEND armnnDelegate_unittest_sources
202 src/test/NeonDelegateTests_NDK_Issue.cpp
203 )
204 else()
205
206 endif()
207
Sadik Armagan4189cc52020-11-11 18:01:48 +0000208 add_executable(DelegateUnitTests ${armnnDelegate_unittest_sources})
Sadik Armagan3c24f432020-10-19 17:35:30 +0100209
Sadik Armagan4189cc52020-11-11 18:01:48 +0000210 # Add half library from armnn third-party libraries
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000211 target_link_libraries(DelegateUnitTests PRIVATE thirdparty_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100212
Finn Williamsbbbefec2020-11-25 14:32:42 +0000213 target_link_libraries(DelegateUnitTests PRIVATE armnnDelegate)
214 target_link_libraries(DelegateUnitTests PRIVATE Armnn::armnnUtils)
Sadik Armagan4189cc52020-11-11 18:01:48 +0000215
Finn Williamsbbbefec2020-11-25 14:32:42 +0000216 target_link_libraries(DelegateUnitTests PRIVATE tflite_headers)
217 target_link_libraries(DelegateUnitTests PRIVATE flatbuffer_headers)
Finn Williams6f9f9902020-11-13 13:23:15 +0000218
Sadik Armagan4189cc52020-11-11 18:01:48 +0000219endif()
Sadik Armagan3c24f432020-10-19 17:35:30 +0100220
221####################################################
222## Export targets
223set(armnn_delegate_export_targets)
224list(APPEND armnn_delegate_export_targets
Finn Williams6f9f9902020-11-13 13:23:15 +0000225 armnnDelegate
226 tflite_headers
227 flatbuffer_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100228
229install(
230 TARGETS ${armnn_delegate_export_targets}
231 EXPORT armnn-delegate-targets
232 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
233 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
234 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
235
236## Set export alias
237set_target_properties(armnnDelegate
238 PROPERTIES
239 EXPORT_NAME ArmnnDelegate)
240
241## Export target scrips
242install(
243 EXPORT armnn-delegate-targets
244 FILE ArmnnDelegateTargets.cmake
245 NAMESPACE ArmnnDelegate::
246 DESTINATION ${CMAKE_INSTALL_LIBDIR})
247
248## Create ArmnnDelegateConfig.cmake
249include(CMakePackageConfigHelpers)
250set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR})
251message(STATUS "CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}" )
252message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}" )
Finn Williamsbbbefec2020-11-25 14:32:42 +0000253SET(Armnn_DIR "${Armnn_DIR}")
254
Sadik Armagan3c24f432020-10-19 17:35:30 +0100255configure_package_config_file(
256 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/ArmnnDelegateConfig.cmake.in
257 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
Finn Williamsbbbefec2020-11-25 14:32:42 +0000258 INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
259 PATH_VARS Armnn_DIR)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100260
261## Install ArmNN Delegate config file
262install(
263 FILES
264 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
265 DESTINATION ${INSTALL_CONFIGDIR})
266
267## Export from build tree
268export(
269 EXPORT armnn-delegate-targets
270 FILE ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateTargets.cmake
271 NAMESPACE ArmnnDelegate::)
Sadik Armagan5d03e312020-11-17 16:43:56 +0000272add_library(ArmnnDelegate::ArmnnDelegate ALIAS armnnDelegate)
273
Sadik Armagan3c24f432020-10-19 17:35:30 +0100274
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000275####################################################