xref: /aosp_15_r20/external/armnn/cmake/GlobalConfig.cmake (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1#
2# Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
3# Copyright 2020 NXP
4# SPDX-License-Identifier: MIT
5#
6
7option(BUILD_ONNX_PARSER "Build Onnx parser" OFF)
8option(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)
13option(ARMNNREF "Build with ArmNN reference support" ON)
14option(ARMNNTOSAREF "Build with TOSA reference support" OFF)
15option(PROFILING_BACKEND_STREAMLINE "Forward the armNN profiling events to DS-5/Streamline as annotations" OFF)
16# options used for heap profiling and leak checking
17option(HEAP_PROFILING "Build with heap profiling enabled" OFF)
18option(LEAK_CHECKING "Build with leak checking enabled" OFF)
19option(GPERFTOOLS_ROOT "Location where the gperftools 'include' and 'lib' folders to be found" Off)
20# options used for tensorflow lite support
21option(BUILD_TF_LITE_PARSER "Build Tensorflow Lite parser" OFF)
22option(BUILD_ARMNN_SERIALIZER "Build Armnn Serializer" OFF)
23option(BUILD_ACCURACY_TOOL "Build Accuracy Tool" OFF)
24option(FLATC_DIR "Path to Flatbuffers compiler" OFF)
25option(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)
27option(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)
29option(TOSA_REFERENCE_MODEL_OUTPUT "TOSA Reference Model output is printed during layer support checks" ON)
30option(DYNAMIC_BACKEND_PATHS "Colon seperated list of paths where to load the dynamic backends from" "")
31option(SAMPLE_DYNAMIC_BACKEND "Include the sample dynamic backend and its tests in the build" OFF)
32option(BUILD_GATORD_MOCK "Build the Gatord simulator for external profiling testing." ON)
33option(BUILD_TIMELINE_DECODER "Build the Timeline Decoder for external profiling." ON)
34option(BUILD_BASE_PIPE_SERVER "Build the server to handle external profiling pipe traffic" ON)
35option(BUILD_PYTHON_WHL "Build Python wheel package" OFF)
36option(BUILD_PYTHON_SRC "Build Python source package" OFF)
37option(BUILD_STATIC_PIPE_LIBS "Build Static PIPE libraries" OFF)
38option(BUILD_PIPE_ONLY "Build the PIPE libraries only" OFF)
39option(BUILD_CLASSIC_DELEGATE "Build the Arm NN TfLite delegate" OFF)
40option(BUILD_OPAQUE_DELEGATE "Build the Arm NN TfLite Opaque delegate" OFF)
41option(BUILD_MEMORY_STRATEGY_BENCHMARK "Build the MemoryBenchmark" OFF)
42option(BUILD_BARE_METAL "Disable features requiring operating system support" OFF)
43option(BUILD_SHARED_LIBS "Determines if Armnn will be built statically or dynamically.
44                          This is an experimental feature and not fully supported.
45                          Only the ArmNN core and the Delegate can be built statically." ON)
46option(EXECUTE_NETWORK_STATIC " This is a limited experimental build that is entirely static.
47                                It currently only supports being set by changing the current CMake default options like so:
48                                BUILD_TF_LITE_PARSER=1/0
49                                BUILD_ARMNN_SERIALIZER=1/0
50                                ARMCOMPUTENEON=1/0
51                                ARMNNREF=1/0
52                                ARMCOMPUTECL=0
53                                BUILD_ONNX_PARSER=0
54                                BUILD_CLASSIC_DELEGATE=0
55                                BUILD_OPAQUE_DELEGATE=0
56                                BUILD_TIMELINE_DECODER=0
57                                BUILD_BASE_PIPE_SERVER=0
58                                BUILD_UNIT_TESTS=0
59                                BUILD_GATORD_MOCK=0" OFF)
60
61if(BUILD_ARMNN_TFLITE_DELEGATE)
62    message(BUILD_ARMNN_TFLITE_DELEGATE option is deprecated, it will be removed in 24.02, please use BUILD_CLASSIC_DELEGATE instead)
63    set(BUILD_CLASSIC_DELEGATE 1)
64endif()
65
66include(SelectLibraryConfigurations)
67
68set(COMPILER_IS_GNU_LIKE 0)
69if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR
70   ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang OR
71   ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang)
72    set(COMPILER_IS_GNU_LIKE 1)
73endif()
74
75# Enable CCache if available and not disabled
76option(USE_CCACHE "USE_CCACHE" ON)
77find_program(CCACHE_FOUND ccache)
78if(CCACHE_FOUND AND USE_CCACHE)
79    get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
80    set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "CCACHE_CPP2=yes ${rule_launch_compile} ccache")
81endif()
82
83# Enable distcc if available and not disabled
84option(USE_DISTCC "USE_DISTCC" OFF)
85find_program(DISTCC_FOUND distcc)
86if(DISTCC_FOUND AND USE_DISTCC)
87    get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
88    set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "${rule_launch_compile} distcc")
89endif()
90
91# Set to release configuration by default
92if(NOT CMAKE_BUILD_TYPE)
93    set(CMAKE_BUILD_TYPE "Release")
94endif()
95
96# Compiler flags that are always set
97set(CMAKE_POSITION_INDEPENDENT_CODE ON)
98if(COMPILER_IS_GNU_LIKE)
99    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Wextra -Werror -Wold-style-cast -Wno-missing-braces -Wconversion -Wsign-conversion")
100    if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
101        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -Wno-psabi")
102    endif()
103elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
104    # Disable C4996 (use of deprecated identifier) due to
105    # https://developercommunity.visualstudio.com/content/problem/252574/deprecated-compilation-warning-for-virtual-overrid.html
106    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /wd4996")
107    add_definitions(-DNO_STRICT=1)
108endif()
109if("${CMAKE_SYSTEM_NAME}" STREQUAL Android)
110    # -lz is necessary for when building with ACL set with compressed kernels
111    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -llog -lz")
112    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -llog -lz")
113endif()
114
115# Compiler flags for Release builds
116set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
117if(COMPILER_IS_GNU_LIKE)
118    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
119elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
120    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2")
121endif()
122
123# Compiler flags for Debug builds
124if(COMPILER_IS_GNU_LIKE)
125    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
126elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
127    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /ZI /Od")
128    # Disable SAFESEH which is necessary for Edit and Continue to work
129    set(CMAKE_EXE_LINKER_FLAGS_DEBUG  "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
130    set(CMAKE_SHARED_LINKER_FLAGS_DEBUG  "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
131endif()
132
133# Modify RelWithDebInfo so that NDEBUG isn't defined.
134# This enables asserts.
135if (COMPILER_IS_GNU_LIKE)
136    string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
137elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
138    string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
139endif()
140
141# Compiler flags for code coverage measurements
142if(BUILD_FOR_COVERAGE)
143    if(NOT CMAKE_BUILD_TYPE EQUAL "Debug")
144        message(WARNING "BUILD_FOR_COVERAGE set so forcing to Debug build")
145        set(CMAKE_BUILD_TYPE "Debug")
146    endif()
147
148    set(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} --coverage")
149    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
150endif()
151
152if(BUILD_FOR_COVERAGE AND NOT BUILD_UNIT_TESTS)
153    message(WARNING "BUILD_FOR_COVERAGE set but not BUILD_UNIT_TESTS, so code coverage will not be able to run")
154endif()
155
156set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
157
158include(CMakeFindDependencyMacro)
159
160
161if(EXECUTE_NETWORK_STATIC)
162    add_definitions(-DARMNN_DISABLE_SOCKETS
163                    -DBUILD_SHARED_LIBS=0
164                    -DARMNN_EXECUTE_NETWORK_STATIC)
165endif()
166
167if(BUILD_BARE_METAL)
168    add_definitions(-DARMNN_BUILD_BARE_METAL
169            -DARMNN_DISABLE_FILESYSTEM
170            -DARMNN_DISABLE_PROCESSES
171            -DARMNN_DISABLE_THREADS
172            -DARMNN_DISABLE_SOCKETS)
173endif()
174
175if (NOT BUILD_PIPE_ONLY)
176  # cxxopts (Alternative to boost::program_options)
177  find_path(CXXOPTS_INCLUDE cxxopts/cxxopts.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
178  include_directories(SYSTEM "${CXXOPTS_INCLUDE}")
179endif()
180
181if (NOT BUILD_PIPE_ONLY)
182  # ghc (Alternative to boost::filesystem)
183  find_path(GHC_INCLUDE ghc/filesystem.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
184  include_directories(SYSTEM "${GHC_INCLUDE}")
185endif()
186
187# JNI_BUILD has DBUILD_SHARED_LIBS set to 0 and not finding libs while building
188# hence added NOT BUILD_CLASSIC_DELEGATE/BUILD_OPAQUE_DELEGATE condition
189if(NOT BUILD_SHARED_LIBS AND NOT BUILD_CLASSIC_DELEGATE AND NOT BUILD_OPAQUE_DELEGATE)
190    set(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib)
191endif()
192
193# pthread
194if (NOT BUILD_BARE_METAL)
195find_package(Threads)
196endif()
197
198if (EXECUTE_NETWORK_STATIC)
199    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -static -pthread")
200endif()
201
202# Favour the protobuf passed on command line
203if(BUILD_ONNX_PARSER)
204    find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd"
205        PATHS ${PROTOBUF_ROOT}/lib
206        NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
207    find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd")
208
209    find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf"
210        PATHS ${PROTOBUF_ROOT}/lib
211        NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
212    find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf")
213
214    select_library_configurations(PROTOBUF)
215
216    find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h"
217              PATHS ${PROTOBUF_ROOT}/include
218              NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
219    find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h")
220
221    include_directories(SYSTEM "${PROTOBUF_INCLUDE_DIRS}")
222    add_definitions(-DPROTOBUF_USE_DLLS)
223
224    add_definitions(-DARMNN_ONNX_PARSER)
225
226    find_path(ONNX_GENERATED_SOURCES "onnx/onnx.pb.cc")
227
228    # C++ headers generated for onnx protobufs
229    include_directories(SYSTEM "${ONNX_GENERATED_SOURCES}")
230endif()
231
232if(BUILD_CLASSIC_DELEGATE)
233    add_definitions(-DARMNN_TFLITE_DELEGATE)
234endif()
235
236if(BUILD_OPAQUE_DELEGATE)
237    add_definitions(-DARMNN_TFLITE_OPAQUE_DELEGATE)
238endif()
239
240# Flatbuffers support for TF Lite, Armnn Serializer or the TOSA backend.
241if(BUILD_TF_LITE_PARSER OR BUILD_ARMNN_SERIALIZER OR ARMNNTOSAREF)
242    # verify we have a valid flatbuffers include path
243    find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
244              HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
245
246    message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
247
248    find_library(FLATBUFFERS_LIBRARY
249                 NAMES libflatbuffers.a flatbuffers
250                 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
251
252    message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
253endif()
254
255# Flatbuffers schema support for TF Lite
256if(BUILD_TF_LITE_PARSER)
257    find_path(TF_LITE_SCHEMA_INCLUDE_PATH
258              schema_generated.h
259              HINTS ${TF_LITE_GENERATED_PATH})
260
261    message(STATUS "Tf Lite generated header found at: ${TF_LITE_SCHEMA_INCLUDE_PATH}")
262
263    add_definitions(-DARMNN_TF_LITE_PARSER)
264endif()
265
266if(BUILD_ARMNN_SERIALIZER)
267    add_definitions(-DARMNN_SERIALIZER)
268    add_definitions(-DARMNN_SERIALIZER_SCHEMA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/src/armnnSerializer/ArmnnSchema.fbs")
269endif()
270
271include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
272include_directories(${CMAKE_CURRENT_SOURCE_DIR}/profiling)
273
274# ARM Compute
275# Note that ARM Compute has a different folder layout depending on the branch but also on
276# whether it comes from a prepackaged archive (this is why we add several hints below)
277if(ARMCOMPUTENEON OR ARMCOMPUTECL)
278    find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h
279              PATHS ${ARMCOMPUTE_ROOT}/include
280              PATHS ${ARMCOMPUTE_ROOT}/applications/arm_compute
281              PATHS ${ARMCOMPUTE_ROOT}
282              NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
283    find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h)
284    include_directories(SYSTEM "${ARMCOMPUTE_INCLUDE}")
285
286    # Find the Arm Compute libraries if not already specified (the user may have already defined this in advance,
287    # e.g. if building clframework as a dependent cmake project)
288    if (NOT DEFINED ARMCOMPUTE_LIBRARIES)
289        # We link to the static variant so that customers don't need to find and build a compatible version of clframework.
290        # First try the folders specified ARMCOMPUTE_BUILD_DIR (with PATH_SUFFIXES for
291        # Windows builds)
292        if ((NOT DEFINED ARMCOMPUTE_BUILD_DIR) AND (DEFINED ARMCOMPUTE_ROOT))
293            # Default build directory for ComputeLibrary is under the root
294            set(ARMCOMPUTE_BUILD_DIR ${ARMCOMPUTE_ROOT}/build)
295        endif()
296
297        find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static
298                     PATHS ${ARMCOMPUTE_BUILD_DIR}
299                     PATH_SUFFIXES "Debug"
300                     NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
301        find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static
302                     PATHS ${ARMCOMPUTE_BUILD_DIR}
303                     PATH_SUFFIXES "Release"
304                     NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
305        find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static
306                     PATHS ${ARMCOMPUTE_BUILD_DIR}
307                     PATH_SUFFIXES "Debug"
308                     NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
309        find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static
310                     PATHS ${ARMCOMPUTE_BUILD_DIR}
311                     PATH_SUFFIXES "Release"
312                     NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
313
314        # In case it wasn't there, try a default search (will work in cases where
315        # the library has been installed into a standard location)
316        find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static)
317        find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static)
318        find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static)
319        find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static)
320
321        # In case it wasn't there, try the dynamic libraries
322        # This case will get used in a linux setup where the Compute Library
323        # has been installed in a standard system library path as a dynamic library
324        find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute)
325        find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute)
326        find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core)
327        find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core)
328
329        set(ARMCOMPUTE_LIBRARIES
330            debug ${ARMCOMPUTE_LIBRARY_DEBUG} ${ARMCOMPUTE_CORE_LIBRARY_DEBUG}
331            optimized ${ARMCOMPUTE_LIBRARY_RELEASE} ${ARMCOMPUTE_CORE_LIBRARY_RELEASE} )
332    endif()
333endif()
334
335# ARM Compute NEON backend
336if(ARMCOMPUTENEON)
337    # Add preprocessor definition for ARM Compute NEON
338    add_definitions(-DARMCOMPUTENEON_ENABLED)
339    # The ARM Compute headers contain some NEON intrinsics, so we need to build armnn with NEON support on armv7
340    if(${CMAKE_SYSTEM_PROCESSOR} MATCHES armv7 AND COMPILER_IS_GNU_LIKE)
341        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
342    endif()
343endif()
344
345# ARM Compute OpenCL backend
346if(ARMCOMPUTECL)
347    # verify we have a valid flatbuffers include path
348    find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
349              HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
350
351    message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
352
353    find_library(FLATBUFFERS_LIBRARY
354                 NAMES libflatbuffers.a flatbuffers
355                 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
356
357    message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
358
359    # Always use Arm compute library OpenCL headers
360    find_path(OPENCL_INCLUDE CL/opencl.hpp
361              PATHS ${ARMCOMPUTE_ROOT}/include
362              NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
363
364    # Link against libOpenCL in opencl-1.2-stubs, but don't search there at runtime
365    link_libraries(-L${ARMCOMPUTE_BUILD_DIR}/opencl-1.2-stubs)
366    set(OPENCL_LIBRARIES OpenCL)
367
368    include_directories(SYSTEM ${OPENCL_INCLUDE})
369
370    # Add preprocessor definition for ARM Compute OpenCL
371    add_definitions(-DARMCOMPUTECL_ENABLED)
372
373    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DARM_COMPUTE_DEBUG_ENABLED")
374endif()
375
376# Used by both Arm Compute backends, but should be added
377# to the search path after the system directories if necessary
378if(ARMCOMPUTENEON OR ARMCOMPUTECL)
379    find_path(HALF_INCLUDE half/half.hpp)
380    find_path(HALF_INCLUDE half/half.hpp
381              PATHS ${ARMCOMPUTE_ROOT}/include
382              NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
383    include_directories(SYSTEM ${HALF_INCLUDE})
384endif()
385
386# ArmNN reference backend
387if(ARMNNREF)
388    add_definitions(-DARMNNREF_ENABLED)
389endif()
390
391# If a backend requires TOSA common, add it here.
392if(ARMNNTOSAREF)
393    set(ARMNNTOSACOMMON ON)
394endif()
395
396if(ARMNNTOSACOMMON)
397    # Locate the includes for the TOSA serialization library as it is needed for TOSA common and TOSA backends.
398    message(STATUS "TOSA serialization library root set to ${TOSA_SERIALIZATION_LIB_ROOT}")
399
400    find_path(TOSA_SERIALIZATION_LIB_INCLUDE tosa_serialization_handler.h
401              HINTS ${TOSA_SERIALIZATION_LIB_ROOT}/include)
402    message(STATUS "TOSA serialization library include directory located at: ${TOSA_SERIALIZATION_LIB_INCLUDE}")
403
404    find_library(TOSA_SERIALIZATION_LIB
405                 NAMES tosa_serialization_lib.a tosa_serialization_lib
406                 HINTS ${TOSA_SERIALIZATION_LIB_ROOT}/lib /usr/local/lib /usr/lib)
407    message(STATUS "TOSA serialization library set to ${TOSA_SERIALIZATION_LIB}")
408
409    # Include required headers for TOSA Serialization Library
410    include_directories(SYSTEM ${FLATBUFFERS_INCLUDE_PATH})
411    include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third-party/half)
412    include_directories(SYSTEM ${TOSA_SERIALIZATION_LIB_INCLUDE})
413endif()
414
415# ArmNN TOSA reference backend
416if(ARMNNTOSAREF)
417    # Locate the includes for the TOSA Reference Model, which is specific to the TOSA Reference Backend.
418    message(STATUS "TOSA Reference Model root set to ${TOSA_REFERENCE_MODEL_ROOT}")
419
420    find_path(TOSA_REFERENCE_MODEL_INCLUDE model_runner.h
421              HINTS ${TOSA_REFERENCE_MODEL_ROOT}/include)
422    message(STATUS "TOSA Reference Model include directory located at: ${TOSA_REFERENCE_MODEL_INCLUDE}")
423
424    include_directories(SYSTEM ${TOSA_REFERENCE_MODEL_INCLUDE})
425
426    find_library(TOSA_REFERENCE_MODEL_LIB
427                 NAMES tosa_reference_model_lib.a tosa_reference_model_lib
428                 HINTS ${TOSA_REFERENCE_MODEL_ROOT}/lib /usr/local/lib /usr/lib)
429    message(STATUS "TOSA Reference Model set to ${TOSA_REFERENCE_MODEL_LIB}")
430
431    if(TOSA_REFERENCE_MODEL_OUTPUT)
432        add_definitions("-DTOSA_REFERENCE_MODEL_OUTPUT=1")
433    endif()
434endif()
435
436# This is the root for the dynamic backend tests to search for dynamic
437# backends. By default it will be the project build directory.
438add_definitions(-DDYNAMIC_BACKEND_BUILD_DIR="${PROJECT_BINARY_DIR}")
439
440# ArmNN dynamic backend
441if(DYNAMIC_BACKEND_PATHS)
442    add_definitions(-DARMNN_DYNAMIC_BACKEND_ENABLED)
443endif()
444
445if(SAMPLE_DYNAMIC_BACKEND)
446    add_definitions(-DSAMPLE_DYNAMIC_BACKEND_ENABLED)
447endif()
448
449# Streamline annotate
450if(PROFILING_BACKEND_STREAMLINE)
451    include_directories("${GATOR_ROOT}/annotate")
452    add_definitions(-DARMNN_STREAMLINE_ENABLED)
453endif()
454
455if(NOT BUILD_BARE_METAL AND NOT EXECUTE_NETWORK_STATIC)
456if(HEAP_PROFILING OR LEAK_CHECKING)
457    find_path(HEAP_PROFILER_INCLUDE gperftools/heap-profiler.h
458            PATHS ${GPERFTOOLS_ROOT}/include
459            NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
460    include_directories(SYSTEM "${HEAP_PROFILER_INCLUDE}")
461    find_library(GPERF_TOOLS_LIBRARY
462                NAMES tcmalloc_debug
463                HINTS ${GPERFTOOLS_ROOT}/lib)
464    link_directories(${GPERFTOOLS_ROOT}/lib)
465
466    link_libraries(${GPERF_TOOLS_LIBRARY})
467    if (HEAP_PROFILING)
468        add_definitions("-DARMNN_HEAP_PROFILING_ENABLED=1")
469    endif()
470    if (LEAK_CHECKING)
471        add_definitions("-DARMNN_LEAK_CHECKING_ENABLED=1")
472    endif()
473else()
474    # Valgrind only works with gperftools version number <= 2.4
475    CHECK_INCLUDE_FILE(valgrind/memcheck.h VALGRIND_FOUND)
476endif()
477endif()
478
479if(NOT BUILD_TF_LITE_PARSER)
480    message(STATUS "Tensorflow Lite parser support is disabled")
481endif()
482
483if(NOT BUILD_ARMNN_SERIALIZER)
484    message(STATUS "Armnn Serializer support is disabled")
485endif()
486
487if(NOT BUILD_PYTHON_WHL)
488    message(STATUS "PyArmNN wheel package is disabled")
489endif()
490
491if(NOT BUILD_PYTHON_SRC)
492    message(STATUS "PyArmNN source package is disabled")
493endif()
494
495if(BUILD_PYTHON_WHL OR BUILD_PYTHON_SRC)
496    find_package(PythonInterp 3 REQUIRED)
497    if(NOT ${PYTHONINTERP_FOUND})
498        message(FATAL_ERROR "Python 3.x required to build PyArmNN, but not found")
499    endif()
500
501    find_package(PythonLibs 3 REQUIRED)
502    if(NOT ${PYTHONLIBS_FOUND})
503        message(FATAL_ERROR "Python 3.x development package required to build PyArmNN, but not found")
504    endif()
505
506    find_package(SWIG 4 REQUIRED)
507    if(NOT ${SWIG_FOUND})
508        message(FATAL_ERROR "SWIG 4.x requried to build PyArmNN, but not found")
509    endif()
510endif()
511
512# ArmNN source files required for all build options
513include_directories(SYSTEM third-party)
514