blob: 031974814bf5bc48dc2fec64dfca58cc4eb1166b [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#
telsoa014fcda012018-03-09 14:13:49 +00006option(BUILD_TF_PARSER "Build Tensorflow parser" OFF)
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)
Jim Flynn3091b062019-02-15 14:45:04 +000022option(BUILD_ARMNN_QUANTIZER "Build ArmNN quantizer" 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)
Matteo Martincighe7d44982019-08-05 12:16:47 +010027option(DYNAMIC_BACKEND_PATHS "Colon seperated list of paths where to load the dynamic backends from" "")
Colm Donelan0dbe00a2020-06-03 08:00:28 +010028option(SAMPLE_DYNAMIC_BACKEND "Include the sample dynamic backend and its tests in the build" OFF)
Colm Donelana21620d2019-10-11 13:09:49 +010029option(BUILD_GATORD_MOCK "Build the Gatord simulator for external profiling testing." ON)
Sadik Armagan6f86b692020-03-09 11:04:32 +000030option(BUILD_TIMELINE_DECODER "Build the Timeline Decoder for external profiling." ON)
Matthew Benthamb4e67202019-10-31 09:55:01 +000031option(SHARED_BOOST "Use dynamic linking for boost libraries" OFF)
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)
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")
telsoa014fcda012018-03-09 14:13:49 +000073elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Rob Hughesfc6bf052019-12-16 17:10:51 +000074 # Disable C4996 (use of deprecated identifier) due to https://developercommunity.visualstudio.com/content/problem/252574/deprecated-compilation-warning-for-virtual-overrid.html
75 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /wd4996")
Rob Hughesbc873d22020-05-20 13:11:37 +010076 add_definitions(-DNO_STRICT=1)
telsoa014fcda012018-03-09 14:13:49 +000077endif()
78if("${CMAKE_SYSTEM_NAME}" STREQUAL Android)
79 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -llog")
80 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -llog")
81endif()
82
83# Compiler flags for Release builds
Matthew Benthame30054f2019-06-24 13:10:54 +010084set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
telsoa014fcda012018-03-09 14:13:49 +000085if(COMPILER_IS_GNU_LIKE)
86 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
87elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
88 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2")
89endif()
90
91# Compiler flags for Debug builds
92if(COMPILER_IS_GNU_LIKE)
Matthew Benthame30054f2019-06-24 13:10:54 +010093 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
telsoa014fcda012018-03-09 14:13:49 +000094elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Matthew Benthame30054f2019-06-24 13:10:54 +010095 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /ZI /Od")
telsoa014fcda012018-03-09 14:13:49 +000096 # Disable SAFESEH which is necessary for Edit and Continue to work
97 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
98 set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
99endif()
100
101# Modify RelWithDebInfo so that NDEBUG isn't defined.
102# This enables asserts.
103if (COMPILER_IS_GNU_LIKE)
104 string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
105elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
106 string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
107endif()
108
109# Compiler flags for code coverage measurements
110if(BUILD_FOR_COVERAGE)
111 if(NOT CMAKE_BUILD_TYPE EQUAL "Debug")
112 message(WARNING "BUILD_FOR_COVERAGE set so forcing to Debug build")
113 set(CMAKE_BUILD_TYPE "Debug")
114 endif()
115
116 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
117 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
118endif()
119
120if(BUILD_FOR_COVERAGE AND NOT BUILD_UNIT_TESTS)
121 message(WARNING "BUILD_FOR_COVERAGE set but not BUILD_UNIT_TESTS, so code coverage will not be able to run")
122endif()
123
124set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
125
Derek Lambertieac4adb2020-08-25 13:05:59 +0100126include(CMakeFindDependencyMacro)
127
Jim Flynnbbfe6032020-07-20 16:57:44 +0100128if (NOT BUILD_PIPE_ONLY)
129 # Boost
130 message(STATUS "Finding Boost")
131 if(SHARED_BOOST)
Matthew Benthamb4e67202019-10-31 09:55:01 +0000132 add_definitions(-DBOOST_ALL_DYN_LINK)
133 set(Boost_USE_STATIC_LIBS OFF)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100134 else()
Matthew Benthamb4e67202019-10-31 09:55:01 +0000135 set(Boost_USE_STATIC_LIBS ON)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100136 endif()
Matthew Benthame688d612020-11-13 12:04:01 +0000137 if (BUILD_UNIT_TESTS)
138 add_definitions("-DBOOST_ALL_NO_LIB") # Turn off auto-linking as we specify the libs manually
139 find_package(Boost 1.59 REQUIRED COMPONENTS unit_test_framework)
140 include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
141 link_directories(${Boost_LIBRARY_DIRS})
142 endif()
Matthew Benthamb4e67202019-10-31 09:55:01 +0000143endif()
telsoa014fcda012018-03-09 14:13:49 +0000144
Jim Flynnbbfe6032020-07-20 16:57:44 +0100145if (NOT BUILD_PIPE_ONLY)
146 # cxxopts (Alternative to boost::program_options)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200147 find_path(CXXOPTS_INCLUDE cxxopts/cxxopts.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100148 include_directories(SYSTEM "${CXXOPTS_INCLUDE}")
149endif()
Jan Eilers7e989832020-06-19 11:47:21 +0100150
Jim Flynnbbfe6032020-07-20 16:57:44 +0100151if (NOT BUILD_PIPE_ONLY)
152 # ghc (Alternative to boost::filesystem)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200153 find_path(GHC_INCLUDE ghc/filesystem.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100154 include_directories(SYSTEM "${GHC_INCLUDE}")
155endif()
Jan Eilers307fd342020-06-23 14:16:04 +0100156
telsoa014fcda012018-03-09 14:13:49 +0000157# pthread
Derek Lambertieac4adb2020-08-25 13:05:59 +0100158find_dependency(Threads)
telsoa014fcda012018-03-09 14:13:49 +0000159
160# Favour the protobuf passed on command line
Nikhil Raj6dd178f2021-04-02 22:04:39 +0100161if(BUILD_TF_PARSER OR BUILD_ONNX_PARSER)
telsoa014fcda012018-03-09 14:13:49 +0000162 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd"
163 PATHS ${PROTOBUF_ROOT}/lib
164 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
165 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd")
166
167 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf"
168 PATHS ${PROTOBUF_ROOT}/lib
169 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
170 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf")
171
172 select_library_configurations(PROTOBUF)
173
174 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h"
175 PATHS ${PROTOBUF_ROOT}/include
176 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
177 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h")
178
179 include_directories(SYSTEM "${PROTOBUF_INCLUDE_DIRS}")
180 add_definitions(-DPROTOBUF_USE_DLLS)
181endif()
182
telsoa014fcda012018-03-09 14:13:49 +0000183if(BUILD_TF_PARSER)
184 add_definitions(-DARMNN_TF_PARSER)
185
186 find_path(TF_GENERATED_SOURCES "tensorflow/core/protobuf/saved_model.pb.cc")
187
188 # C++ sources generated for tf protobufs
189 file(GLOB_RECURSE TF_PROTOBUFS "${TF_GENERATED_SOURCES}/*.pb.cc")
190
191 # C++ headers generated for tf protobufs
192 include_directories(SYSTEM "${TF_GENERATED_SOURCES}")
193endif()
194
telsoa01c577f2c2018-08-31 09:22:23 +0100195if(BUILD_ONNX_PARSER)
196 add_definitions(-DARMNN_ONNX_PARSER)
197
198 find_path(ONNX_GENERATED_SOURCES "onnx/onnx.pb.cc")
199
200 # C++ headers generated for onnx protobufs
201 include_directories(SYSTEM "${ONNX_GENERATED_SOURCES}")
202endif()
203
Sadik Armagan5d03e312020-11-17 16:43:56 +0000204if(BUILD_ARMNN_TFLITE_DELEGATE)
205 add_definitions(-DARMNN_TFLITE_DELEGATE)
206endif()
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000207# Flatbuffers support for TF Lite and Armnn Serializer
208if(BUILD_TF_LITE_PARSER OR BUILD_ARMNN_SERIALIZER)
telsoa01c577f2c2018-08-31 09:22:23 +0100209 # verify we have a valid flatbuffers include path
210 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
211 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
212
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000213 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
telsoa01c577f2c2018-08-31 09:22:23 +0100214
215 find_library(FLATBUFFERS_LIBRARY
216 NAMES libflatbuffers.a flatbuffers
217 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
218
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000219 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000220endif()
221
222# Flatbuffers schema support for TF Lite
223if(BUILD_TF_LITE_PARSER)
224 find_path(TF_LITE_SCHEMA_INCLUDE_PATH
225 schema_generated.h
226 HINTS ${TF_LITE_GENERATED_PATH})
227
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000228 message(STATUS "Tf Lite generated header found at: ${TF_LITE_SCHEMA_INCLUDE_PATH}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000229
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000230 add_definitions(-DARMNN_TF_LITE_PARSER)
telsoa01c577f2c2018-08-31 09:22:23 +0100231endif()
232
Kevin May43a799c2019-02-08 16:31:42 +0000233if(BUILD_ARMNN_SERIALIZER)
Kevin May43a799c2019-02-08 16:31:42 +0000234 add_definitions(-DARMNN_SERIALIZER)
Matthew Bentham268509a2019-02-25 13:58:24 +0000235 add_definitions(-DARMNN_SERIALIZER_SCHEMA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/src/armnnSerializer/ArmnnSchema.fbs")
Kevin May43a799c2019-02-08 16:31:42 +0000236endif()
237
telsoa014fcda012018-03-09 14:13:49 +0000238include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Sadik Armagana97a0be2020-03-03 10:44:56 +0000239include_directories(${CMAKE_CURRENT_SOURCE_DIR}/profiling)
telsoa014fcda012018-03-09 14:13:49 +0000240
241# ARM Compute
242# Note that ARM Compute has a different folder layout depending on the branch but also on
243# whether it comes from a prepackaged archive (this is why we add several hints below)
244if(ARMCOMPUTENEON OR ARMCOMPUTECL)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000245 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h
telsoa014fcda012018-03-09 14:13:49 +0000246 PATHS ${ARMCOMPUTE_ROOT}/include
247 PATHS ${ARMCOMPUTE_ROOT}/applications/arm_compute
248 PATHS ${ARMCOMPUTE_ROOT}
249 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000250 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h)
telsoa014fcda012018-03-09 14:13:49 +0000251 include_directories(SYSTEM "${ARMCOMPUTE_INCLUDE}")
252
253 # Find the Arm Compute libraries if not already specified (the user may have already defined this in advance,
254 # e.g. if building clframework as a dependent cmake project)
255 if (NOT DEFINED ARMCOMPUTE_LIBRARIES)
256 # We link to the static variant so that customers don't need to find and build a compatible version of clframework.
257 # First try the folders specified ARMCOMPUTE_BUILD_DIR (with PATH_SUFFIXES for
258 # Windows builds)
Matthew Bentham2624dd72020-05-20 10:44:18 +0100259 if ((NOT DEFINED ARMCOMPUTE_BUILD_DIR) AND (DEFINED ARMCOMPUTE_ROOT))
260 # Default build directory for ComputeLibrary is under the root
261 set(ARMCOMPUTE_BUILD_DIR ${ARMCOMPUTE_ROOT}/build)
262 endif()
263
telsoa014fcda012018-03-09 14:13:49 +0000264 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static
265 PATHS ${ARMCOMPUTE_BUILD_DIR}
266 PATH_SUFFIXES "Debug"
267 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
268 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static
269 PATHS ${ARMCOMPUTE_BUILD_DIR}
270 PATH_SUFFIXES "Release"
271 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
272 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static
273 PATHS ${ARMCOMPUTE_BUILD_DIR}
274 PATH_SUFFIXES "Debug"
275 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
276 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static
277 PATHS ${ARMCOMPUTE_BUILD_DIR}
278 PATH_SUFFIXES "Release"
279 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
280
281 # In case it wasn't there, try a default search (will work in cases where
282 # the library has been installed into a standard location)
283 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static)
284 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static)
285 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static)
286 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static)
287
Matthew Bentham6445cff2020-03-10 11:13:17 +0000288 # In case it wasn't there, try the dynamic libraries
289 # This case will get used in a linux setup where the Compute Library
290 # has been installed in a standard system library path as a dynamic library
291 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute)
292 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute)
293 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core)
294 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core)
295
telsoa014fcda012018-03-09 14:13:49 +0000296 set(ARMCOMPUTE_LIBRARIES
297 debug ${ARMCOMPUTE_LIBRARY_DEBUG} ${ARMCOMPUTE_CORE_LIBRARY_DEBUG}
298 optimized ${ARMCOMPUTE_LIBRARY_RELEASE} ${ARMCOMPUTE_CORE_LIBRARY_RELEASE} )
299 endif()
300endif()
301
302# ARM Compute NEON backend
303if(ARMCOMPUTENEON)
304 # Add preprocessor definition for ARM Compute NEON
305 add_definitions(-DARMCOMPUTENEON_ENABLED)
306 # The ARM Compute headers contain some NEON intrinsics, so we need to build armnn with NEON support on armv7
307 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES armv7 AND COMPILER_IS_GNU_LIKE)
308 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
309 endif()
310endif()
311
312# ARM Compute OpenCL backend
313if(ARMCOMPUTECL)
Nikhil Rajb55d3662021-02-11 14:49:19 +0000314 # verify we have a valid flatbuffers include path
315 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
316 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
317
318 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
319
320 find_library(FLATBUFFERS_LIBRARY
321 NAMES libflatbuffers.a flatbuffers
322 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
323
324 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
325
telsoa014fcda012018-03-09 14:13:49 +0000326 # Always use Arm compute library OpenCL headers
327 find_path(OPENCL_INCLUDE CL/cl2.hpp
328 PATHS ${ARMCOMPUTE_ROOT}/include
329 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
330
Matthew Bentham3b72db02018-10-11 09:47:01 +0100331 # Link against libOpenCL in opencl-1.2-stubs, but don't search there at runtime
332 link_libraries(-L${ARMCOMPUTE_BUILD_DIR}/opencl-1.2-stubs)
333 set(OPENCL_LIBRARIES OpenCL)
telsoa014fcda012018-03-09 14:13:49 +0000334
Matthew Bentham416b41d2020-02-05 22:15:26 +0000335 include_directories(SYSTEM ${OPENCL_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000336
337 # Add preprocessor definition for ARM Compute OpenCL
338 add_definitions(-DARMCOMPUTECL_ENABLED)
339
340 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DARM_COMPUTE_DEBUG_ENABLED")
341endif()
342
343# Used by both Arm Compute backends, but should be added
344# to the search path after the system directories if necessary
345if(ARMCOMPUTENEON OR ARMCOMPUTECL)
346 find_path(HALF_INCLUDE half/half.hpp)
347 find_path(HALF_INCLUDE half/half.hpp
348 PATHS ${ARMCOMPUTE_ROOT}/include
349 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
telsoa01c577f2c2018-08-31 09:22:23 +0100350 include_directories(SYSTEM ${HALF_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000351endif()
352
Matteo Martincighdb16dd32019-08-27 16:41:11 +0100353# ArmNN reference backend
354if(ARMNNREF)
355 add_definitions(-DARMNNREF_ENABLED)
Matteo Martincighe67edb22019-08-14 14:05:46 +0100356endif()
357
Narumol Prangnawarat060bad52020-11-20 16:17:48 +0000358if(ETHOSN_SUPPORT)
359 add_definitions(-DETHOSN_SUPPORT_ENABLED)
360endif()
361
Colm Donelanaa93d982020-06-28 08:16:46 +0100362# This is the root for the dynamic backend tests to search for dynamic
363# backends. By default it will be the project build directory.
Rob Hughes35c31c02020-08-17 15:47:20 +0100364add_definitions(-DDYNAMIC_BACKEND_BUILD_DIR="${PROJECT_BINARY_DIR}")
Colm Donelanaa93d982020-06-28 08:16:46 +0100365
Narumol Prangnawarat60a20fb2019-12-09 17:24:41 +0000366# ArmNN dynamic backend
367if(DYNAMIC_BACKEND_PATHS)
368 add_definitions(-DARMNN_DYNAMIC_BACKEND_ENABLED)
369endif()
370
Narumol Prangnawarat867eba52020-02-03 12:29:56 +0000371if(SAMPLE_DYNAMIC_BACKEND)
372 add_definitions(-DSAMPLE_DYNAMIC_BACKEND_ENABLED)
373endif()
374
telsoa014fcda012018-03-09 14:13:49 +0000375# Streamline annotate
376if(PROFILING_BACKEND_STREAMLINE)
377 include_directories("${GATOR_ROOT}/annotate")
378 add_definitions(-DARMNN_STREAMLINE_ENABLED)
379endif()
380
telsoa01c577f2c2018-08-31 09:22:23 +0100381if(HEAP_PROFILING OR LEAK_CHECKING)
surmeh013537c2c2018-05-18 16:31:43 +0100382 # enable heap profiling for everything except for referencetests
383 if(NOT ${PROJECT_NAME} STREQUAL "referencetests")
384 find_path(HEAP_PROFILER_INCLUDE gperftools/heap-profiler.h
385 PATHS ${GPERFTOOLS_ROOT}/include
386 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
387 include_directories(SYSTEM "${HEAP_PROFILER_INCLUDE}")
388 find_library(GPERF_TOOLS_LIBRARY
389 NAMES tcmalloc_debug
390 HINTS ${GPERFTOOLS_ROOT}/lib)
391 link_directories(${GPERFTOOLS_ROOT}/lib)
392
393 link_libraries(${GPERF_TOOLS_LIBRARY})
telsoa01c577f2c2018-08-31 09:22:23 +0100394 if (HEAP_PROFILING)
395 add_definitions("-DARMNN_HEAP_PROFILING_ENABLED=1")
396 endif()
397 if (LEAK_CHECKING)
398 add_definitions("-DARMNN_LEAK_CHECKING_ENABLED=1")
399 endif()
surmeh013537c2c2018-05-18 16:31:43 +0100400 else()
Rob Hughes721b82f2019-11-15 09:04:17 +0000401 message(STATUS "Heap profiling and leak checking are disabled for referencetests")
surmeh013537c2c2018-05-18 16:31:43 +0100402 endif()
403else()
404 # Valgrind only works with gperftools version number <= 2.4
405 CHECK_INCLUDE_FILE(valgrind/memcheck.h VALGRIND_FOUND)
406endif()
407
408
surmeh013537c2c2018-05-18 16:31:43 +0100409
410if(NOT BUILD_TF_PARSER)
411 message(STATUS "Tensorflow parser support is disabled")
412endif()
413
telsoa01c577f2c2018-08-31 09:22:23 +0100414if(NOT BUILD_TF_LITE_PARSER)
415 message(STATUS "Tensorflow Lite parser support is disabled")
416endif()
David Beck10b4dfd2018-09-19 12:03:20 +0100417
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000418if(NOT BUILD_ARMNN_SERIALIZER)
419 message(STATUS "Armnn Serializer support is disabled")
420endif()
421
Jim Flynn3091b062019-02-15 14:45:04 +0000422if(NOT BUILD_ARMNN_QUANTIZER)
423 message(STATUS "ArmNN Quantizer support is disabled")
424endif()
425
Pavel Macenauer59e057f2020-04-15 14:17:26 +0000426if(NOT BUILD_PYTHON_WHL)
427 message(STATUS "PyArmNN wheel package is disabled")
428endif()
429
430if(NOT BUILD_PYTHON_SRC)
431 message(STATUS "PyArmNN source package is disabled")
432endif()
433
434if(BUILD_PYTHON_WHL OR BUILD_PYTHON_SRC)
435 find_package(PythonInterp 3 REQUIRED)
436 if(NOT ${PYTHONINTERP_FOUND})
437 message(FATAL_ERROR "Python 3.x required to build PyArmNN, but not found")
438 endif()
439
440 find_package(PythonLibs 3 REQUIRED)
441 if(NOT ${PYTHONLIBS_FOUND})
442 message(FATAL_ERROR "Python 3.x development package required to build PyArmNN, but not found")
443 endif()
444
445 find_package(SWIG 4 REQUIRED)
446 if(NOT ${SWIG_FOUND})
447 message(FATAL_ERROR "SWIG 4.x requried to build PyArmNN, but not found")
448 endif()
449endif()
450
David Beck10b4dfd2018-09-19 12:03:20 +0100451# ArmNN source files required for all build options
452include_directories(SYSTEM third-party)