blob: 411b4f211b98f30c5a73b32c17d083b4b0c190ac [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
46include(${CMAKE_SCRIPTS_DIR}/source_gen_utils.cmake)
47include(${CMAKE_SCRIPTS_DIR}/util_functions.cmake)
48
49if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR})
50 message(FATAL_ERROR "Source and build are in the same directory")
51else()
52 message(STATUS "Source directory: ${CMAKE_SOURCE_DIR}")
53 message(STATUS "Binary directory: ${CMAKE_BINARY_DIR}")
54endif()
55
56USER_OPTION(LOG_LEVEL "Log level for the application"
57 LOG_LEVEL_INFO
58 STRING)
59
60USER_OPTION(TENSORFLOW_SRC_PATH "Path to the root of the tensor flow directory"
61 "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/tensorflow"
62 PATH)
63
64USER_OPTION(TARGET_PLATFORM "Target platform to execute evaluation application: mps3, simple_platform, native"
65 mps3
66 STRING)
67
alexanderd580eee2021-05-04 21:24:22 +010068USER_OPTION(TARGET_SUBSYSTEM "Specify platform target subsystem: sse-300 or none"
alexander3c798932021-03-26 21:42:19 +000069 sse-300
70 STRING)
71
72USER_OPTION(ETHOS_U55_ENABLED "Select if Ethos-U55 is available for the platform and subsystem"
73 ON
74 BOOL)
75
76USER_OPTION(USE_CASE_BUILD "Optional. Defines the use-case to build from the available sources. By default, all use-cases are built."
77 all
78 STRING)
79
80USER_OPTION(CPU_PROFILE_ENABLED "Output CPU performance profiling information. Should be used only for MPS3 board."
81 OFF
82 BOOL)
83
84if (TARGET_PLATFORM STREQUAL mps3)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010085 message(STATUS "Platform: MPS3 FPGA Prototyping Board or FVP")
86 set(DEFAULT_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake)
alexander3c798932021-03-26 21:42:19 +000087elseif (TARGET_PLATFORM STREQUAL simple_platform)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010088 message(STATUS "Platform: Simple platform with minimal peripherals")
89 set(DEFAULT_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake)
alexander3c798932021-03-26 21:42:19 +000090elseif (TARGET_PLATFORM STREQUAL native)
91 message(STATUS "Platform: Native (Linux based x86_64/aarch64 system)")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010092 set(DEFAULT_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/native-gcc.cmake)
alexander3c798932021-03-26 21:42:19 +000093else ()
94 message(FATAL_ERROR "Invalid platform specified: ${TARGET_PLATFORM}")
95endif ()
96
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010097if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
98 set(CMAKE_TOOLCHAIN_FILE ${DEFAULT_TOOLCHAIN_FILE}
99 CACHE FILEPATH "Toolchain file")
100endif()
101message(STATUS "Using CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}")
102
103project(arm_ml_embedded_evaluation_kit
104 VERSION 21.05
105 DESCRIPTION "ARM ML Embedded Evaluation Kit for MPS3 FPGA and FastModel")
106
alexander3c798932021-03-26 21:42:19 +0000107enforce_compiler_version()
108setup_source_generator()
109
110set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
111set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
112set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
113set(SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/source)
Isabella Gottardi85209832021-04-20 14:08:52 +0100114set(TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tests)
115list(APPEND USE_CASES_TESTS_SEARCH_DIR_LIST ${TEST_SRCS}/use_case)
alexander3c798932021-03-26 21:42:19 +0000116
117if (CPU_PROFILE_ENABLED)
118 set(PROFILING_OPT "${PROFILING_OPT} -DCPU_PROFILE_ENABLED")
119endif()
120
121# Include platform specific sources
122if (TARGET_PLATFORM STREQUAL native)
123 set(PLATFORM_SOURCES_CMAKE_FILE ${CMAKE_SCRIPTS_DIR}/${TARGET_PLATFORM}-sources.cmake)
124else ()
125 set(PLATFORM_SOURCES_CMAKE_FILE ${CMAKE_SCRIPTS_DIR}/bare-metal-sources.cmake)
126
127 USER_OPTION(CMSIS_SRC_PATH
128 "Path to CMSIS-5 sources"
129 "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/cmsis"
130 PATH
131 )
132
133 if (CMAKE_BUILD_TYPE STREQUAL Debug AND CMAKE_CXX_COMPILER_ID STREQUAL ARMClang)
134 USER_OPTION(ARMCLANG_DEBUG_DWARF_LEVEL
135 "Dwarf conformance level for armclang toolchain"
136 "4" # Default = 4 (Arm-DS etc). For model debugger specify "3"
137 STRING
138 )
139 elseif (DEFINED ARMCLANG_DEBUG_DWARF_LEVEL)
140 message(WARNING "ARMCLANG_DEBUG_DWARF_LEVEL definition is unsupported"
141 "within current configuration. Removing definition...")
142 unset(ARMCLANG_DEBUG_DWARF_LEVEL CACHE)
143 endif()
144
145endif ()
146message(STATUS "Including ${PLATFORM_SOURCES_CMAKE_FILE}")
147include(${PLATFORM_SOURCES_CMAKE_FILE})
148
149if (${CMAKE_CROSSCOMPILING})
150 enable_language(ASM)
151
152 # For non-native builds, we build with CMSIS-DSP support.
153 include(${CMAKE_SCRIPTS_DIR}/cmsis-dsp.cmake)
154
155 # All CMSIS headers to be used:
156 set(CMSIS_HEADERS
157 ${CMSIS_DSP_INC_DIR}
158 ${CMSIS_CORE_INC_DIR}
159 ${CMSIS_SRC_PATH}/Device/ARM/ARMCM55/Include
160 ${CMSIS_SRC_PATH}/Device/ARM/ARMCM55/Include/Template)
161endif ()
162
163# If we need NPU libraries:
164if (ETHOS_U55_ENABLED)
165
166 message(STATUS "Using ARM Ethos-U55 - adding core-driver and timing-adapter-driver includes and libraries")
167 USER_OPTION(ETHOS_U55_TIMING_ADAPTER_SRC_PATH
168 "Path to Ethos-U55 timing adapter sources"
169 "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/core-software/drivers/timing_adapter"
170 PATH
171 )
172
173 USER_OPTION(ETHOS_U55_DRIVER_SRC_PATH
174 "Path to Ethos-U55 core driver sources"
175 "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/core_driver"
176 PATH
177 )
178
179 include_directories("${ETHOS_U55_TIMING_ADAPTER_SRC_PATH}/include/")
180
181 add_subdirectory("${ETHOS_U55_TIMING_ADAPTER_SRC_PATH}" ${CMAKE_BINARY_DIR}/timing-adapter)
182
183 set(ETHOSU_INCLUDES ${ETHOS_U55_TIMING_ADAPTER_SRC_PATH}/include
184 ${ETHOS_U55_DRIVER_SRC_PATH}/include)
185
186 list(APPEND ETHOS_U55_LIBS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libtiming_adapter.a)
187endif ()
188
189include(${CMAKE_SCRIPTS_DIR}/tensorflow.cmake)
190
191set(DEP_TENSORFLOW_LITE_MICRO_SUB_DIR ${TENSORFLOW_SRC_PATH}/tensorflow/lite/micro)
192set(DEP_TENSORFLOW_LITE_MICRO_MAKE_DIR ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR}/tools/make/targets)
193set(DEP_FLATBUF_INCLUDE ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR}/tools/make/downloads/flatbuffers/include)
194
195set(TENSORFLOW_LIBRARY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME})
196
197set(DEP_TF_INCLUDE_DIRS
198 ${TENSORFLOW_SRC_PATH}
199 ${DEP_TENSORFLOW_LITE_MICRO_SUB_DIR}
200 ${ETHOSU_INCLUDES}
201 ${CMSIS_HEADERS}
202 )
203
204## All TPIP includes
205set(DEP_RUNTIME_INCLUDE_DIRS
206 ${DEP_TF_INCLUDE_DIRS}
207 ${DEP_FLATBUF_INCLUDE}
208 )
209
210# Our entry point into tensorflow world:
211file(GLOB_RECURSE SRC_TENSORFLOW_LITE_MICRO
212 ${SRC_PATH}/application/tensorflow-lite-micro/**/*.cc
213 ${SRC_PATH}/application/tensorflow-lite-micro/*.cc
214 )
215
216set(HAL_DIR ${SRC_PATH}/application/hal)
217
218# HAL API sources
219file(GLOB_RECURSE SRC_HAL
220 "${HAL_DIR}/hal.c"
221 )
222
223# Set platform specific HAL sources; these should be provided
224# by each platform's cmake include file
225list(APPEND SRC_HAL ${SRC_PLAT_HAL})
226
227# Include directories:
228set(APPLICATION_INCLUDE_DIRS
229 ${HAL_DIR}/include
230 ${SRC_PATH}/application/tensorflow-lite-micro/include
231 ${SRC_PATH}/application/main/include
232 ${PLAT_INCLUDE_DIRS}
233 )
234
235file(GLOB_RECURSE SRC_APPLICATION
236 "${SRC_PATH}/application/main/*.cc"
237 "${SRC_PATH}/application/main/*.cpp"
238 "${SRC_PATH}/application/main/*.c"
239 "${SRC_PATH}/application/main/**/*.cc"
240 "${SRC_PATH}/application/main/**/*.cpp"
241 "${SRC_PATH}/application/main/**/*.c"
242 )
243list(FILTER SRC_APPLICATION EXCLUDE REGEX ".*main\\.c.*$")
244
245list(JOIN USE_CASE_BUILD "" USE_CASE_BUILD_STR)
Isabella Gottardi85209832021-04-20 14:08:52 +0100246list(APPEND USE_CASES_SEARCH_DIR_LIST ${SRC_PATH}/use_case)
247message(STATUS "Use-cases source paths: ${USE_CASES_SEARCH_DIR_LIST}.")
alexander3c798932021-03-26 21:42:19 +0000248if (${USE_CASE_BUILD_STR} STREQUAL all)
Isabella Gottardi85209832021-04-20 14:08:52 +0100249 foreach(USE_CASES_SEARCH_DIR ${USE_CASES_SEARCH_DIR_LIST})
250 SUBDIRLIST(USE_CASES_SUBDIRS ${USE_CASES_SEARCH_DIR})
251 list(APPEND USE_CASES ${USE_CASES_SUBDIRS})
252 endforeach()
alexander3c798932021-03-26 21:42:19 +0000253else()
254 set(USE_CASES ${USE_CASE_BUILD})
255endif()
256
alexander3c798932021-03-26 21:42:19 +0000257if (NOT ${CMAKE_CROSSCOMPILING})
258
259 #Test TPIP
260 set(TEST_TPIP ${DOWNLOAD_DEP_DIR}/test)
261 file(MAKE_DIRECTORY ${TEST_TPIP})
262 set(TEST_TPIP_INCLUDE ${TEST_TPIP}/include)
263 file(MAKE_DIRECTORY ${TEST_TPIP_INCLUDE})
264
265 include(ExternalProject)
266
267 ExternalProject_Add(catch2-headers
268 URL https://github.com/catchorg/Catch2/releases/download/v2.11.1/catch.hpp
269 DOWNLOAD_NO_EXTRACT 1
270 CONFIGURE_COMMAND ""
271 BUILD_COMMAND bash -c "cp -R <DOWNLOAD_DIR>/catch.hpp ${TEST_TPIP_INCLUDE}"
272 INSTALL_COMMAND ""
273 )
274endif ()
275
276message(STATUS "Building use-cases: ${USE_CASES}.")
277foreach(use_case ${USE_CASES})
278
Isabella Gottardi85209832021-04-20 14:08:52 +0100279 set(SRC_USE_CASE "")
280 foreach(USE_CASES_SEARCH_DIR ${USE_CASES_SEARCH_DIR_LIST})
281 if (EXISTS ${USE_CASES_SEARCH_DIR}/${use_case})
282 message(STATUS "Found sources for use-case ${use_case}")
283 set(SRC_USE_CASE ${USE_CASES_SEARCH_DIR})
284 break()
285 endif ()
286 endforeach()
287
288 if (${SRC_USE_CASE} STREQUAL "")
289 message(FATAL_ERROR "Failed to find sources for ${use_case}!")
alexander3c798932021-03-26 21:42:19 +0000290 endif ()
291 # Executable application:
292 set(TARGET_NAME "ethos-u-${use_case}")
293
Isabella Gottardi2181d0a2021-04-07 09:27:38 +0100294 set(DEFAULT_MODEL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources_downloaded/${use_case})
295 set(DEFAULT_TEST_DATA_DIR ${DEFAULT_MODEL_DIR})
alexander3c798932021-03-26 21:42:19 +0000296 set(SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/src)
297 set(INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/include)
298
299 # Remove old files and recreate dirs
300 file(REMOVE_RECURSE ${SRC_GEN_DIR} ${INC_GEN_DIR})
301 file(MAKE_DIRECTORY ${SRC_GEN_DIR} ${INC_GEN_DIR})
302
303 file(GLOB_RECURSE UC_SRC
Isabella Gottardi85209832021-04-20 14:08:52 +0100304 "${SRC_USE_CASE}/${use_case}/src/*.cpp"
305 "${SRC_USE_CASE}/${use_case}/src/*.cc"
306 "${SRC_USE_CASE}/${use_case}/src/*.c"
307 "${SRC_USE_CASE}/${use_case}/src/**/*.cpp"
308 "${SRC_USE_CASE}/${use_case}/src/**/*.cc"
309 "${SRC_USE_CASE}/${use_case}/src/**/*.c"
alexander3c798932021-03-26 21:42:19 +0000310 )
311
312 set(UC_INCLUDE
Isabella Gottardi85209832021-04-20 14:08:52 +0100313 ${SRC_USE_CASE}/${use_case}/include
alexander3c798932021-03-26 21:42:19 +0000314 )
315
316 file(GLOB UC_CMAKE_FILE
Isabella Gottardi85209832021-04-20 14:08:52 +0100317 "${SRC_USE_CASE}/${use_case}/*.cmake"
alexander3c798932021-03-26 21:42:19 +0000318 )
319
320 include(${UC_CMAKE_FILE})
321
322 file(GLOB_RECURSE SRC_GEN
323 "${SRC_GEN_DIR}/*.cc"
324 "${SRC_GEN_DIR}/*.cpp"
325 "${SRC_GEN_DIR}/*.c"
326 )
327
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100328 set(SRC_MAIN "${SRC_PATH}/application/main/Main.cc")
329
330 set_source_files_properties(${SRC_MAIN}
331 PROPERTIES COMPILE_DEFINITIONS
332 "PRJ_VER_STR=\"${PROJECT_VERSION}\";PRJ_DES_STR=\"${PROJECT_DESCRIPTION}\"")
alexander3c798932021-03-26 21:42:19 +0000333
334 set(UC_LIB_NAME lib${TARGET_NAME})
335
336 # Consolidated application static lib:
337 add_library(${UC_LIB_NAME} STATIC
338 ${SRC_APPLICATION}
339 ${SRC_TENSORFLOW_LITE_MICRO}
340 ${SRC_HAL}
341 ${UC_SRC}
342 ${SRC_GEN}
343 )
344 target_include_directories(${UC_LIB_NAME} PUBLIC
345 ${APPLICATION_INCLUDE_DIRS}
346 ${DEP_RUNTIME_INCLUDE_DIRS}
347 ${UC_INCLUDE}
348 ${INC_GEN_DIR}
349 )
350
351 # Set the activation buffer size
352 target_compile_definitions(${UC_LIB_NAME} PUBLIC
353 "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}")
354
355 add_dependencies(${UC_LIB_NAME} tensorflow-lite-micro)
356
357 if (${CMAKE_CROSSCOMPILING})
358 # If we are building timing adapter, set the dependency:
359 if (ETHOS_U55_ENABLED)
360 message(STATUS "Adding timing_adapter as a dependency to ${UC_LIB_NAME}")
361 add_dependencies(${UC_LIB_NAME} timing_adapter)
362 endif()
363
364 # If building with CMSIS-DSP support:
365 if (DEFINED CMSIS_DSP_TARGET)
366 message(STATUS "Adding ${CMSIS_DSP_TARGET} as a dependency to ${UC_LIB_NAME}")
367 add_dependencies(${UC_LIB_NAME} ${CMSIS_DSP_TARGET})
368 endif()
369 endif()
370
371 target_link_libraries(${UC_LIB_NAME} PUBLIC
372 ${TENSORFLOW_LIBRARY}
373 $<$<BOOL:${ETHOS_U55_ENABLED}>:${ETHOS_U55_LIBS}>
374 $<$<BOOL:${CMSIS_DSP_LIB}>:${CMSIS_DSP_LIB}>)
375
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100376 add_executable(${TARGET_NAME} ${SRC_MAIN} ${PLAT_RETARGET_SOURCE})
alexander3c798932021-03-26 21:42:19 +0000377
378 target_link_libraries(${TARGET_NAME} ${UC_LIB_NAME})
379
380 if (${CMAKE_CROSSCOMPILING})
381 set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".axf")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100382 add_target_map_file(${TARGET_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}.map)
alexander3c798932021-03-26 21:42:19 +0000383 endif()
384
385 if (${TARGET_PLATFORM} STREQUAL mps3)
386
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100387 set(SECTORS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sectors)
388 set(SECTORS_BIN_DIR ${SECTORS_DIR}/${use_case})
alexander3c798932021-03-26 21:42:19 +0000389
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100390 file(REMOVE_RECURSE ${SECTORS_BIN_DIR})
391 file(MAKE_DIRECTORY ${SECTORS_BIN_DIR})
392 file(COPY ${MPS3_FPGA_CONFIG} DESTINATION ${SECTORS_DIR})
alexander3c798932021-03-26 21:42:19 +0000393
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100394 add_bin_generation_command(
395 TARGET_NAME ${TARGET_NAME}
396 OUTPUT_DIR ${SECTORS_BIN_DIR}
397 AXF_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_NAME}.axf
398 SECTION_PATTERNS "${MPS3_SECTION_PATTERNS}"
399 OUTPUT_BIN_NAMES "${MPS3_OUTPUT_BIN_NAMES}")
alexander3c798932021-03-26 21:42:19 +0000400 elseif (${TARGET_PLATFORM} STREQUAL native)
Isabella Gottardi85209832021-04-20 14:08:52 +0100401
402 # If native build tests
403 set(TEST_SRC_USE_CASE "")
404 foreach(USE_CASES_TESTS_SEARCH_DIR ${USE_CASES_TESTS_SEARCH_DIR_LIST})
405
406 if (EXISTS ${USE_CASES_TESTS_SEARCH_DIR}/${use_case})
407 message(STATUS "Found tests for use-case ${use_case} at ${USE_CASES_TESTS_SEARCH_DIR}/${use_case}.")
408 set(TEST_SRC_USE_CASE ${USE_CASES_TESTS_SEARCH_DIR})
409 break()
410 endif ()
411 endforeach()
412
alexander3c798932021-03-26 21:42:19 +0000413 # Add tests only if they exists for the usecase
Isabella Gottardi85209832021-04-20 14:08:52 +0100414 if (NOT ${TEST_SRC_USE_CASE} STREQUAL "")
alexander3c798932021-03-26 21:42:19 +0000415
416 set(TEST_RESOURCES_INCLUDE
417 "${TEST_SRCS}/utils/"
Isabella Gottardicce00052021-04-26 09:24:02 +0100418 "${TEST_SRC_USE_CASE}/${use_case}/include/"
alexander3c798932021-03-26 21:42:19 +0000419 )
420
421 # Define Test sources and new target to run unit tests
422 file(GLOB_RECURSE TEST_SOURCES
423 "${TEST_SRCS}/common/*.cpp"
424 "${TEST_SRCS}/common/*.cc"
425 "${TEST_SRCS}/utils/*.cc"
426 "${TEST_SRCS}/utils/*.cpp"
Isabella Gottardi85209832021-04-20 14:08:52 +0100427 "${TEST_SRC_USE_CASE}/${use_case}/*.cpp"
428 "${TEST_SRC_USE_CASE}/${use_case}/*.cc"
429 "${TEST_SRC_USE_CASE}/${use_case}/*.c"
430 "${TEST_SRC_USE_CASE}/${use_case}/**/*.cpp"
431 "${TEST_SRC_USE_CASE}/${use_case}/**/*.cc"
432 "${TEST_SRC_USE_CASE}/${use_case}/**/*.c"
alexander3c798932021-03-26 21:42:19 +0000433 )
434
Isabella Gottardi2181d0a2021-04-07 09:27:38 +0100435 set(TEST_SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/src)
436 set(TEST_INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/tests/include)
437 file(MAKE_DIRECTORY ${TEST_SRC_GEN_DIR} ${TEST_INC_GEN_DIR})
alexander3c798932021-03-26 21:42:19 +0000438
Isabella Gottardi2181d0a2021-04-07 09:27:38 +0100439 # Generate test data files to be included in x86 tests
440 generate_test_data_code(
441 INPUT_DIR "${DEFAULT_TEST_DATA_DIR}"
442 DESTINATION_SRC ${TEST_SRC_GEN_DIR}
443 DESTINATION_HDR ${TEST_INC_GEN_DIR}
444 NAMESPACE "test"
445 )
446
447 file(GLOB_RECURSE TEST_SOURCES_GEN
448 "${TEST_SRC_GEN_DIR}/*.cc"
449 "${TEST_SRC_GEN_DIR}/**/*.cc"
450 )
451 message(STATUS "Adding ${TEST_SOURCES_GEN} to test sources")
452 list(APPEND TEST_SOURCES ${TEST_SOURCES_GEN})
453 list(APPEND TEST_RESOURCES_INCLUDE ${TEST_INC_GEN_DIR})
alexander3c798932021-03-26 21:42:19 +0000454
455 set(TEST_TARGET_NAME "${CMAKE_PROJECT_NAME}-${use_case}-tests")
456 add_executable(${TEST_TARGET_NAME} ${TEST_SOURCES})
457 target_include_directories(${TEST_TARGET_NAME} PUBLIC
458 ${TEST_TPIP_INCLUDE} ${TEST_RESOURCES_INCLUDE})
459 target_link_libraries(${TEST_TARGET_NAME} libethos-u-${use_case})
460 target_compile_definitions(${TEST_TARGET_NAME} PRIVATE
461 "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}"
462 TESTS)
463
464 add_dependencies(
465 "${TEST_TARGET_NAME}"
466 "catch2-headers"
467 )
Isabella Gottardi85209832021-04-20 14:08:52 +0100468
alexander3c798932021-03-26 21:42:19 +0000469 endif ()
470 endif ()
471endforeach()
472
473print_useroptions()