blob: a5c17d574908cc0b47a918d88346f86e6148fab6 [file] [log] [blame]
Pavel Macenauer59e057f2020-04-15 14:17:26 +00001#
Jim Flynnbbfe6032020-07-20 16:57:44 +01002# Copyright © 2020 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)
telsoa014fcda012018-03-09 14:13:49 +000014option(PROFILING_BACKEND_STREAMLINE "Forward the armNN profiling events to DS-5/Streamline as annotations" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010015# options used for heap profiling and leak checking
surmeh013537c2c2018-05-18 16:31:43 +010016option(HEAP_PROFILING "Build with heap profiling enabled" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010017option(LEAK_CHECKING "Build with leak checking enabled" OFF)
surmeh013537c2c2018-05-18 16:31:43 +010018option(GPERFTOOLS_ROOT "Location where the gperftools 'include' and 'lib' folders to be found" Off)
telsoa01c577f2c2018-08-31 09:22:23 +010019# options used for tensorflow lite support
20option(BUILD_TF_LITE_PARSER "Build Tensorflow Lite parser" OFF)
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +000021option(BUILD_ARMNN_SERIALIZER "Build Armnn Serializer" OFF)
Éanna Ó Catháina563b922019-05-09 11:34:06 +010022option(BUILD_ACCURACY_TOOL "Build Accuracy Tool" OFF)
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +000023option(FLATC_DIR "Path to Flatbuffers compiler" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010024option(TF_LITE_GENERATED_PATH "Tensorflow lite generated C++ schema location" OFF)
25option(FLATBUFFERS_ROOT "Location where the flatbuffers 'include' and 'lib' folders to be found" Off)
Matteo Martincighe7d44982019-08-05 12:16:47 +010026option(DYNAMIC_BACKEND_PATHS "Colon seperated list of paths where to load the dynamic backends from" "")
Colm Donelan0dbe00a2020-06-03 08:00:28 +010027option(SAMPLE_DYNAMIC_BACKEND "Include the sample dynamic backend and its tests in the build" OFF)
Colm Donelana21620d2019-10-11 13:09:49 +010028option(BUILD_GATORD_MOCK "Build the Gatord simulator for external profiling testing." ON)
Sadik Armagan6f86b692020-03-09 11:04:32 +000029option(BUILD_TIMELINE_DECODER "Build the Timeline Decoder for external profiling." ON)
Finn Williams2ed809c2020-04-20 21:21:07 +010030option(BUILD_BASE_PIPE_SERVER "Build the server to handle external profiling pipe traffic" ON)
Pavel Macenauer59e057f2020-04-15 14:17:26 +000031option(BUILD_PYTHON_WHL "Build Python wheel package" OFF)
32option(BUILD_PYTHON_SRC "Build Python source package" OFF)
Jim Flynnbbfe6032020-07-20 16:57:44 +010033option(BUILD_STATIC_PIPE_LIBS "Build Static PIPE libraries" OFF)
34option(BUILD_PIPE_ONLY "Build the PIPE libraries only" OFF)
Sadik Armagan5d03e312020-11-17 16:43:56 +000035option(BUILD_ARMNN_TFLITE_DELEGATE "Build the Arm NN TfLite delegate" OFF)
Jim Flynne1fdd282021-10-26 21:26:10 +010036option(BUILD_MEMORY_STRATEGY_BENCHMARK "Build the MemoryBenchmark" OFF)
Jim Flynn870b96c2022-03-25 21:24:56 +000037option(BUILD_BARE_METAL "Disable features requiring operating system support" OFF)
telsoa014fcda012018-03-09 14:13:49 +000038
39include(SelectLibraryConfigurations)
40
41set(COMPILER_IS_GNU_LIKE 0)
Jim Flynn82262f52020-07-16 11:23:45 +010042if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR
43 ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang OR
44 ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang)
telsoa014fcda012018-03-09 14:13:49 +000045 set(COMPILER_IS_GNU_LIKE 1)
46endif()
47
48# Enable CCache if available and not disabled
49option(USE_CCACHE "USE_CCACHE" ON)
50find_program(CCACHE_FOUND ccache)
51if(CCACHE_FOUND AND USE_CCACHE)
52 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
53 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "CCACHE_CPP2=yes ${rule_launch_compile} ccache")
54endif()
55
56# Enable distcc if available and not disabled
57option(USE_DISTCC "USE_DISTCC" OFF)
58find_program(DISTCC_FOUND distcc)
59if(DISTCC_FOUND AND USE_DISTCC)
60 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
61 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "${rule_launch_compile} distcc")
62endif()
63
64# Set to release configuration by default
65if(NOT CMAKE_BUILD_TYPE)
66 set(CMAKE_BUILD_TYPE "Release")
67endif()
68
69# Compiler flags that are always set
70set(CMAKE_POSITION_INDEPENDENT_CODE ON)
71if(COMPILER_IS_GNU_LIKE)
Derek Lambertiba25aee2019-12-10 22:20:54 +000072 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 +010073 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
74 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi")
75 endif()
telsoa014fcda012018-03-09 14:13:49 +000076elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Jim Flynn870b96c2022-03-25 21:24:56 +000077 # Disable C4996 (use of deprecated identifier) due to
78 # https://developercommunity.visualstudio.com/content/problem/252574/deprecated-compilation-warning-for-virtual-overrid.html
Rob Hughesfc6bf052019-12-16 17:10:51 +000079 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /wd4996")
Rob Hughesbc873d22020-05-20 13:11:37 +010080 add_definitions(-DNO_STRICT=1)
telsoa014fcda012018-03-09 14:13:49 +000081endif()
82if("${CMAKE_SYSTEM_NAME}" STREQUAL Android)
Keith Davisb8942bf2021-05-31 11:22:35 +010083 # -lz is necessary for when building with ACL set with compressed kernels
84 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -llog -lz")
85 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -llog -lz")
telsoa014fcda012018-03-09 14:13:49 +000086endif()
87
88# Compiler flags for Release builds
Matthew Benthame30054f2019-06-24 13:10:54 +010089set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
telsoa014fcda012018-03-09 14:13:49 +000090if(COMPILER_IS_GNU_LIKE)
91 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
92elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
93 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2")
94endif()
95
96# Compiler flags for Debug builds
97if(COMPILER_IS_GNU_LIKE)
Matthew Benthame30054f2019-06-24 13:10:54 +010098 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
telsoa014fcda012018-03-09 14:13:49 +000099elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Matthew Benthame30054f2019-06-24 13:10:54 +0100100 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /ZI /Od")
telsoa014fcda012018-03-09 14:13:49 +0000101 # Disable SAFESEH which is necessary for Edit and Continue to work
102 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
103 set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
104endif()
105
106# Modify RelWithDebInfo so that NDEBUG isn't defined.
107# This enables asserts.
108if (COMPILER_IS_GNU_LIKE)
109 string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
110elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
111 string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
112endif()
113
114# Compiler flags for code coverage measurements
115if(BUILD_FOR_COVERAGE)
116 if(NOT CMAKE_BUILD_TYPE EQUAL "Debug")
117 message(WARNING "BUILD_FOR_COVERAGE set so forcing to Debug build")
118 set(CMAKE_BUILD_TYPE "Debug")
119 endif()
120
121 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
122 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
123endif()
124
125if(BUILD_FOR_COVERAGE AND NOT BUILD_UNIT_TESTS)
126 message(WARNING "BUILD_FOR_COVERAGE set but not BUILD_UNIT_TESTS, so code coverage will not be able to run")
127endif()
128
129set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
130
Derek Lambertieac4adb2020-08-25 13:05:59 +0100131include(CMakeFindDependencyMacro)
132
Jim Flynnbbfe6032020-07-20 16:57:44 +0100133if (NOT BUILD_PIPE_ONLY)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100134 # cxxopts (Alternative to boost::program_options)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200135 find_path(CXXOPTS_INCLUDE cxxopts/cxxopts.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100136 include_directories(SYSTEM "${CXXOPTS_INCLUDE}")
137endif()
Jan Eilers7e989832020-06-19 11:47:21 +0100138
Jim Flynnbbfe6032020-07-20 16:57:44 +0100139if (NOT BUILD_PIPE_ONLY)
140 # ghc (Alternative to boost::filesystem)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200141 find_path(GHC_INCLUDE ghc/filesystem.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100142 include_directories(SYSTEM "${GHC_INCLUDE}")
143endif()
Jan Eilers307fd342020-06-23 14:16:04 +0100144
telsoa014fcda012018-03-09 14:13:49 +0000145# pthread
Jim Flynn870b96c2022-03-25 21:24:56 +0000146if (NOT BUILD_BARE_METAL)
147find_package(Threads)
148endif()
telsoa014fcda012018-03-09 14:13:49 +0000149
150# Favour the protobuf passed on command line
Nikhil Raj5d955cf2021-04-19 16:59:48 +0100151if(BUILD_ONNX_PARSER)
telsoa014fcda012018-03-09 14:13:49 +0000152 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd"
153 PATHS ${PROTOBUF_ROOT}/lib
154 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
155 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd")
156
157 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf"
158 PATHS ${PROTOBUF_ROOT}/lib
159 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
160 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf")
161
162 select_library_configurations(PROTOBUF)
163
164 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h"
165 PATHS ${PROTOBUF_ROOT}/include
166 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
167 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h")
168
169 include_directories(SYSTEM "${PROTOBUF_INCLUDE_DIRS}")
170 add_definitions(-DPROTOBUF_USE_DLLS)
telsoa014fcda012018-03-09 14:13:49 +0000171
telsoa01c577f2c2018-08-31 09:22:23 +0100172 add_definitions(-DARMNN_ONNX_PARSER)
173
174 find_path(ONNX_GENERATED_SOURCES "onnx/onnx.pb.cc")
175
176 # C++ headers generated for onnx protobufs
177 include_directories(SYSTEM "${ONNX_GENERATED_SOURCES}")
178endif()
179
Sadik Armagan5d03e312020-11-17 16:43:56 +0000180if(BUILD_ARMNN_TFLITE_DELEGATE)
181 add_definitions(-DARMNN_TFLITE_DELEGATE)
182endif()
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000183# Flatbuffers support for TF Lite and Armnn Serializer
184if(BUILD_TF_LITE_PARSER OR BUILD_ARMNN_SERIALIZER)
telsoa01c577f2c2018-08-31 09:22:23 +0100185 # verify we have a valid flatbuffers include path
186 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
187 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
188
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000189 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
telsoa01c577f2c2018-08-31 09:22:23 +0100190
191 find_library(FLATBUFFERS_LIBRARY
192 NAMES libflatbuffers.a flatbuffers
193 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
194
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000195 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000196endif()
197
198# Flatbuffers schema support for TF Lite
199if(BUILD_TF_LITE_PARSER)
200 find_path(TF_LITE_SCHEMA_INCLUDE_PATH
201 schema_generated.h
202 HINTS ${TF_LITE_GENERATED_PATH})
203
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000204 message(STATUS "Tf Lite generated header found at: ${TF_LITE_SCHEMA_INCLUDE_PATH}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000205
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000206 add_definitions(-DARMNN_TF_LITE_PARSER)
telsoa01c577f2c2018-08-31 09:22:23 +0100207endif()
208
Kevin May43a799c2019-02-08 16:31:42 +0000209if(BUILD_ARMNN_SERIALIZER)
Kevin May43a799c2019-02-08 16:31:42 +0000210 add_definitions(-DARMNN_SERIALIZER)
Matthew Bentham268509a2019-02-25 13:58:24 +0000211 add_definitions(-DARMNN_SERIALIZER_SCHEMA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/src/armnnSerializer/ArmnnSchema.fbs")
Kevin May43a799c2019-02-08 16:31:42 +0000212endif()
213
telsoa014fcda012018-03-09 14:13:49 +0000214include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Sadik Armagana97a0be2020-03-03 10:44:56 +0000215include_directories(${CMAKE_CURRENT_SOURCE_DIR}/profiling)
telsoa014fcda012018-03-09 14:13:49 +0000216
217# ARM Compute
218# Note that ARM Compute has a different folder layout depending on the branch but also on
219# whether it comes from a prepackaged archive (this is why we add several hints below)
220if(ARMCOMPUTENEON OR ARMCOMPUTECL)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000221 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h
telsoa014fcda012018-03-09 14:13:49 +0000222 PATHS ${ARMCOMPUTE_ROOT}/include
223 PATHS ${ARMCOMPUTE_ROOT}/applications/arm_compute
224 PATHS ${ARMCOMPUTE_ROOT}
225 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
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 include_directories(SYSTEM "${ARMCOMPUTE_INCLUDE}")
228
229 # Find the Arm Compute libraries if not already specified (the user may have already defined this in advance,
230 # e.g. if building clframework as a dependent cmake project)
231 if (NOT DEFINED ARMCOMPUTE_LIBRARIES)
232 # We link to the static variant so that customers don't need to find and build a compatible version of clframework.
233 # First try the folders specified ARMCOMPUTE_BUILD_DIR (with PATH_SUFFIXES for
234 # Windows builds)
Matthew Bentham2624dd72020-05-20 10:44:18 +0100235 if ((NOT DEFINED ARMCOMPUTE_BUILD_DIR) AND (DEFINED ARMCOMPUTE_ROOT))
236 # Default build directory for ComputeLibrary is under the root
237 set(ARMCOMPUTE_BUILD_DIR ${ARMCOMPUTE_ROOT}/build)
238 endif()
239
telsoa014fcda012018-03-09 14:13:49 +0000240 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static
241 PATHS ${ARMCOMPUTE_BUILD_DIR}
242 PATH_SUFFIXES "Debug"
243 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
244 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static
245 PATHS ${ARMCOMPUTE_BUILD_DIR}
246 PATH_SUFFIXES "Release"
247 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
248 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static
249 PATHS ${ARMCOMPUTE_BUILD_DIR}
250 PATH_SUFFIXES "Debug"
251 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
252 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static
253 PATHS ${ARMCOMPUTE_BUILD_DIR}
254 PATH_SUFFIXES "Release"
255 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
256
257 # In case it wasn't there, try a default search (will work in cases where
258 # the library has been installed into a standard location)
259 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static)
260 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static)
261 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static)
262 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static)
263
Matthew Bentham6445cff2020-03-10 11:13:17 +0000264 # In case it wasn't there, try the dynamic libraries
265 # This case will get used in a linux setup where the Compute Library
266 # has been installed in a standard system library path as a dynamic library
267 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute)
268 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute)
269 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core)
270 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core)
271
telsoa014fcda012018-03-09 14:13:49 +0000272 set(ARMCOMPUTE_LIBRARIES
273 debug ${ARMCOMPUTE_LIBRARY_DEBUG} ${ARMCOMPUTE_CORE_LIBRARY_DEBUG}
274 optimized ${ARMCOMPUTE_LIBRARY_RELEASE} ${ARMCOMPUTE_CORE_LIBRARY_RELEASE} )
275 endif()
276endif()
277
278# ARM Compute NEON backend
279if(ARMCOMPUTENEON)
280 # Add preprocessor definition for ARM Compute NEON
281 add_definitions(-DARMCOMPUTENEON_ENABLED)
282 # The ARM Compute headers contain some NEON intrinsics, so we need to build armnn with NEON support on armv7
283 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES armv7 AND COMPILER_IS_GNU_LIKE)
284 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
285 endif()
286endif()
287
288# ARM Compute OpenCL backend
289if(ARMCOMPUTECL)
Nikhil Rajb55d3662021-02-11 14:49:19 +0000290 # verify we have a valid flatbuffers include path
291 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
292 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
293
294 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
295
296 find_library(FLATBUFFERS_LIBRARY
297 NAMES libflatbuffers.a flatbuffers
298 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
299
300 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
301
telsoa014fcda012018-03-09 14:13:49 +0000302 # Always use Arm compute library OpenCL headers
Nikhil Raj407cddf2021-11-30 09:57:08 +0000303 find_path(OPENCL_INCLUDE CL/opencl.hpp
telsoa014fcda012018-03-09 14:13:49 +0000304 PATHS ${ARMCOMPUTE_ROOT}/include
305 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
306
Matthew Bentham3b72db02018-10-11 09:47:01 +0100307 # Link against libOpenCL in opencl-1.2-stubs, but don't search there at runtime
308 link_libraries(-L${ARMCOMPUTE_BUILD_DIR}/opencl-1.2-stubs)
309 set(OPENCL_LIBRARIES OpenCL)
telsoa014fcda012018-03-09 14:13:49 +0000310
Matthew Bentham416b41d2020-02-05 22:15:26 +0000311 include_directories(SYSTEM ${OPENCL_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000312
313 # Add preprocessor definition for ARM Compute OpenCL
314 add_definitions(-DARMCOMPUTECL_ENABLED)
315
316 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DARM_COMPUTE_DEBUG_ENABLED")
317endif()
318
319# Used by both Arm Compute backends, but should be added
320# to the search path after the system directories if necessary
321if(ARMCOMPUTENEON OR ARMCOMPUTECL)
322 find_path(HALF_INCLUDE half/half.hpp)
323 find_path(HALF_INCLUDE half/half.hpp
324 PATHS ${ARMCOMPUTE_ROOT}/include
325 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
telsoa01c577f2c2018-08-31 09:22:23 +0100326 include_directories(SYSTEM ${HALF_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000327endif()
328
Matteo Martincighdb16dd32019-08-27 16:41:11 +0100329# ArmNN reference backend
330if(ARMNNREF)
331 add_definitions(-DARMNNREF_ENABLED)
Matteo Martincighe67edb22019-08-14 14:05:46 +0100332endif()
333
Colm Donelanaa93d982020-06-28 08:16:46 +0100334# This is the root for the dynamic backend tests to search for dynamic
335# backends. By default it will be the project build directory.
Rob Hughes35c31c02020-08-17 15:47:20 +0100336add_definitions(-DDYNAMIC_BACKEND_BUILD_DIR="${PROJECT_BINARY_DIR}")
Colm Donelanaa93d982020-06-28 08:16:46 +0100337
Narumol Prangnawarat60a20fb2019-12-09 17:24:41 +0000338# ArmNN dynamic backend
339if(DYNAMIC_BACKEND_PATHS)
340 add_definitions(-DARMNN_DYNAMIC_BACKEND_ENABLED)
341endif()
342
Narumol Prangnawarat867eba52020-02-03 12:29:56 +0000343if(SAMPLE_DYNAMIC_BACKEND)
344 add_definitions(-DSAMPLE_DYNAMIC_BACKEND_ENABLED)
345endif()
346
telsoa014fcda012018-03-09 14:13:49 +0000347# Streamline annotate
348if(PROFILING_BACKEND_STREAMLINE)
349 include_directories("${GATOR_ROOT}/annotate")
350 add_definitions(-DARMNN_STREAMLINE_ENABLED)
351endif()
352
Jim Flynn870b96c2022-03-25 21:24:56 +0000353if(NOT BUILD_BARE_METAL)
telsoa01c577f2c2018-08-31 09:22:23 +0100354if(HEAP_PROFILING OR LEAK_CHECKING)
surmeh013537c2c2018-05-18 16:31:43 +0100355 # enable heap profiling for everything except for referencetests
356 if(NOT ${PROJECT_NAME} STREQUAL "referencetests")
357 find_path(HEAP_PROFILER_INCLUDE gperftools/heap-profiler.h
358 PATHS ${GPERFTOOLS_ROOT}/include
359 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
360 include_directories(SYSTEM "${HEAP_PROFILER_INCLUDE}")
361 find_library(GPERF_TOOLS_LIBRARY
362 NAMES tcmalloc_debug
363 HINTS ${GPERFTOOLS_ROOT}/lib)
364 link_directories(${GPERFTOOLS_ROOT}/lib)
365
366 link_libraries(${GPERF_TOOLS_LIBRARY})
telsoa01c577f2c2018-08-31 09:22:23 +0100367 if (HEAP_PROFILING)
368 add_definitions("-DARMNN_HEAP_PROFILING_ENABLED=1")
369 endif()
370 if (LEAK_CHECKING)
371 add_definitions("-DARMNN_LEAK_CHECKING_ENABLED=1")
372 endif()
surmeh013537c2c2018-05-18 16:31:43 +0100373 else()
Rob Hughes721b82f2019-11-15 09:04:17 +0000374 message(STATUS "Heap profiling and leak checking are disabled for referencetests")
surmeh013537c2c2018-05-18 16:31:43 +0100375 endif()
376else()
377 # Valgrind only works with gperftools version number <= 2.4
378 CHECK_INCLUDE_FILE(valgrind/memcheck.h VALGRIND_FOUND)
379endif()
Jim Flynn870b96c2022-03-25 21:24:56 +0000380endif()
surmeh013537c2c2018-05-18 16:31:43 +0100381
telsoa01c577f2c2018-08-31 09:22:23 +0100382if(NOT BUILD_TF_LITE_PARSER)
383 message(STATUS "Tensorflow Lite parser support is disabled")
384endif()
David Beck10b4dfd2018-09-19 12:03:20 +0100385
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000386if(NOT BUILD_ARMNN_SERIALIZER)
387 message(STATUS "Armnn Serializer support is disabled")
388endif()
389
Pavel Macenauer59e057f2020-04-15 14:17:26 +0000390if(NOT BUILD_PYTHON_WHL)
391 message(STATUS "PyArmNN wheel package is disabled")
392endif()
393
394if(NOT BUILD_PYTHON_SRC)
395 message(STATUS "PyArmNN source package is disabled")
396endif()
397
398if(BUILD_PYTHON_WHL OR BUILD_PYTHON_SRC)
399 find_package(PythonInterp 3 REQUIRED)
400 if(NOT ${PYTHONINTERP_FOUND})
401 message(FATAL_ERROR "Python 3.x required to build PyArmNN, but not found")
402 endif()
403
404 find_package(PythonLibs 3 REQUIRED)
405 if(NOT ${PYTHONLIBS_FOUND})
406 message(FATAL_ERROR "Python 3.x development package required to build PyArmNN, but not found")
407 endif()
408
409 find_package(SWIG 4 REQUIRED)
410 if(NOT ${SWIG_FOUND})
411 message(FATAL_ERROR "SWIG 4.x requried to build PyArmNN, but not found")
412 endif()
413endif()
414
Jim Flynn870b96c2022-03-25 21:24:56 +0000415if(BUILD_BARE_METAL)
416 add_definitions(-DARMNN_BUILD_BARE_METAL
417 -DARMNN_DISABLE_FILESYSTEM
418 -DARMNN_DISABLE_PROCESSES
419 -DARMNN_DISABLE_THREADS
420 -DARMNN_DISABLE_SOCKETS)
421endif()
422
David Beck10b4dfd2018-09-19 12:03:20 +0100423# ArmNN source files required for all build options
424include_directories(SYSTEM third-party)