blob: ca0228450927b9956460940e13735c73d28237d7 [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)
É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)
Matthew Benthamb4e67202019-10-31 09:55:01 +000030option(SHARED_BOOST "Use dynamic linking for boost libraries" OFF)
Finn Williams2ed809c2020-04-20 21:21:07 +010031option(BUILD_BASE_PIPE_SERVER "Build the server to handle external profiling pipe traffic" ON)
Pavel Macenauer59e057f2020-04-15 14:17:26 +000032option(BUILD_PYTHON_WHL "Build Python wheel package" OFF)
33option(BUILD_PYTHON_SRC "Build Python source package" OFF)
Jim Flynnbbfe6032020-07-20 16:57:44 +010034option(BUILD_STATIC_PIPE_LIBS "Build Static PIPE libraries" OFF)
35option(BUILD_PIPE_ONLY "Build the PIPE libraries only" OFF)
Sadik Armagan5d03e312020-11-17 16:43:56 +000036option(BUILD_ARMNN_TFLITE_DELEGATE "Build the Arm NN TfLite delegate" OFF)
telsoa014fcda012018-03-09 14:13:49 +000037
38include(SelectLibraryConfigurations)
39
40set(COMPILER_IS_GNU_LIKE 0)
Jim Flynn82262f52020-07-16 11:23:45 +010041if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR
42 ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang OR
43 ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang)
telsoa014fcda012018-03-09 14:13:49 +000044 set(COMPILER_IS_GNU_LIKE 1)
45endif()
46
47# Enable CCache if available and not disabled
48option(USE_CCACHE "USE_CCACHE" ON)
49find_program(CCACHE_FOUND ccache)
50if(CCACHE_FOUND AND USE_CCACHE)
51 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
52 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "CCACHE_CPP2=yes ${rule_launch_compile} ccache")
53endif()
54
55# Enable distcc if available and not disabled
56option(USE_DISTCC "USE_DISTCC" OFF)
57find_program(DISTCC_FOUND distcc)
58if(DISTCC_FOUND AND USE_DISTCC)
59 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
60 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "${rule_launch_compile} distcc")
61endif()
62
63# Set to release configuration by default
64if(NOT CMAKE_BUILD_TYPE)
65 set(CMAKE_BUILD_TYPE "Release")
66endif()
67
68# Compiler flags that are always set
69set(CMAKE_POSITION_INDEPENDENT_CODE ON)
70if(COMPILER_IS_GNU_LIKE)
Derek Lambertiba25aee2019-12-10 22:20:54 +000071 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 +000072elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Rob Hughesfc6bf052019-12-16 17:10:51 +000073 # Disable C4996 (use of deprecated identifier) due to https://developercommunity.visualstudio.com/content/problem/252574/deprecated-compilation-warning-for-virtual-overrid.html
74 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /wd4996")
Rob Hughesbc873d22020-05-20 13:11:37 +010075 add_definitions(-DNO_STRICT=1)
telsoa014fcda012018-03-09 14:13:49 +000076endif()
77if("${CMAKE_SYSTEM_NAME}" STREQUAL Android)
78 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -llog")
79 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -llog")
80endif()
81
82# Compiler flags for Release builds
Matthew Benthame30054f2019-06-24 13:10:54 +010083set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
telsoa014fcda012018-03-09 14:13:49 +000084if(COMPILER_IS_GNU_LIKE)
85 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
86elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
87 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2")
88endif()
89
90# Compiler flags for Debug builds
91if(COMPILER_IS_GNU_LIKE)
Matthew Benthame30054f2019-06-24 13:10:54 +010092 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
telsoa014fcda012018-03-09 14:13:49 +000093elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Matthew Benthame30054f2019-06-24 13:10:54 +010094 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /ZI /Od")
telsoa014fcda012018-03-09 14:13:49 +000095 # Disable SAFESEH which is necessary for Edit and Continue to work
96 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
97 set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
98endif()
99
100# Modify RelWithDebInfo so that NDEBUG isn't defined.
101# This enables asserts.
102if (COMPILER_IS_GNU_LIKE)
103 string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
104elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
105 string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
106endif()
107
108# Compiler flags for code coverage measurements
109if(BUILD_FOR_COVERAGE)
110 if(NOT CMAKE_BUILD_TYPE EQUAL "Debug")
111 message(WARNING "BUILD_FOR_COVERAGE set so forcing to Debug build")
112 set(CMAKE_BUILD_TYPE "Debug")
113 endif()
114
115 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
116 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
117endif()
118
119if(BUILD_FOR_COVERAGE AND NOT BUILD_UNIT_TESTS)
120 message(WARNING "BUILD_FOR_COVERAGE set but not BUILD_UNIT_TESTS, so code coverage will not be able to run")
121endif()
122
123set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
124
Derek Lambertieac4adb2020-08-25 13:05:59 +0100125include(CMakeFindDependencyMacro)
126
Jim Flynnbbfe6032020-07-20 16:57:44 +0100127if (NOT BUILD_PIPE_ONLY)
128 # Boost
129 message(STATUS "Finding Boost")
130 if(SHARED_BOOST)
Matthew Benthamb4e67202019-10-31 09:55:01 +0000131 add_definitions(-DBOOST_ALL_DYN_LINK)
132 set(Boost_USE_STATIC_LIBS OFF)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100133 else()
Matthew Benthamb4e67202019-10-31 09:55:01 +0000134 set(Boost_USE_STATIC_LIBS ON)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100135 endif()
Matthew Benthame688d612020-11-13 12:04:01 +0000136 if (BUILD_UNIT_TESTS)
137 add_definitions("-DBOOST_ALL_NO_LIB") # Turn off auto-linking as we specify the libs manually
138 find_package(Boost 1.59 REQUIRED COMPONENTS unit_test_framework)
139 include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
140 link_directories(${Boost_LIBRARY_DIRS})
141 endif()
Matthew Benthamb4e67202019-10-31 09:55:01 +0000142endif()
telsoa014fcda012018-03-09 14:13:49 +0000143
Jim Flynnbbfe6032020-07-20 16:57:44 +0100144if (NOT BUILD_PIPE_ONLY)
145 # cxxopts (Alternative to boost::program_options)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200146 find_path(CXXOPTS_INCLUDE cxxopts/cxxopts.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100147 include_directories(SYSTEM "${CXXOPTS_INCLUDE}")
148endif()
Jan Eilers7e989832020-06-19 11:47:21 +0100149
Jim Flynnbbfe6032020-07-20 16:57:44 +0100150if (NOT BUILD_PIPE_ONLY)
151 # ghc (Alternative to boost::filesystem)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200152 find_path(GHC_INCLUDE ghc/filesystem.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100153 include_directories(SYSTEM "${GHC_INCLUDE}")
154endif()
Jan Eilers307fd342020-06-23 14:16:04 +0100155
telsoa014fcda012018-03-09 14:13:49 +0000156# pthread
Derek Lambertieac4adb2020-08-25 13:05:59 +0100157find_dependency(Threads)
telsoa014fcda012018-03-09 14:13:49 +0000158
159# Favour the protobuf passed on command line
Nikhil Raj6dd178f2021-04-02 22:04:39 +0100160if(BUILD_TF_PARSER OR BUILD_ONNX_PARSER)
telsoa014fcda012018-03-09 14:13:49 +0000161 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd"
162 PATHS ${PROTOBUF_ROOT}/lib
163 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
164 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd")
165
166 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf"
167 PATHS ${PROTOBUF_ROOT}/lib
168 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
169 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf")
170
171 select_library_configurations(PROTOBUF)
172
173 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h"
174 PATHS ${PROTOBUF_ROOT}/include
175 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
176 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h")
177
178 include_directories(SYSTEM "${PROTOBUF_INCLUDE_DIRS}")
179 add_definitions(-DPROTOBUF_USE_DLLS)
180endif()
181
telsoa014fcda012018-03-09 14:13:49 +0000182if(BUILD_TF_PARSER)
183 add_definitions(-DARMNN_TF_PARSER)
184
185 find_path(TF_GENERATED_SOURCES "tensorflow/core/protobuf/saved_model.pb.cc")
186
187 # C++ sources generated for tf protobufs
188 file(GLOB_RECURSE TF_PROTOBUFS "${TF_GENERATED_SOURCES}/*.pb.cc")
189
190 # C++ headers generated for tf protobufs
191 include_directories(SYSTEM "${TF_GENERATED_SOURCES}")
192endif()
193
telsoa01c577f2c2018-08-31 09:22:23 +0100194if(BUILD_ONNX_PARSER)
195 add_definitions(-DARMNN_ONNX_PARSER)
196
197 find_path(ONNX_GENERATED_SOURCES "onnx/onnx.pb.cc")
198
199 # C++ headers generated for onnx protobufs
200 include_directories(SYSTEM "${ONNX_GENERATED_SOURCES}")
201endif()
202
Sadik Armagan5d03e312020-11-17 16:43:56 +0000203if(BUILD_ARMNN_TFLITE_DELEGATE)
204 add_definitions(-DARMNN_TFLITE_DELEGATE)
205endif()
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000206# Flatbuffers support for TF Lite and Armnn Serializer
207if(BUILD_TF_LITE_PARSER OR BUILD_ARMNN_SERIALIZER)
telsoa01c577f2c2018-08-31 09:22:23 +0100208 # verify we have a valid flatbuffers include path
209 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
210 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
211
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000212 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
telsoa01c577f2c2018-08-31 09:22:23 +0100213
214 find_library(FLATBUFFERS_LIBRARY
215 NAMES libflatbuffers.a flatbuffers
216 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
217
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000218 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000219endif()
220
221# Flatbuffers schema support for TF Lite
222if(BUILD_TF_LITE_PARSER)
223 find_path(TF_LITE_SCHEMA_INCLUDE_PATH
224 schema_generated.h
225 HINTS ${TF_LITE_GENERATED_PATH})
226
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000227 message(STATUS "Tf Lite generated header found at: ${TF_LITE_SCHEMA_INCLUDE_PATH}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000228
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000229 add_definitions(-DARMNN_TF_LITE_PARSER)
telsoa01c577f2c2018-08-31 09:22:23 +0100230endif()
231
Kevin May43a799c2019-02-08 16:31:42 +0000232if(BUILD_ARMNN_SERIALIZER)
Kevin May43a799c2019-02-08 16:31:42 +0000233 add_definitions(-DARMNN_SERIALIZER)
Matthew Bentham268509a2019-02-25 13:58:24 +0000234 add_definitions(-DARMNN_SERIALIZER_SCHEMA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/src/armnnSerializer/ArmnnSchema.fbs")
Kevin May43a799c2019-02-08 16:31:42 +0000235endif()
236
telsoa014fcda012018-03-09 14:13:49 +0000237include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Sadik Armagana97a0be2020-03-03 10:44:56 +0000238include_directories(${CMAKE_CURRENT_SOURCE_DIR}/profiling)
telsoa014fcda012018-03-09 14:13:49 +0000239
240# ARM Compute
241# Note that ARM Compute has a different folder layout depending on the branch but also on
242# whether it comes from a prepackaged archive (this is why we add several hints below)
243if(ARMCOMPUTENEON OR ARMCOMPUTECL)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000244 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h
telsoa014fcda012018-03-09 14:13:49 +0000245 PATHS ${ARMCOMPUTE_ROOT}/include
246 PATHS ${ARMCOMPUTE_ROOT}/applications/arm_compute
247 PATHS ${ARMCOMPUTE_ROOT}
248 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000249 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h)
telsoa014fcda012018-03-09 14:13:49 +0000250 include_directories(SYSTEM "${ARMCOMPUTE_INCLUDE}")
251
252 # Find the Arm Compute libraries if not already specified (the user may have already defined this in advance,
253 # e.g. if building clframework as a dependent cmake project)
254 if (NOT DEFINED ARMCOMPUTE_LIBRARIES)
255 # We link to the static variant so that customers don't need to find and build a compatible version of clframework.
256 # First try the folders specified ARMCOMPUTE_BUILD_DIR (with PATH_SUFFIXES for
257 # Windows builds)
Matthew Bentham2624dd72020-05-20 10:44:18 +0100258 if ((NOT DEFINED ARMCOMPUTE_BUILD_DIR) AND (DEFINED ARMCOMPUTE_ROOT))
259 # Default build directory for ComputeLibrary is under the root
260 set(ARMCOMPUTE_BUILD_DIR ${ARMCOMPUTE_ROOT}/build)
261 endif()
262
telsoa014fcda012018-03-09 14:13:49 +0000263 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static
264 PATHS ${ARMCOMPUTE_BUILD_DIR}
265 PATH_SUFFIXES "Debug"
266 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
267 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static
268 PATHS ${ARMCOMPUTE_BUILD_DIR}
269 PATH_SUFFIXES "Release"
270 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
271 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static
272 PATHS ${ARMCOMPUTE_BUILD_DIR}
273 PATH_SUFFIXES "Debug"
274 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
275 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static
276 PATHS ${ARMCOMPUTE_BUILD_DIR}
277 PATH_SUFFIXES "Release"
278 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
279
280 # In case it wasn't there, try a default search (will work in cases where
281 # the library has been installed into a standard location)
282 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static)
283 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static)
284 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static)
285 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static)
286
Matthew Bentham6445cff2020-03-10 11:13:17 +0000287 # In case it wasn't there, try the dynamic libraries
288 # This case will get used in a linux setup where the Compute Library
289 # has been installed in a standard system library path as a dynamic library
290 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute)
291 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute)
292 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core)
293 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core)
294
telsoa014fcda012018-03-09 14:13:49 +0000295 set(ARMCOMPUTE_LIBRARIES
296 debug ${ARMCOMPUTE_LIBRARY_DEBUG} ${ARMCOMPUTE_CORE_LIBRARY_DEBUG}
297 optimized ${ARMCOMPUTE_LIBRARY_RELEASE} ${ARMCOMPUTE_CORE_LIBRARY_RELEASE} )
298 endif()
299endif()
300
301# ARM Compute NEON backend
302if(ARMCOMPUTENEON)
303 # Add preprocessor definition for ARM Compute NEON
304 add_definitions(-DARMCOMPUTENEON_ENABLED)
305 # The ARM Compute headers contain some NEON intrinsics, so we need to build armnn with NEON support on armv7
306 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES armv7 AND COMPILER_IS_GNU_LIKE)
307 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
308 endif()
309endif()
310
311# ARM Compute OpenCL backend
312if(ARMCOMPUTECL)
Nikhil Rajb55d3662021-02-11 14:49:19 +0000313 # verify we have a valid flatbuffers include path
314 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
315 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
316
317 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
318
319 find_library(FLATBUFFERS_LIBRARY
320 NAMES libflatbuffers.a flatbuffers
321 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
322
323 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
324
telsoa014fcda012018-03-09 14:13:49 +0000325 # Always use Arm compute library OpenCL headers
326 find_path(OPENCL_INCLUDE CL/cl2.hpp
327 PATHS ${ARMCOMPUTE_ROOT}/include
328 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
329
Matthew Bentham3b72db02018-10-11 09:47:01 +0100330 # Link against libOpenCL in opencl-1.2-stubs, but don't search there at runtime
331 link_libraries(-L${ARMCOMPUTE_BUILD_DIR}/opencl-1.2-stubs)
332 set(OPENCL_LIBRARIES OpenCL)
telsoa014fcda012018-03-09 14:13:49 +0000333
Matthew Bentham416b41d2020-02-05 22:15:26 +0000334 include_directories(SYSTEM ${OPENCL_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000335
336 # Add preprocessor definition for ARM Compute OpenCL
337 add_definitions(-DARMCOMPUTECL_ENABLED)
338
339 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DARM_COMPUTE_DEBUG_ENABLED")
340endif()
341
342# Used by both Arm Compute backends, but should be added
343# to the search path after the system directories if necessary
344if(ARMCOMPUTENEON OR ARMCOMPUTECL)
345 find_path(HALF_INCLUDE half/half.hpp)
346 find_path(HALF_INCLUDE half/half.hpp
347 PATHS ${ARMCOMPUTE_ROOT}/include
348 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
telsoa01c577f2c2018-08-31 09:22:23 +0100349 include_directories(SYSTEM ${HALF_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000350endif()
351
Matteo Martincighdb16dd32019-08-27 16:41:11 +0100352# ArmNN reference backend
353if(ARMNNREF)
354 add_definitions(-DARMNNREF_ENABLED)
Matteo Martincighe67edb22019-08-14 14:05:46 +0100355endif()
356
Narumol Prangnawarat060bad52020-11-20 16:17:48 +0000357if(ETHOSN_SUPPORT)
358 add_definitions(-DETHOSN_SUPPORT_ENABLED)
359endif()
360
Colm Donelanaa93d982020-06-28 08:16:46 +0100361# This is the root for the dynamic backend tests to search for dynamic
362# backends. By default it will be the project build directory.
Rob Hughes35c31c02020-08-17 15:47:20 +0100363add_definitions(-DDYNAMIC_BACKEND_BUILD_DIR="${PROJECT_BINARY_DIR}")
Colm Donelanaa93d982020-06-28 08:16:46 +0100364
Narumol Prangnawarat60a20fb2019-12-09 17:24:41 +0000365# ArmNN dynamic backend
366if(DYNAMIC_BACKEND_PATHS)
367 add_definitions(-DARMNN_DYNAMIC_BACKEND_ENABLED)
368endif()
369
Narumol Prangnawarat867eba52020-02-03 12:29:56 +0000370if(SAMPLE_DYNAMIC_BACKEND)
371 add_definitions(-DSAMPLE_DYNAMIC_BACKEND_ENABLED)
372endif()
373
telsoa014fcda012018-03-09 14:13:49 +0000374# Streamline annotate
375if(PROFILING_BACKEND_STREAMLINE)
376 include_directories("${GATOR_ROOT}/annotate")
377 add_definitions(-DARMNN_STREAMLINE_ENABLED)
378endif()
379
telsoa01c577f2c2018-08-31 09:22:23 +0100380if(HEAP_PROFILING OR LEAK_CHECKING)
surmeh013537c2c2018-05-18 16:31:43 +0100381 # enable heap profiling for everything except for referencetests
382 if(NOT ${PROJECT_NAME} STREQUAL "referencetests")
383 find_path(HEAP_PROFILER_INCLUDE gperftools/heap-profiler.h
384 PATHS ${GPERFTOOLS_ROOT}/include
385 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
386 include_directories(SYSTEM "${HEAP_PROFILER_INCLUDE}")
387 find_library(GPERF_TOOLS_LIBRARY
388 NAMES tcmalloc_debug
389 HINTS ${GPERFTOOLS_ROOT}/lib)
390 link_directories(${GPERFTOOLS_ROOT}/lib)
391
392 link_libraries(${GPERF_TOOLS_LIBRARY})
telsoa01c577f2c2018-08-31 09:22:23 +0100393 if (HEAP_PROFILING)
394 add_definitions("-DARMNN_HEAP_PROFILING_ENABLED=1")
395 endif()
396 if (LEAK_CHECKING)
397 add_definitions("-DARMNN_LEAK_CHECKING_ENABLED=1")
398 endif()
surmeh013537c2c2018-05-18 16:31:43 +0100399 else()
Rob Hughes721b82f2019-11-15 09:04:17 +0000400 message(STATUS "Heap profiling and leak checking are disabled for referencetests")
surmeh013537c2c2018-05-18 16:31:43 +0100401 endif()
402else()
403 # Valgrind only works with gperftools version number <= 2.4
404 CHECK_INCLUDE_FILE(valgrind/memcheck.h VALGRIND_FOUND)
405endif()
406
407
surmeh013537c2c2018-05-18 16:31:43 +0100408
409if(NOT BUILD_TF_PARSER)
410 message(STATUS "Tensorflow parser support is disabled")
411endif()
412
telsoa01c577f2c2018-08-31 09:22:23 +0100413if(NOT BUILD_TF_LITE_PARSER)
414 message(STATUS "Tensorflow Lite parser support is disabled")
415endif()
David Beck10b4dfd2018-09-19 12:03:20 +0100416
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000417if(NOT BUILD_ARMNN_SERIALIZER)
418 message(STATUS "Armnn Serializer support is disabled")
419endif()
420
Pavel Macenauer59e057f2020-04-15 14:17:26 +0000421if(NOT BUILD_PYTHON_WHL)
422 message(STATUS "PyArmNN wheel package is disabled")
423endif()
424
425if(NOT BUILD_PYTHON_SRC)
426 message(STATUS "PyArmNN source package is disabled")
427endif()
428
429if(BUILD_PYTHON_WHL OR BUILD_PYTHON_SRC)
430 find_package(PythonInterp 3 REQUIRED)
431 if(NOT ${PYTHONINTERP_FOUND})
432 message(FATAL_ERROR "Python 3.x required to build PyArmNN, but not found")
433 endif()
434
435 find_package(PythonLibs 3 REQUIRED)
436 if(NOT ${PYTHONLIBS_FOUND})
437 message(FATAL_ERROR "Python 3.x development package required to build PyArmNN, but not found")
438 endif()
439
440 find_package(SWIG 4 REQUIRED)
441 if(NOT ${SWIG_FOUND})
442 message(FATAL_ERROR "SWIG 4.x requried to build PyArmNN, but not found")
443 endif()
444endif()
445
David Beck10b4dfd2018-09-19 12:03:20 +0100446# ArmNN source files required for all build options
447include_directories(SYSTEM third-party)