blob: 38f7bd10e1aceed223903f939ce5187c159ce127 [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
11set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
12
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
31 src/Lstm.hpp
32 src/Normalization.hpp
33 src/Pad.hpp
34 src/Pooling.hpp
35 src/Quantization.hpp
36 src/Redefine.hpp
37 src/Resize.hpp
38 src/Round.hpp
39 src/Slice.hpp
40 src/Softmax.hpp
41 src/SpaceDepth.hpp
42 src/Transpose.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +010043
44add_library(armnnDelegate SHARED ${armnnDelegate_sources})
45
46target_include_directories(armnnDelegate
47 PUBLIC
48 $<INSTALL_INTERFACE:include>
49 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
50 PRIVATE
51 ${CMAKE_CURRENT_SOURCE_DIR}/src)
52
53include(GNUInstallDirs)
54
55## Add Armnn as a Dependency
56find_package(Armnn REQUIRED)
57target_link_libraries(armnnDelegate Armnn::Armnn)
58
59## Add Tensorflow v2.3.1 dependency
60find_package(Tensorflow 2.3.1 REQUIRED MODULE)
61
62target_link_libraries(armnnDelegate
63 ${Tensorflow_LIB})
64
65target_include_directories(armnnDelegate
66 PRIVATE
67 ${Tensorflow_INCLUDE_DIR})
68
69## Add TfLite v2.3.1 dependency
70find_package(TfLite REQUIRED MODULE)
71
72target_link_libraries(armnnDelegate
73 ${TfLite_LIB})
74
Finn Williams6f9f9902020-11-13 13:23:15 +000075# Various tflite header files are not warning clean
76# We can't change compilation flags on header files directly, so we need to add them to an interface library first
77add_library(tflite_headers INTERFACE)
78target_include_directories(tflite_headers INTERFACE $<BUILD_INTERFACE:${TfLite_INCLUDE_DIR}>
79 $<INSTALL_INTERFACE:include/tflite_headers>)
80
81target_compile_options(tflite_headers INTERFACE $<$<CXX_COMPILER_ID:GNU>:-Wno-conversion
82 -Wno-sign-conversion
83 -Wno-unused-parameter
84 -Wno-unused-function>)
85
86target_link_libraries(armnnDelegate tflite_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +010087
Sadik Armagan3c24f432020-10-19 17:35:30 +010088## Add Flatbuffers dependency
89find_package(Flatbuffers REQUIRED MODULE)
90
91target_link_libraries(armnnDelegate
92 ${Flatbuffers_LIB})
93
Finn Williams6f9f9902020-11-13 13:23:15 +000094# include/flatbuffers/flatbuffers.h is not warning clean
95# We can't change compilation flags on header files directly, so we need to add them to an interface library first
96add_library(flatbuffer_headers INTERFACE)
97target_include_directories(flatbuffer_headers INTERFACE $<BUILD_INTERFACE:${Flatbuffers_INCLUDE_DIR}>
98 $<INSTALL_INTERFACE:include/flatbuffer_headers>)
99target_compile_options(flatbuffer_headers INTERFACE $<$<CXX_COMPILER_ID:GNU>:-Wno-sign-conversion>)
100
101target_link_libraries(armnnDelegate flatbuffer_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100102
Sadik Armagan4189cc52020-11-11 18:01:48 +0000103option(BUILD_UNIT_TESTS "Build unit tests" ON)
104if(BUILD_UNIT_TESTS)
105 set(armnnDelegate_unittest_sources)
106 list(APPEND armnnDelegate_unittest_sources
David Monahan0cf84422020-11-16 15:53:03 +0000107 src/test/ActivationTest.cpp
108 src/test/ActivationTestHelper.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +0100109 src/test/ArmnnDelegateTest.cpp
Sadik Armagan8b9858d2020-11-09 08:26:22 +0000110 src/test/ComparisonTest.cpp
111 src/test/ComparisonTestHelper.hpp
Matthew Sloyan91c41712020-11-13 09:47:35 +0000112 src/test/ControlTest.cpp
113 src/test/ControlTestHelper.hpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000114 src/test/Convolution2dTest.cpp
115 src/test/ConvolutionTestHelper.hpp
116 src/test/DepthwiseConvolution2dTest.cpp
Sadik Armagan67e95f22020-10-29 16:14:54 +0000117 src/test/ElementwiseBinaryTest.cpp
118 src/test/ElementwiseBinaryTestHelper.hpp
Sadik Armagan0534e032020-10-27 17:30:18 +0000119 src/test/ElementwiseUnaryTest.cpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000120 src/test/ElementwiseUnaryTestHelper.hpp
Sadik Armagan6e36a642020-11-10 21:18:41 +0000121 src/test/FullyConnectedTest.cpp
122 src/test/FullyConnectedTestHelper.hpp
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000123 src/test/Pooling2dTest.cpp
124 src/test/Pooling2dTestHelper.hpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000125 src/test/QuantizationTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000126 src/test/QuantizationTestHelper.hpp
David Monahan1670b0c2020-11-18 14:40:27 +0000127 src/test/RedefineTestHelper.hpp
128 src/test/ReshapeTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000129 src/test/ResizeTest.cpp
130 src/test/ResizeTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000131 src/test/SoftmaxTest.cpp
132 src/test/SoftmaxTestHelper.hpp
133 src/test/TestUtils.hpp
Jan Eilers3812fbc2020-11-17 19:06:35 +0000134 src/test/TestUtils.cpp
James Wardf89964e2020-11-09 11:57:47 +0000135 src/test/TransposeTest.cpp
James Warda8578102020-11-13 18:05:04 +0000136 src/test/TransposeTestHelper.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100137
Sadik Armagan4189cc52020-11-11 18:01:48 +0000138 add_executable(DelegateUnitTests ${armnnDelegate_unittest_sources})
139 target_include_directories(DelegateUnitTests PRIVATE third-party)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100140
Sadik Armagan4189cc52020-11-11 18:01:48 +0000141 # Add half library from armnn third-party libraries
142 target_include_directories(DelegateUnitTests PRIVATE ${ARMNN_SOURCE_DIR}/third-party)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100143
Sadik Armagan4189cc52020-11-11 18:01:48 +0000144 target_link_libraries(DelegateUnitTests armnnDelegate)
145 target_link_libraries(DelegateUnitTests Armnn::armnnUtils)
146
Finn Williams6f9f9902020-11-13 13:23:15 +0000147target_link_libraries(DelegateUnitTests tflite_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100148
Finn Williams6f9f9902020-11-13 13:23:15 +0000149target_link_libraries(DelegateUnitTests flatbuffer_headers)
150
Sadik Armagan4189cc52020-11-11 18:01:48 +0000151endif()
Sadik Armagan3c24f432020-10-19 17:35:30 +0100152
153####################################################
154## Export targets
155set(armnn_delegate_export_targets)
156list(APPEND armnn_delegate_export_targets
Finn Williams6f9f9902020-11-13 13:23:15 +0000157 armnnDelegate
158 tflite_headers
159 flatbuffer_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100160
161install(
162 TARGETS ${armnn_delegate_export_targets}
163 EXPORT armnn-delegate-targets
164 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
165 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
166 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
167
168## Set export alias
169set_target_properties(armnnDelegate
170 PROPERTIES
171 EXPORT_NAME ArmnnDelegate)
172
173## Export target scrips
174install(
175 EXPORT armnn-delegate-targets
176 FILE ArmnnDelegateTargets.cmake
177 NAMESPACE ArmnnDelegate::
178 DESTINATION ${CMAKE_INSTALL_LIBDIR})
179
180## Create ArmnnDelegateConfig.cmake
181include(CMakePackageConfigHelpers)
182set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR})
183message(STATUS "CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}" )
184message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}" )
185configure_package_config_file(
186 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/ArmnnDelegateConfig.cmake.in
187 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
188 INSTALL_DESTINATION ${INSTALL_CONFIGDIR})
189
190## Install ArmNN Delegate config file
191install(
192 FILES
193 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
194 DESTINATION ${INSTALL_CONFIGDIR})
195
196## Export from build tree
197export(
198 EXPORT armnn-delegate-targets
199 FILE ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateTargets.cmake
200 NAMESPACE ArmnnDelegate::)
Sadik Armagan5d03e312020-11-17 16:43:56 +0000201add_library(ArmnnDelegate::ArmnnDelegate ALIAS armnnDelegate)
202
Sadik Armagan3c24f432020-10-19 17:35:30 +0100203
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000204####################################################