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 | |
| 6 | cmake_minimum_required(VERSION 3.15.0) |
| 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 | ef1aa48 | 2024-11-18 16:44:11 +0000 | [diff] [blame] | 55 | project(RMM VERSION 0.6.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) |
| 63 | set(CMAKE_C_EXTENSIONS TRUE) |
| 64 | |
| 65 | if(RMM_STATIC_ANALYSIS_CPPCHECK) |
| 66 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 67 | endif() |
Javier Almansa Sobrino | 576071e | 2022-09-09 16:01:17 +0100 | [diff] [blame] | 68 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 69 | # |
AlexeiFedorov | 0f300ac | 2024-03-05 15:55:06 +0000 | [diff] [blame] | 70 | # Set march compiler option |
| 71 | # |
| 72 | detect_and_set_march() |
| 73 | |
| 74 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 75 | # Include the platform makefile |
| 76 | # |
| 77 | include("cmake/Platforms.cmake") |
| 78 | |
| 79 | # |
Javier Almansa Sobrino | 576071e | 2022-09-09 16:01:17 +0100 | [diff] [blame] | 80 | # Include Coverage report framework |
| 81 | # |
| 82 | include("cmake/CoverageReport.cmake") |
| 83 | |
| 84 | # |
Javier Almansa Sobrino | c4ad5b0 | 2022-07-05 19:05:14 +0100 | [diff] [blame] | 85 | # Include the Unit Test Framework |
| 86 | # |
| 87 | include(UnitTestFramework) |
| 88 | |
| 89 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 90 | # Include the common configuration options |
| 91 | # |
| 92 | include("cmake/CommonConfigs.cmake") |
| 93 | |
| 94 | # |
| 95 | # Load in our C standard library and link it to any targets created after this |
| 96 | # point. This will automatically transition these targets away from the standard |
| 97 | # library provided by the toolchain, and towards our libc. |
| 98 | # |
| 99 | |
| 100 | add_subdirectory("lib/libc") |
| 101 | |
| 102 | link_libraries(rmm-lib-libc) |
| 103 | |
| 104 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 105 | # Recurse into the various component subdirectories |
| 106 | # |
| 107 | add_subdirectory("lib") |
| 108 | add_subdirectory("runtime") |
| 109 | |
| 110 | if(RMM_DOCS) |
| 111 | add_subdirectory("docs") |
| 112 | endif() |
| 113 | |
| 114 | # |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 115 | # Copy 'rmm-runtime' executable to 'build/$<CONFIG>/rmm.elf'. |
| 116 | # |
| 117 | |
| 118 | set(ARTEFACT_DIR "${CMAKE_BINARY_DIR}/$<CONFIG>") |
| 119 | add_custom_command( |
| 120 | COMMAND ${CMAKE_COMMAND} -E make_directory "${ARTEFACT_DIR}" |
| 121 | COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>" "${ARTEFACT_DIR}/rmm.elf" |
| 122 | OUTPUT rmm.elf |
| 123 | DEPENDS rmm-runtime) |
| 124 | |
| 125 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 126 | # Create the flat binary using whatever tool comes with the toolchain. |
| 127 | # |
| 128 | |
| 129 | if(CMAKE_OBJCOPY) |
| 130 | add_custom_command( |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 131 | COMMAND "${CMAKE_OBJCOPY}" -O binary "${ARTEFACT_DIR}/rmm.elf" "${ARTEFACT_DIR}/rmm.img" |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 132 | OUTPUT rmm.img |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 133 | DEPENDS rmm.elf) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 134 | endif() |
| 135 | |
| 136 | # |
| 137 | # Create the dump file using whatever tool comes with the toolchain. |
| 138 | # |
| 139 | |
| 140 | if(CMAKE_OBJDUMP) |
| 141 | add_custom_command( |
AlexeiFedorov | df16e65 | 2023-10-26 13:19:53 +0100 | [diff] [blame] | 142 | COMMAND "${CMAKE_OBJDUMP}" -dxS "${ARTEFACT_DIR}/rmm.elf" > "${ARTEFACT_DIR}/rmm.dump" |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 143 | OUTPUT rmm.dump |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 144 | DEPENDS rmm.elf) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 145 | endif() |
| 146 | |
| 147 | # |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 148 | # Copy 'rmm-runtime.map' to 'build/$<CONFIG>/rmm.map' |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 149 | # |
| 150 | |
| 151 | add_custom_command( |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 152 | COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>.map" "${ARTEFACT_DIR}/rmm.map" |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 153 | OUTPUT rmm.map |
| 154 | DEPENDS rmm-runtime) |
| 155 | |
| 156 | add_custom_target(rmm ALL DEPENDS rmm.img rmm.dump rmm.elf rmm.map) |
| 157 | |
| 158 | # |
| 159 | # Set up additional tooling. |
| 160 | # |
| 161 | |
| 162 | add_subdirectory("tools") |