blob: 9137fa33d89f20ccdf485738e7f8c050be4b421a [file] [log] [blame]
Pavel Macenauer59e057f2020-04-15 14:17:26 +00001#
Cathal Corbett9c9d5b92022-08-17 17:30:16 +01002# Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
Pavel Macenauer59e057f2020-04-15 14:17:26 +00003# Copyright 2020 NXP
4# SPDX-License-Identifier: MIT
5#
Jim Flynn870b96c2022-03-25 21:24:56 +00006
telsoa01c577f2c2018-08-31 09:22:23 +01007option(BUILD_ONNX_PARSER "Build Onnx parser" OFF)
telsoa014fcda012018-03-09 14:13:49 +00008option(BUILD_UNIT_TESTS "Build unit tests" ON)
9option(BUILD_TESTS "Build test applications" OFF)
10option(BUILD_FOR_COVERAGE "Use no optimization and output .gcno and .gcda files" OFF)
11option(ARMCOMPUTENEON "Build with ARM Compute NEON support" OFF)
12option(ARMCOMPUTECL "Build with ARM Compute OpenCL support" OFF)
Matteo Martincighf88663c2019-08-28 16:38:53 +010013option(ARMNNREF "Build with ArmNN reference support" ON)
Cathal Corbett9c9d5b92022-08-17 17:30:16 +010014option(ARMNNTOSAREF "Build with Tosa reference support" OFF)
telsoa014fcda012018-03-09 14:13:49 +000015option(PROFILING_BACKEND_STREAMLINE "Forward the armNN profiling events to DS-5/Streamline as annotations" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010016# options used for heap profiling and leak checking
surmeh013537c2c2018-05-18 16:31:43 +010017option(HEAP_PROFILING "Build with heap profiling enabled" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010018option(LEAK_CHECKING "Build with leak checking enabled" OFF)
surmeh013537c2c2018-05-18 16:31:43 +010019option(GPERFTOOLS_ROOT "Location where the gperftools 'include' and 'lib' folders to be found" Off)
telsoa01c577f2c2018-08-31 09:22:23 +010020# options used for tensorflow lite support
21option(BUILD_TF_LITE_PARSER "Build Tensorflow Lite parser" OFF)
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +000022option(BUILD_ARMNN_SERIALIZER "Build Armnn Serializer" OFF)
Éanna Ó Catháina563b922019-05-09 11:34:06 +010023option(BUILD_ACCURACY_TOOL "Build Accuracy Tool" OFF)
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +000024option(FLATC_DIR "Path to Flatbuffers compiler" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010025option(TF_LITE_GENERATED_PATH "Tensorflow lite generated C++ schema location" OFF)
26option(FLATBUFFERS_ROOT "Location where the flatbuffers 'include' and 'lib' folders to be found" Off)
Cathal Corbett9c9d5b92022-08-17 17:30:16 +010027option(TOSA_SERIALIZATION_LIB_ROOT "Location where the TOSA serialization library 'include' and 'lib' folders can be found" OFF)
Matteo Martincighe7d44982019-08-05 12:16:47 +010028option(DYNAMIC_BACKEND_PATHS "Colon seperated list of paths where to load the dynamic backends from" "")
Colm Donelan0dbe00a2020-06-03 08:00:28 +010029option(SAMPLE_DYNAMIC_BACKEND "Include the sample dynamic backend and its tests in the build" OFF)
Colm Donelana21620d2019-10-11 13:09:49 +010030option(BUILD_GATORD_MOCK "Build the Gatord simulator for external profiling testing." ON)
Sadik Armagan6f86b692020-03-09 11:04:32 +000031option(BUILD_TIMELINE_DECODER "Build the Timeline Decoder for external profiling." ON)
Finn Williams2ed809c2020-04-20 21:21:07 +010032option(BUILD_BASE_PIPE_SERVER "Build the server to handle external profiling pipe traffic" ON)
Pavel Macenauer59e057f2020-04-15 14:17:26 +000033option(BUILD_PYTHON_WHL "Build Python wheel package" OFF)
34option(BUILD_PYTHON_SRC "Build Python source package" OFF)
Jim Flynnbbfe6032020-07-20 16:57:44 +010035option(BUILD_STATIC_PIPE_LIBS "Build Static PIPE libraries" OFF)
36option(BUILD_PIPE_ONLY "Build the PIPE libraries only" OFF)
Sadik Armagan5d03e312020-11-17 16:43:56 +000037option(BUILD_ARMNN_TFLITE_DELEGATE "Build the Arm NN TfLite delegate" OFF)
Jim Flynne1fdd282021-10-26 21:26:10 +010038option(BUILD_MEMORY_STRATEGY_BENCHMARK "Build the MemoryBenchmark" OFF)
Jim Flynn870b96c2022-03-25 21:24:56 +000039option(BUILD_BARE_METAL "Disable features requiring operating system support" OFF)
Jan Eilersa96489a2021-12-08 10:05:47 +000040option(BUILD_SHARED_LIBS "Determines if Armnn will be built statically or dynamically.
41 This is an experimental feature and not fully supported.
42 Only the ArmNN core and the Delegate can be built statically." ON)
telsoa014fcda012018-03-09 14:13:49 +000043
44include(SelectLibraryConfigurations)
45
46set(COMPILER_IS_GNU_LIKE 0)
Jim Flynn82262f52020-07-16 11:23:45 +010047if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR
48 ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang OR
49 ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang)
telsoa014fcda012018-03-09 14:13:49 +000050 set(COMPILER_IS_GNU_LIKE 1)
51endif()
52
53# Enable CCache if available and not disabled
54option(USE_CCACHE "USE_CCACHE" ON)
55find_program(CCACHE_FOUND ccache)
56if(CCACHE_FOUND AND USE_CCACHE)
57 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
58 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "CCACHE_CPP2=yes ${rule_launch_compile} ccache")
59endif()
60
61# Enable distcc if available and not disabled
62option(USE_DISTCC "USE_DISTCC" OFF)
63find_program(DISTCC_FOUND distcc)
64if(DISTCC_FOUND AND USE_DISTCC)
65 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
66 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "${rule_launch_compile} distcc")
67endif()
68
69# Set to release configuration by default
70if(NOT CMAKE_BUILD_TYPE)
71 set(CMAKE_BUILD_TYPE "Release")
72endif()
73
74# Compiler flags that are always set
75set(CMAKE_POSITION_INDEPENDENT_CODE ON)
76if(COMPILER_IS_GNU_LIKE)
Derek Lambertiba25aee2019-12-10 22:20:54 +000077 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Werror -Wold-style-cast -Wno-missing-braces -Wconversion -Wsign-conversion")
Finn Williams3d626142021-08-11 13:04:32 +010078 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
79 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi")
80 endif()
telsoa014fcda012018-03-09 14:13:49 +000081elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Jim Flynn870b96c2022-03-25 21:24:56 +000082 # Disable C4996 (use of deprecated identifier) due to
83 # https://developercommunity.visualstudio.com/content/problem/252574/deprecated-compilation-warning-for-virtual-overrid.html
Rob Hughesfc6bf052019-12-16 17:10:51 +000084 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /wd4996")
Rob Hughesbc873d22020-05-20 13:11:37 +010085 add_definitions(-DNO_STRICT=1)
telsoa014fcda012018-03-09 14:13:49 +000086endif()
87if("${CMAKE_SYSTEM_NAME}" STREQUAL Android)
Keith Davisb8942bf2021-05-31 11:22:35 +010088 # -lz is necessary for when building with ACL set with compressed kernels
89 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -llog -lz")
90 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -llog -lz")
telsoa014fcda012018-03-09 14:13:49 +000091endif()
92
93# Compiler flags for Release builds
Matthew Benthame30054f2019-06-24 13:10:54 +010094set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
telsoa014fcda012018-03-09 14:13:49 +000095if(COMPILER_IS_GNU_LIKE)
96 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
97elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
98 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2")
99endif()
100
101# Compiler flags for Debug builds
102if(COMPILER_IS_GNU_LIKE)
Matthew Benthame30054f2019-06-24 13:10:54 +0100103 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
telsoa014fcda012018-03-09 14:13:49 +0000104elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Matthew Benthame30054f2019-06-24 13:10:54 +0100105 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /ZI /Od")
telsoa014fcda012018-03-09 14:13:49 +0000106 # Disable SAFESEH which is necessary for Edit and Continue to work
107 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
108 set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
109endif()
110
111# Modify RelWithDebInfo so that NDEBUG isn't defined.
112# This enables asserts.
113if (COMPILER_IS_GNU_LIKE)
114 string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
115elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
116 string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
117endif()
118
119# Compiler flags for code coverage measurements
120if(BUILD_FOR_COVERAGE)
121 if(NOT CMAKE_BUILD_TYPE EQUAL "Debug")
122 message(WARNING "BUILD_FOR_COVERAGE set so forcing to Debug build")
123 set(CMAKE_BUILD_TYPE "Debug")
124 endif()
125
126 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
127 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
128endif()
129
130if(BUILD_FOR_COVERAGE AND NOT BUILD_UNIT_TESTS)
131 message(WARNING "BUILD_FOR_COVERAGE set but not BUILD_UNIT_TESTS, so code coverage will not be able to run")
132endif()
133
134set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
135
Derek Lambertieac4adb2020-08-25 13:05:59 +0100136include(CMakeFindDependencyMacro)
137
Jim Flynnbbfe6032020-07-20 16:57:44 +0100138if (NOT BUILD_PIPE_ONLY)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100139 # cxxopts (Alternative to boost::program_options)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200140 find_path(CXXOPTS_INCLUDE cxxopts/cxxopts.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100141 include_directories(SYSTEM "${CXXOPTS_INCLUDE}")
142endif()
Jan Eilers7e989832020-06-19 11:47:21 +0100143
Jim Flynnbbfe6032020-07-20 16:57:44 +0100144if (NOT BUILD_PIPE_ONLY)
145 # ghc (Alternative to boost::filesystem)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200146 find_path(GHC_INCLUDE ghc/filesystem.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100147 include_directories(SYSTEM "${GHC_INCLUDE}")
148endif()
Jan Eilers307fd342020-06-23 14:16:04 +0100149
telsoa014fcda012018-03-09 14:13:49 +0000150# pthread
Jim Flynn870b96c2022-03-25 21:24:56 +0000151if (NOT BUILD_BARE_METAL)
152find_package(Threads)
153endif()
telsoa014fcda012018-03-09 14:13:49 +0000154
155# Favour the protobuf passed on command line
Nikhil Raj5d955cf2021-04-19 16:59:48 +0100156if(BUILD_ONNX_PARSER)
telsoa014fcda012018-03-09 14:13:49 +0000157 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd"
158 PATHS ${PROTOBUF_ROOT}/lib
159 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
160 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd")
161
162 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf"
163 PATHS ${PROTOBUF_ROOT}/lib
164 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
165 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf")
166
167 select_library_configurations(PROTOBUF)
168
169 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h"
170 PATHS ${PROTOBUF_ROOT}/include
171 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
172 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h")
173
174 include_directories(SYSTEM "${PROTOBUF_INCLUDE_DIRS}")
175 add_definitions(-DPROTOBUF_USE_DLLS)
telsoa014fcda012018-03-09 14:13:49 +0000176
telsoa01c577f2c2018-08-31 09:22:23 +0100177 add_definitions(-DARMNN_ONNX_PARSER)
178
179 find_path(ONNX_GENERATED_SOURCES "onnx/onnx.pb.cc")
180
181 # C++ headers generated for onnx protobufs
182 include_directories(SYSTEM "${ONNX_GENERATED_SOURCES}")
183endif()
184
Sadik Armagan5d03e312020-11-17 16:43:56 +0000185if(BUILD_ARMNN_TFLITE_DELEGATE)
186 add_definitions(-DARMNN_TFLITE_DELEGATE)
187endif()
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100188# Flatbuffers support for TF Lite, Armnn Serializer or the TOSA backend.
189if(BUILD_TF_LITE_PARSER OR BUILD_ARMNN_SERIALIZER OR ARMNNTOSAREF)
telsoa01c577f2c2018-08-31 09:22:23 +0100190 # verify we have a valid flatbuffers include path
191 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
192 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
193
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000194 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
telsoa01c577f2c2018-08-31 09:22:23 +0100195
196 find_library(FLATBUFFERS_LIBRARY
197 NAMES libflatbuffers.a flatbuffers
198 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
199
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000200 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000201endif()
202
203# Flatbuffers schema support for TF Lite
204if(BUILD_TF_LITE_PARSER)
205 find_path(TF_LITE_SCHEMA_INCLUDE_PATH
206 schema_generated.h
207 HINTS ${TF_LITE_GENERATED_PATH})
208
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000209 message(STATUS "Tf Lite generated header found at: ${TF_LITE_SCHEMA_INCLUDE_PATH}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000210
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000211 add_definitions(-DARMNN_TF_LITE_PARSER)
telsoa01c577f2c2018-08-31 09:22:23 +0100212endif()
213
Kevin May43a799c2019-02-08 16:31:42 +0000214if(BUILD_ARMNN_SERIALIZER)
Kevin May43a799c2019-02-08 16:31:42 +0000215 add_definitions(-DARMNN_SERIALIZER)
Matthew Bentham268509a2019-02-25 13:58:24 +0000216 add_definitions(-DARMNN_SERIALIZER_SCHEMA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/src/armnnSerializer/ArmnnSchema.fbs")
Kevin May43a799c2019-02-08 16:31:42 +0000217endif()
218
telsoa014fcda012018-03-09 14:13:49 +0000219include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Sadik Armagana97a0be2020-03-03 10:44:56 +0000220include_directories(${CMAKE_CURRENT_SOURCE_DIR}/profiling)
telsoa014fcda012018-03-09 14:13:49 +0000221
222# ARM Compute
223# Note that ARM Compute has a different folder layout depending on the branch but also on
224# whether it comes from a prepackaged archive (this is why we add several hints below)
225if(ARMCOMPUTENEON OR ARMCOMPUTECL)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000226 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h
telsoa014fcda012018-03-09 14:13:49 +0000227 PATHS ${ARMCOMPUTE_ROOT}/include
228 PATHS ${ARMCOMPUTE_ROOT}/applications/arm_compute
229 PATHS ${ARMCOMPUTE_ROOT}
230 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000231 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h)
telsoa014fcda012018-03-09 14:13:49 +0000232 include_directories(SYSTEM "${ARMCOMPUTE_INCLUDE}")
233
234 # Find the Arm Compute libraries if not already specified (the user may have already defined this in advance,
235 # e.g. if building clframework as a dependent cmake project)
236 if (NOT DEFINED ARMCOMPUTE_LIBRARIES)
237 # We link to the static variant so that customers don't need to find and build a compatible version of clframework.
238 # First try the folders specified ARMCOMPUTE_BUILD_DIR (with PATH_SUFFIXES for
239 # Windows builds)
Matthew Bentham2624dd72020-05-20 10:44:18 +0100240 if ((NOT DEFINED ARMCOMPUTE_BUILD_DIR) AND (DEFINED ARMCOMPUTE_ROOT))
241 # Default build directory for ComputeLibrary is under the root
242 set(ARMCOMPUTE_BUILD_DIR ${ARMCOMPUTE_ROOT}/build)
243 endif()
244
telsoa014fcda012018-03-09 14:13:49 +0000245 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static
246 PATHS ${ARMCOMPUTE_BUILD_DIR}
247 PATH_SUFFIXES "Debug"
248 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
249 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static
250 PATHS ${ARMCOMPUTE_BUILD_DIR}
251 PATH_SUFFIXES "Release"
252 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
253 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static
254 PATHS ${ARMCOMPUTE_BUILD_DIR}
255 PATH_SUFFIXES "Debug"
256 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
257 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static
258 PATHS ${ARMCOMPUTE_BUILD_DIR}
259 PATH_SUFFIXES "Release"
260 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
261
262 # In case it wasn't there, try a default search (will work in cases where
263 # the library has been installed into a standard location)
264 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static)
265 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static)
266 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static)
267 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static)
268
Matthew Bentham6445cff2020-03-10 11:13:17 +0000269 # In case it wasn't there, try the dynamic libraries
270 # This case will get used in a linux setup where the Compute Library
271 # has been installed in a standard system library path as a dynamic library
272 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute)
273 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute)
274 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core)
275 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core)
276
telsoa014fcda012018-03-09 14:13:49 +0000277 set(ARMCOMPUTE_LIBRARIES
278 debug ${ARMCOMPUTE_LIBRARY_DEBUG} ${ARMCOMPUTE_CORE_LIBRARY_DEBUG}
279 optimized ${ARMCOMPUTE_LIBRARY_RELEASE} ${ARMCOMPUTE_CORE_LIBRARY_RELEASE} )
280 endif()
281endif()
282
283# ARM Compute NEON backend
284if(ARMCOMPUTENEON)
285 # Add preprocessor definition for ARM Compute NEON
286 add_definitions(-DARMCOMPUTENEON_ENABLED)
287 # The ARM Compute headers contain some NEON intrinsics, so we need to build armnn with NEON support on armv7
288 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES armv7 AND COMPILER_IS_GNU_LIKE)
289 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
290 endif()
291endif()
292
293# ARM Compute OpenCL backend
294if(ARMCOMPUTECL)
Nikhil Rajb55d3662021-02-11 14:49:19 +0000295 # verify we have a valid flatbuffers include path
296 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
297 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
298
299 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
300
301 find_library(FLATBUFFERS_LIBRARY
302 NAMES libflatbuffers.a flatbuffers
303 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
304
305 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
306
telsoa014fcda012018-03-09 14:13:49 +0000307 # Always use Arm compute library OpenCL headers
Nikhil Raj407cddf2021-11-30 09:57:08 +0000308 find_path(OPENCL_INCLUDE CL/opencl.hpp
telsoa014fcda012018-03-09 14:13:49 +0000309 PATHS ${ARMCOMPUTE_ROOT}/include
310 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
311
Matthew Bentham3b72db02018-10-11 09:47:01 +0100312 # Link against libOpenCL in opencl-1.2-stubs, but don't search there at runtime
313 link_libraries(-L${ARMCOMPUTE_BUILD_DIR}/opencl-1.2-stubs)
314 set(OPENCL_LIBRARIES OpenCL)
telsoa014fcda012018-03-09 14:13:49 +0000315
Matthew Bentham416b41d2020-02-05 22:15:26 +0000316 include_directories(SYSTEM ${OPENCL_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000317
318 # Add preprocessor definition for ARM Compute OpenCL
319 add_definitions(-DARMCOMPUTECL_ENABLED)
320
321 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DARM_COMPUTE_DEBUG_ENABLED")
322endif()
323
324# Used by both Arm Compute backends, but should be added
325# to the search path after the system directories if necessary
326if(ARMCOMPUTENEON OR ARMCOMPUTECL)
327 find_path(HALF_INCLUDE half/half.hpp)
328 find_path(HALF_INCLUDE half/half.hpp
329 PATHS ${ARMCOMPUTE_ROOT}/include
330 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
telsoa01c577f2c2018-08-31 09:22:23 +0100331 include_directories(SYSTEM ${HALF_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000332endif()
333
Matteo Martincighdb16dd32019-08-27 16:41:11 +0100334# ArmNN reference backend
335if(ARMNNREF)
336 add_definitions(-DARMNNREF_ENABLED)
Matteo Martincighe67edb22019-08-14 14:05:46 +0100337endif()
338
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100339# ArmNN TOSA reference backend
340if(ARMNNTOSAREF)
341 # Locate the includes for the TOSA serialization library.
342 message(STATUS "TOSA serialization library root set to ${TOSA_SERIALIZATION_LIB_ROOT}")
343
344 find_path(TOSA_SERIALIZATION_LIB_INCLUDE tosa_serialization_handler.h HINTS
345 ${TOSA_SERIALIZATION_LIB_ROOT}/include)
346 message(STATUS "TOSA serialization library include directory located at: ${TOSA_SERIALIZATION_LIB_INCLUDE}")
347
348 find_library(TOSA_SERIALIZATION_LIB
349 NAMES tosa_serialization_lib.a tosa_serialization_lib
350 HINTS ${TOSA_SERIALIZATION_LIB_ROOT}/lib /usr/local/lib /usr/lib)
351 message(STATUS "TOSA serialization library set to ${TOSA_SERIALIZATION_LIB}")
352endif()
353
Colm Donelanaa93d982020-06-28 08:16:46 +0100354# This is the root for the dynamic backend tests to search for dynamic
355# backends. By default it will be the project build directory.
Rob Hughes35c31c02020-08-17 15:47:20 +0100356add_definitions(-DDYNAMIC_BACKEND_BUILD_DIR="${PROJECT_BINARY_DIR}")
Colm Donelanaa93d982020-06-28 08:16:46 +0100357
Narumol Prangnawarat60a20fb2019-12-09 17:24:41 +0000358# ArmNN dynamic backend
359if(DYNAMIC_BACKEND_PATHS)
360 add_definitions(-DARMNN_DYNAMIC_BACKEND_ENABLED)
361endif()
362
Narumol Prangnawarat867eba52020-02-03 12:29:56 +0000363if(SAMPLE_DYNAMIC_BACKEND)
364 add_definitions(-DSAMPLE_DYNAMIC_BACKEND_ENABLED)
365endif()
366
telsoa014fcda012018-03-09 14:13:49 +0000367# Streamline annotate
368if(PROFILING_BACKEND_STREAMLINE)
369 include_directories("${GATOR_ROOT}/annotate")
370 add_definitions(-DARMNN_STREAMLINE_ENABLED)
371endif()
372
Jim Flynn870b96c2022-03-25 21:24:56 +0000373if(NOT BUILD_BARE_METAL)
telsoa01c577f2c2018-08-31 09:22:23 +0100374if(HEAP_PROFILING OR LEAK_CHECKING)
surmeh013537c2c2018-05-18 16:31:43 +0100375 # enable heap profiling for everything except for referencetests
376 if(NOT ${PROJECT_NAME} STREQUAL "referencetests")
377 find_path(HEAP_PROFILER_INCLUDE gperftools/heap-profiler.h
378 PATHS ${GPERFTOOLS_ROOT}/include
379 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
380 include_directories(SYSTEM "${HEAP_PROFILER_INCLUDE}")
381 find_library(GPERF_TOOLS_LIBRARY
382 NAMES tcmalloc_debug
383 HINTS ${GPERFTOOLS_ROOT}/lib)
384 link_directories(${GPERFTOOLS_ROOT}/lib)
385
386 link_libraries(${GPERF_TOOLS_LIBRARY})
telsoa01c577f2c2018-08-31 09:22:23 +0100387 if (HEAP_PROFILING)
388 add_definitions("-DARMNN_HEAP_PROFILING_ENABLED=1")
389 endif()
390 if (LEAK_CHECKING)
391 add_definitions("-DARMNN_LEAK_CHECKING_ENABLED=1")
392 endif()
surmeh013537c2c2018-05-18 16:31:43 +0100393 else()
Rob Hughes721b82f2019-11-15 09:04:17 +0000394 message(STATUS "Heap profiling and leak checking are disabled for referencetests")
surmeh013537c2c2018-05-18 16:31:43 +0100395 endif()
396else()
397 # Valgrind only works with gperftools version number <= 2.4
398 CHECK_INCLUDE_FILE(valgrind/memcheck.h VALGRIND_FOUND)
399endif()
Jim Flynn870b96c2022-03-25 21:24:56 +0000400endif()
surmeh013537c2c2018-05-18 16:31:43 +0100401
telsoa01c577f2c2018-08-31 09:22:23 +0100402if(NOT BUILD_TF_LITE_PARSER)
403 message(STATUS "Tensorflow Lite parser support is disabled")
404endif()
David Beck10b4dfd2018-09-19 12:03:20 +0100405
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000406if(NOT BUILD_ARMNN_SERIALIZER)
407 message(STATUS "Armnn Serializer support is disabled")
408endif()
409
Pavel Macenauer59e057f2020-04-15 14:17:26 +0000410if(NOT BUILD_PYTHON_WHL)
411 message(STATUS "PyArmNN wheel package is disabled")
412endif()
413
414if(NOT BUILD_PYTHON_SRC)
415 message(STATUS "PyArmNN source package is disabled")
416endif()
417
418if(BUILD_PYTHON_WHL OR BUILD_PYTHON_SRC)
419 find_package(PythonInterp 3 REQUIRED)
420 if(NOT ${PYTHONINTERP_FOUND})
421 message(FATAL_ERROR "Python 3.x required to build PyArmNN, but not found")
422 endif()
423
424 find_package(PythonLibs 3 REQUIRED)
425 if(NOT ${PYTHONLIBS_FOUND})
426 message(FATAL_ERROR "Python 3.x development package required to build PyArmNN, but not found")
427 endif()
428
429 find_package(SWIG 4 REQUIRED)
430 if(NOT ${SWIG_FOUND})
431 message(FATAL_ERROR "SWIG 4.x requried to build PyArmNN, but not found")
432 endif()
433endif()
434
Jim Flynn870b96c2022-03-25 21:24:56 +0000435if(BUILD_BARE_METAL)
436 add_definitions(-DARMNN_BUILD_BARE_METAL
437 -DARMNN_DISABLE_FILESYSTEM
438 -DARMNN_DISABLE_PROCESSES
439 -DARMNN_DISABLE_THREADS
440 -DARMNN_DISABLE_SOCKETS)
441endif()
442
David Beck10b4dfd2018-09-19 12:03:20 +0100443# ArmNN source files required for all build options
444include_directories(SYSTEM third-party)