blob: 0320448758a3f101ca5fb9c9ae93658421dca5ed [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001#----------------------------------------------------------------------------
Kshitij Sisodia774c7ca2024-04-12 11:30:02 +01002# SPDX-FileCopyrightText: Copyright 2021-2024 Arm Limited and/or its
3# affiliates <open-source-office@arm.com>
alexander3c798932021-03-26 21:42:19 +00004# SPDX-License-Identifier: Apache-2.0
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#----------------------------------------------------------------------------
Kshitij Sisodia9c6f9f82022-05-20 14:30:02 +010018cmake_minimum_required(VERSION 3.21.0)
alexander3c798932021-03-26 21:42:19 +000019
20# Build in release mode by default
21if (NOT CMAKE_BUILD_TYPE STREQUAL Debug)
22 set(CMAKE_BUILD_TYPE Release CACHE INTERNAL "")
23endif()
24
25message(STATUS "Build type is set to ${CMAKE_BUILD_TYPE}")
26
alexander31ae9f02022-02-10 16:15:54 +000027# Set language standards.
alexander3c798932021-03-26 21:42:19 +000028set(CMAKE_C_STANDARD 99)
ayamas0115f80702021-11-18 14:22:23 +000029set(CMAKE_CXX_STANDARD 14)
alexander3c798932021-03-26 21:42:19 +000030
31# Make the standard a requirement => prevent fallback to previous
32# supported standard
33set(CMAKE_C_STANDARD_REQUIRED ON)
34set(CMAKE_CXX_STANDARD_REQUIRED ON)
35
36# We want to pass standard C/C++ flags, without gnu extensions
37set(CMAKE_C_EXTENSIONS OFF)
38set(CMAKE_CXX_EXTENSIONS OFF)
39
Kshitij Sisodia72377a42024-05-16 09:15:12 +010040# Initialise global settings
41include("${CMAKE_CURRENT_SOURCE_DIR}/MlekModule.cmake")
Nina Drozd59169522022-02-10 13:33:20 +000042
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010043project(arm_ml_embedded_evaluation_kit
Kshitij Sisodia4cef9ac2024-04-08 09:58:46 +010044 VERSION 24.02.0
alexander31ae9f02022-02-10 16:15:54 +000045 DESCRIPTION "ARM ML Embedded Evaluation Kit"
46 LANGUAGES C CXX ASM)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010047
alexander3c798932021-03-26 21:42:19 +000048enforce_compiler_version()
49setup_source_generator()
50
51set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
52set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
53set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
54set(SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/source)
Isabella Gottardi85209832021-04-20 14:08:52 +010055set(TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tests)
56list(APPEND USE_CASES_TESTS_SEARCH_DIR_LIST ${TEST_SRCS}/use_case)
alexander3c798932021-03-26 21:42:19 +000057
alexander31ae9f02022-02-10 16:15:54 +000058# We include log target
59add_subdirectory(${SRC_PATH}/log ${CMAKE_BINARY_DIR}/log)
alexander3c798932021-03-26 21:42:19 +000060
alexander31ae9f02022-02-10 16:15:54 +000061# We include arm_math target
62add_subdirectory(${SRC_PATH}/math ${CMAKE_BINARY_DIR}/math)
alexander3c798932021-03-26 21:42:19 +000063
alexander31ae9f02022-02-10 16:15:54 +000064# We include the hal target
65add_subdirectory(${SRC_PATH}/hal ${CMAKE_BINARY_DIR}/hal)
alexander3c798932021-03-26 21:42:19 +000066
Kshitij Sisodiae2da7ee2022-02-14 11:22:58 +000067# Add the profiler target
68if (NOT DEFINED PROFILER_DIR)
69 set(PROFILER_DIR ${SRC_PATH}/profiler)
70endif ()
71add_subdirectory(${PROFILER_DIR} ${CMAKE_BINARY_DIR}/profiler)
72
alexander31ae9f02022-02-10 16:15:54 +000073# Include the tensorflow build target
Kshitij Sisodia774c7ca2024-04-12 11:30:02 +010074include(tensorflow_lite_micro)
alexander3c798932021-03-26 21:42:19 +000075
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010076# Add the common API library target (tensorflow-lite-micro target is needed)
77add_subdirectory(${SRC_PATH}/application/api/common ${CMAKE_BINARY_DIR}/api/common)
78
alexander31ae9f02022-02-10 16:15:54 +000079# Include directories for application module:
80set(APPLICATION_INCLUDE_DIRS
Kshitij Sisodiae2da7ee2022-02-14 11:22:58 +000081 ${SRC_PATH}/application/main/include)
alexander3c798932021-03-26 21:42:19 +000082
alexander31ae9f02022-02-10 16:15:54 +000083# Source files for application module:
alexander3c798932021-03-26 21:42:19 +000084file(GLOB_RECURSE SRC_APPLICATION
85 "${SRC_PATH}/application/main/*.cc"
86 "${SRC_PATH}/application/main/*.cpp"
87 "${SRC_PATH}/application/main/*.c"
alexander3c798932021-03-26 21:42:19 +000088 )
89list(FILTER SRC_APPLICATION EXCLUDE REGEX ".*main\\.c.*$")
alexander31ae9f02022-02-10 16:15:54 +000090set(SRC_MAIN "${SRC_PATH}/application/main/Main.cc")
91set_source_files_properties(${SRC_MAIN}
92 PROPERTIES COMPILE_DEFINITIONS
93 "PRJ_VER_STR=\"${PROJECT_VERSION}\";PRJ_DES_STR=\"${PROJECT_DESCRIPTION}\"")
alexander3c798932021-03-26 21:42:19 +000094
95list(JOIN USE_CASE_BUILD "" USE_CASE_BUILD_STR)
Isabella Gottardi85209832021-04-20 14:08:52 +010096list(APPEND USE_CASES_SEARCH_DIR_LIST ${SRC_PATH}/use_case)
97message(STATUS "Use-cases source paths: ${USE_CASES_SEARCH_DIR_LIST}.")
alexander31ae9f02022-02-10 16:15:54 +000098
alexander3c798932021-03-26 21:42:19 +000099if (${USE_CASE_BUILD_STR} STREQUAL all)
Isabella Gottardi85209832021-04-20 14:08:52 +0100100 foreach(USE_CASES_SEARCH_DIR ${USE_CASES_SEARCH_DIR_LIST})
101 SUBDIRLIST(USE_CASES_SUBDIRS ${USE_CASES_SEARCH_DIR})
102 list(APPEND USE_CASES ${USE_CASES_SUBDIRS})
103 endforeach()
alexander3c798932021-03-26 21:42:19 +0000104else()
105 set(USE_CASES ${USE_CASE_BUILD})
106endif()
107
alexandercb8a9872022-02-11 13:23:22 +0000108list(REMOVE_ITEM USE_CASES "" ${EXCLUDED_USE_CASES})
109message(STATUS "Use-cases excluded by platform configuration: ${EXCLUDED_USE_CASES}")
alexander3c798932021-03-26 21:42:19 +0000110message(STATUS "Building use-cases: ${USE_CASES}.")
Eanna O Cathain7bc68322022-05-31 14:14:32 +0100111
alexander3c798932021-03-26 21:42:19 +0000112foreach(use_case ${USE_CASES})
113
Isabella Gottardi85209832021-04-20 14:08:52 +0100114 set(SRC_USE_CASE "")
115 foreach(USE_CASES_SEARCH_DIR ${USE_CASES_SEARCH_DIR_LIST})
116 if (EXISTS ${USE_CASES_SEARCH_DIR}/${use_case})
117 message(STATUS "Found sources for use-case ${use_case}")
118 set(SRC_USE_CASE ${USE_CASES_SEARCH_DIR})
119 break()
120 endif ()
121 endforeach()
122
123 if (${SRC_USE_CASE} STREQUAL "")
124 message(FATAL_ERROR "Failed to find sources for ${use_case}!")
alexander3c798932021-03-26 21:42:19 +0000125 endif ()
Kshitij Sisodia661959c2021-11-24 10:39:52 +0000126
alexander3c798932021-03-26 21:42:19 +0000127 # Executable application:
128 set(TARGET_NAME "ethos-u-${use_case}")
129
Kshitij Sisodia72377a42024-05-16 09:15:12 +0100130 set(DEFAULT_MODEL_DIR ${MLEK_RESOURCES_DIR}/${use_case})
alexander31ae9f02022-02-10 16:15:54 +0000131 set(DEFAULT_TEST_DATA_DIR ${DEFAULT_MODEL_DIR})
alexander3c798932021-03-26 21:42:19 +0000132 set(SRC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/src)
133 set(INC_GEN_DIR ${CMAKE_BINARY_DIR}/generated/${use_case}/include)
134
135 # Remove old files and recreate dirs
136 file(REMOVE_RECURSE ${SRC_GEN_DIR} ${INC_GEN_DIR})
137 file(MAKE_DIRECTORY ${SRC_GEN_DIR} ${INC_GEN_DIR})
138
alexander31ae9f02022-02-10 16:15:54 +0000139 file(GLOB UC_CMAKE_FILE
140 "${SRC_USE_CASE}/${use_case}/*.cmake")
141
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100142 # Include the use case cmake file.
alexander31ae9f02022-02-10 16:15:54 +0000143 include(${UC_CMAKE_FILE})
144
alexander3c798932021-03-26 21:42:19 +0000145 file(GLOB_RECURSE UC_SRC
Isabella Gottardi85209832021-04-20 14:08:52 +0100146 "${SRC_USE_CASE}/${use_case}/src/*.cpp"
147 "${SRC_USE_CASE}/${use_case}/src/*.cc"
148 "${SRC_USE_CASE}/${use_case}/src/*.c"
149 "${SRC_USE_CASE}/${use_case}/src/**/*.cpp"
150 "${SRC_USE_CASE}/${use_case}/src/**/*.cc"
alexander31ae9f02022-02-10 16:15:54 +0000151 "${SRC_USE_CASE}/${use_case}/src/**/*.c")
alexander3c798932021-03-26 21:42:19 +0000152
153 file(GLOB_RECURSE SRC_GEN
154 "${SRC_GEN_DIR}/*.cc"
155 "${SRC_GEN_DIR}/*.cpp"
alexander31ae9f02022-02-10 16:15:54 +0000156 "${SRC_GEN_DIR}/*.c")
alexander3c798932021-03-26 21:42:19 +0000157
alexander31ae9f02022-02-10 16:15:54 +0000158 set(UC_INCLUDE ${SRC_USE_CASE}/${use_case}/include)
alexander3c798932021-03-26 21:42:19 +0000159
Kshitij Sisodiaaa5e1f62021-09-24 14:42:08 +0100160 if (DEFINED ${use_case}_COMPILE_DEFS)
161 message(STATUS "Additional compilation flags for ${use_case}: ${${use_case}_COMPILE_DEFS}")
162 set_source_files_properties(${UC_SRC}
163 PROPERTIES COMPILE_DEFINITIONS
164 "${${use_case}_COMPILE_DEFS}")
165 endif()
166
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100167 set(UC_LIB_NAME ${use_case})
alexander3c798932021-03-26 21:42:19 +0000168
169 # Consolidated application static lib:
170 add_library(${UC_LIB_NAME} STATIC
171 ${SRC_APPLICATION}
alexander3c798932021-03-26 21:42:19 +0000172 ${UC_SRC}
alexander31ae9f02022-02-10 16:15:54 +0000173 ${SRC_GEN})
174
alexander3c798932021-03-26 21:42:19 +0000175 target_include_directories(${UC_LIB_NAME} PUBLIC
176 ${APPLICATION_INCLUDE_DIRS}
alexander3c798932021-03-26 21:42:19 +0000177 ${UC_INCLUDE}
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100178 ${INC_GEN_DIR})
alexander3c798932021-03-26 21:42:19 +0000179
180 # Set the activation buffer size
181 target_compile_definitions(${UC_LIB_NAME} PUBLIC
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100182 "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}")
alexander3c798932021-03-26 21:42:19 +0000183
alexander31ae9f02022-02-10 16:15:54 +0000184 target_link_libraries(${UC_LIB_NAME} PUBLIC
185 log
186 arm_math
187 hal
Kshitij Sisodiae2da7ee2022-02-14 11:22:58 +0000188 profiler
Kshitij Sisodia9c6f9f82022-05-20 14:30:02 +0100189 tensorflow-lite-micro
190 common_api)
alexander3c798932021-03-26 21:42:19 +0000191
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100192 # If an API exists for this use case, include the projects here and add to
193 # the library list.
194 foreach(API_TO_USE ${${use_case}_API_LIST})
195
196 # If the required target doesn't yet exist, include the project here:
197 if (NOT TARGET ${API_TO_USE}_api)
198 add_subdirectory(
199 ${SRC_PATH}/application/api/use_case/${API_TO_USE} # Source path
Isabella Gottardi8ce2be82023-03-20 15:35:42 +0000200 ${CMAKE_BINARY_DIR}/api/use_case/${API_TO_USE}) # Binary path
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +0100201 endif()
202
203 # Check if the target now exists
204 if (TARGET ${API_TO_USE}_api)
205 message(STATUS "Using ${API_TO_USE}_api for ${use_case}")
206 target_link_libraries(${UC_LIB_NAME} PUBLIC ${API_TO_USE}_api)
207 else()
208 message(FATAL_ERROR "${API_TO_USE}_api target not found!")
209 endif()
210 endforeach()
211
alexander31ae9f02022-02-10 16:15:54 +0000212 add_executable(${TARGET_NAME} ${SRC_MAIN})
alexander3c798932021-03-26 21:42:19 +0000213
alexander31ae9f02022-02-10 16:15:54 +0000214 target_link_libraries(${TARGET_NAME} PUBLIC ${UC_LIB_NAME})
alexander3c798932021-03-26 21:42:19 +0000215
alexander31ae9f02022-02-10 16:15:54 +0000216 platform_custom_post_build(TARGET_NAME ${TARGET_NAME})
alexander3c798932021-03-26 21:42:19 +0000217
alexander3c798932021-03-26 21:42:19 +0000218endforeach()
219
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +0000220print_useroptions()