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