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 | # |
| 66 | # Include the platform makefile |
| 67 | # |
| 68 | include("cmake/Platforms.cmake") |
| 69 | |
| 70 | # |
Javier Almansa Sobrino | 576071e | 2022-09-09 16:01:17 +0100 | [diff] [blame] | 71 | # Include Coverage report framework |
| 72 | # |
| 73 | include("cmake/CoverageReport.cmake") |
| 74 | |
| 75 | # |
Javier Almansa Sobrino | c4ad5b0 | 2022-07-05 19:05:14 +0100 | [diff] [blame] | 76 | # Include the Unit Test Framework |
| 77 | # |
| 78 | include(UnitTestFramework) |
| 79 | |
| 80 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 81 | # Include the common configuration options |
| 82 | # |
| 83 | include("cmake/CommonConfigs.cmake") |
| 84 | |
| 85 | # |
| 86 | # Load in our C standard library and link it to any targets created after this |
| 87 | # point. This will automatically transition these targets away from the standard |
| 88 | # library provided by the toolchain, and towards our libc. |
| 89 | # |
| 90 | |
| 91 | add_subdirectory("lib/libc") |
| 92 | |
| 93 | link_libraries(rmm-lib-libc) |
| 94 | |
| 95 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 96 | # Recurse into the various component subdirectories |
| 97 | # |
| 98 | add_subdirectory("lib") |
| 99 | add_subdirectory("runtime") |
| 100 | |
| 101 | if(RMM_DOCS) |
| 102 | add_subdirectory("docs") |
| 103 | endif() |
| 104 | |
| 105 | # |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 106 | # Copy 'rmm-runtime' executable to 'build/$<CONFIG>/rmm.elf'. |
| 107 | # |
| 108 | |
| 109 | set(ARTEFACT_DIR "${CMAKE_BINARY_DIR}/$<CONFIG>") |
| 110 | add_custom_command( |
| 111 | COMMAND ${CMAKE_COMMAND} -E make_directory "${ARTEFACT_DIR}" |
| 112 | COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>" "${ARTEFACT_DIR}/rmm.elf" |
| 113 | OUTPUT rmm.elf |
| 114 | DEPENDS rmm-runtime) |
| 115 | |
| 116 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 117 | # Create the flat binary using whatever tool comes with the toolchain. |
| 118 | # |
| 119 | |
| 120 | if(CMAKE_OBJCOPY) |
| 121 | add_custom_command( |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 122 | 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] | 123 | OUTPUT rmm.img |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 124 | DEPENDS rmm.elf) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 125 | endif() |
| 126 | |
| 127 | # |
| 128 | # Create the dump file using whatever tool comes with the toolchain. |
| 129 | # |
| 130 | |
| 131 | if(CMAKE_OBJDUMP) |
| 132 | add_custom_command( |
AlexeiFedorov | df16e65 | 2023-10-26 13:19:53 +0100 | [diff] [blame] | 133 | COMMAND "${CMAKE_OBJDUMP}" -dxS "${ARTEFACT_DIR}/rmm.elf" > "${ARTEFACT_DIR}/rmm.dump" |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 134 | OUTPUT rmm.dump |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 135 | DEPENDS rmm.elf) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 136 | endif() |
| 137 | |
| 138 | # |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 139 | # Copy 'rmm-runtime.map' to 'build/$<CONFIG>/rmm.map' |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 140 | # |
| 141 | |
| 142 | add_custom_command( |
Soby Mathew | a6fd380 | 2023-01-25 14:43:08 +0000 | [diff] [blame] | 143 | 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] | 144 | OUTPUT rmm.map |
| 145 | DEPENDS rmm-runtime) |
| 146 | |
| 147 | add_custom_target(rmm ALL DEPENDS rmm.img rmm.dump rmm.elf rmm.map) |
| 148 | |
| 149 | # |
| 150 | # Set up additional tooling. |
| 151 | # |
| 152 | |
| 153 | add_subdirectory("tools") |
| 154 | |
| 155 | # |
| 156 | # Rules for checkpatch |
| 157 | # |
| 158 | |
| 159 | add_custom_target(checkcodebase |
| 160 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 161 | COMMAND ${CMAKE_COMMAND} -DCHECKCODEBASE_RUN=1 -P ${CMAKE_SOURCE_DIR}/tools/checkpatch/CheckPatch.cmake |
| 162 | ) |
| 163 | |
| 164 | add_custom_target(checkpatch |
| 165 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 166 | COMMAND ${CMAKE_COMMAND} -DCHECKPATCH_RUN=1 -P ${CMAKE_SOURCE_DIR}/tools/checkpatch/CheckPatch.cmake |
| 167 | ) |
| 168 | |
| 169 | # |
| 170 | # Rules for checking license and copyright headers |
| 171 | # |
| 172 | add_custom_target(checkspdx-codebase |
| 173 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 174 | COMMAND ${CMAKE_COMMAND} -DCHECKSPDX_CODEBASE=1 -P ${CMAKE_SOURCE_DIR}/tools/checkspdx/CheckSPDX.cmake |
| 175 | ) |
| 176 | |
| 177 | add_custom_target(checkspdx-patch |
| 178 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 179 | COMMAND ${CMAKE_COMMAND} -DCHECKSPDX_PATCH=1 -P ${CMAKE_SOURCE_DIR}/tools/checkspdx/CheckSPDX.cmake |
| 180 | ) |
| 181 | |
| 182 | # |
| 183 | # Rules for checking header files include order |
| 184 | # |
| 185 | add_custom_target(checkincludes-codebase |
| 186 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 187 | COMMAND ${CMAKE_COMMAND} -DCHECKINCLUDES_CODEBASE=1 -P ${CMAKE_SOURCE_DIR}/tools/checkincludes/CheckIncludes.cmake |
| 188 | ) |
| 189 | |
| 190 | add_custom_target(checkincludes-patch |
| 191 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 192 | COMMAND ${CMAKE_COMMAND} -DCHECKINCLUDES_PATCH=1 -P ${CMAKE_SOURCE_DIR}/tools/checkincludes/CheckIncludes.cmake |
| 193 | ) |
Chuyue Luo | 88c0719 | 2023-09-25 16:11:36 +0100 | [diff] [blame] | 194 | |
| 195 | # |
| 196 | # Rules for running clang-tidy checks |
| 197 | # |
| 198 | # Pass through the value of RMM_TOOLCHAIN as this must be verified before |
| 199 | # clang-tidy can be run. |
| 200 | # |
| 201 | # Also pass through the build directory as this cannot be accessed when the |
| 202 | # clang-tidy target is built. |
| 203 | # |
| 204 | add_custom_target(clang-tidy-codebase |
| 205 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 206 | COMMAND ${CMAKE_COMMAND} -DCLANG-TIDY_CODEBASE=1 |
| 207 | -DRMM_TOOLCHAIN=${RMM_TOOLCHAIN} |
| 208 | -DBUILD_DIR=${CMAKE_BINARY_DIR} |
| 209 | -P ${CMAKE_SOURCE_DIR}/tools/clang-tidy/clang-tidy.cmake |
| 210 | ) |
| 211 | |
| 212 | add_custom_target(clang-tidy-patch |
| 213 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 214 | COMMAND ${CMAKE_COMMAND} -DCLANG-TIDY_PATCH=1 |
| 215 | -DRMM_TOOLCHAIN=${RMM_TOOLCHAIN} |
| 216 | -DBUILD_DIR=${CMAKE_BINARY_DIR} |
| 217 | -P ${CMAKE_SOURCE_DIR}/tools/clang-tidy/clang-tidy.cmake |
| 218 | ) |
Mate Toth-Pal | 83a45bd | 2023-09-01 11:17:19 +0200 | [diff] [blame] | 219 | |