blob: eda5b935e325ab45da7080567244bc4c6b2304d4 [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
Jan Eilers2cd18472020-12-15 10:42:38 +000018 src/armnn_external_delegate.cpp
Sadik Armagan62483be2020-10-23 17:14:43 +010019 src/DelegateOptions.cpp
20 src/Activation.hpp
21 src/ArgMinMax.hpp
22 src/BatchSpace.hpp
23 src/Comparison.hpp
24 src/Convolution.hpp
25 src/Control.hpp
26 src/DelegateUtils.hpp
27 src/ElementwiseBinary.hpp
28 src/ElementwiseUnary.hpp
29 src/Fill.hpp
30 src/FullyConnected.hpp
31 src/Gather.hpp
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000032 src/LogicalBinary.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010033 src/Lstm.hpp
34 src/Normalization.hpp
35 src/Pad.hpp
36 src/Pooling.hpp
37 src/Quantization.hpp
38 src/Redefine.hpp
39 src/Resize.hpp
40 src/Round.hpp
41 src/Slice.hpp
42 src/Softmax.hpp
43 src/SpaceDepth.hpp
Sadik Armagan34fa1bd2020-11-27 12:40:52 +000044 src/Split.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010045 src/Transpose.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +010046
47add_library(armnnDelegate SHARED ${armnnDelegate_sources})
48
49target_include_directories(armnnDelegate
50 PUBLIC
51 $<INSTALL_INTERFACE:include>
52 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
53 PRIVATE
54 ${CMAKE_CURRENT_SOURCE_DIR}/src)
55
56include(GNUInstallDirs)
57
58## Add Armnn as a Dependency
Finn Williamsbbbefec2020-11-25 14:32:42 +000059if(NOT ARMNN_SUB_PROJECT)
60 find_package(Armnn REQUIRED CONFIG HINTS ${Armnn_DIR})
61endif()
62target_link_libraries(armnnDelegate PUBLIC Armnn::Armnn)
Sadik Armagan3c24f432020-10-19 17:35:30 +010063
64## Add TfLite v2.3.1 dependency
65find_package(TfLite REQUIRED MODULE)
66
Finn Williamsbbbefec2020-11-25 14:32:42 +000067target_link_libraries(armnnDelegate PUBLIC ${TfLite_LIB})
Sadik Armagan3c24f432020-10-19 17:35:30 +010068
Finn Williams6f9f9902020-11-13 13:23:15 +000069# Various tflite header files are not warning clean
70# We can't change compilation flags on header files directly, so we need to add them to an interface library first
71add_library(tflite_headers INTERFACE)
72target_include_directories(tflite_headers INTERFACE $<BUILD_INTERFACE:${TfLite_INCLUDE_DIR}>
73 $<INSTALL_INTERFACE:include/tflite_headers>)
74
Finn Williams019840d2020-11-30 17:43:28 +000075target_compile_options(tflite_headers INTERFACE -Wno-conversion
76 -Wno-sign-conversion
77 -Wno-unused-parameter
78 -Wno-unused-function)
Finn Williams6f9f9902020-11-13 13:23:15 +000079
Finn Williamsbbbefec2020-11-25 14:32:42 +000080target_link_libraries(armnnDelegate PUBLIC tflite_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +010081
Sadik Armagan3c24f432020-10-19 17:35:30 +010082## Add Flatbuffers dependency
83find_package(Flatbuffers REQUIRED MODULE)
84
Finn Williamsbbbefec2020-11-25 14:32:42 +000085target_link_libraries(armnnDelegate PRIVATE
Sadik Armagan3c24f432020-10-19 17:35:30 +010086 ${Flatbuffers_LIB})
87
Finn Williams6f9f9902020-11-13 13:23:15 +000088# include/flatbuffers/flatbuffers.h is not warning clean
89# We can't change compilation flags on header files directly, so we need to add them to an interface library first
90add_library(flatbuffer_headers INTERFACE)
91target_include_directories(flatbuffer_headers INTERFACE $<BUILD_INTERFACE:${Flatbuffers_INCLUDE_DIR}>
92 $<INSTALL_INTERFACE:include/flatbuffer_headers>)
Finn Williams019840d2020-11-30 17:43:28 +000093target_compile_options(flatbuffer_headers INTERFACE -Wno-sign-conversion)
Finn Williams6f9f9902020-11-13 13:23:15 +000094
Finn Williamsbbbefec2020-11-25 14:32:42 +000095target_link_libraries(armnnDelegate PUBLIC flatbuffer_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +010096
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +000097# Add libraries from armnn third-party libraries
98# Third-party header files are not warning clean
99# We can't change compilation flags on header files directly, so we need to add them to an interface library first
100add_library(thirdparty_headers INTERFACE)
101target_include_directories(thirdparty_headers INTERFACE $<BUILD_INTERFACE:${ARMNN_SOURCE_DIR}/third-party>
102 $<INSTALL_INTERFACE:include/thirdparty_headers>)
103
104target_compile_options(thirdparty_headers INTERFACE -Wno-old-style-cast)
105
Sadik Armagan4189cc52020-11-11 18:01:48 +0000106option(BUILD_UNIT_TESTS "Build unit tests" ON)
107if(BUILD_UNIT_TESTS)
108 set(armnnDelegate_unittest_sources)
109 list(APPEND armnnDelegate_unittest_sources
David Monahan0cf84422020-11-16 15:53:03 +0000110 src/test/ActivationTest.cpp
111 src/test/ActivationTestHelper.hpp
Sadik Armagandc032fc2021-01-19 17:24:21 +0000112 src/test/ArgMinMaxTest.cpp
113 src/test/ArgMinMaxTestHelper.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +0100114 src/test/ArmnnDelegateTest.cpp
Sadik Armagan8b9858d2020-11-09 08:26:22 +0000115 src/test/ComparisonTest.cpp
116 src/test/ComparisonTestHelper.hpp
Matthew Sloyan91c41712020-11-13 09:47:35 +0000117 src/test/ControlTest.cpp
118 src/test/ControlTestHelper.hpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000119 src/test/Convolution2dTest.cpp
120 src/test/ConvolutionTestHelper.hpp
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000121 src/test/DelegateOptionsTest.cpp
122 src/test/DelegateOptionsTestHelper.hpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000123 src/test/DepthwiseConvolution2dTest.cpp
Sadik Armagan67e95f22020-10-29 16:14:54 +0000124 src/test/ElementwiseBinaryTest.cpp
125 src/test/ElementwiseBinaryTestHelper.hpp
Sadik Armagan0534e032020-10-27 17:30:18 +0000126 src/test/ElementwiseUnaryTest.cpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000127 src/test/ElementwiseUnaryTestHelper.hpp
Sadik Armagan6e36a642020-11-10 21:18:41 +0000128 src/test/FullyConnectedTest.cpp
129 src/test/FullyConnectedTestHelper.hpp
Teresa Charlin98427a12020-11-25 18:22:57 +0000130 src/test/GatherTest.cpp
131 src/test/GatherTestHelper.hpp
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000132 src/test/LogicalTest.cpp
133 src/test/LogicalTestHelper.hpp
Sadik Armagan4b227bb2021-01-22 10:53:38 +0000134 src/test/NormalizationTest.cpp
135 src/test/NormalizationTestHelper.hpp
Narumol Prangnawarat958024b2020-12-17 12:17:58 +0000136 src/test/PadTest.cpp
137 src/test/PadTestHelper.hpp
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000138 src/test/Pooling2dTest.cpp
139 src/test/Pooling2dTestHelper.hpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000140 src/test/QuantizationTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000141 src/test/QuantizationTestHelper.hpp
David Monahan1670b0c2020-11-18 14:40:27 +0000142 src/test/RedefineTestHelper.hpp
143 src/test/ReshapeTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000144 src/test/ResizeTest.cpp
145 src/test/ResizeTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000146 src/test/SoftmaxTest.cpp
147 src/test/SoftmaxTestHelper.hpp
Sadik Armagan89c5a9e2021-01-20 17:48:07 +0000148 src/test/SpaceDepthTest.cpp
149 src/test/SpaceDepthTestHelper.hpp
Sadik Armagan34fa1bd2020-11-27 12:40:52 +0000150 src/test/SplitTest.cpp
151 src/test/SplitTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000152 src/test/TestUtils.hpp
Jan Eilers3812fbc2020-11-17 19:06:35 +0000153 src/test/TestUtils.cpp
James Wardf89964e2020-11-09 11:57:47 +0000154 src/test/TransposeTest.cpp
James Warda8578102020-11-13 18:05:04 +0000155 src/test/TransposeTestHelper.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100156
Sadik Armagan4189cc52020-11-11 18:01:48 +0000157 add_executable(DelegateUnitTests ${armnnDelegate_unittest_sources})
158 target_include_directories(DelegateUnitTests PRIVATE third-party)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100159
Sadik Armagan4189cc52020-11-11 18:01:48 +0000160 # Add half library from armnn third-party libraries
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000161 target_link_libraries(DelegateUnitTests PRIVATE thirdparty_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100162
Finn Williamsbbbefec2020-11-25 14:32:42 +0000163 target_link_libraries(DelegateUnitTests PRIVATE armnnDelegate)
164 target_link_libraries(DelegateUnitTests PRIVATE Armnn::armnnUtils)
Sadik Armagan4189cc52020-11-11 18:01:48 +0000165
Finn Williamsbbbefec2020-11-25 14:32:42 +0000166 target_link_libraries(DelegateUnitTests PRIVATE tflite_headers)
167 target_link_libraries(DelegateUnitTests PRIVATE flatbuffer_headers)
Finn Williams6f9f9902020-11-13 13:23:15 +0000168
Sadik Armagan4189cc52020-11-11 18:01:48 +0000169endif()
Sadik Armagan3c24f432020-10-19 17:35:30 +0100170
171####################################################
172## Export targets
173set(armnn_delegate_export_targets)
174list(APPEND armnn_delegate_export_targets
Finn Williams6f9f9902020-11-13 13:23:15 +0000175 armnnDelegate
176 tflite_headers
177 flatbuffer_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100178
179install(
180 TARGETS ${armnn_delegate_export_targets}
181 EXPORT armnn-delegate-targets
182 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
183 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
184 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
185
186## Set export alias
187set_target_properties(armnnDelegate
188 PROPERTIES
189 EXPORT_NAME ArmnnDelegate)
190
191## Export target scrips
192install(
193 EXPORT armnn-delegate-targets
194 FILE ArmnnDelegateTargets.cmake
195 NAMESPACE ArmnnDelegate::
196 DESTINATION ${CMAKE_INSTALL_LIBDIR})
197
198## Create ArmnnDelegateConfig.cmake
199include(CMakePackageConfigHelpers)
200set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR})
201message(STATUS "CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}" )
202message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}" )
Finn Williamsbbbefec2020-11-25 14:32:42 +0000203SET(Armnn_DIR "${Armnn_DIR}")
204
Sadik Armagan3c24f432020-10-19 17:35:30 +0100205configure_package_config_file(
206 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/ArmnnDelegateConfig.cmake.in
207 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
Finn Williamsbbbefec2020-11-25 14:32:42 +0000208 INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
209 PATH_VARS Armnn_DIR)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100210
211## Install ArmNN Delegate config file
212install(
213 FILES
214 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
215 DESTINATION ${INSTALL_CONFIGDIR})
216
217## Export from build tree
218export(
219 EXPORT armnn-delegate-targets
220 FILE ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateTargets.cmake
221 NAMESPACE ArmnnDelegate::)
Sadik Armagan5d03e312020-11-17 16:43:56 +0000222add_library(ArmnnDelegate::ArmnnDelegate ALIAS armnnDelegate)
223
Sadik Armagan3c24f432020-10-19 17:35:30 +0100224
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000225####################################################