Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: BSD-3-Clause |
| 3 | # SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | # |
| 5 | |
Soby Mathew | d2024c0 | 2025-05-21 13:14:33 +0100 | [diff] [blame] | 6 | cmake_minimum_required(VERSION 3.20.0) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 7 | |
| 8 | # allow target_link_libraries() to be used with targets in other directories |
| 9 | cmake_policy(SET CMP0079 NEW) |
| 10 | |
| 11 | # |
| 12 | # Add our module search paths so we can `include()` our CMake modules. |
| 13 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 14 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules") |
Soby Mathew | b5a2975 | 2024-11-14 14:26:11 +0000 | [diff] [blame] | 15 | include(GitUtils) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 16 | |
| 17 | # |
| 18 | # Include any dependencies. |
| 19 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 20 | include(ArmConfigOption) |
| 21 | include(ArmConfigOptionOverride) |
| 22 | |
| 23 | # |
Soby Mathew | b5a2975 | 2024-11-14 14:26:11 +0000 | [diff] [blame] | 24 | # Update the Submodules |
| 25 | # |
| 26 | Git_Update_Submodule() |
| 27 | |
| 28 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 29 | # Run preliminary setup scripts. |
| 30 | # |
| 31 | set(RMM_CONFIG_FILE "${CMAKE_SOURCE_DIR}/configs/${RMM_CONFIG}.cmake") |
| 32 | if(NOT EXISTS ${RMM_CONFIG_FILE}) |
| 33 | message(FATAL_ERROR "Please provide config ${RMM_CONFIG_FILE}") |
| 34 | endif() |
| 35 | |
| 36 | include("${RMM_CONFIG_FILE}") |
| 37 | |
| 38 | # |
| 39 | # Set the target build Architecture before we proceed further. |
| 40 | # Default is aarch64. |
| 41 | # |
| 42 | arm_config_option( |
| 43 | NAME RMM_ARCH |
| 44 | HELP "Target Architecture for RMM build." |
| 45 | STRINGS "aarch64" "fake_host") |
| 46 | |
| 47 | include("cmake/Toolchains.cmake") |
| 48 | include("cmake/BuildType.cmake") |
| 49 | |
| 50 | # |
| 51 | # Initialize the project. Note that this is where the toolchain file is loaded, |
| 52 | # and also where the project directory and version variables are set up. |
| 53 | # |
| 54 | |
Soby Mathew | 399e62e | 2025-05-21 17:19:54 +0100 | [diff] [blame] | 55 | project(RMM VERSION 0.7.0 LANGUAGES C CXX ASM) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 56 | |
| 57 | # |
| 58 | # Set global flags. |
| 59 | # |
| 60 | |
| 61 | set(CMAKE_C_STANDARD 11) |
| 62 | set(CMAKE_C_STANDARD_REQUIRED TRUE) |
Soby Mathew | e558fa3 | 2024-12-31 11:59:11 +0000 | [diff] [blame] | 63 | set(CMAKE_CXX_STANDARD 11) |
| 64 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 65 | set(CMAKE_C_EXTENSIONS TRUE) |
| 66 | |
| 67 | if(RMM_STATIC_ANALYSIS_CPPCHECK) |
| 68 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 69 | endif() |
Javier Almansa Sobrino | 576071e | 2022-09-09 16:01:17 +0100 | [diff] [blame] | 70 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 71 | # |
AlexeiFedorov | 0f300ac | 2024-03-05 15:55:06 +0000 | [diff] [blame] | 72 | # Set march compiler option |
| 73 | # |
| 74 | detect_and_set_march() |
| 75 | |
| 76 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 77 | # Include the platform makefile |
| 78 | # |
| 79 | include("cmake/Platforms.cmake") |
| 80 | |
| 81 | # |
Javier Almansa Sobrino | 576071e | 2022-09-09 16:01:17 +0100 | [diff] [blame] | 82 | # Include Coverage report framework |
| 83 | # |
| 84 | include("cmake/CoverageReport.cmake") |
| 85 | |
| 86 | # |
Javier Almansa Sobrino | c4ad5b0 | 2022-07-05 19:05:14 +0100 | [diff] [blame] | 87 | # Include the Unit Test Framework |
| 88 | # |
| 89 | include(UnitTestFramework) |
| 90 | |
| 91 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 92 | # Include the common configuration options |
| 93 | # |
| 94 | include("cmake/CommonConfigs.cmake") |
| 95 | |
| 96 | # |
| 97 | # Load in our C standard library and link it to any targets created after this |
| 98 | # point. This will automatically transition these targets away from the standard |
| 99 | # library provided by the toolchain, and towards our libc. |
| 100 | # |
| 101 | |
| 102 | add_subdirectory("lib/libc") |
| 103 | |
| 104 | link_libraries(rmm-lib-libc) |
| 105 | |
| 106 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 107 | # Recurse into the various component subdirectories |
| 108 | # |
| 109 | add_subdirectory("lib") |
Mate Toth-Pal | bbb816d | 2024-08-01 10:41:35 +0200 | [diff] [blame] | 110 | add_subdirectory("app") |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 111 | add_subdirectory("runtime") |
| 112 | |
| 113 | if(RMM_DOCS) |
| 114 | add_subdirectory("docs") |
| 115 | endif() |
| 116 | |
| 117 | # |
Mate Toth-Pal | bbb816d | 2024-08-01 10:41:35 +0200 | [diff] [blame] | 118 | # Copy 'rmm-runtime' executable to 'build/$<CONFIG>/rmm_core.elf'. |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 119 | # |
| 120 | |
| 121 | set(ARTEFACT_DIR "${CMAKE_BINARY_DIR}/$<CONFIG>") |
| 122 | add_custom_command( |
| 123 | COMMAND ${CMAKE_COMMAND} -E make_directory "${ARTEFACT_DIR}" |
Mate Toth-Pal | bbb816d | 2024-08-01 10:41:35 +0200 | [diff] [blame] | 124 | COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>" "${ARTEFACT_DIR}/rmm_core.elf" |
| 125 | OUTPUT rmm_core.elf |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 126 | DEPENDS rmm-runtime) |
| 127 | |
| 128 | # |
Mate Toth-Pal | bbb816d | 2024-08-01 10:41:35 +0200 | [diff] [blame] | 129 | # Create rmm.elf as a copy of rmm_core.elf to keep CI working |
| 130 | # |
| 131 | add_custom_command( |
| 132 | COMMAND "${CMAKE_COMMAND}" -E copy ${ARTEFACT_DIR}/rmm_core.elf ${ARTEFACT_DIR}/rmm.elf |
| 133 | OUTPUT rmm.elf |
| 134 | DEPENDS rmm_core.elf) |
| 135 | |
| 136 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 137 | # Create the flat binary using whatever tool comes with the toolchain. |
| 138 | # |
| 139 | |
| 140 | if(CMAKE_OBJCOPY) |
| 141 | add_custom_command( |
Mate Toth-Pal | bbb816d | 2024-08-01 10:41:35 +0200 | [diff] [blame] | 142 | COMMAND "${CMAKE_OBJCOPY}" -O binary "${ARTEFACT_DIR}/rmm_core.elf" "${ARTEFACT_DIR}/rmm_core.img" |
| 143 | OUTPUT rmm_core.img |
| 144 | DEPENDS rmm_core.elf) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 145 | endif() |
| 146 | |
| 147 | # |
| 148 | # Create the dump file using whatever tool comes with the toolchain. |
| 149 | # |
| 150 | |
| 151 | if(CMAKE_OBJDUMP) |
| 152 | add_custom_command( |
Mate Toth-Pal | bbb816d | 2024-08-01 10:41:35 +0200 | [diff] [blame] | 153 | COMMAND "${CMAKE_OBJDUMP}" -dxS "${ARTEFACT_DIR}/rmm_core.elf" > "${ARTEFACT_DIR}/rmm_core.dump" |
| 154 | OUTPUT rmm_core.dump |
| 155 | DEPENDS rmm_core.elf) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 156 | endif() |
| 157 | |
| 158 | # |
Mate Toth-Pal | bbb816d | 2024-08-01 10:41:35 +0200 | [diff] [blame] | 159 | # Copy 'rmm-runtime.map' to 'build/$<CONFIG>/rmm_core.map' |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 160 | # |
| 161 | |
| 162 | add_custom_command( |
Mate Toth-Pal | bbb816d | 2024-08-01 10:41:35 +0200 | [diff] [blame] | 163 | COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>.map" "${ARTEFACT_DIR}/rmm_core.map" |
| 164 | OUTPUT rmm_core.map |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 165 | DEPENDS rmm-runtime) |
| 166 | |
Mate Toth-Pal | bbb816d | 2024-08-01 10:41:35 +0200 | [diff] [blame] | 167 | if(NOT RMM_ARCH STREQUAL fake_host) |
| 168 | set(RMM_IMG "rmm.img") |
| 169 | find_program(BUNDLE_APP_RMM "bundle_app_rmm.py" |
| 170 | PATHS ${CMAKE_SOURCE_DIR} |
| 171 | PATH_SUFFIXES app |
| 172 | DOC "bundle_app_rmm.py") |
| 173 | |
| 174 | set(BUNDLE_COMMAND_OUTPUT "${ARTEFACT_DIR}/bundle_app_out.txt") |
| 175 | add_custom_command( |
Jacob Man Chun Yiu | 2e8d19e | 2025-04-09 13:58:59 +0100 | [diff] [blame] | 176 | COMMAND "${BUNDLE_APP_RMM}" --out-bin ${ARTEFACT_DIR}/${RMM_IMG} --rmm-bin ${ARTEFACT_DIR}/rmm_core.img --log-file-name ${BUNDLE_COMMAND_OUTPUT} ${EL0_APP_BIN_LIST} |
Mate Toth-Pal | bbb816d | 2024-08-01 10:41:35 +0200 | [diff] [blame] | 177 | OUTPUT ${RMM_IMG} |
Soby Mathew | 4ec65bc | 2025-04-24 07:54:04 +0100 | [diff] [blame] | 178 | DEPENDS rmm_core.img rmm-random-app rmm-attestation-app rmm-dev-assign-app) |
Mate Toth-Pal | bbb816d | 2024-08-01 10:41:35 +0200 | [diff] [blame] | 179 | endif() |
| 180 | |
Soby Mathew | 22a667e | 2025-05-06 18:36:27 +0100 | [diff] [blame] | 181 | add_custom_target(rmm ALL DEPENDS rmm_core.img rmm_core.dump rmm_core.elf rmm.elf rmm_core.map ${RMM_IMG} rmm-attestation-app rmm-random-app) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 182 | |
| 183 | # |
| 184 | # Set up additional tooling. |
| 185 | # |
| 186 | |
| 187 | add_subdirectory("tools") |