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 | # |
| 14 | |
| 15 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules") |
| 16 | |
| 17 | # |
| 18 | # Include any dependencies. |
| 19 | # |
| 20 | |
| 21 | include(ArmConfigOption) |
| 22 | include(ArmConfigOptionOverride) |
| 23 | |
| 24 | # |
| 25 | # Run preliminary setup scripts. |
| 26 | # |
| 27 | set(RMM_CONFIG_FILE "${CMAKE_SOURCE_DIR}/configs/${RMM_CONFIG}.cmake") |
| 28 | if(NOT EXISTS ${RMM_CONFIG_FILE}) |
| 29 | message(FATAL_ERROR "Please provide config ${RMM_CONFIG_FILE}") |
| 30 | endif() |
| 31 | |
| 32 | include("${RMM_CONFIG_FILE}") |
| 33 | |
| 34 | # |
| 35 | # Set the target build Architecture before we proceed further. |
| 36 | # Default is aarch64. |
| 37 | # |
| 38 | arm_config_option( |
| 39 | NAME RMM_ARCH |
| 40 | HELP "Target Architecture for RMM build." |
| 41 | STRINGS "aarch64" "fake_host") |
| 42 | |
| 43 | include("cmake/Toolchains.cmake") |
| 44 | include("cmake/BuildType.cmake") |
| 45 | |
| 46 | # |
| 47 | # Initialize the project. Note that this is where the toolchain file is loaded, |
| 48 | # and also where the project directory and version variables are set up. |
| 49 | # |
| 50 | |
Soby Mathew | e400b53 | 2023-11-21 14:21:00 +0000 | [diff] [blame] | 51 | project(RMM VERSION 0.4.0 LANGUAGES C CXX ASM) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 52 | |
| 53 | # |
| 54 | # Set global flags. |
| 55 | # |
| 56 | |
| 57 | set(CMAKE_C_STANDARD 11) |
| 58 | set(CMAKE_C_STANDARD_REQUIRED TRUE) |
| 59 | set(CMAKE_C_EXTENSIONS TRUE) |
| 60 | |
| 61 | if(RMM_STATIC_ANALYSIS_CPPCHECK) |
| 62 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 63 | endif() |
Javier Almansa Sobrino | 576071e | 2022-09-09 16:01:17 +0100 | [diff] [blame] | 64 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 65 | # |
AlexeiFedorov | 0f300ac | 2024-03-05 15:55:06 +0000 | [diff] [blame^] | 66 | # Set march compiler option |
| 67 | # |
| 68 | detect_and_set_march() |
| 69 | |
| 70 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 71 | # Include the platform makefile |
| 72 | # |
| 73 | include("cmake/Platforms.cmake") |
| 74 | |
| 75 | # |
Javier Almansa Sobrino | 576071e | 2022-09-09 16:01:17 +0100 | [diff] [blame] | 76 | # Include Coverage report framework |
| 77 | # |
| 78 | include("cmake/CoverageReport.cmake") |
| 79 | |
| 80 | # |
Javier Almansa Sobrino | c4ad5b0 | 2022-07-05 19:05:14 +0100 | [diff] [blame] | 81 | # Include the Unit Test Framework |
| 82 | # |
| 83 | include(UnitTestFramework) |
| 84 | |
| 85 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 86 | # Include the common configuration options |
| 87 | # |
| 88 | include("cmake/CommonConfigs.cmake") |
| 89 | |
| 90 | # |
| 91 | # Load in our C standard library and link it to any targets created after this |
| 92 | # point. This will automatically transition these targets away from the standard |
| 93 | # library provided by the toolchain, and towards our libc. |
| 94 | # |
| 95 | |
| 96 | add_subdirectory("lib/libc") |
| 97 | |
| 98 | link_libraries(rmm-lib-libc) |
| 99 | |
| 100 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 101 | # Recurse into the various component subdirectories |
| 102 | # |
| 103 | add_subdirectory("lib") |
| 104 | add_subdirectory("runtime") |
| 105 | |
| 106 | if(RMM_DOCS) |
| 107 | add_subdirectory("docs") |
| 108 | endif() |
| 109 | |
| 110 | # |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 111 | # Copy 'rmm-runtime' executable to 'build/$<CONFIG>/rmm.elf'. |
| 112 | # |
| 113 | |
| 114 | set(ARTEFACT_DIR "${CMAKE_BINARY_DIR}/$<CONFIG>") |
| 115 | add_custom_command( |
| 116 | COMMAND ${CMAKE_COMMAND} -E make_directory "${ARTEFACT_DIR}" |
| 117 | COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>" "${ARTEFACT_DIR}/rmm.elf" |
| 118 | OUTPUT rmm.elf |
| 119 | DEPENDS rmm-runtime) |
| 120 | |
| 121 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 122 | # Create the flat binary using whatever tool comes with the toolchain. |
| 123 | # |
| 124 | |
| 125 | if(CMAKE_OBJCOPY) |
| 126 | add_custom_command( |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 127 | 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] | 128 | OUTPUT rmm.img |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 129 | DEPENDS rmm.elf) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 130 | endif() |
| 131 | |
| 132 | # |
| 133 | # Create the dump file using whatever tool comes with the toolchain. |
| 134 | # |
| 135 | |
| 136 | if(CMAKE_OBJDUMP) |
| 137 | add_custom_command( |
AlexeiFedorov | df16e65 | 2023-10-26 13:19:53 +0100 | [diff] [blame] | 138 | COMMAND "${CMAKE_OBJDUMP}" -dxS "${ARTEFACT_DIR}/rmm.elf" > "${ARTEFACT_DIR}/rmm.dump" |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 139 | OUTPUT rmm.dump |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 140 | DEPENDS rmm.elf) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 141 | endif() |
| 142 | |
| 143 | # |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 144 | # Copy 'rmm-runtime.map' to 'build/$<CONFIG>/rmm.map' |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 145 | # |
| 146 | |
| 147 | add_custom_command( |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 148 | 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] | 149 | OUTPUT rmm.map |
| 150 | DEPENDS rmm-runtime) |
| 151 | |
| 152 | add_custom_target(rmm ALL DEPENDS rmm.img rmm.dump rmm.elf rmm.map) |
| 153 | |
| 154 | # |
| 155 | # Set up additional tooling. |
| 156 | # |
| 157 | |
| 158 | add_subdirectory("tools") |