alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | #---------------------------------------------------------------------------- |
Kshitij Sisodia | 774c7ca | 2024-04-12 11:30:02 +0100 | [diff] [blame] | 2 | # SPDX-FileCopyrightText: Copyright 2021-2024 Arm Limited and/or its |
| 3 | # affiliates <open-source-office@arm.com> |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 4 | # 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 Sisodia | 9c6f9f8 | 2022-05-20 14:30:02 +0100 | [diff] [blame] | 18 | cmake_minimum_required(VERSION 3.21.0) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 19 | |
| 20 | # Build in release mode by default |
| 21 | if (NOT CMAKE_BUILD_TYPE STREQUAL Debug) |
| 22 | set(CMAKE_BUILD_TYPE Release CACHE INTERNAL "") |
| 23 | endif() |
| 24 | |
| 25 | message(STATUS "Build type is set to ${CMAKE_BUILD_TYPE}") |
| 26 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 27 | # Set language standards. |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 28 | set(CMAKE_C_STANDARD 99) |
ayamas01 | 15f8070 | 2021-11-18 14:22:23 +0000 | [diff] [blame] | 29 | set(CMAKE_CXX_STANDARD 14) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 30 | |
| 31 | # Make the standard a requirement => prevent fallback to previous |
| 32 | # supported standard |
| 33 | set(CMAKE_C_STANDARD_REQUIRED ON) |
| 34 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 35 | |
| 36 | # We want to pass standard C/C++ flags, without gnu extensions |
| 37 | set(CMAKE_C_EXTENSIONS OFF) |
| 38 | set(CMAKE_CXX_EXTENSIONS OFF) |
| 39 | |
Kshitij Sisodia | 72377a4 | 2024-05-16 09:15:12 +0100 | [diff] [blame] | 40 | # Initialise global settings |
| 41 | include("${CMAKE_CURRENT_SOURCE_DIR}/MlekModule.cmake") |
Nina Drozd | 5916952 | 2022-02-10 13:33:20 +0000 | [diff] [blame] | 42 | |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 43 | project(arm_ml_embedded_evaluation_kit |
Kshitij Sisodia | 4cef9ac | 2024-04-08 09:58:46 +0100 | [diff] [blame] | 44 | VERSION 24.02.0 |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 45 | DESCRIPTION "ARM ML Embedded Evaluation Kit" |
| 46 | LANGUAGES C CXX ASM) |
Kshitij Sisodia | f9c19ea | 2021-05-07 16:08:14 +0100 | [diff] [blame] | 47 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 48 | enforce_compiler_version() |
| 49 | setup_source_generator() |
| 50 | |
| 51 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 52 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) |
| 53 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) |
| 54 | set(SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/source) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 55 | set(TEST_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tests) |
| 56 | list(APPEND USE_CASES_TESTS_SEARCH_DIR_LIST ${TEST_SRCS}/use_case) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 57 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 58 | # We include log target |
| 59 | add_subdirectory(${SRC_PATH}/log ${CMAKE_BINARY_DIR}/log) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 60 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 61 | # We include arm_math target |
| 62 | add_subdirectory(${SRC_PATH}/math ${CMAKE_BINARY_DIR}/math) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 63 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 64 | # We include the hal target |
| 65 | add_subdirectory(${SRC_PATH}/hal ${CMAKE_BINARY_DIR}/hal) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 66 | |
Kshitij Sisodia | e2da7ee | 2022-02-14 11:22:58 +0000 | [diff] [blame] | 67 | # Add the profiler target |
| 68 | if (NOT DEFINED PROFILER_DIR) |
| 69 | set(PROFILER_DIR ${SRC_PATH}/profiler) |
| 70 | endif () |
| 71 | add_subdirectory(${PROFILER_DIR} ${CMAKE_BINARY_DIR}/profiler) |
| 72 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 73 | # Include the tensorflow build target |
Kshitij Sisodia | 774c7ca | 2024-04-12 11:30:02 +0100 | [diff] [blame] | 74 | include(tensorflow_lite_micro) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 75 | |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 76 | # Add the common API library target (tensorflow-lite-micro target is needed) |
| 77 | add_subdirectory(${SRC_PATH}/application/api/common ${CMAKE_BINARY_DIR}/api/common) |
| 78 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 79 | # Include directories for application module: |
| 80 | set(APPLICATION_INCLUDE_DIRS |
Kshitij Sisodia | e2da7ee | 2022-02-14 11:22:58 +0000 | [diff] [blame] | 81 | ${SRC_PATH}/application/main/include) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 82 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 83 | # Source files for application module: |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 84 | file(GLOB_RECURSE SRC_APPLICATION |
| 85 | "${SRC_PATH}/application/main/*.cc" |
| 86 | "${SRC_PATH}/application/main/*.cpp" |
| 87 | "${SRC_PATH}/application/main/*.c" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 88 | ) |
| 89 | list(FILTER SRC_APPLICATION EXCLUDE REGEX ".*main\\.c.*$") |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 90 | set(SRC_MAIN "${SRC_PATH}/application/main/Main.cc") |
| 91 | set_source_files_properties(${SRC_MAIN} |
| 92 | PROPERTIES COMPILE_DEFINITIONS |
| 93 | "PRJ_VER_STR=\"${PROJECT_VERSION}\";PRJ_DES_STR=\"${PROJECT_DESCRIPTION}\"") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 94 | |
| 95 | list(JOIN USE_CASE_BUILD "" USE_CASE_BUILD_STR) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 96 | list(APPEND USE_CASES_SEARCH_DIR_LIST ${SRC_PATH}/use_case) |
| 97 | message(STATUS "Use-cases source paths: ${USE_CASES_SEARCH_DIR_LIST}.") |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 98 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 99 | if (${USE_CASE_BUILD_STR} STREQUAL all) |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 100 | 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() |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 104 | else() |
| 105 | set(USE_CASES ${USE_CASE_BUILD}) |
| 106 | endif() |
| 107 | |
alexander | cb8a987 | 2022-02-11 13:23:22 +0000 | [diff] [blame] | 108 | list(REMOVE_ITEM USE_CASES "" ${EXCLUDED_USE_CASES}) |
| 109 | message(STATUS "Use-cases excluded by platform configuration: ${EXCLUDED_USE_CASES}") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 110 | message(STATUS "Building use-cases: ${USE_CASES}.") |
Eanna O Cathain | 7bc6832 | 2022-05-31 14:14:32 +0100 | [diff] [blame] | 111 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 112 | foreach(use_case ${USE_CASES}) |
| 113 | |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 114 | 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}!") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 125 | endif () |
Kshitij Sisodia | 661959c | 2021-11-24 10:39:52 +0000 | [diff] [blame] | 126 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 127 | # Executable application: |
| 128 | set(TARGET_NAME "ethos-u-${use_case}") |
| 129 | |
Kshitij Sisodia | 72377a4 | 2024-05-16 09:15:12 +0100 | [diff] [blame] | 130 | set(DEFAULT_MODEL_DIR ${MLEK_RESOURCES_DIR}/${use_case}) |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 131 | set(DEFAULT_TEST_DATA_DIR ${DEFAULT_MODEL_DIR}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 132 | 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 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 139 | file(GLOB UC_CMAKE_FILE |
| 140 | "${SRC_USE_CASE}/${use_case}/*.cmake") |
| 141 | |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 142 | # Include the use case cmake file. |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 143 | include(${UC_CMAKE_FILE}) |
| 144 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 145 | file(GLOB_RECURSE UC_SRC |
Isabella Gottardi | 8520983 | 2021-04-20 14:08:52 +0100 | [diff] [blame] | 146 | "${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" |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 151 | "${SRC_USE_CASE}/${use_case}/src/**/*.c") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 152 | |
| 153 | file(GLOB_RECURSE SRC_GEN |
| 154 | "${SRC_GEN_DIR}/*.cc" |
| 155 | "${SRC_GEN_DIR}/*.cpp" |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 156 | "${SRC_GEN_DIR}/*.c") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 157 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 158 | set(UC_INCLUDE ${SRC_USE_CASE}/${use_case}/include) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 159 | |
Kshitij Sisodia | aa5e1f6 | 2021-09-24 14:42:08 +0100 | [diff] [blame] | 160 | 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 Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 167 | set(UC_LIB_NAME ${use_case}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 168 | |
| 169 | # Consolidated application static lib: |
| 170 | add_library(${UC_LIB_NAME} STATIC |
| 171 | ${SRC_APPLICATION} |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 172 | ${UC_SRC} |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 173 | ${SRC_GEN}) |
| 174 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 175 | target_include_directories(${UC_LIB_NAME} PUBLIC |
| 176 | ${APPLICATION_INCLUDE_DIRS} |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 177 | ${UC_INCLUDE} |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 178 | ${INC_GEN_DIR}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 179 | |
| 180 | # Set the activation buffer size |
| 181 | target_compile_definitions(${UC_LIB_NAME} PUBLIC |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 182 | "ACTIVATION_BUF_SZ=${${use_case}_ACTIVATION_BUF_SZ}") |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 183 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 184 | target_link_libraries(${UC_LIB_NAME} PUBLIC |
| 185 | log |
| 186 | arm_math |
| 187 | hal |
Kshitij Sisodia | e2da7ee | 2022-02-14 11:22:58 +0000 | [diff] [blame] | 188 | profiler |
Kshitij Sisodia | 9c6f9f8 | 2022-05-20 14:30:02 +0100 | [diff] [blame] | 189 | tensorflow-lite-micro |
| 190 | common_api) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 191 | |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 192 | # 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 Gottardi | 8ce2be8 | 2023-03-20 15:35:42 +0000 | [diff] [blame] | 200 | ${CMAKE_BINARY_DIR}/api/use_case/${API_TO_USE}) # Binary path |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 201 | 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 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 212 | add_executable(${TARGET_NAME} ${SRC_MAIN}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 213 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 214 | target_link_libraries(${TARGET_NAME} PUBLIC ${UC_LIB_NAME}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 215 | |
alexander | 31ae9f0 | 2022-02-10 16:15:54 +0000 | [diff] [blame] | 216 | platform_custom_post_build(TARGET_NAME ${TARGET_NAME}) |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 217 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 218 | endforeach() |
| 219 | |
Kshitij Sisodia | a1256e3 | 2022-02-23 14:40:45 +0000 | [diff] [blame] | 220 | print_useroptions() |