blob: 83837226289d6fd41140db24bd3bbac3daf6e4be [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
17 src/armnn_delegate.cpp
Sadik Armagan62483be2020-10-23 17:14:43 +010018 src/DelegateOptions.cpp
19 src/Activation.hpp
20 src/ArgMinMax.hpp
21 src/BatchSpace.hpp
22 src/Comparison.hpp
23 src/Convolution.hpp
24 src/Control.hpp
25 src/DelegateUtils.hpp
26 src/ElementwiseBinary.hpp
27 src/ElementwiseUnary.hpp
28 src/Fill.hpp
29 src/FullyConnected.hpp
30 src/Gather.hpp
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000031 src/LogicalBinary.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010032 src/Lstm.hpp
33 src/Normalization.hpp
34 src/Pad.hpp
35 src/Pooling.hpp
36 src/Quantization.hpp
37 src/Redefine.hpp
38 src/Resize.hpp
39 src/Round.hpp
40 src/Slice.hpp
41 src/Softmax.hpp
42 src/SpaceDepth.hpp
Sadik Armagan34fa1bd2020-11-27 12:40:52 +000043 src/Split.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010044 src/Transpose.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +010045
46add_library(armnnDelegate SHARED ${armnnDelegate_sources})
47
48target_include_directories(armnnDelegate
49 PUBLIC
50 $<INSTALL_INTERFACE:include>
51 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
52 PRIVATE
53 ${CMAKE_CURRENT_SOURCE_DIR}/src)
54
55include(GNUInstallDirs)
56
57## Add Armnn as a Dependency
Finn Williamsbbbefec2020-11-25 14:32:42 +000058if(NOT ARMNN_SUB_PROJECT)
59 find_package(Armnn REQUIRED CONFIG HINTS ${Armnn_DIR})
60endif()
61target_link_libraries(armnnDelegate PUBLIC Armnn::Armnn)
Sadik Armagan3c24f432020-10-19 17:35:30 +010062
63## Add TfLite v2.3.1 dependency
64find_package(TfLite REQUIRED MODULE)
65
Finn Williamsbbbefec2020-11-25 14:32:42 +000066target_link_libraries(armnnDelegate PUBLIC ${TfLite_LIB})
Sadik Armagan3c24f432020-10-19 17:35:30 +010067
Finn Williams6f9f9902020-11-13 13:23:15 +000068# Various tflite header files are not warning clean
69# We can't change compilation flags on header files directly, so we need to add them to an interface library first
70add_library(tflite_headers INTERFACE)
71target_include_directories(tflite_headers INTERFACE $<BUILD_INTERFACE:${TfLite_INCLUDE_DIR}>
72 $<INSTALL_INTERFACE:include/tflite_headers>)
73
Finn Williams019840d2020-11-30 17:43:28 +000074target_compile_options(tflite_headers INTERFACE -Wno-conversion
75 -Wno-sign-conversion
76 -Wno-unused-parameter
77 -Wno-unused-function)
Finn Williams6f9f9902020-11-13 13:23:15 +000078
Finn Williamsbbbefec2020-11-25 14:32:42 +000079target_link_libraries(armnnDelegate PUBLIC tflite_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +010080
Sadik Armagan3c24f432020-10-19 17:35:30 +010081## Add Flatbuffers dependency
82find_package(Flatbuffers REQUIRED MODULE)
83
Finn Williamsbbbefec2020-11-25 14:32:42 +000084target_link_libraries(armnnDelegate PRIVATE
Sadik Armagan3c24f432020-10-19 17:35:30 +010085 ${Flatbuffers_LIB})
86
Finn Williams6f9f9902020-11-13 13:23:15 +000087# include/flatbuffers/flatbuffers.h is not warning clean
88# We can't change compilation flags on header files directly, so we need to add them to an interface library first
89add_library(flatbuffer_headers INTERFACE)
90target_include_directories(flatbuffer_headers INTERFACE $<BUILD_INTERFACE:${Flatbuffers_INCLUDE_DIR}>
91 $<INSTALL_INTERFACE:include/flatbuffer_headers>)
Finn Williams019840d2020-11-30 17:43:28 +000092target_compile_options(flatbuffer_headers INTERFACE -Wno-sign-conversion)
Finn Williams6f9f9902020-11-13 13:23:15 +000093
Finn Williamsbbbefec2020-11-25 14:32:42 +000094target_link_libraries(armnnDelegate PUBLIC flatbuffer_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +010095
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +000096# Add libraries from armnn third-party libraries
97# Third-party header files are not warning clean
98# We can't change compilation flags on header files directly, so we need to add them to an interface library first
99add_library(thirdparty_headers INTERFACE)
100target_include_directories(thirdparty_headers INTERFACE $<BUILD_INTERFACE:${ARMNN_SOURCE_DIR}/third-party>
101 $<INSTALL_INTERFACE:include/thirdparty_headers>)
102
103target_compile_options(thirdparty_headers INTERFACE -Wno-old-style-cast)
104
Sadik Armagan4189cc52020-11-11 18:01:48 +0000105option(BUILD_UNIT_TESTS "Build unit tests" ON)
106if(BUILD_UNIT_TESTS)
107 set(armnnDelegate_unittest_sources)
108 list(APPEND armnnDelegate_unittest_sources
David Monahan0cf84422020-11-16 15:53:03 +0000109 src/test/ActivationTest.cpp
110 src/test/ActivationTestHelper.hpp
Sadik Armagandc032fc2021-01-19 17:24:21 +0000111 src/test/ArgMinMaxTest.cpp
112 src/test/ArgMinMaxTestHelper.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +0100113 src/test/ArmnnDelegateTest.cpp
Sadik Armagan8b9858d2020-11-09 08:26:22 +0000114 src/test/ComparisonTest.cpp
115 src/test/ComparisonTestHelper.hpp
Matthew Sloyan91c41712020-11-13 09:47:35 +0000116 src/test/ControlTest.cpp
117 src/test/ControlTestHelper.hpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000118 src/test/Convolution2dTest.cpp
119 src/test/ConvolutionTestHelper.hpp
120 src/test/DepthwiseConvolution2dTest.cpp
Sadik Armagan67e95f22020-10-29 16:14:54 +0000121 src/test/ElementwiseBinaryTest.cpp
122 src/test/ElementwiseBinaryTestHelper.hpp
Sadik Armagan0534e032020-10-27 17:30:18 +0000123 src/test/ElementwiseUnaryTest.cpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000124 src/test/ElementwiseUnaryTestHelper.hpp
Sadik Armagan6e36a642020-11-10 21:18:41 +0000125 src/test/FullyConnectedTest.cpp
126 src/test/FullyConnectedTestHelper.hpp
Teresa Charlin98427a12020-11-25 18:22:57 +0000127 src/test/GatherTest.cpp
128 src/test/GatherTestHelper.hpp
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000129 src/test/LogicalTest.cpp
130 src/test/LogicalTestHelper.hpp
Narumol Prangnawarat958024b2020-12-17 12:17:58 +0000131 src/test/PadTest.cpp
132 src/test/PadTestHelper.hpp
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000133 src/test/Pooling2dTest.cpp
134 src/test/Pooling2dTestHelper.hpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000135 src/test/QuantizationTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000136 src/test/QuantizationTestHelper.hpp
David Monahan1670b0c2020-11-18 14:40:27 +0000137 src/test/RedefineTestHelper.hpp
138 src/test/ReshapeTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000139 src/test/ResizeTest.cpp
140 src/test/ResizeTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000141 src/test/SoftmaxTest.cpp
142 src/test/SoftmaxTestHelper.hpp
Sadik Armagan34fa1bd2020-11-27 12:40:52 +0000143 src/test/SplitTest.cpp
144 src/test/SplitTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000145 src/test/TestUtils.hpp
Jan Eilers3812fbc2020-11-17 19:06:35 +0000146 src/test/TestUtils.cpp
James Wardf89964e2020-11-09 11:57:47 +0000147 src/test/TransposeTest.cpp
James Warda8578102020-11-13 18:05:04 +0000148 src/test/TransposeTestHelper.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100149
Sadik Armagan4189cc52020-11-11 18:01:48 +0000150 add_executable(DelegateUnitTests ${armnnDelegate_unittest_sources})
151 target_include_directories(DelegateUnitTests PRIVATE third-party)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100152
Sadik Armagan4189cc52020-11-11 18:01:48 +0000153 # Add half library from armnn third-party libraries
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000154 target_link_libraries(DelegateUnitTests PRIVATE thirdparty_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100155
Finn Williamsbbbefec2020-11-25 14:32:42 +0000156 target_link_libraries(DelegateUnitTests PRIVATE armnnDelegate)
157 target_link_libraries(DelegateUnitTests PRIVATE Armnn::armnnUtils)
Sadik Armagan4189cc52020-11-11 18:01:48 +0000158
Finn Williamsbbbefec2020-11-25 14:32:42 +0000159 target_link_libraries(DelegateUnitTests PRIVATE tflite_headers)
160 target_link_libraries(DelegateUnitTests PRIVATE flatbuffer_headers)
Finn Williams6f9f9902020-11-13 13:23:15 +0000161
Sadik Armagan4189cc52020-11-11 18:01:48 +0000162endif()
Sadik Armagan3c24f432020-10-19 17:35:30 +0100163
164####################################################
165## Export targets
166set(armnn_delegate_export_targets)
167list(APPEND armnn_delegate_export_targets
Finn Williams6f9f9902020-11-13 13:23:15 +0000168 armnnDelegate
169 tflite_headers
170 flatbuffer_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100171
172install(
173 TARGETS ${armnn_delegate_export_targets}
174 EXPORT armnn-delegate-targets
175 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
176 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
177 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
178
179## Set export alias
180set_target_properties(armnnDelegate
181 PROPERTIES
182 EXPORT_NAME ArmnnDelegate)
183
184## Export target scrips
185install(
186 EXPORT armnn-delegate-targets
187 FILE ArmnnDelegateTargets.cmake
188 NAMESPACE ArmnnDelegate::
189 DESTINATION ${CMAKE_INSTALL_LIBDIR})
190
191## Create ArmnnDelegateConfig.cmake
192include(CMakePackageConfigHelpers)
193set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR})
194message(STATUS "CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}" )
195message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}" )
Finn Williamsbbbefec2020-11-25 14:32:42 +0000196SET(Armnn_DIR "${Armnn_DIR}")
197
Sadik Armagan3c24f432020-10-19 17:35:30 +0100198configure_package_config_file(
199 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/ArmnnDelegateConfig.cmake.in
200 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
Finn Williamsbbbefec2020-11-25 14:32:42 +0000201 INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
202 PATH_VARS Armnn_DIR)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100203
204## Install ArmNN Delegate config file
205install(
206 FILES
207 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
208 DESTINATION ${INSTALL_CONFIGDIR})
209
210## Export from build tree
211export(
212 EXPORT armnn-delegate-targets
213 FILE ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateTargets.cmake
214 NAMESPACE ArmnnDelegate::)
Sadik Armagan5d03e312020-11-17 16:43:56 +0000215add_library(ArmnnDelegate::ArmnnDelegate ALIAS armnnDelegate)
216
Sadik Armagan3c24f432020-10-19 17:35:30 +0100217
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000218####################################################