blob: fb70d1a0e0dd954b32c242ea3261aca0b4c5c8dc [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)
Matthew Sloyand646b552022-10-10 12:42: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)
Matthew Sloyand646b552022-10-10 12:42:16 +010027option(TOSA_SERIALIZATION_LIB_ROOT "Location where the TOSA Serialization Library 'include' and 'lib' folders can be found" OFF)
28option(TOSA_REFERENCE_MODEL_ROOT "Location where the TOSA Reference Model 'include' and 'lib' folders can be found" OFF)
Matteo Martincighe7d44982019-08-05 12:16:47 +010029option(DYNAMIC_BACKEND_PATHS "Colon seperated list of paths where to load the dynamic backends from" "")
Colm Donelan0dbe00a2020-06-03 08:00:28 +010030option(SAMPLE_DYNAMIC_BACKEND "Include the sample dynamic backend and its tests in the build" OFF)
Colm Donelana21620d2019-10-11 13:09:49 +010031option(BUILD_GATORD_MOCK "Build the Gatord simulator for external profiling testing." ON)
Sadik Armagan6f86b692020-03-09 11:04:32 +000032option(BUILD_TIMELINE_DECODER "Build the Timeline Decoder for external profiling." ON)
Finn Williams2ed809c2020-04-20 21:21:07 +010033option(BUILD_BASE_PIPE_SERVER "Build the server to handle external profiling pipe traffic" ON)
Pavel Macenauer59e057f2020-04-15 14:17:26 +000034option(BUILD_PYTHON_WHL "Build Python wheel package" OFF)
35option(BUILD_PYTHON_SRC "Build Python source package" OFF)
Jim Flynnbbfe6032020-07-20 16:57:44 +010036option(BUILD_STATIC_PIPE_LIBS "Build Static PIPE libraries" OFF)
37option(BUILD_PIPE_ONLY "Build the PIPE libraries only" OFF)
Sadik Armagan5d03e312020-11-17 16:43:56 +000038option(BUILD_ARMNN_TFLITE_DELEGATE "Build the Arm NN TfLite delegate" OFF)
Jim Flynne1fdd282021-10-26 21:26:10 +010039option(BUILD_MEMORY_STRATEGY_BENCHMARK "Build the MemoryBenchmark" OFF)
Jim Flynn870b96c2022-03-25 21:24:56 +000040option(BUILD_BARE_METAL "Disable features requiring operating system support" OFF)
Jan Eilersa96489a2021-12-08 10:05:47 +000041option(BUILD_SHARED_LIBS "Determines if Armnn will be built statically or dynamically.
42 This is an experimental feature and not fully supported.
43 Only the ArmNN core and the Delegate can be built statically." ON)
telsoa014fcda012018-03-09 14:13:49 +000044
45include(SelectLibraryConfigurations)
46
47set(COMPILER_IS_GNU_LIKE 0)
Jim Flynn82262f52020-07-16 11:23:45 +010048if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR
49 ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang OR
50 ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang)
telsoa014fcda012018-03-09 14:13:49 +000051 set(COMPILER_IS_GNU_LIKE 1)
52endif()
53
54# Enable CCache if available and not disabled
55option(USE_CCACHE "USE_CCACHE" ON)
56find_program(CCACHE_FOUND ccache)
57if(CCACHE_FOUND AND USE_CCACHE)
58 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
59 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "CCACHE_CPP2=yes ${rule_launch_compile} ccache")
60endif()
61
62# Enable distcc if available and not disabled
63option(USE_DISTCC "USE_DISTCC" OFF)
64find_program(DISTCC_FOUND distcc)
65if(DISTCC_FOUND AND USE_DISTCC)
66 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
67 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "${rule_launch_compile} distcc")
68endif()
69
70# Set to release configuration by default
71if(NOT CMAKE_BUILD_TYPE)
72 set(CMAKE_BUILD_TYPE "Release")
73endif()
74
75# Compiler flags that are always set
76set(CMAKE_POSITION_INDEPENDENT_CODE ON)
77if(COMPILER_IS_GNU_LIKE)
Derek Lambertiba25aee2019-12-10 22:20:54 +000078 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 +010079 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
80 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi")
81 endif()
telsoa014fcda012018-03-09 14:13:49 +000082elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Jim Flynn870b96c2022-03-25 21:24:56 +000083 # Disable C4996 (use of deprecated identifier) due to
84 # https://developercommunity.visualstudio.com/content/problem/252574/deprecated-compilation-warning-for-virtual-overrid.html
Rob Hughesfc6bf052019-12-16 17:10:51 +000085 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /wd4996")
Rob Hughesbc873d22020-05-20 13:11:37 +010086 add_definitions(-DNO_STRICT=1)
telsoa014fcda012018-03-09 14:13:49 +000087endif()
88if("${CMAKE_SYSTEM_NAME}" STREQUAL Android)
Keith Davisb8942bf2021-05-31 11:22:35 +010089 # -lz is necessary for when building with ACL set with compressed kernels
90 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -llog -lz")
91 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -llog -lz")
telsoa014fcda012018-03-09 14:13:49 +000092endif()
93
94# Compiler flags for Release builds
Matthew Benthame30054f2019-06-24 13:10:54 +010095set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
telsoa014fcda012018-03-09 14:13:49 +000096if(COMPILER_IS_GNU_LIKE)
97 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
98elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
99 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2")
100endif()
101
102# Compiler flags for Debug builds
103if(COMPILER_IS_GNU_LIKE)
Matthew Benthame30054f2019-06-24 13:10:54 +0100104 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
telsoa014fcda012018-03-09 14:13:49 +0000105elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Matthew Benthame30054f2019-06-24 13:10:54 +0100106 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /ZI /Od")
telsoa014fcda012018-03-09 14:13:49 +0000107 # Disable SAFESEH which is necessary for Edit and Continue to work
108 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
109 set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
110endif()
111
112# Modify RelWithDebInfo so that NDEBUG isn't defined.
113# This enables asserts.
114if (COMPILER_IS_GNU_LIKE)
115 string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
116elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
117 string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
118endif()
119
120# Compiler flags for code coverage measurements
121if(BUILD_FOR_COVERAGE)
122 if(NOT CMAKE_BUILD_TYPE EQUAL "Debug")
123 message(WARNING "BUILD_FOR_COVERAGE set so forcing to Debug build")
124 set(CMAKE_BUILD_TYPE "Debug")
125 endif()
126
127 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
128 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
129endif()
130
131if(BUILD_FOR_COVERAGE AND NOT BUILD_UNIT_TESTS)
132 message(WARNING "BUILD_FOR_COVERAGE set but not BUILD_UNIT_TESTS, so code coverage will not be able to run")
133endif()
134
135set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
136
Derek Lambertieac4adb2020-08-25 13:05:59 +0100137include(CMakeFindDependencyMacro)
138
Jim Flynnbbfe6032020-07-20 16:57:44 +0100139if (NOT BUILD_PIPE_ONLY)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100140 # cxxopts (Alternative to boost::program_options)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200141 find_path(CXXOPTS_INCLUDE cxxopts/cxxopts.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100142 include_directories(SYSTEM "${CXXOPTS_INCLUDE}")
143endif()
Jan Eilers7e989832020-06-19 11:47:21 +0100144
Jim Flynnbbfe6032020-07-20 16:57:44 +0100145if (NOT BUILD_PIPE_ONLY)
146 # ghc (Alternative to boost::filesystem)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200147 find_path(GHC_INCLUDE ghc/filesystem.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100148 include_directories(SYSTEM "${GHC_INCLUDE}")
149endif()
Jan Eilers307fd342020-06-23 14:16:04 +0100150
telsoa014fcda012018-03-09 14:13:49 +0000151# pthread
Jim Flynn870b96c2022-03-25 21:24:56 +0000152if (NOT BUILD_BARE_METAL)
153find_package(Threads)
154endif()
telsoa014fcda012018-03-09 14:13:49 +0000155
156# Favour the protobuf passed on command line
Nikhil Raj5d955cf2021-04-19 16:59:48 +0100157if(BUILD_ONNX_PARSER)
telsoa014fcda012018-03-09 14:13:49 +0000158 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd"
159 PATHS ${PROTOBUF_ROOT}/lib
160 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
161 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd")
162
163 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf"
164 PATHS ${PROTOBUF_ROOT}/lib
165 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
166 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf")
167
168 select_library_configurations(PROTOBUF)
169
170 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h"
171 PATHS ${PROTOBUF_ROOT}/include
172 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
173 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h")
174
175 include_directories(SYSTEM "${PROTOBUF_INCLUDE_DIRS}")
176 add_definitions(-DPROTOBUF_USE_DLLS)
telsoa014fcda012018-03-09 14:13:49 +0000177
telsoa01c577f2c2018-08-31 09:22:23 +0100178 add_definitions(-DARMNN_ONNX_PARSER)
179
180 find_path(ONNX_GENERATED_SOURCES "onnx/onnx.pb.cc")
181
182 # C++ headers generated for onnx protobufs
183 include_directories(SYSTEM "${ONNX_GENERATED_SOURCES}")
184endif()
185
Sadik Armagan5d03e312020-11-17 16:43:56 +0000186if(BUILD_ARMNN_TFLITE_DELEGATE)
187 add_definitions(-DARMNN_TFLITE_DELEGATE)
188endif()
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100189# Flatbuffers support for TF Lite, Armnn Serializer or the TOSA backend.
190if(BUILD_TF_LITE_PARSER OR BUILD_ARMNN_SERIALIZER OR ARMNNTOSAREF)
telsoa01c577f2c2018-08-31 09:22:23 +0100191 # verify we have a valid flatbuffers include path
192 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
193 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
194
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000195 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
telsoa01c577f2c2018-08-31 09:22:23 +0100196
197 find_library(FLATBUFFERS_LIBRARY
198 NAMES libflatbuffers.a flatbuffers
199 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
200
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000201 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000202endif()
203
204# Flatbuffers schema support for TF Lite
205if(BUILD_TF_LITE_PARSER)
206 find_path(TF_LITE_SCHEMA_INCLUDE_PATH
207 schema_generated.h
208 HINTS ${TF_LITE_GENERATED_PATH})
209
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000210 message(STATUS "Tf Lite generated header found at: ${TF_LITE_SCHEMA_INCLUDE_PATH}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000211
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000212 add_definitions(-DARMNN_TF_LITE_PARSER)
telsoa01c577f2c2018-08-31 09:22:23 +0100213endif()
214
Kevin May43a799c2019-02-08 16:31:42 +0000215if(BUILD_ARMNN_SERIALIZER)
Kevin May43a799c2019-02-08 16:31:42 +0000216 add_definitions(-DARMNN_SERIALIZER)
Matthew Bentham268509a2019-02-25 13:58:24 +0000217 add_definitions(-DARMNN_SERIALIZER_SCHEMA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/src/armnnSerializer/ArmnnSchema.fbs")
Kevin May43a799c2019-02-08 16:31:42 +0000218endif()
219
telsoa014fcda012018-03-09 14:13:49 +0000220include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Sadik Armagana97a0be2020-03-03 10:44:56 +0000221include_directories(${CMAKE_CURRENT_SOURCE_DIR}/profiling)
telsoa014fcda012018-03-09 14:13:49 +0000222
223# ARM Compute
224# Note that ARM Compute has a different folder layout depending on the branch but also on
225# whether it comes from a prepackaged archive (this is why we add several hints below)
226if(ARMCOMPUTENEON OR ARMCOMPUTECL)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000227 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h
telsoa014fcda012018-03-09 14:13:49 +0000228 PATHS ${ARMCOMPUTE_ROOT}/include
229 PATHS ${ARMCOMPUTE_ROOT}/applications/arm_compute
230 PATHS ${ARMCOMPUTE_ROOT}
231 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000232 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h)
telsoa014fcda012018-03-09 14:13:49 +0000233 include_directories(SYSTEM "${ARMCOMPUTE_INCLUDE}")
234
235 # Find the Arm Compute libraries if not already specified (the user may have already defined this in advance,
236 # e.g. if building clframework as a dependent cmake project)
237 if (NOT DEFINED ARMCOMPUTE_LIBRARIES)
238 # We link to the static variant so that customers don't need to find and build a compatible version of clframework.
239 # First try the folders specified ARMCOMPUTE_BUILD_DIR (with PATH_SUFFIXES for
240 # Windows builds)
Matthew Bentham2624dd72020-05-20 10:44:18 +0100241 if ((NOT DEFINED ARMCOMPUTE_BUILD_DIR) AND (DEFINED ARMCOMPUTE_ROOT))
242 # Default build directory for ComputeLibrary is under the root
243 set(ARMCOMPUTE_BUILD_DIR ${ARMCOMPUTE_ROOT}/build)
244 endif()
245
telsoa014fcda012018-03-09 14:13:49 +0000246 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static
247 PATHS ${ARMCOMPUTE_BUILD_DIR}
248 PATH_SUFFIXES "Debug"
249 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
250 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static
251 PATHS ${ARMCOMPUTE_BUILD_DIR}
252 PATH_SUFFIXES "Release"
253 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
254 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static
255 PATHS ${ARMCOMPUTE_BUILD_DIR}
256 PATH_SUFFIXES "Debug"
257 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
258 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static
259 PATHS ${ARMCOMPUTE_BUILD_DIR}
260 PATH_SUFFIXES "Release"
261 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
262
263 # In case it wasn't there, try a default search (will work in cases where
264 # the library has been installed into a standard location)
265 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static)
266 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static)
267 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static)
268 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static)
269
Matthew Bentham6445cff2020-03-10 11:13:17 +0000270 # In case it wasn't there, try the dynamic libraries
271 # This case will get used in a linux setup where the Compute Library
272 # has been installed in a standard system library path as a dynamic library
273 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute)
274 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute)
275 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core)
276 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core)
277
telsoa014fcda012018-03-09 14:13:49 +0000278 set(ARMCOMPUTE_LIBRARIES
279 debug ${ARMCOMPUTE_LIBRARY_DEBUG} ${ARMCOMPUTE_CORE_LIBRARY_DEBUG}
280 optimized ${ARMCOMPUTE_LIBRARY_RELEASE} ${ARMCOMPUTE_CORE_LIBRARY_RELEASE} )
281 endif()
282endif()
283
284# ARM Compute NEON backend
285if(ARMCOMPUTENEON)
286 # Add preprocessor definition for ARM Compute NEON
287 add_definitions(-DARMCOMPUTENEON_ENABLED)
288 # The ARM Compute headers contain some NEON intrinsics, so we need to build armnn with NEON support on armv7
289 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES armv7 AND COMPILER_IS_GNU_LIKE)
290 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
291 endif()
292endif()
293
294# ARM Compute OpenCL backend
295if(ARMCOMPUTECL)
Nikhil Rajb55d3662021-02-11 14:49:19 +0000296 # verify we have a valid flatbuffers include path
297 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
298 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
299
300 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
301
302 find_library(FLATBUFFERS_LIBRARY
303 NAMES libflatbuffers.a flatbuffers
304 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
305
306 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
307
telsoa014fcda012018-03-09 14:13:49 +0000308 # Always use Arm compute library OpenCL headers
Nikhil Raj407cddf2021-11-30 09:57:08 +0000309 find_path(OPENCL_INCLUDE CL/opencl.hpp
telsoa014fcda012018-03-09 14:13:49 +0000310 PATHS ${ARMCOMPUTE_ROOT}/include
311 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
312
Matthew Bentham3b72db02018-10-11 09:47:01 +0100313 # Link against libOpenCL in opencl-1.2-stubs, but don't search there at runtime
314 link_libraries(-L${ARMCOMPUTE_BUILD_DIR}/opencl-1.2-stubs)
315 set(OPENCL_LIBRARIES OpenCL)
telsoa014fcda012018-03-09 14:13:49 +0000316
Matthew Bentham416b41d2020-02-05 22:15:26 +0000317 include_directories(SYSTEM ${OPENCL_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000318
319 # Add preprocessor definition for ARM Compute OpenCL
320 add_definitions(-DARMCOMPUTECL_ENABLED)
321
322 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DARM_COMPUTE_DEBUG_ENABLED")
323endif()
324
325# Used by both Arm Compute backends, but should be added
326# to the search path after the system directories if necessary
327if(ARMCOMPUTENEON OR ARMCOMPUTECL)
328 find_path(HALF_INCLUDE half/half.hpp)
329 find_path(HALF_INCLUDE half/half.hpp
330 PATHS ${ARMCOMPUTE_ROOT}/include
331 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
telsoa01c577f2c2018-08-31 09:22:23 +0100332 include_directories(SYSTEM ${HALF_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000333endif()
334
Matteo Martincighdb16dd32019-08-27 16:41:11 +0100335# ArmNN reference backend
336if(ARMNNREF)
337 add_definitions(-DARMNNREF_ENABLED)
Matteo Martincighe67edb22019-08-14 14:05:46 +0100338endif()
339
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100340# ArmNN TOSA reference backend
341if(ARMNNTOSAREF)
342 # Locate the includes for the TOSA serialization library.
343 message(STATUS "TOSA serialization library root set to ${TOSA_SERIALIZATION_LIB_ROOT}")
344
Matthew Sloyand646b552022-10-10 12:42:16 +0100345 find_path(TOSA_SERIALIZATION_LIB_INCLUDE tosa_serialization_handler.h
346 HINTS ${TOSA_SERIALIZATION_LIB_ROOT}/include)
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100347 message(STATUS "TOSA serialization library include directory located at: ${TOSA_SERIALIZATION_LIB_INCLUDE}")
348
349 find_library(TOSA_SERIALIZATION_LIB
Matthew Sloyand646b552022-10-10 12:42:16 +0100350 NAMES tosa_serialization_lib.a tosa_serialization_lib
351 HINTS ${TOSA_SERIALIZATION_LIB_ROOT}/lib /usr/local/lib /usr/lib)
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100352 message(STATUS "TOSA serialization library set to ${TOSA_SERIALIZATION_LIB}")
Matthew Sloyand646b552022-10-10 12:42:16 +0100353
354 # Next, locate the includes for the TOSA Reference Model.
355 message(STATUS "TOSA Reference Model root set to ${TOSA_REFERENCE_MODEL_ROOT}")
356
357 find_path(TOSA_REFERENCE_MODEL_INCLUDE model_runner.h
358 HINTS ${TOSA_REFERENCE_MODEL_ROOT}/include)
359 message(STATUS "TOSA Reference Model include directory located at: ${TOSA_REFERENCE_MODEL_INCLUDE}")
360
361 find_library(TOSA_REFERENCE_MODEL_LIB
362 NAMES tosa_reference_model_lib.a tosa_reference_model_lib
363 HINTS ${TOSA_REFERENCE_MODEL_ROOT}/lib /usr/local/lib /usr/lib)
364 message(STATUS "TOSA Reference Model set to ${TOSA_REFERENCE_MODEL_LIB}")
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100365endif()
366
Colm Donelanaa93d982020-06-28 08:16:46 +0100367# This is the root for the dynamic backend tests to search for dynamic
368# backends. By default it will be the project build directory.
Rob Hughes35c31c02020-08-17 15:47:20 +0100369add_definitions(-DDYNAMIC_BACKEND_BUILD_DIR="${PROJECT_BINARY_DIR}")
Colm Donelanaa93d982020-06-28 08:16:46 +0100370
Narumol Prangnawarat60a20fb2019-12-09 17:24:41 +0000371# ArmNN dynamic backend
372if(DYNAMIC_BACKEND_PATHS)
373 add_definitions(-DARMNN_DYNAMIC_BACKEND_ENABLED)
374endif()
375
Narumol Prangnawarat867eba52020-02-03 12:29:56 +0000376if(SAMPLE_DYNAMIC_BACKEND)
377 add_definitions(-DSAMPLE_DYNAMIC_BACKEND_ENABLED)
378endif()
379
telsoa014fcda012018-03-09 14:13:49 +0000380# Streamline annotate
381if(PROFILING_BACKEND_STREAMLINE)
382 include_directories("${GATOR_ROOT}/annotate")
383 add_definitions(-DARMNN_STREAMLINE_ENABLED)
384endif()
385
Jim Flynn870b96c2022-03-25 21:24:56 +0000386if(NOT BUILD_BARE_METAL)
telsoa01c577f2c2018-08-31 09:22:23 +0100387if(HEAP_PROFILING OR LEAK_CHECKING)
surmeh013537c2c2018-05-18 16:31:43 +0100388 # enable heap profiling for everything except for referencetests
389 if(NOT ${PROJECT_NAME} STREQUAL "referencetests")
390 find_path(HEAP_PROFILER_INCLUDE gperftools/heap-profiler.h
391 PATHS ${GPERFTOOLS_ROOT}/include
392 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
393 include_directories(SYSTEM "${HEAP_PROFILER_INCLUDE}")
394 find_library(GPERF_TOOLS_LIBRARY
395 NAMES tcmalloc_debug
396 HINTS ${GPERFTOOLS_ROOT}/lib)
397 link_directories(${GPERFTOOLS_ROOT}/lib)
398
399 link_libraries(${GPERF_TOOLS_LIBRARY})
telsoa01c577f2c2018-08-31 09:22:23 +0100400 if (HEAP_PROFILING)
401 add_definitions("-DARMNN_HEAP_PROFILING_ENABLED=1")
402 endif()
403 if (LEAK_CHECKING)
404 add_definitions("-DARMNN_LEAK_CHECKING_ENABLED=1")
405 endif()
surmeh013537c2c2018-05-18 16:31:43 +0100406 else()
Rob Hughes721b82f2019-11-15 09:04:17 +0000407 message(STATUS "Heap profiling and leak checking are disabled for referencetests")
surmeh013537c2c2018-05-18 16:31:43 +0100408 endif()
409else()
410 # Valgrind only works with gperftools version number <= 2.4
411 CHECK_INCLUDE_FILE(valgrind/memcheck.h VALGRIND_FOUND)
412endif()
Jim Flynn870b96c2022-03-25 21:24:56 +0000413endif()
surmeh013537c2c2018-05-18 16:31:43 +0100414
telsoa01c577f2c2018-08-31 09:22:23 +0100415if(NOT BUILD_TF_LITE_PARSER)
416 message(STATUS "Tensorflow Lite parser support is disabled")
417endif()
David Beck10b4dfd2018-09-19 12:03:20 +0100418
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000419if(NOT BUILD_ARMNN_SERIALIZER)
420 message(STATUS "Armnn Serializer support is disabled")
421endif()
422
Pavel Macenauer59e057f2020-04-15 14:17:26 +0000423if(NOT BUILD_PYTHON_WHL)
424 message(STATUS "PyArmNN wheel package is disabled")
425endif()
426
427if(NOT BUILD_PYTHON_SRC)
428 message(STATUS "PyArmNN source package is disabled")
429endif()
430
431if(BUILD_PYTHON_WHL OR BUILD_PYTHON_SRC)
432 find_package(PythonInterp 3 REQUIRED)
433 if(NOT ${PYTHONINTERP_FOUND})
434 message(FATAL_ERROR "Python 3.x required to build PyArmNN, but not found")
435 endif()
436
437 find_package(PythonLibs 3 REQUIRED)
438 if(NOT ${PYTHONLIBS_FOUND})
439 message(FATAL_ERROR "Python 3.x development package required to build PyArmNN, but not found")
440 endif()
441
442 find_package(SWIG 4 REQUIRED)
443 if(NOT ${SWIG_FOUND})
444 message(FATAL_ERROR "SWIG 4.x requried to build PyArmNN, but not found")
445 endif()
446endif()
447
Jim Flynn870b96c2022-03-25 21:24:56 +0000448if(BUILD_BARE_METAL)
449 add_definitions(-DARMNN_BUILD_BARE_METAL
450 -DARMNN_DISABLE_FILESYSTEM
451 -DARMNN_DISABLE_PROCESSES
452 -DARMNN_DISABLE_THREADS
453 -DARMNN_DISABLE_SOCKETS)
454endif()
455
David Beck10b4dfd2018-09-19 12:03:20 +0100456# ArmNN source files required for all build options
457include_directories(SYSTEM third-party)