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 | |
Javier Almansa Sobrino | c4ad5b0 | 2022-07-05 19:05:14 +0100 | [diff] [blame^] | 51 | project(RMM VERSION 0.2.0 LANGUAGES ASM C CXX) |
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() |
| 64 | # |
| 65 | # Include the platform makefile |
| 66 | # |
| 67 | include("cmake/Platforms.cmake") |
| 68 | |
| 69 | # |
Javier Almansa Sobrino | c4ad5b0 | 2022-07-05 19:05:14 +0100 | [diff] [blame^] | 70 | # Include the Unit Test Framework |
| 71 | # |
| 72 | include(UnitTestFramework) |
| 73 | |
| 74 | # |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 75 | # Include the common configuration options |
| 76 | # |
| 77 | include("cmake/CommonConfigs.cmake") |
| 78 | |
| 79 | # |
| 80 | # Load in our C standard library and link it to any targets created after this |
| 81 | # point. This will automatically transition these targets away from the standard |
| 82 | # library provided by the toolchain, and towards our libc. |
| 83 | # |
| 84 | |
| 85 | add_subdirectory("lib/libc") |
| 86 | |
| 87 | link_libraries(rmm-lib-libc) |
| 88 | |
| 89 | # |
| 90 | # Build the MbedTLS we package in the source tree, and import the targets from |
| 91 | # it so that we can model the library dependency properly. |
| 92 | # |
| 93 | |
| 94 | include("cmake/BuildMbedTLS.cmake") |
| 95 | |
| 96 | set(MbedTLS_ROOT "${MbedTLS_INSTALL_DIR}") |
| 97 | find_package(MbedTLS COMPONENTS Crypto REQUIRED) |
| 98 | |
| 99 | target_link_libraries(MbedTLS |
| 100 | INTERFACE rmm-lib-libc) |
| 101 | |
| 102 | # |
| 103 | # Build and link QCBOR |
| 104 | # |
| 105 | include("cmake/BuildQCBOR.cmake") |
| 106 | |
| 107 | # |
| 108 | # Recurse into the various component subdirectories |
| 109 | # |
| 110 | add_subdirectory("lib") |
| 111 | add_subdirectory("runtime") |
| 112 | |
| 113 | if(RMM_DOCS) |
| 114 | add_subdirectory("docs") |
| 115 | endif() |
| 116 | |
| 117 | # |
| 118 | # Create the flat binary using whatever tool comes with the toolchain. |
| 119 | # |
| 120 | |
| 121 | if(CMAKE_OBJCOPY) |
| 122 | add_custom_command( |
| 123 | COMMAND "${CMAKE_OBJCOPY}" -O binary "$<TARGET_FILE:rmm-runtime>" rmm.img |
| 124 | OUTPUT rmm.img |
| 125 | DEPENDS rmm-runtime) |
| 126 | endif() |
| 127 | |
| 128 | # |
| 129 | # Create the dump file using whatever tool comes with the toolchain. |
| 130 | # |
| 131 | |
| 132 | if(CMAKE_OBJDUMP) |
| 133 | add_custom_command( |
| 134 | COMMAND "${CMAKE_OBJDUMP}" -dx "$<TARGET_FILE:rmm-runtime>" > rmm.dump |
| 135 | OUTPUT rmm.dump |
| 136 | DEPENDS rmm-runtime) |
| 137 | endif() |
| 138 | |
| 139 | # |
| 140 | # Copy 'rmm-runtime' executable to 'build\rmm.elf'. |
| 141 | # |
| 142 | |
| 143 | add_custom_command( |
| 144 | COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>" rmm.elf |
| 145 | OUTPUT rmm.elf |
| 146 | DEPENDS rmm-runtime) |
| 147 | |
| 148 | # |
| 149 | # Copy 'rmm-runtime.map' to 'build\rmm.map' |
| 150 | # |
| 151 | |
| 152 | add_custom_command( |
| 153 | COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>.map" rmm.map |
| 154 | OUTPUT rmm.map |
| 155 | DEPENDS rmm-runtime) |
| 156 | |
| 157 | add_custom_target(rmm ALL DEPENDS rmm.img rmm.dump rmm.elf rmm.map) |
| 158 | |
| 159 | # |
| 160 | # Set up additional tooling. |
| 161 | # |
| 162 | |
| 163 | add_subdirectory("tools") |
| 164 | |
| 165 | # |
| 166 | # Rules for checkpatch |
| 167 | # |
| 168 | |
| 169 | add_custom_target(checkcodebase |
| 170 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 171 | COMMAND ${CMAKE_COMMAND} -DCHECKCODEBASE_RUN=1 -P ${CMAKE_SOURCE_DIR}/tools/checkpatch/CheckPatch.cmake |
| 172 | ) |
| 173 | |
| 174 | add_custom_target(checkpatch |
| 175 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 176 | COMMAND ${CMAKE_COMMAND} -DCHECKPATCH_RUN=1 -P ${CMAKE_SOURCE_DIR}/tools/checkpatch/CheckPatch.cmake |
| 177 | ) |
| 178 | |
| 179 | # |
| 180 | # Rules for checking license and copyright headers |
| 181 | # |
| 182 | add_custom_target(checkspdx-codebase |
| 183 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 184 | COMMAND ${CMAKE_COMMAND} -DCHECKSPDX_CODEBASE=1 -P ${CMAKE_SOURCE_DIR}/tools/checkspdx/CheckSPDX.cmake |
| 185 | ) |
| 186 | |
| 187 | add_custom_target(checkspdx-patch |
| 188 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 189 | COMMAND ${CMAKE_COMMAND} -DCHECKSPDX_PATCH=1 -P ${CMAKE_SOURCE_DIR}/tools/checkspdx/CheckSPDX.cmake |
| 190 | ) |
| 191 | |
| 192 | # |
| 193 | # Rules for checking header files include order |
| 194 | # |
| 195 | add_custom_target(checkincludes-codebase |
| 196 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 197 | COMMAND ${CMAKE_COMMAND} -DCHECKINCLUDES_CODEBASE=1 -P ${CMAKE_SOURCE_DIR}/tools/checkincludes/CheckIncludes.cmake |
| 198 | ) |
| 199 | |
| 200 | add_custom_target(checkincludes-patch |
| 201 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" |
| 202 | COMMAND ${CMAKE_COMMAND} -DCHECKINCLUDES_PATCH=1 -P ${CMAKE_SOURCE_DIR}/tools/checkincludes/CheckIncludes.cmake |
| 203 | ) |