alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2021 Arm Limited. All rights reserved. |
| 3 | # SPDX-License-Identifier: Apache-2.0 |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | #---------------------------------------------------------------------------- |
| 17 | # minimum version of cmake = 3.15 for legit reason: |
| 18 | # armclang support doesn't work work in previous releases |
| 19 | cmake_minimum_required(VERSION 3.15.0) |
| 20 | |
| 21 | # Build in release mode by default |
| 22 | if (NOT CMAKE_BUILD_TYPE STREQUAL Debug) |
| 23 | set(CMAKE_BUILD_TYPE Release CACHE INTERNAL "") |
| 24 | endif() |
| 25 | |
| 26 | message(STATUS "Build type is set to ${CMAKE_BUILD_TYPE}") |
| 27 | |
| 28 | # Set language standards. TensorFlow Lite requires |
| 29 | # std=c++11. |
| 30 | set(CMAKE_C_STANDARD 99) |
ayamas01 | 15f8070 | 2021-11-18 14:22:23 +0000 | [diff] [blame] | 31 | set(CMAKE_CXX_STANDARD 14) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 32 | |
| 33 | # Make the standard a requirement => prevent fallback to previous |
| 34 | # supported standard |
| 35 | set(CMAKE_C_STANDARD_REQUIRED ON) |
| 36 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 37 | |
| 38 | # We want to pass standard C/C++ flags, without gnu extensions |
| 39 | set(CMAKE_C_EXTENSIONS OFF) |
| 40 | set(CMAKE_CXX_EXTENSIONS OFF) |
| 41 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 42 | set(CMAKE_SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake) |
| 43 | set(DOWNLOAD_DEP_DIR ${CMAKE_BINARY_DIR}/dependencies) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 44 | |
Kshitij Sisodia | ddcb56d | 2021-05-11 14:46:01 +0100 | [diff] [blame] | 45 | set(RESOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources_downloaded |
| 46 | CACHE PATH "Resources directory") |
| 47 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 48 | include(${CMAKE_SCRIPTS_DIR}/source_gen_utils.cmake) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 49 | |
| 50 | if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR}) |
| 51 | message(FATAL_ERROR "Source and build are in the same directory") |
| 52 | else() |
| 53 | message(STATUS "Source directory: ${CMAKE_SOURCE_DIR}") |
| 54 | message(STATUS "Binary directory: ${CMAKE_BINARY_DIR}") |
| 55 | endif() |
| 56 | |
Kshitij Sisodia | b59ba68 | 2021-11-23 17:19:52 +0000 | [diff] [blame] | 57 | include(${CMAKE_SCRIPTS_DIR}/common_user_options.cmake) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 58 | |
Kshitij Sisodia | b59ba68 | 2021-11-23 17:19:52 +0000 | [diff] [blame] | 59 | # Make sure the following options are defined before proceeding: |
| 60 | assert_defined(LOG_LEVEL) |
| 61 | assert_defined(TENSORFLOW_SRC_PATH) |
| 62 | assert_defined(TARGET_PLATFORM) |
| 63 | assert_defined(TARGET_SUBSYSTEM) |
| 64 | assert_defined(ETHOS_U_NPU_ENABLED) |
| 65 | assert_defined(USE_CASE_BUILD) |
| 66 | assert_defined(CPU_PROFILE_ENABLED) |
| 67 | assert_defined(CMAKE_TOOLCHAIN_FILE) |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 68 | |
| 69 | project(arm_ml_embedded_evaluation_kit |
Kshitij Sisodia | b59ba68 | 2021-11-23 17:19:52 +0000 | [diff] [blame] | 70 | VERSION 21.11 |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 71 | DESCRIPTION "ARM ML Embedded Evaluation Kit for MPS3 FPGA and FastModel") |
| 72 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 73 | enforce_compiler_version() |
| 74 | setup_source_generator() |
| 75 | |
| 76 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 77 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 78 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 79 | set(SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/source) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 80 | set(TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tests) |
| 81 | list(APPEND USE_CASES_TESTS_SEARCH_DIR_LIST ${TEST_SRCS}/use_case) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 82 | |
| 83 | if (CPU_PROFILE_ENABLED) |
| 84 | set(PROFILING_OPT "${PROFILING_OPT} -DCPU_PROFILE_ENABLED") |
| 85 | endif() |
| 86 | |
| 87 | # Include platform specific sources |
| 88 | if (TARGET_PLATFORM STREQUAL native) |
| 89 | set(PLATFORM_SOURCES_CMAKE_FILE ${CMAKE_SCRIPTS_DIR}/${TARGET_PLATFORM}-sources.cmake) |
| 90 | else () |
| 91 | set(PLATFORM_SOURCES_CMAKE_FILE ${CMAKE_SCRIPTS_DIR}/bare-metal-sources.cmake) |
| 92 | |
Kshitij Sisodia | b59ba68 | 2021-11-23 17:19:52 +0000 | [diff] [blame] | 93 | assert_defined(CMSIS_SRC_PATH) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 94 | |
| 95 | if (CMAKE_BUILD_TYPE STREQUAL Debug AND CMAKE_CXX_COMPILER_ID STREQUAL ARMClang) |
Kshitij Sisodia | b59ba68 | 2021-11-23 17:19:52 +0000 | [diff] [blame] | 96 | assert_defined(ARMCLANG_DEBUG_DWARF_LEVEL) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 97 | endif() |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 98 | endif () |
Kshitij Sisodia | b59ba68 | 2021-11-23 17:19:52 +0000 | [diff] [blame] | 99 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 100 | message(STATUS "Including ${PLATFORM_SOURCES_CMAKE_FILE}") |
| 101 | include(${PLATFORM_SOURCES_CMAKE_FILE}) |
| 102 | |
| 103 | if (${CMAKE_CROSSCOMPILING}) |
| 104 | enable_language(ASM) |
| 105 | |
| 106 | # For non-native builds, we build with CMSIS-DSP support. |
| 107 | include(${CMAKE_SCRIPTS_DIR}/cmsis-dsp.cmake) |
| 108 | |
| 109 | # All CMSIS headers to be used: |
| 110 | set(CMSIS_HEADERS |
| 111 | ${CMSIS_DSP_INC_DIR} |
| 112 | ${CMSIS_CORE_INC_DIR} |
ayamas01 | 15f8070 | 2021-11-18 14:22:23 +0000 | [diff] [blame] | 113 | ${CMSIS_SRC_PATH}/Device/ARM/${ARM_CPU}/Include |
| 114 | ${CMSIS_SRC_PATH}/Device/ARM/${ARM_CPU}/Include/Template) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 115 | endif () |
| 116 | |
| 117 | # If we need NPU libraries: |
Cisco Cervellera | f085fa5 | 2021-08-02 09:32:07 +0100 | [diff] [blame] | 118 | if (ETHOS_U_NPU_ENABLED) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 119 | |
Kshitij Sisodia | 3be2623 | 2021-10-29 12:29:06 +0100 | [diff] [blame] | 120 | message(STATUS "Using ARM Ethos-U NPU - adding core-driver and timing-adapter-driver includes and libraries") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 121 | |
Kshitij Sisodia | b59ba68 | 2021-11-23 17:19:52 +0000 | [diff] [blame] | 122 | assert_defined(ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH) |
| 123 | assert_defined(ETHOS_U_NPU_DRIVER_SRC_PATH) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 124 | |
Cisco Cervellera | f085fa5 | 2021-08-02 09:32:07 +0100 | [diff] [blame] | 125 | include_directories("${ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH}/include/") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 126 | |
Cisco Cervellera | f085fa5 | 2021-08-02 09:32:07 +0100 | [diff] [blame] | 127 | add_subdirectory("${ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH}" ${CMAKE_BINARY_DIR}/timing-adapter) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 128 | |
Cisco Cervellera | f085fa5 | 2021-08-02 09:32:07 +0100 | [diff] [blame] | 129 | set(ETHOSU_INCLUDES ${ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH}/include |
| 130 | ${ETHOS_U_NPU_DRIVER_SRC_PATH}/include) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 131 | |
Cisco Cervellera | f085fa5 | 2021-08-02 09:32:07 +0100 | [diff] [blame] | 132 | list(APPEND ETHOS_U_NPU_LIBS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libtiming_adapter.a) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 133 | endif () |
| 134 | |
| 135 | include(${CMAKE_SCRIPTS_DIR}/tensorflow.cmake) |
| 136 | |
| 137 | set(DEP_TENSORFLOW_LITE_MICRO_SUB_DIR ${TENSORFLOW_SRC_PATH}/tensorflow/lite/micro) |
| 138 | set(DEP_TENSORFLOW_LITE_MICRO_MAKE_DIR ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR}/tools/make/targets) |
| 139 | set(DEP_FLATBUF_INCLUDE ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR}/tools/make/downloads/flatbuffers/include) |
| 140 | |
| 141 | set(TENSORFLOW_LIBRARY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME}) |
| 142 | |
| 143 | set(DEP_TF_INCLUDE_DIRS |
| 144 | ${TENSORFLOW_SRC_PATH} |
| 145 | ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR} |
| 146 | ${ETHOSU_INCLUDES} |
| 147 | ${CMSIS_HEADERS} |
| 148 | ) |
| 149 | |
| 150 | ## All TPIP includes |
| 151 | set(DEP_RUNTIME_INCLUDE_DIRS |
| 152 | ${DEP_TF_INCLUDE_DIRS} |
| 153 | ${DEP_FLATBUF_INCLUDE} |
| 154 | ) |
| 155 | |
| 156 | # Our entry point into tensorflow world: |
| 157 | file(GLOB_RECURSE SRC_TENSORFLOW_LITE_MICRO |
| 158 | ${SRC_PATH}/application/tensorflow-lite-micro/**/*.cc |
| 159 | ${SRC_PATH}/application/tensorflow-lite-micro/*.cc |
| 160 | ) |
| 161 | |
| 162 | set(HAL_DIR ${SRC_PATH}/application/hal) |
| 163 | |
| 164 | # HAL API sources |
| 165 | file(GLOB_RECURSE SRC_HAL |
| 166 | "${HAL_DIR}/hal.c" |
| 167 | ) |
| 168 | |
| 169 | # Set platform specific HAL sources; these should be provided |
| 170 | # by each platform's cmake include file |
| 171 | list(APPEND SRC_HAL ${SRC_PLAT_HAL}) |
| 172 | |
| 173 | # Include directories: |
| 174 | set(APPLICATION_INCLUDE_DIRS |
| 175 | ${HAL_DIR}/include |
| 176 | ${SRC_PATH}/application/tensorflow-lite-micro/include |
| 177 | ${SRC_PATH}/application/main/include |
| 178 | ${PLAT_INCLUDE_DIRS} |
| 179 | ) |
| 180 | |
| 181 | file(GLOB_RECURSE SRC_APPLICATION |
| 182 | "${SRC_PATH}/application/main/*.cc" |
| 183 | "${SRC_PATH}/application/main/*.cpp" |
| 184 | "${SRC_PATH}/application/main/*.c" |
| 185 | "${SRC_PATH}/application/main/**/*.cc" |
| 186 | "${SRC_PATH}/application/main/**/*.cpp" |
| 187 | "${SRC_PATH}/application/main/**/*.c" |
| 188 | ) |
| 189 | list(FILTER SRC_APPLICATION EXCLUDE REGEX ".*main\\.c.*$") |
| 190 | |
| 191 | list(JOIN USE_CASE_BUILD "" USE_CASE_BUILD_STR) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 192 | list(APPEND USE_CASES_SEARCH_DIR_LIST ${SRC_PATH}/use_case) |
| 193 | message(STATUS "Use-cases source paths: ${USE_CASES_SEARCH_DIR_LIST}.") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 194 | if (${USE_CASE_BUILD_STR} STREQUAL all) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 195 | foreach(USE_CASES_SEARCH_DIR ${USE_CASES_SEARCH_DIR_LIST}) |
| 196 | SUBDIRLIST(USE_CASES_SUBDIRS ${USE_CASES_SEARCH_DIR}) |
| 197 | list(APPEND USE_CASES ${USE_CASES_SUBDIRS}) |
| 198 | endforeach() |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 199 | else() |
| 200 | set(USE_CASES ${USE_CASE_BUILD}) |
| 201 | endif() |
| 202 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 203 | if (NOT ${CMAKE_CROSSCOMPILING}) |
| 204 | |
| 205 | #Test TPIP |
| 206 | set(TEST_TPIP ${DOWNLOAD_DEP_DIR}/test) |
| 207 | file(MAKE_DIRECTORY ${TEST_TPIP}) |
| 208 | set(TEST_TPIP_INCLUDE ${TEST_TPIP}/include) |
| 209 | file(MAKE_DIRECTORY ${TEST_TPIP_INCLUDE}) |
| 210 | |
| 211 | include(ExternalProject) |
| 212 | |
| 213 | ExternalProject_Add(catch2-headers |
| 214 | URL https://github.com/catchorg/Catch2/releases/download/v2.11.1/catch.hpp |
| 215 | DOWNLOAD_NO_EXTRACT 1 |
| 216 | CONFIGURE_COMMAND "" |
| 217 | BUILD_COMMAND bash -c "cp -R <DOWNLOAD_DIR>/catch.hpp ${TEST_TPIP_INCLUDE}" |
| 218 | INSTALL_COMMAND "" |
| 219 | ) |
| 220 | endif () |
| 221 | |
| 222 | message(STATUS "Building use-cases: ${USE_CASES}.") |
| 223 | foreach(use_case ${USE_CASES}) |
| 224 | |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 225 | set(SRC_USE_CASE "") |
| 226 | foreach(USE_CASES_SEARCH_DIR ${USE_CASES_SEARCH_DIR_LIST}) |
| 227 | if (EXISTS ${USE_CASES_SEARCH_DIR}/${use_case}) |
| 228 | message(STATUS "Found sources for use-case ${use_case}") |
| 229 | set(SRC_USE_CASE ${USE_CASES_SEARCH_DIR}) |
| 230 | break() |
| 231 | endif () |
| 232 | endforeach() |
| 233 | |
| 234 | if (${SRC_USE_CASE} STREQUAL "") |
| 235 | message(FATAL_ERROR "Failed to find sources for ${use_case}!") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 236 | endif () |
Kshitij Sisodia | 661959c | 2021-11-24 10:39:52 +0000 | [diff] [blame] | 237 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 238 | # Executable application: |
| 239 | set(TARGET_NAME "ethos-u-${use_case}") |
| 240 | |
Kshitij Sisodia | ddcb56d | 2021-05-11 14:46:01 +0100 | [diff] [blame] | 241 | set(DEFAULT_MODEL_DIR ${RESOURCES_DIR}/${use_case}) |
Isabella Gottardi | 2181d0a | 2021-04-07 09:27:38 +0100 | [diff] [blame] | 242 | set(DEFAULT_TEST_DATA_DIR ${DEFAULT_MODEL_DIR}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 243 | set(SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/src) |
| 244 | set(INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/include) |
| 245 | |
| 246 | # Remove old files and recreate dirs |
| 247 | file(REMOVE_RECURSE ${SRC_GEN_DIR} ${INC_GEN_DIR}) |
| 248 | file(MAKE_DIRECTORY ${SRC_GEN_DIR} ${INC_GEN_DIR}) |
| 249 | |
| 250 | file(GLOB_RECURSE UC_SRC |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 251 | "${SRC_USE_CASE}/${use_case}/src/*.cpp" |
| 252 | "${SRC_USE_CASE}/${use_case}/src/*.cc" |
| 253 | "${SRC_USE_CASE}/${use_case}/src/*.c" |
| 254 | "${SRC_USE_CASE}/${use_case}/src/**/*.cpp" |
| 255 | "${SRC_USE_CASE}/${use_case}/src/**/*.cc" |
| 256 | "${SRC_USE_CASE}/${use_case}/src/**/*.c" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 257 | ) |
| 258 | |
| 259 | set(UC_INCLUDE |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 260 | ${SRC_USE_CASE}/${use_case}/include |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 261 | ) |
| 262 | |
| 263 | file(GLOB UC_CMAKE_FILE |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 264 | "${SRC_USE_CASE}/${use_case}/*.cmake" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 265 | ) |
| 266 | |
| 267 | include(${UC_CMAKE_FILE}) |
| 268 | |
| 269 | file(GLOB_RECURSE SRC_GEN |
| 270 | "${SRC_GEN_DIR}/*.cc" |
| 271 | "${SRC_GEN_DIR}/*.cpp" |
| 272 | "${SRC_GEN_DIR}/*.c" |
| 273 | ) |
| 274 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 275 | set(SRC_MAIN "${SRC_PATH}/application/main/Main.cc") |
| 276 | |
| 277 | set_source_files_properties(${SRC_MAIN} |
| 278 | PROPERTIES COMPILE_DEFINITIONS |
| 279 | "PRJ_VER_STR=\"${PROJECT_VERSION}\";PRJ_DES_STR=\"${PROJECT_DESCRIPTION}\"") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 280 | |
Kshitij Sisodia | aa5e1f6 | 2021-09-24 14:42:08 +0100 | [diff] [blame] | 281 | if (DEFINED ${use_case}_COMPILE_DEFS) |
| 282 | message(STATUS "Additional compilation flags for ${use_case}: ${${use_case}_COMPILE_DEFS}") |
| 283 | set_source_files_properties(${UC_SRC} |
| 284 | PROPERTIES COMPILE_DEFINITIONS |
| 285 | "${${use_case}_COMPILE_DEFS}") |
| 286 | endif() |
| 287 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 288 | set(UC_LIB_NAME lib${TARGET_NAME}) |
| 289 | |
| 290 | # Consolidated application static lib: |
| 291 | add_library(${UC_LIB_NAME} STATIC |
| 292 | ${SRC_APPLICATION} |
| 293 | ${SRC_TENSORFLOW_LITE_MICRO} |
| 294 | ${SRC_HAL} |
| 295 | ${UC_SRC} |
| 296 | ${SRC_GEN} |
| 297 | ) |
| 298 | target_include_directories(${UC_LIB_NAME} PUBLIC |
| 299 | ${APPLICATION_INCLUDE_DIRS} |
| 300 | ${DEP_RUNTIME_INCLUDE_DIRS} |
| 301 | ${UC_INCLUDE} |
| 302 | ${INC_GEN_DIR} |
| 303 | ) |
| 304 | |
| 305 | # Set the activation buffer size |
| 306 | target_compile_definitions(${UC_LIB_NAME} PUBLIC |
| 307 | "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}") |
| 308 | |
| 309 | add_dependencies(${UC_LIB_NAME} tensorflow-lite-micro) |
| 310 | |
| 311 | if (${CMAKE_CROSSCOMPILING}) |
| 312 | # If we are building timing adapter, set the dependency: |
Cisco Cervellera | f085fa5 | 2021-08-02 09:32:07 +0100 | [diff] [blame] | 313 | if (ETHOS_U_NPU_ENABLED) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 314 | message(STATUS "Adding timing_adapter as a dependency to ${UC_LIB_NAME}") |
| 315 | add_dependencies(${UC_LIB_NAME} timing_adapter) |
| 316 | endif() |
| 317 | |
| 318 | # If building with CMSIS-DSP support: |
| 319 | if (DEFINED CMSIS_DSP_TARGET) |
| 320 | message(STATUS "Adding ${CMSIS_DSP_TARGET} as a dependency to ${UC_LIB_NAME}") |
| 321 | add_dependencies(${UC_LIB_NAME} ${CMSIS_DSP_TARGET}) |
| 322 | endif() |
| 323 | endif() |
| 324 | |
| 325 | target_link_libraries(${UC_LIB_NAME} PUBLIC |
| 326 | ${TENSORFLOW_LIBRARY} |
Cisco Cervellera | f085fa5 | 2021-08-02 09:32:07 +0100 | [diff] [blame] | 327 | $<$<BOOL:${ETHOS_U_NPU_ENABLED}>:${ETHOS_U_NPU_LIBS}> |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 328 | $<$<BOOL:${CMSIS_DSP_LIB}>:${CMSIS_DSP_LIB}>) |
| 329 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 330 | add_executable(${TARGET_NAME} ${SRC_MAIN} ${PLAT_RETARGET_SOURCE}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 331 | |
| 332 | target_link_libraries(${TARGET_NAME} ${UC_LIB_NAME}) |
| 333 | |
| 334 | if (${CMAKE_CROSSCOMPILING}) |
| 335 | set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".axf") |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 336 | add_target_map_file(${TARGET_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}.map) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 337 | endif() |
| 338 | |
Kshitij Sisodia | 69a4745 | 2021-07-23 17:43:54 +0100 | [diff] [blame] | 339 | if (${TARGET_PLATFORM} STREQUAL mps3 OR ${TARGET_PLATFORM} STREQUAL simple_platform) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 340 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 341 | set(SECTORS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sectors) |
| 342 | set(SECTORS_BIN_DIR ${SECTORS_DIR}/${use_case}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 343 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 344 | file(REMOVE_RECURSE ${SECTORS_BIN_DIR}) |
| 345 | file(MAKE_DIRECTORY ${SECTORS_BIN_DIR}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 346 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 347 | add_bin_generation_command( |
| 348 | TARGET_NAME ${TARGET_NAME} |
| 349 | OUTPUT_DIR ${SECTORS_BIN_DIR} |
| 350 | AXF_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}.axf |
Kshitij Sisodia | 69a4745 | 2021-07-23 17:43:54 +0100 | [diff] [blame] | 351 | SECTION_PATTERNS "${LINKER_SECTION_TAGS}" |
| 352 | OUTPUT_BIN_NAMES "${LINKER_OUTPUT_BIN_TAGS}") |
| 353 | |
| 354 | if (${TARGET_PLATFORM} STREQUAL mps3) |
| 355 | file(COPY ${MPS3_FPGA_CONFIG} DESTINATION ${SECTORS_DIR}) |
| 356 | endif() |
| 357 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 358 | elseif (${TARGET_PLATFORM} STREQUAL native) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 359 | |
| 360 | # If native build tests |
| 361 | set(TEST_SRC_USE_CASE "") |
| 362 | foreach(USE_CASES_TESTS_SEARCH_DIR ${USE_CASES_TESTS_SEARCH_DIR_LIST}) |
| 363 | |
| 364 | if (EXISTS ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}) |
| 365 | message(STATUS "Found tests for use-case ${use_case} at ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}.") |
| 366 | set(TEST_SRC_USE_CASE ${USE_CASES_TESTS_SEARCH_DIR}) |
| 367 | break() |
| 368 | endif () |
| 369 | endforeach() |
| 370 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 371 | # Add tests only if they exists for the usecase |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 372 | if (NOT ${TEST_SRC_USE_CASE} STREQUAL "") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 373 | |
| 374 | set(TEST_RESOURCES_INCLUDE |
| 375 | "${TEST_SRCS}/utils/" |
Isabella Gottardi | cce0005 | 2021-04-26 09:24:02 +0100 | [diff] [blame] | 376 | "${TEST_SRC_USE_CASE}/${use_case}/include/" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 377 | ) |
| 378 | |
| 379 | # Define Test sources and new target to run unit tests |
| 380 | file(GLOB_RECURSE TEST_SOURCES |
| 381 | "${TEST_SRCS}/common/*.cpp" |
| 382 | "${TEST_SRCS}/common/*.cc" |
| 383 | "${TEST_SRCS}/utils/*.cc" |
| 384 | "${TEST_SRCS}/utils/*.cpp" |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 385 | "${TEST_SRC_USE_CASE}/${use_case}/*.cpp" |
| 386 | "${TEST_SRC_USE_CASE}/${use_case}/*.cc" |
| 387 | "${TEST_SRC_USE_CASE}/${use_case}/*.c" |
| 388 | "${TEST_SRC_USE_CASE}/${use_case}/**/*.cpp" |
| 389 | "${TEST_SRC_USE_CASE}/${use_case}/**/*.cc" |
| 390 | "${TEST_SRC_USE_CASE}/${use_case}/**/*.c" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 391 | ) |
| 392 | |
Isabella Gottardi | 2181d0a | 2021-04-07 09:27:38 +0100 | [diff] [blame] | 393 | set(TEST_SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/src) |
| 394 | set(TEST_INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/include) |
| 395 | file(MAKE_DIRECTORY ${TEST_SRC_GEN_DIR} ${TEST_INC_GEN_DIR}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 396 | |
alexander | 50a0650 | 2021-05-12 19:06:02 +0100 | [diff] [blame] | 397 | set(${use_case}_DEFAULT_TEST_DATA_DIR ${DEFAULT_TEST_DATA_DIR} CACHE PATH "") |
Isabella Gottardi | 2181d0a | 2021-04-07 09:27:38 +0100 | [diff] [blame] | 398 | # Generate test data files to be included in x86 tests |
| 399 | generate_test_data_code( |
alexander | 50a0650 | 2021-05-12 19:06:02 +0100 | [diff] [blame] | 400 | INPUT_DIR "${${use_case}_DEFAULT_TEST_DATA_DIR}" |
Isabella Gottardi | 2181d0a | 2021-04-07 09:27:38 +0100 | [diff] [blame] | 401 | DESTINATION_SRC ${TEST_SRC_GEN_DIR} |
| 402 | DESTINATION_HDR ${TEST_INC_GEN_DIR} |
| 403 | NAMESPACE "test" |
| 404 | ) |
| 405 | |
| 406 | file(GLOB_RECURSE TEST_SOURCES_GEN |
| 407 | "${TEST_SRC_GEN_DIR}/*.cc" |
| 408 | "${TEST_SRC_GEN_DIR}/**/*.cc" |
| 409 | ) |
| 410 | message(STATUS "Adding ${TEST_SOURCES_GEN} to test sources") |
| 411 | list(APPEND TEST_SOURCES ${TEST_SOURCES_GEN}) |
| 412 | list(APPEND TEST_RESOURCES_INCLUDE ${TEST_INC_GEN_DIR}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 413 | |
| 414 | set(TEST_TARGET_NAME "${CMAKE_PROJECT_NAME}-${use_case}-tests") |
| 415 | add_executable(${TEST_TARGET_NAME} ${TEST_SOURCES}) |
| 416 | target_include_directories(${TEST_TARGET_NAME} PUBLIC |
| 417 | ${TEST_TPIP_INCLUDE} ${TEST_RESOURCES_INCLUDE}) |
alexander | 80eecfb | 2021-07-06 19:47:59 +0100 | [diff] [blame] | 418 | target_link_libraries(${TEST_TARGET_NAME} ${UC_LIB_NAME}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 419 | target_compile_definitions(${TEST_TARGET_NAME} PRIVATE |
| 420 | "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}" |
| 421 | TESTS) |
| 422 | |
| 423 | add_dependencies( |
| 424 | "${TEST_TARGET_NAME}" |
| 425 | "catch2-headers" |
| 426 | ) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 427 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 428 | endif () |
| 429 | endif () |
| 430 | endforeach() |
| 431 | |
| 432 | print_useroptions() |