blob: bc69c76fe552a446d67da314007897ddb7216514 [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001#----------------------------------------------------------------------------
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
19cmake_minimum_required(VERSION 3.15.0)
20
21# Build in release mode by default
22if (NOT CMAKE_BUILD_TYPE STREQUAL Debug)
23 set(CMAKE_BUILD_TYPE Release CACHE INTERNAL "")
24endif()
25
26message(STATUS "Build type is set to ${CMAKE_BUILD_TYPE}")
27
28# Set language standards. TensorFlow Lite requires
29# std=c++11.
30set(CMAKE_C_STANDARD 99)
31set(CMAKE_CXX_STANDARD 11)
32
33# Make the standard a requirement => prevent fallback to previous
34# supported standard
35set(CMAKE_C_STANDARD_REQUIRED ON)
36set(CMAKE_CXX_STANDARD_REQUIRED ON)
37
38# We want to pass standard C/C++ flags, without gnu extensions
39set(CMAKE_C_EXTENSIONS OFF)
40set(CMAKE_CXX_EXTENSIONS OFF)
41
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010042set(CMAKE_SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake)
43set(DOWNLOAD_DEP_DIR ${CMAKE_BINARY_DIR}/dependencies)
44set(CMAKE_TOOLCHAIN_DIR ${CMAKE_SCRIPTS_DIR}/toolchains)
alexander3c798932021-03-26 21:42:19 +000045
Kshitij Sisodiaddcb56d2021-05-11 14:46:01 +010046set(RESOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources_downloaded
47 CACHE PATH "Resources directory")
48
alexander3c798932021-03-26 21:42:19 +000049include(${CMAKE_SCRIPTS_DIR}/source_gen_utils.cmake)
50include(${CMAKE_SCRIPTS_DIR}/util_functions.cmake)
51
52if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
53 message(FATAL_ERROR "Source and build are in the same directory")
54else()
55 message(STATUS "Source directory: ${CMAKE_SOURCE_DIR}")
56 message(STATUS "Binary directory: ${CMAKE_BINARY_DIR}")
57endif()
58
59USER_OPTION(LOG_LEVEL "Log level for the application"
60 LOG_LEVEL_INFO
61 STRING)
62
63USER_OPTION(TENSORFLOW_SRC_PATH "Path to the root of the tensor flow directory"
64 "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/tensorflow"
65 PATH)
66
67USER_OPTION(TARGET_PLATFORM "Target platform to execute evaluation application: mps3, simple_platform, native"
68 mps3
69 STRING)
70
alexanderd580eee2021-05-04 21:24:22 +010071USER_OPTION(TARGET_SUBSYSTEM "Specify platform target subsystem: sse-300 or none"
alexander3c798932021-03-26 21:42:19 +000072 sse-300
73 STRING)
74
75USER_OPTION(ETHOS_U55_ENABLED "Select if Ethos-U55 is available for the platform and subsystem"
76 ON
77 BOOL)
78
79USER_OPTION(USE_CASE_BUILD "Optional. Defines the use-case to build from the available sources. By default, all use-cases are built."
80 all
81 STRING)
82
83USER_OPTION(CPU_PROFILE_ENABLED "Output CPU performance profiling information. Should be used only for MPS3 board."
84 OFF
85 BOOL)
86
87if (TARGET_PLATFORM STREQUAL mps3)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010088 message(STATUS "Platform: MPS3 FPGA Prototyping Board or FVP")
89 set(DEFAULT_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake)
alexander3c798932021-03-26 21:42:19 +000090elseif (TARGET_PLATFORM STREQUAL simple_platform)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010091 message(STATUS "Platform: Simple platform with minimal peripherals")
92 set(DEFAULT_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake)
alexander3c798932021-03-26 21:42:19 +000093elseif (TARGET_PLATFORM STREQUAL native)
94 message(STATUS "Platform: Native (Linux based x86_64/aarch64 system)")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010095 set(DEFAULT_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/native-gcc.cmake)
alexander3c798932021-03-26 21:42:19 +000096else ()
97 message(FATAL_ERROR "Invalid platform specified: ${TARGET_PLATFORM}")
98endif ()
99
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100100if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
101 set(CMAKE_TOOLCHAIN_FILE ${DEFAULT_TOOLCHAIN_FILE}
102 CACHE FILEPATH "Toolchain file")
103endif()
104message(STATUS "Using CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}")
105
106project(arm_ml_embedded_evaluation_kit
107 VERSION 21.05
108 DESCRIPTION "ARM ML Embedded Evaluation Kit for MPS3 FPGA and FastModel")
109
alexander3c798932021-03-26 21:42:19 +0000110enforce_compiler_version()
111setup_source_generator()
112
113set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
114set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
115set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
116set(SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/source)
Isabella Gottardi85209832021-04-20 14:08:52 +0100117set(TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tests)
118list(APPEND USE_CASES_TESTS_SEARCH_DIR_LIST ${TEST_SRCS}/use_case)
alexander3c798932021-03-26 21:42:19 +0000119
120if (CPU_PROFILE_ENABLED)
121 set(PROFILING_OPT "${PROFILING_OPT} -DCPU_PROFILE_ENABLED")
122endif()
123
124# Include platform specific sources
125if (TARGET_PLATFORM STREQUAL native)
126 set(PLATFORM_SOURCES_CMAKE_FILE ${CMAKE_SCRIPTS_DIR}/${TARGET_PLATFORM}-sources.cmake)
127else ()
128 set(PLATFORM_SOURCES_CMAKE_FILE ${CMAKE_SCRIPTS_DIR}/bare-metal-sources.cmake)
129
130 USER_OPTION(CMSIS_SRC_PATH
131 "Path to CMSIS-5 sources"
132 "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/cmsis"
133 PATH
134 )
135
136 if (CMAKE_BUILD_TYPE STREQUAL Debug AND CMAKE_CXX_COMPILER_ID STREQUAL ARMClang)
137 USER_OPTION(ARMCLANG_DEBUG_DWARF_LEVEL
138 "Dwarf conformance level for armclang toolchain"
139 "4" # Default = 4 (Arm-DS etc). For model debugger specify "3"
140 STRING
141 )
142 elseif (DEFINED ARMCLANG_DEBUG_DWARF_LEVEL)
143 message(WARNING "ARMCLANG_DEBUG_DWARF_LEVEL definition is unsupported"
144 "within current configuration. Removing definition...")
145 unset(ARMCLANG_DEBUG_DWARF_LEVEL CACHE)
146 endif()
147
148endif ()
149message(STATUS "Including ${PLATFORM_SOURCES_CMAKE_FILE}")
150include(${PLATFORM_SOURCES_CMAKE_FILE})
151
152if (${CMAKE_CROSSCOMPILING})
153 enable_language(ASM)
154
155 # For non-native builds, we build with CMSIS-DSP support.
156 include(${CMAKE_SCRIPTS_DIR}/cmsis-dsp.cmake)
157
158 # All CMSIS headers to be used:
159 set(CMSIS_HEADERS
160 ${CMSIS_DSP_INC_DIR}
161 ${CMSIS_CORE_INC_DIR}
162 ${CMSIS_SRC_PATH}/Device/ARM/ARMCM55/Include
163 ${CMSIS_SRC_PATH}/Device/ARM/ARMCM55/Include/Template)
164endif ()
165
166# If we need NPU libraries:
167if (ETHOS_U55_ENABLED)
168
169 message(STATUS "Using ARM Ethos-U55 - adding core-driver and timing-adapter-driver includes and libraries")
170 USER_OPTION(ETHOS_U55_TIMING_ADAPTER_SRC_PATH
171 "Path to Ethos-U55 timing adapter sources"
172 "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/core-software/drivers/timing_adapter"
173 PATH
174 )
175
176 USER_OPTION(ETHOS_U55_DRIVER_SRC_PATH
177 "Path to Ethos-U55 core driver sources"
178 "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/core_driver"
179 PATH
180 )
181
182 include_directories("${ETHOS_U55_TIMING_ADAPTER_SRC_PATH}/include/")
183
184 add_subdirectory("${ETHOS_U55_TIMING_ADAPTER_SRC_PATH}" ${CMAKE_BINARY_DIR}/timing-adapter)
185
186 set(ETHOSU_INCLUDES ${ETHOS_U55_TIMING_ADAPTER_SRC_PATH}/include
187 ${ETHOS_U55_DRIVER_SRC_PATH}/include)
188
189 list(APPEND ETHOS_U55_LIBS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libtiming_adapter.a)
190endif ()
191
192include(${CMAKE_SCRIPTS_DIR}/tensorflow.cmake)
193
194set(DEP_TENSORFLOW_LITE_MICRO_SUB_DIR ${TENSORFLOW_SRC_PATH}/tensorflow/lite/micro)
195set(DEP_TENSORFLOW_LITE_MICRO_MAKE_DIR ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR}/tools/make/targets)
196set(DEP_FLATBUF_INCLUDE ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR}/tools/make/downloads/flatbuffers/include)
197
198set(TENSORFLOW_LIBRARY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME})
199
200set(DEP_TF_INCLUDE_DIRS
201 ${TENSORFLOW_SRC_PATH}
202 ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR}
203 ${ETHOSU_INCLUDES}
204 ${CMSIS_HEADERS}
205 )
206
207## All TPIP includes
208set(DEP_RUNTIME_INCLUDE_DIRS
209 ${DEP_TF_INCLUDE_DIRS}
210 ${DEP_FLATBUF_INCLUDE}
211 )
212
213# Our entry point into tensorflow world:
214file(GLOB_RECURSE SRC_TENSORFLOW_LITE_MICRO
215 ${SRC_PATH}/application/tensorflow-lite-micro/**/*.cc
216 ${SRC_PATH}/application/tensorflow-lite-micro/*.cc
217 )
218
219set(HAL_DIR ${SRC_PATH}/application/hal)
220
221# HAL API sources
222file(GLOB_RECURSE SRC_HAL
223 "${HAL_DIR}/hal.c"
224 )
225
226# Set platform specific HAL sources; these should be provided
227# by each platform's cmake include file
228list(APPEND SRC_HAL ${SRC_PLAT_HAL})
229
230# Include directories:
231set(APPLICATION_INCLUDE_DIRS
232 ${HAL_DIR}/include
233 ${SRC_PATH}/application/tensorflow-lite-micro/include
234 ${SRC_PATH}/application/main/include
235 ${PLAT_INCLUDE_DIRS}
236 )
237
238file(GLOB_RECURSE SRC_APPLICATION
239 "${SRC_PATH}/application/main/*.cc"
240 "${SRC_PATH}/application/main/*.cpp"
241 "${SRC_PATH}/application/main/*.c"
242 "${SRC_PATH}/application/main/**/*.cc"
243 "${SRC_PATH}/application/main/**/*.cpp"
244 "${SRC_PATH}/application/main/**/*.c"
245 )
246list(FILTER SRC_APPLICATION EXCLUDE REGEX ".*main\\.c.*$")
247
248list(JOIN USE_CASE_BUILD "" USE_CASE_BUILD_STR)
Isabella Gottardi85209832021-04-20 14:08:52 +0100249list(APPEND USE_CASES_SEARCH_DIR_LIST ${SRC_PATH}/use_case)
250message(STATUS "Use-cases source paths: ${USE_CASES_SEARCH_DIR_LIST}.")
alexander3c798932021-03-26 21:42:19 +0000251if (${USE_CASE_BUILD_STR} STREQUAL all)
Isabella Gottardi85209832021-04-20 14:08:52 +0100252 foreach(USE_CASES_SEARCH_DIR ${USE_CASES_SEARCH_DIR_LIST})
253 SUBDIRLIST(USE_CASES_SUBDIRS ${USE_CASES_SEARCH_DIR})
254 list(APPEND USE_CASES ${USE_CASES_SUBDIRS})
255 endforeach()
alexander3c798932021-03-26 21:42:19 +0000256else()
257 set(USE_CASES ${USE_CASE_BUILD})
258endif()
259
alexander3c798932021-03-26 21:42:19 +0000260if (NOT ${CMAKE_CROSSCOMPILING})
261
262 #Test TPIP
263 set(TEST_TPIP ${DOWNLOAD_DEP_DIR}/test)
264 file(MAKE_DIRECTORY ${TEST_TPIP})
265 set(TEST_TPIP_INCLUDE ${TEST_TPIP}/include)
266 file(MAKE_DIRECTORY ${TEST_TPIP_INCLUDE})
267
268 include(ExternalProject)
269
270 ExternalProject_Add(catch2-headers
271 URL https://github.com/catchorg/Catch2/releases/download/v2.11.1/catch.hpp
272 DOWNLOAD_NO_EXTRACT 1
273 CONFIGURE_COMMAND ""
274 BUILD_COMMAND bash -c "cp -R <DOWNLOAD_DIR>/catch.hpp ${TEST_TPIP_INCLUDE}"
275 INSTALL_COMMAND ""
276 )
277endif ()
278
279message(STATUS "Building use-cases: ${USE_CASES}.")
280foreach(use_case ${USE_CASES})
281
Isabella Gottardi85209832021-04-20 14:08:52 +0100282 set(SRC_USE_CASE "")
283 foreach(USE_CASES_SEARCH_DIR ${USE_CASES_SEARCH_DIR_LIST})
284 if (EXISTS ${USE_CASES_SEARCH_DIR}/${use_case})
285 message(STATUS "Found sources for use-case ${use_case}")
286 set(SRC_USE_CASE ${USE_CASES_SEARCH_DIR})
287 break()
288 endif ()
289 endforeach()
290
291 if (${SRC_USE_CASE} STREQUAL "")
292 message(FATAL_ERROR "Failed to find sources for ${use_case}!")
alexander3c798932021-03-26 21:42:19 +0000293 endif ()
294 # Executable application:
295 set(TARGET_NAME "ethos-u-${use_case}")
296
Kshitij Sisodiaddcb56d2021-05-11 14:46:01 +0100297 set(DEFAULT_MODEL_DIR ${RESOURCES_DIR}/${use_case})
Isabella Gottardi2181d0a2021-04-07 09:27:38 +0100298 set(DEFAULT_TEST_DATA_DIR ${DEFAULT_MODEL_DIR})
alexander3c798932021-03-26 21:42:19 +0000299 set(SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/src)
300 set(INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/include)
301
302 # Remove old files and recreate dirs
303 file(REMOVE_RECURSE ${SRC_GEN_DIR} ${INC_GEN_DIR})
304 file(MAKE_DIRECTORY ${SRC_GEN_DIR} ${INC_GEN_DIR})
305
306 file(GLOB_RECURSE UC_SRC
Isabella Gottardi85209832021-04-20 14:08:52 +0100307 "${SRC_USE_CASE}/${use_case}/src/*.cpp"
308 "${SRC_USE_CASE}/${use_case}/src/*.cc"
309 "${SRC_USE_CASE}/${use_case}/src/*.c"
310 "${SRC_USE_CASE}/${use_case}/src/**/*.cpp"
311 "${SRC_USE_CASE}/${use_case}/src/**/*.cc"
312 "${SRC_USE_CASE}/${use_case}/src/**/*.c"
alexander3c798932021-03-26 21:42:19 +0000313 )
314
315 set(UC_INCLUDE
Isabella Gottardi85209832021-04-20 14:08:52 +0100316 ${SRC_USE_CASE}/${use_case}/include
alexander3c798932021-03-26 21:42:19 +0000317 )
318
319 file(GLOB UC_CMAKE_FILE
Isabella Gottardi85209832021-04-20 14:08:52 +0100320 "${SRC_USE_CASE}/${use_case}/*.cmake"
alexander3c798932021-03-26 21:42:19 +0000321 )
322
323 include(${UC_CMAKE_FILE})
324
325 file(GLOB_RECURSE SRC_GEN
326 "${SRC_GEN_DIR}/*.cc"
327 "${SRC_GEN_DIR}/*.cpp"
328 "${SRC_GEN_DIR}/*.c"
329 )
330
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100331 set(SRC_MAIN "${SRC_PATH}/application/main/Main.cc")
332
333 set_source_files_properties(${SRC_MAIN}
334 PROPERTIES COMPILE_DEFINITIONS
335 "PRJ_VER_STR=\"${PROJECT_VERSION}\";PRJ_DES_STR=\"${PROJECT_DESCRIPTION}\"")
alexander3c798932021-03-26 21:42:19 +0000336
337 set(UC_LIB_NAME lib${TARGET_NAME})
338
339 # Consolidated application static lib:
340 add_library(${UC_LIB_NAME} STATIC
341 ${SRC_APPLICATION}
342 ${SRC_TENSORFLOW_LITE_MICRO}
343 ${SRC_HAL}
344 ${UC_SRC}
345 ${SRC_GEN}
346 )
347 target_include_directories(${UC_LIB_NAME} PUBLIC
348 ${APPLICATION_INCLUDE_DIRS}
349 ${DEP_RUNTIME_INCLUDE_DIRS}
350 ${UC_INCLUDE}
351 ${INC_GEN_DIR}
352 )
353
354 # Set the activation buffer size
355 target_compile_definitions(${UC_LIB_NAME} PUBLIC
356 "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}")
357
358 add_dependencies(${UC_LIB_NAME} tensorflow-lite-micro)
359
360 if (${CMAKE_CROSSCOMPILING})
361 # If we are building timing adapter, set the dependency:
362 if (ETHOS_U55_ENABLED)
363 message(STATUS "Adding timing_adapter as a dependency to ${UC_LIB_NAME}")
364 add_dependencies(${UC_LIB_NAME} timing_adapter)
365 endif()
366
367 # If building with CMSIS-DSP support:
368 if (DEFINED CMSIS_DSP_TARGET)
369 message(STATUS "Adding ${CMSIS_DSP_TARGET} as a dependency to ${UC_LIB_NAME}")
370 add_dependencies(${UC_LIB_NAME} ${CMSIS_DSP_TARGET})
371 endif()
372 endif()
373
374 target_link_libraries(${UC_LIB_NAME} PUBLIC
375 ${TENSORFLOW_LIBRARY}
376 $<$<BOOL:${ETHOS_U55_ENABLED}>:${ETHOS_U55_LIBS}>
377 $<$<BOOL:${CMSIS_DSP_LIB}>:${CMSIS_DSP_LIB}>)
378
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100379 add_executable(${TARGET_NAME} ${SRC_MAIN} ${PLAT_RETARGET_SOURCE})
alexander3c798932021-03-26 21:42:19 +0000380
381 target_link_libraries(${TARGET_NAME} ${UC_LIB_NAME})
382
383 if (${CMAKE_CROSSCOMPILING})
384 set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".axf")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100385 add_target_map_file(${TARGET_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}.map)
alexander3c798932021-03-26 21:42:19 +0000386 endif()
387
388 if (${TARGET_PLATFORM} STREQUAL mps3)
389
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100390 set(SECTORS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sectors)
391 set(SECTORS_BIN_DIR ${SECTORS_DIR}/${use_case})
alexander3c798932021-03-26 21:42:19 +0000392
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100393 file(REMOVE_RECURSE ${SECTORS_BIN_DIR})
394 file(MAKE_DIRECTORY ${SECTORS_BIN_DIR})
395 file(COPY ${MPS3_FPGA_CONFIG} DESTINATION ${SECTORS_DIR})
alexander3c798932021-03-26 21:42:19 +0000396
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100397 add_bin_generation_command(
398 TARGET_NAME ${TARGET_NAME}
399 OUTPUT_DIR ${SECTORS_BIN_DIR}
400 AXF_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}.axf
401 SECTION_PATTERNS "${MPS3_SECTION_PATTERNS}"
402 OUTPUT_BIN_NAMES "${MPS3_OUTPUT_BIN_NAMES}")
alexander3c798932021-03-26 21:42:19 +0000403 elseif (${TARGET_PLATFORM} STREQUAL native)
Isabella Gottardi85209832021-04-20 14:08:52 +0100404
405 # If native build tests
406 set(TEST_SRC_USE_CASE "")
407 foreach(USE_CASES_TESTS_SEARCH_DIR ${USE_CASES_TESTS_SEARCH_DIR_LIST})
408
409 if (EXISTS ${USE_CASES_TESTS_SEARCH_DIR}/${use_case})
410 message(STATUS "Found tests for use-case ${use_case} at ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}.")
411 set(TEST_SRC_USE_CASE ${USE_CASES_TESTS_SEARCH_DIR})
412 break()
413 endif ()
414 endforeach()
415
alexander3c798932021-03-26 21:42:19 +0000416 # Add tests only if they exists for the usecase
Isabella Gottardi85209832021-04-20 14:08:52 +0100417 if (NOT ${TEST_SRC_USE_CASE} STREQUAL "")
alexander3c798932021-03-26 21:42:19 +0000418
419 set(TEST_RESOURCES_INCLUDE
420 "${TEST_SRCS}/utils/"
Isabella Gottardicce00052021-04-26 09:24:02 +0100421 "${TEST_SRC_USE_CASE}/${use_case}/include/"
alexander3c798932021-03-26 21:42:19 +0000422 )
423
424 # Define Test sources and new target to run unit tests
425 file(GLOB_RECURSE TEST_SOURCES
426 "${TEST_SRCS}/common/*.cpp"
427 "${TEST_SRCS}/common/*.cc"
428 "${TEST_SRCS}/utils/*.cc"
429 "${TEST_SRCS}/utils/*.cpp"
Isabella Gottardi85209832021-04-20 14:08:52 +0100430 "${TEST_SRC_USE_CASE}/${use_case}/*.cpp"
431 "${TEST_SRC_USE_CASE}/${use_case}/*.cc"
432 "${TEST_SRC_USE_CASE}/${use_case}/*.c"
433 "${TEST_SRC_USE_CASE}/${use_case}/**/*.cpp"
434 "${TEST_SRC_USE_CASE}/${use_case}/**/*.cc"
435 "${TEST_SRC_USE_CASE}/${use_case}/**/*.c"
alexander3c798932021-03-26 21:42:19 +0000436 )
437
Isabella Gottardi2181d0a2021-04-07 09:27:38 +0100438 set(TEST_SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/src)
439 set(TEST_INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/include)
440 file(MAKE_DIRECTORY ${TEST_SRC_GEN_DIR} ${TEST_INC_GEN_DIR})
alexander3c798932021-03-26 21:42:19 +0000441
Isabella Gottardi2181d0a2021-04-07 09:27:38 +0100442 # Generate test data files to be included in x86 tests
443 generate_test_data_code(
444 INPUT_DIR "${DEFAULT_TEST_DATA_DIR}"
445 DESTINATION_SRC ${TEST_SRC_GEN_DIR}
446 DESTINATION_HDR ${TEST_INC_GEN_DIR}
447 NAMESPACE "test"
448 )
449
450 file(GLOB_RECURSE TEST_SOURCES_GEN
451 "${TEST_SRC_GEN_DIR}/*.cc"
452 "${TEST_SRC_GEN_DIR}/**/*.cc"
453 )
454 message(STATUS "Adding ${TEST_SOURCES_GEN} to test sources")
455 list(APPEND TEST_SOURCES ${TEST_SOURCES_GEN})
456 list(APPEND TEST_RESOURCES_INCLUDE ${TEST_INC_GEN_DIR})
alexander3c798932021-03-26 21:42:19 +0000457
458 set(TEST_TARGET_NAME "${CMAKE_PROJECT_NAME}-${use_case}-tests")
459 add_executable(${TEST_TARGET_NAME} ${TEST_SOURCES})
460 target_include_directories(${TEST_TARGET_NAME} PUBLIC
461 ${TEST_TPIP_INCLUDE} ${TEST_RESOURCES_INCLUDE})
462 target_link_libraries(${TEST_TARGET_NAME} libethos-u-${use_case})
463 target_compile_definitions(${TEST_TARGET_NAME} PRIVATE
464 "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}"
465 TESTS)
466
467 add_dependencies(
468 "${TEST_TARGET_NAME}"
469 "catch2-headers"
470 )
Isabella Gottardi85209832021-04-20 14:08:52 +0100471
alexander3c798932021-03-26 21:42:19 +0000472 endif ()
473 endif ()
474endforeach()
475
476print_useroptions()