blob: 2c5bc837e6bbff9f89d511bfacb1d211135a2c25 [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#
telsoa01c577f2c2018-08-31 09:22:23 +01006option(BUILD_ONNX_PARSER "Build Onnx parser" OFF)
telsoa014fcda012018-03-09 14:13:49 +00007option(BUILD_UNIT_TESTS "Build unit tests" ON)
8option(BUILD_TESTS "Build test applications" OFF)
9option(BUILD_FOR_COVERAGE "Use no optimization and output .gcno and .gcda files" OFF)
10option(ARMCOMPUTENEON "Build with ARM Compute NEON support" OFF)
11option(ARMCOMPUTECL "Build with ARM Compute OpenCL support" OFF)
Matteo Martincighf88663c2019-08-28 16:38:53 +010012option(ARMNNREF "Build with ArmNN reference support" ON)
telsoa014fcda012018-03-09 14:13:49 +000013option(PROFILING_BACKEND_STREAMLINE "Forward the armNN profiling events to DS-5/Streamline as annotations" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010014# options used for heap profiling and leak checking
surmeh013537c2c2018-05-18 16:31:43 +010015option(HEAP_PROFILING "Build with heap profiling enabled" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010016option(LEAK_CHECKING "Build with leak checking enabled" OFF)
surmeh013537c2c2018-05-18 16:31:43 +010017option(GPERFTOOLS_ROOT "Location where the gperftools 'include' and 'lib' folders to be found" Off)
telsoa01c577f2c2018-08-31 09:22:23 +010018# options used for tensorflow lite support
19option(BUILD_TF_LITE_PARSER "Build Tensorflow Lite parser" OFF)
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +000020option(BUILD_ARMNN_SERIALIZER "Build Armnn Serializer" OFF)
Éanna Ó Catháina563b922019-05-09 11:34:06 +010021option(BUILD_ACCURACY_TOOL "Build Accuracy Tool" OFF)
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +000022option(FLATC_DIR "Path to Flatbuffers compiler" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010023option(TF_LITE_GENERATED_PATH "Tensorflow lite generated C++ schema location" OFF)
24option(FLATBUFFERS_ROOT "Location where the flatbuffers 'include' and 'lib' folders to be found" Off)
Matteo Martincighe7d44982019-08-05 12:16:47 +010025option(DYNAMIC_BACKEND_PATHS "Colon seperated list of paths where to load the dynamic backends from" "")
Colm Donelan0dbe00a2020-06-03 08:00:28 +010026option(SAMPLE_DYNAMIC_BACKEND "Include the sample dynamic backend and its tests in the build" OFF)
Colm Donelana21620d2019-10-11 13:09:49 +010027option(BUILD_GATORD_MOCK "Build the Gatord simulator for external profiling testing." ON)
Sadik Armagan6f86b692020-03-09 11:04:32 +000028option(BUILD_TIMELINE_DECODER "Build the Timeline Decoder for external profiling." ON)
Finn Williams2ed809c2020-04-20 21:21:07 +010029option(BUILD_BASE_PIPE_SERVER "Build the server to handle external profiling pipe traffic" ON)
Pavel Macenauer59e057f2020-04-15 14:17:26 +000030option(BUILD_PYTHON_WHL "Build Python wheel package" OFF)
31option(BUILD_PYTHON_SRC "Build Python source package" OFF)
Jim Flynnbbfe6032020-07-20 16:57:44 +010032option(BUILD_STATIC_PIPE_LIBS "Build Static PIPE libraries" OFF)
33option(BUILD_PIPE_ONLY "Build the PIPE libraries only" OFF)
Sadik Armagan5d03e312020-11-17 16:43:56 +000034option(BUILD_ARMNN_TFLITE_DELEGATE "Build the Arm NN TfLite delegate" OFF)
Jim Flynne1fdd282021-10-26 21:26:10 +010035option(BUILD_MEMORY_STRATEGY_BENCHMARK "Build the MemoryBenchmark" OFF)
telsoa014fcda012018-03-09 14:13:49 +000036
37include(SelectLibraryConfigurations)
38
39set(COMPILER_IS_GNU_LIKE 0)
Jim Flynn82262f52020-07-16 11:23:45 +010040if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR
41 ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang OR
42 ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang)
telsoa014fcda012018-03-09 14:13:49 +000043 set(COMPILER_IS_GNU_LIKE 1)
44endif()
45
46# Enable CCache if available and not disabled
47option(USE_CCACHE "USE_CCACHE" ON)
48find_program(CCACHE_FOUND ccache)
49if(CCACHE_FOUND AND USE_CCACHE)
50 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
51 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "CCACHE_CPP2=yes ${rule_launch_compile} ccache")
52endif()
53
54# Enable distcc if available and not disabled
55option(USE_DISTCC "USE_DISTCC" OFF)
56find_program(DISTCC_FOUND distcc)
57if(DISTCC_FOUND AND USE_DISTCC)
58 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
59 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "${rule_launch_compile} distcc")
60endif()
61
62# Set to release configuration by default
63if(NOT CMAKE_BUILD_TYPE)
64 set(CMAKE_BUILD_TYPE "Release")
65endif()
66
67# Compiler flags that are always set
68set(CMAKE_POSITION_INDEPENDENT_CODE ON)
69if(COMPILER_IS_GNU_LIKE)
Derek Lambertiba25aee2019-12-10 22:20:54 +000070 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 +010071 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
72 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi")
73 endif()
telsoa014fcda012018-03-09 14:13:49 +000074elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Rob Hughesfc6bf052019-12-16 17:10:51 +000075 # Disable C4996 (use of deprecated identifier) due to https://developercommunity.visualstudio.com/content/problem/252574/deprecated-compilation-warning-for-virtual-overrid.html
76 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /wd4996")
Rob Hughesbc873d22020-05-20 13:11:37 +010077 add_definitions(-DNO_STRICT=1)
telsoa014fcda012018-03-09 14:13:49 +000078endif()
79if("${CMAKE_SYSTEM_NAME}" STREQUAL Android)
Keith Davisb8942bf2021-05-31 11:22:35 +010080 # -lz is necessary for when building with ACL set with compressed kernels
81 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -llog -lz")
82 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -llog -lz")
telsoa014fcda012018-03-09 14:13:49 +000083endif()
84
85# Compiler flags for Release builds
Matthew Benthame30054f2019-06-24 13:10:54 +010086set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
telsoa014fcda012018-03-09 14:13:49 +000087if(COMPILER_IS_GNU_LIKE)
88 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
89elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
90 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2")
91endif()
92
93# Compiler flags for Debug builds
94if(COMPILER_IS_GNU_LIKE)
Matthew Benthame30054f2019-06-24 13:10:54 +010095 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
telsoa014fcda012018-03-09 14:13:49 +000096elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Matthew Benthame30054f2019-06-24 13:10:54 +010097 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /ZI /Od")
telsoa014fcda012018-03-09 14:13:49 +000098 # Disable SAFESEH which is necessary for Edit and Continue to work
99 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
100 set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
101endif()
102
103# Modify RelWithDebInfo so that NDEBUG isn't defined.
104# This enables asserts.
105if (COMPILER_IS_GNU_LIKE)
106 string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
107elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
108 string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
109endif()
110
111# Compiler flags for code coverage measurements
112if(BUILD_FOR_COVERAGE)
113 if(NOT CMAKE_BUILD_TYPE EQUAL "Debug")
114 message(WARNING "BUILD_FOR_COVERAGE set so forcing to Debug build")
115 set(CMAKE_BUILD_TYPE "Debug")
116 endif()
117
118 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
119 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
120endif()
121
122if(BUILD_FOR_COVERAGE AND NOT BUILD_UNIT_TESTS)
123 message(WARNING "BUILD_FOR_COVERAGE set but not BUILD_UNIT_TESTS, so code coverage will not be able to run")
124endif()
125
126set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
127
Derek Lambertieac4adb2020-08-25 13:05:59 +0100128include(CMakeFindDependencyMacro)
129
Jim Flynnbbfe6032020-07-20 16:57:44 +0100130if (NOT BUILD_PIPE_ONLY)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100131 # cxxopts (Alternative to boost::program_options)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200132 find_path(CXXOPTS_INCLUDE cxxopts/cxxopts.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100133 include_directories(SYSTEM "${CXXOPTS_INCLUDE}")
134endif()
Jan Eilers7e989832020-06-19 11:47:21 +0100135
Jim Flynnbbfe6032020-07-20 16:57:44 +0100136if (NOT BUILD_PIPE_ONLY)
137 # ghc (Alternative to boost::filesystem)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200138 find_path(GHC_INCLUDE ghc/filesystem.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100139 include_directories(SYSTEM "${GHC_INCLUDE}")
140endif()
Jan Eilers307fd342020-06-23 14:16:04 +0100141
telsoa014fcda012018-03-09 14:13:49 +0000142# pthread
Derek Lambertieac4adb2020-08-25 13:05:59 +0100143find_dependency(Threads)
telsoa014fcda012018-03-09 14:13:49 +0000144
145# Favour the protobuf passed on command line
Nikhil Raj5d955cf2021-04-19 16:59:48 +0100146if(BUILD_ONNX_PARSER)
telsoa014fcda012018-03-09 14:13:49 +0000147 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd"
148 PATHS ${PROTOBUF_ROOT}/lib
149 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
150 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd")
151
152 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf"
153 PATHS ${PROTOBUF_ROOT}/lib
154 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
155 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf")
156
157 select_library_configurations(PROTOBUF)
158
159 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h"
160 PATHS ${PROTOBUF_ROOT}/include
161 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
162 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h")
163
164 include_directories(SYSTEM "${PROTOBUF_INCLUDE_DIRS}")
165 add_definitions(-DPROTOBUF_USE_DLLS)
telsoa014fcda012018-03-09 14:13:49 +0000166
telsoa01c577f2c2018-08-31 09:22:23 +0100167 add_definitions(-DARMNN_ONNX_PARSER)
168
169 find_path(ONNX_GENERATED_SOURCES "onnx/onnx.pb.cc")
170
171 # C++ headers generated for onnx protobufs
172 include_directories(SYSTEM "${ONNX_GENERATED_SOURCES}")
173endif()
174
Sadik Armagan5d03e312020-11-17 16:43:56 +0000175if(BUILD_ARMNN_TFLITE_DELEGATE)
176 add_definitions(-DARMNN_TFLITE_DELEGATE)
177endif()
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000178# Flatbuffers support for TF Lite and Armnn Serializer
179if(BUILD_TF_LITE_PARSER OR BUILD_ARMNN_SERIALIZER)
telsoa01c577f2c2018-08-31 09:22:23 +0100180 # verify we have a valid flatbuffers include path
181 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
182 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
183
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000184 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
telsoa01c577f2c2018-08-31 09:22:23 +0100185
186 find_library(FLATBUFFERS_LIBRARY
187 NAMES libflatbuffers.a flatbuffers
188 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
189
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000190 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000191endif()
192
193# Flatbuffers schema support for TF Lite
194if(BUILD_TF_LITE_PARSER)
195 find_path(TF_LITE_SCHEMA_INCLUDE_PATH
196 schema_generated.h
197 HINTS ${TF_LITE_GENERATED_PATH})
198
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000199 message(STATUS "Tf Lite generated header found at: ${TF_LITE_SCHEMA_INCLUDE_PATH}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000200
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000201 add_definitions(-DARMNN_TF_LITE_PARSER)
telsoa01c577f2c2018-08-31 09:22:23 +0100202endif()
203
Kevin May43a799c2019-02-08 16:31:42 +0000204if(BUILD_ARMNN_SERIALIZER)
Kevin May43a799c2019-02-08 16:31:42 +0000205 add_definitions(-DARMNN_SERIALIZER)
Matthew Bentham268509a2019-02-25 13:58:24 +0000206 add_definitions(-DARMNN_SERIALIZER_SCHEMA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/src/armnnSerializer/ArmnnSchema.fbs")
Kevin May43a799c2019-02-08 16:31:42 +0000207endif()
208
telsoa014fcda012018-03-09 14:13:49 +0000209include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Sadik Armagana97a0be2020-03-03 10:44:56 +0000210include_directories(${CMAKE_CURRENT_SOURCE_DIR}/profiling)
telsoa014fcda012018-03-09 14:13:49 +0000211
212# ARM Compute
213# Note that ARM Compute has a different folder layout depending on the branch but also on
214# whether it comes from a prepackaged archive (this is why we add several hints below)
215if(ARMCOMPUTENEON OR ARMCOMPUTECL)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000216 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h
telsoa014fcda012018-03-09 14:13:49 +0000217 PATHS ${ARMCOMPUTE_ROOT}/include
218 PATHS ${ARMCOMPUTE_ROOT}/applications/arm_compute
219 PATHS ${ARMCOMPUTE_ROOT}
220 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
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 include_directories(SYSTEM "${ARMCOMPUTE_INCLUDE}")
223
224 # Find the Arm Compute libraries if not already specified (the user may have already defined this in advance,
225 # e.g. if building clframework as a dependent cmake project)
226 if (NOT DEFINED ARMCOMPUTE_LIBRARIES)
227 # We link to the static variant so that customers don't need to find and build a compatible version of clframework.
228 # First try the folders specified ARMCOMPUTE_BUILD_DIR (with PATH_SUFFIXES for
229 # Windows builds)
Matthew Bentham2624dd72020-05-20 10:44:18 +0100230 if ((NOT DEFINED ARMCOMPUTE_BUILD_DIR) AND (DEFINED ARMCOMPUTE_ROOT))
231 # Default build directory for ComputeLibrary is under the root
232 set(ARMCOMPUTE_BUILD_DIR ${ARMCOMPUTE_ROOT}/build)
233 endif()
234
telsoa014fcda012018-03-09 14:13:49 +0000235 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static
236 PATHS ${ARMCOMPUTE_BUILD_DIR}
237 PATH_SUFFIXES "Debug"
238 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
239 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static
240 PATHS ${ARMCOMPUTE_BUILD_DIR}
241 PATH_SUFFIXES "Release"
242 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
243 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static
244 PATHS ${ARMCOMPUTE_BUILD_DIR}
245 PATH_SUFFIXES "Debug"
246 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
247 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static
248 PATHS ${ARMCOMPUTE_BUILD_DIR}
249 PATH_SUFFIXES "Release"
250 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
251
252 # In case it wasn't there, try a default search (will work in cases where
253 # the library has been installed into a standard location)
254 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static)
255 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static)
256 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static)
257 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static)
258
Matthew Bentham6445cff2020-03-10 11:13:17 +0000259 # In case it wasn't there, try the dynamic libraries
260 # This case will get used in a linux setup where the Compute Library
261 # has been installed in a standard system library path as a dynamic library
262 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute)
263 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute)
264 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core)
265 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core)
266
telsoa014fcda012018-03-09 14:13:49 +0000267 set(ARMCOMPUTE_LIBRARIES
268 debug ${ARMCOMPUTE_LIBRARY_DEBUG} ${ARMCOMPUTE_CORE_LIBRARY_DEBUG}
269 optimized ${ARMCOMPUTE_LIBRARY_RELEASE} ${ARMCOMPUTE_CORE_LIBRARY_RELEASE} )
270 endif()
271endif()
272
273# ARM Compute NEON backend
274if(ARMCOMPUTENEON)
275 # Add preprocessor definition for ARM Compute NEON
276 add_definitions(-DARMCOMPUTENEON_ENABLED)
277 # The ARM Compute headers contain some NEON intrinsics, so we need to build armnn with NEON support on armv7
278 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES armv7 AND COMPILER_IS_GNU_LIKE)
279 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
280 endif()
281endif()
282
283# ARM Compute OpenCL backend
284if(ARMCOMPUTECL)
Nikhil Rajb55d3662021-02-11 14:49:19 +0000285 # verify we have a valid flatbuffers include path
286 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
287 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
288
289 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
290
291 find_library(FLATBUFFERS_LIBRARY
292 NAMES libflatbuffers.a flatbuffers
293 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
294
295 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
296
telsoa014fcda012018-03-09 14:13:49 +0000297 # Always use Arm compute library OpenCL headers
Nikhil Raj407cddf2021-11-30 09:57:08 +0000298 find_path(OPENCL_INCLUDE CL/opencl.hpp
telsoa014fcda012018-03-09 14:13:49 +0000299 PATHS ${ARMCOMPUTE_ROOT}/include
300 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
301
Matthew Bentham3b72db02018-10-11 09:47:01 +0100302 # Link against libOpenCL in opencl-1.2-stubs, but don't search there at runtime
303 link_libraries(-L${ARMCOMPUTE_BUILD_DIR}/opencl-1.2-stubs)
304 set(OPENCL_LIBRARIES OpenCL)
telsoa014fcda012018-03-09 14:13:49 +0000305
Matthew Bentham416b41d2020-02-05 22:15:26 +0000306 include_directories(SYSTEM ${OPENCL_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000307
308 # Add preprocessor definition for ARM Compute OpenCL
309 add_definitions(-DARMCOMPUTECL_ENABLED)
310
311 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DARM_COMPUTE_DEBUG_ENABLED")
312endif()
313
314# Used by both Arm Compute backends, but should be added
315# to the search path after the system directories if necessary
316if(ARMCOMPUTENEON OR ARMCOMPUTECL)
317 find_path(HALF_INCLUDE half/half.hpp)
318 find_path(HALF_INCLUDE half/half.hpp
319 PATHS ${ARMCOMPUTE_ROOT}/include
320 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
telsoa01c577f2c2018-08-31 09:22:23 +0100321 include_directories(SYSTEM ${HALF_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000322endif()
323
Matteo Martincighdb16dd32019-08-27 16:41:11 +0100324# ArmNN reference backend
325if(ARMNNREF)
326 add_definitions(-DARMNNREF_ENABLED)
Matteo Martincighe67edb22019-08-14 14:05:46 +0100327endif()
328
Colm Donelanaa93d982020-06-28 08:16:46 +0100329# This is the root for the dynamic backend tests to search for dynamic
330# backends. By default it will be the project build directory.
Rob Hughes35c31c02020-08-17 15:47:20 +0100331add_definitions(-DDYNAMIC_BACKEND_BUILD_DIR="${PROJECT_BINARY_DIR}")
Colm Donelanaa93d982020-06-28 08:16:46 +0100332
Narumol Prangnawarat60a20fb2019-12-09 17:24:41 +0000333# ArmNN dynamic backend
334if(DYNAMIC_BACKEND_PATHS)
335 add_definitions(-DARMNN_DYNAMIC_BACKEND_ENABLED)
336endif()
337
Narumol Prangnawarat867eba52020-02-03 12:29:56 +0000338if(SAMPLE_DYNAMIC_BACKEND)
339 add_definitions(-DSAMPLE_DYNAMIC_BACKEND_ENABLED)
340endif()
341
telsoa014fcda012018-03-09 14:13:49 +0000342# Streamline annotate
343if(PROFILING_BACKEND_STREAMLINE)
344 include_directories("${GATOR_ROOT}/annotate")
345 add_definitions(-DARMNN_STREAMLINE_ENABLED)
346endif()
347
telsoa01c577f2c2018-08-31 09:22:23 +0100348if(HEAP_PROFILING OR LEAK_CHECKING)
surmeh013537c2c2018-05-18 16:31:43 +0100349 # enable heap profiling for everything except for referencetests
350 if(NOT ${PROJECT_NAME} STREQUAL "referencetests")
351 find_path(HEAP_PROFILER_INCLUDE gperftools/heap-profiler.h
352 PATHS ${GPERFTOOLS_ROOT}/include
353 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
354 include_directories(SYSTEM "${HEAP_PROFILER_INCLUDE}")
355 find_library(GPERF_TOOLS_LIBRARY
356 NAMES tcmalloc_debug
357 HINTS ${GPERFTOOLS_ROOT}/lib)
358 link_directories(${GPERFTOOLS_ROOT}/lib)
359
360 link_libraries(${GPERF_TOOLS_LIBRARY})
telsoa01c577f2c2018-08-31 09:22:23 +0100361 if (HEAP_PROFILING)
362 add_definitions("-DARMNN_HEAP_PROFILING_ENABLED=1")
363 endif()
364 if (LEAK_CHECKING)
365 add_definitions("-DARMNN_LEAK_CHECKING_ENABLED=1")
366 endif()
surmeh013537c2c2018-05-18 16:31:43 +0100367 else()
Rob Hughes721b82f2019-11-15 09:04:17 +0000368 message(STATUS "Heap profiling and leak checking are disabled for referencetests")
surmeh013537c2c2018-05-18 16:31:43 +0100369 endif()
370else()
371 # Valgrind only works with gperftools version number <= 2.4
372 CHECK_INCLUDE_FILE(valgrind/memcheck.h VALGRIND_FOUND)
373endif()
374
375
telsoa01c577f2c2018-08-31 09:22:23 +0100376if(NOT BUILD_TF_LITE_PARSER)
377 message(STATUS "Tensorflow Lite parser support is disabled")
378endif()
David Beck10b4dfd2018-09-19 12:03:20 +0100379
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000380if(NOT BUILD_ARMNN_SERIALIZER)
381 message(STATUS "Armnn Serializer support is disabled")
382endif()
383
Pavel Macenauer59e057f2020-04-15 14:17:26 +0000384if(NOT BUILD_PYTHON_WHL)
385 message(STATUS "PyArmNN wheel package is disabled")
386endif()
387
388if(NOT BUILD_PYTHON_SRC)
389 message(STATUS "PyArmNN source package is disabled")
390endif()
391
392if(BUILD_PYTHON_WHL OR BUILD_PYTHON_SRC)
393 find_package(PythonInterp 3 REQUIRED)
394 if(NOT ${PYTHONINTERP_FOUND})
395 message(FATAL_ERROR "Python 3.x required to build PyArmNN, but not found")
396 endif()
397
398 find_package(PythonLibs 3 REQUIRED)
399 if(NOT ${PYTHONLIBS_FOUND})
400 message(FATAL_ERROR "Python 3.x development package required to build PyArmNN, but not found")
401 endif()
402
403 find_package(SWIG 4 REQUIRED)
404 if(NOT ${SWIG_FOUND})
405 message(FATAL_ERROR "SWIG 4.x requried to build PyArmNN, but not found")
406 endif()
407endif()
408
David Beck10b4dfd2018-09-19 12:03:20 +0100409# ArmNN source files required for all build options
410include_directories(SYSTEM third-party)