Pavel Macenauer | 59e057f | 2020-04-15 14:17:26 +0000 | [diff] [blame] | 1 | # |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 2 | # Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
Pavel Macenauer | 59e057f | 2020-04-15 14:17:26 +0000 | [diff] [blame] | 3 | # Copyright 2020 NXP |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
Jim Flynn | 870b96c | 2022-03-25 21:24:56 +0000 | [diff] [blame] | 6 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 7 | option(BUILD_ONNX_PARSER "Build Onnx parser" OFF) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 8 | option(BUILD_UNIT_TESTS "Build unit tests" ON) |
| 9 | option(BUILD_TESTS "Build test applications" OFF) |
| 10 | option(BUILD_FOR_COVERAGE "Use no optimization and output .gcno and .gcda files" OFF) |
| 11 | option(ARMCOMPUTENEON "Build with ARM Compute NEON support" OFF) |
| 12 | option(ARMCOMPUTECL "Build with ARM Compute OpenCL support" OFF) |
Matteo Martincigh | f88663c | 2019-08-28 16:38:53 +0100 | [diff] [blame] | 13 | option(ARMNNREF "Build with ArmNN reference support" ON) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 14 | option(PROFILING_BACKEND_STREAMLINE "Forward the armNN profiling events to DS-5/Streamline as annotations" OFF) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 15 | # options used for heap profiling and leak checking |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 16 | option(HEAP_PROFILING "Build with heap profiling enabled" OFF) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 17 | option(LEAK_CHECKING "Build with leak checking enabled" OFF) |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 18 | option(GPERFTOOLS_ROOT "Location where the gperftools 'include' and 'lib' folders to be found" Off) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 19 | # options used for tensorflow lite support |
| 20 | option(BUILD_TF_LITE_PARSER "Build Tensorflow Lite parser" OFF) |
Nattapat Chaimanowong | 949f125 | 2019-01-31 15:36:39 +0000 | [diff] [blame] | 21 | option(BUILD_ARMNN_SERIALIZER "Build Armnn Serializer" OFF) |
Éanna Ó Catháin | a563b92 | 2019-05-09 11:34:06 +0100 | [diff] [blame] | 22 | option(BUILD_ACCURACY_TOOL "Build Accuracy Tool" OFF) |
Nattapat Chaimanowong | 949f125 | 2019-01-31 15:36:39 +0000 | [diff] [blame] | 23 | option(FLATC_DIR "Path to Flatbuffers compiler" OFF) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 24 | option(TF_LITE_GENERATED_PATH "Tensorflow lite generated C++ schema location" OFF) |
| 25 | option(FLATBUFFERS_ROOT "Location where the flatbuffers 'include' and 'lib' folders to be found" Off) |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 26 | option(DYNAMIC_BACKEND_PATHS "Colon seperated list of paths where to load the dynamic backends from" "") |
Colm Donelan | 0dbe00a | 2020-06-03 08:00:28 +0100 | [diff] [blame] | 27 | option(SAMPLE_DYNAMIC_BACKEND "Include the sample dynamic backend and its tests in the build" OFF) |
Colm Donelan | a21620d | 2019-10-11 13:09:49 +0100 | [diff] [blame] | 28 | option(BUILD_GATORD_MOCK "Build the Gatord simulator for external profiling testing." ON) |
Sadik Armagan | 6f86b69 | 2020-03-09 11:04:32 +0000 | [diff] [blame] | 29 | option(BUILD_TIMELINE_DECODER "Build the Timeline Decoder for external profiling." ON) |
Finn Williams | 2ed809c | 2020-04-20 21:21:07 +0100 | [diff] [blame] | 30 | option(BUILD_BASE_PIPE_SERVER "Build the server to handle external profiling pipe traffic" ON) |
Pavel Macenauer | 59e057f | 2020-04-15 14:17:26 +0000 | [diff] [blame] | 31 | option(BUILD_PYTHON_WHL "Build Python wheel package" OFF) |
| 32 | option(BUILD_PYTHON_SRC "Build Python source package" OFF) |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 33 | option(BUILD_STATIC_PIPE_LIBS "Build Static PIPE libraries" OFF) |
| 34 | option(BUILD_PIPE_ONLY "Build the PIPE libraries only" OFF) |
Sadik Armagan | 5d03e31 | 2020-11-17 16:43:56 +0000 | [diff] [blame] | 35 | option(BUILD_ARMNN_TFLITE_DELEGATE "Build the Arm NN TfLite delegate" OFF) |
Jim Flynn | e1fdd28 | 2021-10-26 21:26:10 +0100 | [diff] [blame] | 36 | option(BUILD_MEMORY_STRATEGY_BENCHMARK "Build the MemoryBenchmark" OFF) |
Jim Flynn | 870b96c | 2022-03-25 21:24:56 +0000 | [diff] [blame] | 37 | option(BUILD_BARE_METAL "Disable features requiring operating system support" OFF) |
Jan Eilers | a96489a | 2021-12-08 10:05:47 +0000 | [diff] [blame] | 38 | option(BUILD_SHARED_LIBS "Determines if Armnn will be built statically or dynamically. |
| 39 | This is an experimental feature and not fully supported. |
| 40 | Only the ArmNN core and the Delegate can be built statically." ON) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 41 | |
| 42 | include(SelectLibraryConfigurations) |
| 43 | |
| 44 | set(COMPILER_IS_GNU_LIKE 0) |
Jim Flynn | 82262f5 | 2020-07-16 11:23:45 +0100 | [diff] [blame] | 45 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR |
| 46 | ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang OR |
| 47 | ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 48 | set(COMPILER_IS_GNU_LIKE 1) |
| 49 | endif() |
| 50 | |
| 51 | # Enable CCache if available and not disabled |
| 52 | option(USE_CCACHE "USE_CCACHE" ON) |
| 53 | find_program(CCACHE_FOUND ccache) |
| 54 | if(CCACHE_FOUND AND USE_CCACHE) |
| 55 | get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE) |
| 56 | set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "CCACHE_CPP2=yes ${rule_launch_compile} ccache") |
| 57 | endif() |
| 58 | |
| 59 | # Enable distcc if available and not disabled |
| 60 | option(USE_DISTCC "USE_DISTCC" OFF) |
| 61 | find_program(DISTCC_FOUND distcc) |
| 62 | if(DISTCC_FOUND AND USE_DISTCC) |
| 63 | get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE) |
| 64 | set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "${rule_launch_compile} distcc") |
| 65 | endif() |
| 66 | |
| 67 | # Set to release configuration by default |
| 68 | if(NOT CMAKE_BUILD_TYPE) |
| 69 | set(CMAKE_BUILD_TYPE "Release") |
| 70 | endif() |
| 71 | |
| 72 | # Compiler flags that are always set |
| 73 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 74 | if(COMPILER_IS_GNU_LIKE) |
Derek Lamberti | ba25aee | 2019-12-10 22:20:54 +0000 | [diff] [blame] | 75 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Werror -Wold-style-cast -Wno-missing-braces -Wconversion -Wsign-conversion") |
Finn Williams | 3d62614 | 2021-08-11 13:04:32 +0100 | [diff] [blame] | 76 | if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 77 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi") |
| 78 | endif() |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 79 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) |
Jim Flynn | 870b96c | 2022-03-25 21:24:56 +0000 | [diff] [blame] | 80 | # Disable C4996 (use of deprecated identifier) due to |
| 81 | # https://developercommunity.visualstudio.com/content/problem/252574/deprecated-compilation-warning-for-virtual-overrid.html |
Rob Hughes | fc6bf05 | 2019-12-16 17:10:51 +0000 | [diff] [blame] | 82 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /wd4996") |
Rob Hughes | bc873d2 | 2020-05-20 13:11:37 +0100 | [diff] [blame] | 83 | add_definitions(-DNO_STRICT=1) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 84 | endif() |
| 85 | if("${CMAKE_SYSTEM_NAME}" STREQUAL Android) |
Keith Davis | b8942bf | 2021-05-31 11:22:35 +0100 | [diff] [blame] | 86 | # -lz is necessary for when building with ACL set with compressed kernels |
| 87 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -llog -lz") |
| 88 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -llog -lz") |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 89 | endif() |
| 90 | |
| 91 | # Compiler flags for Release builds |
Matthew Bentham | e30054f | 2019-06-24 13:10:54 +0100 | [diff] [blame] | 92 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG") |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 93 | if(COMPILER_IS_GNU_LIKE) |
| 94 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") |
| 95 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) |
| 96 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2") |
| 97 | endif() |
| 98 | |
| 99 | # Compiler flags for Debug builds |
| 100 | if(COMPILER_IS_GNU_LIKE) |
Matthew Bentham | e30054f | 2019-06-24 13:10:54 +0100 | [diff] [blame] | 101 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0") |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 102 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) |
Matthew Bentham | e30054f | 2019-06-24 13:10:54 +0100 | [diff] [blame] | 103 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /ZI /Od") |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 104 | # Disable SAFESEH which is necessary for Edit and Continue to work |
| 105 | set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO") |
| 106 | set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO") |
| 107 | endif() |
| 108 | |
| 109 | # Modify RelWithDebInfo so that NDEBUG isn't defined. |
| 110 | # This enables asserts. |
| 111 | if (COMPILER_IS_GNU_LIKE) |
| 112 | string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") |
| 113 | elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC) |
| 114 | string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") |
| 115 | endif() |
| 116 | |
| 117 | # Compiler flags for code coverage measurements |
| 118 | if(BUILD_FOR_COVERAGE) |
| 119 | if(NOT CMAKE_BUILD_TYPE EQUAL "Debug") |
| 120 | message(WARNING "BUILD_FOR_COVERAGE set so forcing to Debug build") |
| 121 | set(CMAKE_BUILD_TYPE "Debug") |
| 122 | endif() |
| 123 | |
| 124 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") |
| 125 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage") |
| 126 | endif() |
| 127 | |
| 128 | if(BUILD_FOR_COVERAGE AND NOT BUILD_UNIT_TESTS) |
| 129 | message(WARNING "BUILD_FOR_COVERAGE set but not BUILD_UNIT_TESTS, so code coverage will not be able to run") |
| 130 | endif() |
| 131 | |
| 132 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH}) |
| 133 | |
Derek Lamberti | eac4adb | 2020-08-25 13:05:59 +0100 | [diff] [blame] | 134 | include(CMakeFindDependencyMacro) |
| 135 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 136 | if (NOT BUILD_PIPE_ONLY) |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 137 | # cxxopts (Alternative to boost::program_options) |
Vincent ABRIOU | 5494019 | 2020-09-03 13:02:43 +0200 | [diff] [blame] | 138 | find_path(CXXOPTS_INCLUDE cxxopts/cxxopts.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH) |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 139 | include_directories(SYSTEM "${CXXOPTS_INCLUDE}") |
| 140 | endif() |
Jan Eilers | 7e98983 | 2020-06-19 11:47:21 +0100 | [diff] [blame] | 141 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 142 | if (NOT BUILD_PIPE_ONLY) |
| 143 | # ghc (Alternative to boost::filesystem) |
Vincent ABRIOU | 5494019 | 2020-09-03 13:02:43 +0200 | [diff] [blame] | 144 | find_path(GHC_INCLUDE ghc/filesystem.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH) |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 145 | include_directories(SYSTEM "${GHC_INCLUDE}") |
| 146 | endif() |
Jan Eilers | 307fd34 | 2020-06-23 14:16:04 +0100 | [diff] [blame] | 147 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 148 | # pthread |
Jim Flynn | 870b96c | 2022-03-25 21:24:56 +0000 | [diff] [blame] | 149 | if (NOT BUILD_BARE_METAL) |
| 150 | find_package(Threads) |
| 151 | endif() |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 152 | |
| 153 | # Favour the protobuf passed on command line |
Nikhil Raj | 5d955cf | 2021-04-19 16:59:48 +0100 | [diff] [blame] | 154 | if(BUILD_ONNX_PARSER) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 155 | find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd" |
| 156 | PATHS ${PROTOBUF_ROOT}/lib |
| 157 | NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) |
| 158 | find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd") |
| 159 | |
| 160 | find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf" |
| 161 | PATHS ${PROTOBUF_ROOT}/lib |
| 162 | NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) |
| 163 | find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf") |
| 164 | |
| 165 | select_library_configurations(PROTOBUF) |
| 166 | |
| 167 | find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h" |
| 168 | PATHS ${PROTOBUF_ROOT}/include |
| 169 | NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) |
| 170 | find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h") |
| 171 | |
| 172 | include_directories(SYSTEM "${PROTOBUF_INCLUDE_DIRS}") |
| 173 | add_definitions(-DPROTOBUF_USE_DLLS) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 174 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 175 | add_definitions(-DARMNN_ONNX_PARSER) |
| 176 | |
| 177 | find_path(ONNX_GENERATED_SOURCES "onnx/onnx.pb.cc") |
| 178 | |
| 179 | # C++ headers generated for onnx protobufs |
| 180 | include_directories(SYSTEM "${ONNX_GENERATED_SOURCES}") |
| 181 | endif() |
| 182 | |
Sadik Armagan | 5d03e31 | 2020-11-17 16:43:56 +0000 | [diff] [blame] | 183 | if(BUILD_ARMNN_TFLITE_DELEGATE) |
| 184 | add_definitions(-DARMNN_TFLITE_DELEGATE) |
| 185 | endif() |
Nattapat Chaimanowong | 949f125 | 2019-01-31 15:36:39 +0000 | [diff] [blame] | 186 | # Flatbuffers support for TF Lite and Armnn Serializer |
| 187 | if(BUILD_TF_LITE_PARSER OR BUILD_ARMNN_SERIALIZER) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 188 | # verify we have a valid flatbuffers include path |
| 189 | find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h |
| 190 | HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include) |
| 191 | |
Matthew Bentham | d1ae3a6 | 2019-02-22 17:30:32 +0000 | [diff] [blame] | 192 | message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 193 | |
| 194 | find_library(FLATBUFFERS_LIBRARY |
| 195 | NAMES libflatbuffers.a flatbuffers |
| 196 | HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib) |
| 197 | |
Matthew Bentham | d1ae3a6 | 2019-02-22 17:30:32 +0000 | [diff] [blame] | 198 | message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}") |
Nattapat Chaimanowong | 949f125 | 2019-01-31 15:36:39 +0000 | [diff] [blame] | 199 | endif() |
| 200 | |
| 201 | # Flatbuffers schema support for TF Lite |
| 202 | if(BUILD_TF_LITE_PARSER) |
| 203 | find_path(TF_LITE_SCHEMA_INCLUDE_PATH |
| 204 | schema_generated.h |
| 205 | HINTS ${TF_LITE_GENERATED_PATH}) |
| 206 | |
Matthew Bentham | d1ae3a6 | 2019-02-22 17:30:32 +0000 | [diff] [blame] | 207 | message(STATUS "Tf Lite generated header found at: ${TF_LITE_SCHEMA_INCLUDE_PATH}") |
Nattapat Chaimanowong | 949f125 | 2019-01-31 15:36:39 +0000 | [diff] [blame] | 208 | |
Matthew Bentham | d1ae3a6 | 2019-02-22 17:30:32 +0000 | [diff] [blame] | 209 | add_definitions(-DARMNN_TF_LITE_PARSER) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 210 | endif() |
| 211 | |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 212 | if(BUILD_ARMNN_SERIALIZER) |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 213 | add_definitions(-DARMNN_SERIALIZER) |
Matthew Bentham | 268509a | 2019-02-25 13:58:24 +0000 | [diff] [blame] | 214 | add_definitions(-DARMNN_SERIALIZER_SCHEMA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/src/armnnSerializer/ArmnnSchema.fbs") |
Kevin May | 43a799c | 2019-02-08 16:31:42 +0000 | [diff] [blame] | 215 | endif() |
| 216 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 217 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) |
Sadik Armagan | a97a0be | 2020-03-03 10:44:56 +0000 | [diff] [blame] | 218 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/profiling) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 219 | |
| 220 | # ARM Compute |
| 221 | # Note that ARM Compute has a different folder layout depending on the branch but also on |
| 222 | # whether it comes from a prepackaged archive (this is why we add several hints below) |
| 223 | if(ARMCOMPUTENEON OR ARMCOMPUTECL) |
Francis Murtagh | 82490ee | 2020-11-04 13:33:41 +0000 | [diff] [blame] | 224 | find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 225 | PATHS ${ARMCOMPUTE_ROOT}/include |
| 226 | PATHS ${ARMCOMPUTE_ROOT}/applications/arm_compute |
| 227 | PATHS ${ARMCOMPUTE_ROOT} |
| 228 | NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) |
Francis Murtagh | 82490ee | 2020-11-04 13:33:41 +0000 | [diff] [blame] | 229 | find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 230 | include_directories(SYSTEM "${ARMCOMPUTE_INCLUDE}") |
| 231 | |
| 232 | # Find the Arm Compute libraries if not already specified (the user may have already defined this in advance, |
| 233 | # e.g. if building clframework as a dependent cmake project) |
| 234 | if (NOT DEFINED ARMCOMPUTE_LIBRARIES) |
| 235 | # We link to the static variant so that customers don't need to find and build a compatible version of clframework. |
| 236 | # First try the folders specified ARMCOMPUTE_BUILD_DIR (with PATH_SUFFIXES for |
| 237 | # Windows builds) |
Matthew Bentham | 2624dd7 | 2020-05-20 10:44:18 +0100 | [diff] [blame] | 238 | if ((NOT DEFINED ARMCOMPUTE_BUILD_DIR) AND (DEFINED ARMCOMPUTE_ROOT)) |
| 239 | # Default build directory for ComputeLibrary is under the root |
| 240 | set(ARMCOMPUTE_BUILD_DIR ${ARMCOMPUTE_ROOT}/build) |
| 241 | endif() |
| 242 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 243 | find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static |
| 244 | PATHS ${ARMCOMPUTE_BUILD_DIR} |
| 245 | PATH_SUFFIXES "Debug" |
| 246 | NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) |
| 247 | find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static |
| 248 | PATHS ${ARMCOMPUTE_BUILD_DIR} |
| 249 | PATH_SUFFIXES "Release" |
| 250 | NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) |
| 251 | find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static |
| 252 | PATHS ${ARMCOMPUTE_BUILD_DIR} |
| 253 | PATH_SUFFIXES "Debug" |
| 254 | NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) |
| 255 | find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static |
| 256 | PATHS ${ARMCOMPUTE_BUILD_DIR} |
| 257 | PATH_SUFFIXES "Release" |
| 258 | NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) |
| 259 | |
| 260 | # In case it wasn't there, try a default search (will work in cases where |
| 261 | # the library has been installed into a standard location) |
| 262 | find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static) |
| 263 | find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static) |
| 264 | find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static) |
| 265 | find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static) |
| 266 | |
Matthew Bentham | 6445cff | 2020-03-10 11:13:17 +0000 | [diff] [blame] | 267 | # In case it wasn't there, try the dynamic libraries |
| 268 | # This case will get used in a linux setup where the Compute Library |
| 269 | # has been installed in a standard system library path as a dynamic library |
| 270 | find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute) |
| 271 | find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute) |
| 272 | find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core) |
| 273 | find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core) |
| 274 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 275 | set(ARMCOMPUTE_LIBRARIES |
| 276 | debug ${ARMCOMPUTE_LIBRARY_DEBUG} ${ARMCOMPUTE_CORE_LIBRARY_DEBUG} |
| 277 | optimized ${ARMCOMPUTE_LIBRARY_RELEASE} ${ARMCOMPUTE_CORE_LIBRARY_RELEASE} ) |
| 278 | endif() |
| 279 | endif() |
| 280 | |
| 281 | # ARM Compute NEON backend |
| 282 | if(ARMCOMPUTENEON) |
| 283 | # Add preprocessor definition for ARM Compute NEON |
| 284 | add_definitions(-DARMCOMPUTENEON_ENABLED) |
| 285 | # The ARM Compute headers contain some NEON intrinsics, so we need to build armnn with NEON support on armv7 |
| 286 | if(${CMAKE_SYSTEM_PROCESSOR} MATCHES armv7 AND COMPILER_IS_GNU_LIKE) |
| 287 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon") |
| 288 | endif() |
| 289 | endif() |
| 290 | |
| 291 | # ARM Compute OpenCL backend |
| 292 | if(ARMCOMPUTECL) |
Nikhil Raj | b55d366 | 2021-02-11 14:49:19 +0000 | [diff] [blame] | 293 | # verify we have a valid flatbuffers include path |
| 294 | find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h |
| 295 | HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include) |
| 296 | |
| 297 | message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}") |
| 298 | |
| 299 | find_library(FLATBUFFERS_LIBRARY |
| 300 | NAMES libflatbuffers.a flatbuffers |
| 301 | HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib) |
| 302 | |
| 303 | message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}") |
| 304 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 305 | # Always use Arm compute library OpenCL headers |
Nikhil Raj | 407cddf | 2021-11-30 09:57:08 +0000 | [diff] [blame] | 306 | find_path(OPENCL_INCLUDE CL/opencl.hpp |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 307 | PATHS ${ARMCOMPUTE_ROOT}/include |
| 308 | NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) |
| 309 | |
Matthew Bentham | 3b72db0 | 2018-10-11 09:47:01 +0100 | [diff] [blame] | 310 | # Link against libOpenCL in opencl-1.2-stubs, but don't search there at runtime |
| 311 | link_libraries(-L${ARMCOMPUTE_BUILD_DIR}/opencl-1.2-stubs) |
| 312 | set(OPENCL_LIBRARIES OpenCL) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 313 | |
Matthew Bentham | 416b41d | 2020-02-05 22:15:26 +0000 | [diff] [blame] | 314 | include_directories(SYSTEM ${OPENCL_INCLUDE}) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 315 | |
| 316 | # Add preprocessor definition for ARM Compute OpenCL |
| 317 | add_definitions(-DARMCOMPUTECL_ENABLED) |
| 318 | |
| 319 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DARM_COMPUTE_DEBUG_ENABLED") |
| 320 | endif() |
| 321 | |
| 322 | # Used by both Arm Compute backends, but should be added |
| 323 | # to the search path after the system directories if necessary |
| 324 | if(ARMCOMPUTENEON OR ARMCOMPUTECL) |
| 325 | find_path(HALF_INCLUDE half/half.hpp) |
| 326 | find_path(HALF_INCLUDE half/half.hpp |
| 327 | PATHS ${ARMCOMPUTE_ROOT}/include |
| 328 | NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 329 | include_directories(SYSTEM ${HALF_INCLUDE}) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 330 | endif() |
| 331 | |
Matteo Martincigh | db16dd3 | 2019-08-27 16:41:11 +0100 | [diff] [blame] | 332 | # ArmNN reference backend |
| 333 | if(ARMNNREF) |
| 334 | add_definitions(-DARMNNREF_ENABLED) |
Matteo Martincigh | e67edb2 | 2019-08-14 14:05:46 +0100 | [diff] [blame] | 335 | endif() |
| 336 | |
Colm Donelan | aa93d98 | 2020-06-28 08:16:46 +0100 | [diff] [blame] | 337 | # This is the root for the dynamic backend tests to search for dynamic |
| 338 | # backends. By default it will be the project build directory. |
Rob Hughes | 35c31c0 | 2020-08-17 15:47:20 +0100 | [diff] [blame] | 339 | add_definitions(-DDYNAMIC_BACKEND_BUILD_DIR="${PROJECT_BINARY_DIR}") |
Colm Donelan | aa93d98 | 2020-06-28 08:16:46 +0100 | [diff] [blame] | 340 | |
Narumol Prangnawarat | 60a20fb | 2019-12-09 17:24:41 +0000 | [diff] [blame] | 341 | # ArmNN dynamic backend |
| 342 | if(DYNAMIC_BACKEND_PATHS) |
| 343 | add_definitions(-DARMNN_DYNAMIC_BACKEND_ENABLED) |
| 344 | endif() |
| 345 | |
Narumol Prangnawarat | 867eba5 | 2020-02-03 12:29:56 +0000 | [diff] [blame] | 346 | if(SAMPLE_DYNAMIC_BACKEND) |
| 347 | add_definitions(-DSAMPLE_DYNAMIC_BACKEND_ENABLED) |
| 348 | endif() |
| 349 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 350 | # Streamline annotate |
| 351 | if(PROFILING_BACKEND_STREAMLINE) |
| 352 | include_directories("${GATOR_ROOT}/annotate") |
| 353 | add_definitions(-DARMNN_STREAMLINE_ENABLED) |
| 354 | endif() |
| 355 | |
Jim Flynn | 870b96c | 2022-03-25 21:24:56 +0000 | [diff] [blame] | 356 | if(NOT BUILD_BARE_METAL) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 357 | if(HEAP_PROFILING OR LEAK_CHECKING) |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 358 | # enable heap profiling for everything except for referencetests |
| 359 | if(NOT ${PROJECT_NAME} STREQUAL "referencetests") |
| 360 | find_path(HEAP_PROFILER_INCLUDE gperftools/heap-profiler.h |
| 361 | PATHS ${GPERFTOOLS_ROOT}/include |
| 362 | NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) |
| 363 | include_directories(SYSTEM "${HEAP_PROFILER_INCLUDE}") |
| 364 | find_library(GPERF_TOOLS_LIBRARY |
| 365 | NAMES tcmalloc_debug |
| 366 | HINTS ${GPERFTOOLS_ROOT}/lib) |
| 367 | link_directories(${GPERFTOOLS_ROOT}/lib) |
| 368 | |
| 369 | link_libraries(${GPERF_TOOLS_LIBRARY}) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 370 | if (HEAP_PROFILING) |
| 371 | add_definitions("-DARMNN_HEAP_PROFILING_ENABLED=1") |
| 372 | endif() |
| 373 | if (LEAK_CHECKING) |
| 374 | add_definitions("-DARMNN_LEAK_CHECKING_ENABLED=1") |
| 375 | endif() |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 376 | else() |
Rob Hughes | 721b82f | 2019-11-15 09:04:17 +0000 | [diff] [blame] | 377 | message(STATUS "Heap profiling and leak checking are disabled for referencetests") |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 378 | endif() |
| 379 | else() |
| 380 | # Valgrind only works with gperftools version number <= 2.4 |
| 381 | CHECK_INCLUDE_FILE(valgrind/memcheck.h VALGRIND_FOUND) |
| 382 | endif() |
Jim Flynn | 870b96c | 2022-03-25 21:24:56 +0000 | [diff] [blame] | 383 | endif() |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 384 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 385 | if(NOT BUILD_TF_LITE_PARSER) |
| 386 | message(STATUS "Tensorflow Lite parser support is disabled") |
| 387 | endif() |
David Beck | 10b4dfd | 2018-09-19 12:03:20 +0100 | [diff] [blame] | 388 | |
Nattapat Chaimanowong | 949f125 | 2019-01-31 15:36:39 +0000 | [diff] [blame] | 389 | if(NOT BUILD_ARMNN_SERIALIZER) |
| 390 | message(STATUS "Armnn Serializer support is disabled") |
| 391 | endif() |
| 392 | |
Pavel Macenauer | 59e057f | 2020-04-15 14:17:26 +0000 | [diff] [blame] | 393 | if(NOT BUILD_PYTHON_WHL) |
| 394 | message(STATUS "PyArmNN wheel package is disabled") |
| 395 | endif() |
| 396 | |
| 397 | if(NOT BUILD_PYTHON_SRC) |
| 398 | message(STATUS "PyArmNN source package is disabled") |
| 399 | endif() |
| 400 | |
| 401 | if(BUILD_PYTHON_WHL OR BUILD_PYTHON_SRC) |
| 402 | find_package(PythonInterp 3 REQUIRED) |
| 403 | if(NOT ${PYTHONINTERP_FOUND}) |
| 404 | message(FATAL_ERROR "Python 3.x required to build PyArmNN, but not found") |
| 405 | endif() |
| 406 | |
| 407 | find_package(PythonLibs 3 REQUIRED) |
| 408 | if(NOT ${PYTHONLIBS_FOUND}) |
| 409 | message(FATAL_ERROR "Python 3.x development package required to build PyArmNN, but not found") |
| 410 | endif() |
| 411 | |
| 412 | find_package(SWIG 4 REQUIRED) |
| 413 | if(NOT ${SWIG_FOUND}) |
| 414 | message(FATAL_ERROR "SWIG 4.x requried to build PyArmNN, but not found") |
| 415 | endif() |
| 416 | endif() |
| 417 | |
Jim Flynn | 870b96c | 2022-03-25 21:24:56 +0000 | [diff] [blame] | 418 | if(BUILD_BARE_METAL) |
| 419 | add_definitions(-DARMNN_BUILD_BARE_METAL |
| 420 | -DARMNN_DISABLE_FILESYSTEM |
| 421 | -DARMNN_DISABLE_PROCESSES |
| 422 | -DARMNN_DISABLE_THREADS |
| 423 | -DARMNN_DISABLE_SOCKETS) |
| 424 | endif() |
| 425 | |
David Beck | 10b4dfd | 2018-09-19 12:03:20 +0100 | [diff] [blame] | 426 | # ArmNN source files required for all build options |
| 427 | include_directories(SYSTEM third-party) |