1# 2# SPDX-License-Identifier: BSD-3-Clause 3# SPDX-FileCopyrightText: Copyright TF-RMM Contributors. 4# 5 6cmake_minimum_required(VERSION 3.15.0) 7 8# allow target_link_libraries() to be used with targets in other directories 9cmake_policy(SET CMP0079 NEW) 10 11# 12# Add our module search paths so we can `include()` our CMake modules. 13# 14 15list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules") 16 17# 18# Include any dependencies. 19# 20 21include(ArmConfigOption) 22include(ArmConfigOptionOverride) 23 24# 25# Run preliminary setup scripts. 26# 27set(RMM_CONFIG_FILE "${CMAKE_SOURCE_DIR}/configs/${RMM_CONFIG}.cmake") 28if(NOT EXISTS ${RMM_CONFIG_FILE}) 29 message(FATAL_ERROR "Please provide config ${RMM_CONFIG_FILE}") 30endif() 31 32include("${RMM_CONFIG_FILE}") 33 34# 35# Set the target build Architecture before we proceed further. 36# Default is aarch64. 37# 38arm_config_option( 39 NAME RMM_ARCH 40 HELP "Target Architecture for RMM build." 41 STRINGS "aarch64" "fake_host") 42 43include("cmake/Toolchains.cmake") 44include("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 51project(RMM VERSION 0.2.0 LANGUAGES ASM C) 52 53# 54# Set global flags. 55# 56 57set(CMAKE_C_STANDARD 11) 58set(CMAKE_C_STANDARD_REQUIRED TRUE) 59set(CMAKE_C_EXTENSIONS TRUE) 60 61if(RMM_STATIC_ANALYSIS_CPPCHECK) 62 set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 63endif() 64# 65# Include the platform makefile 66# 67include("cmake/Platforms.cmake") 68 69# 70# Include the common configuration options 71# 72include("cmake/CommonConfigs.cmake") 73 74# 75# Load in our C standard library and link it to any targets created after this 76# point. This will automatically transition these targets away from the standard 77# library provided by the toolchain, and towards our libc. 78# 79 80add_subdirectory("lib/libc") 81 82link_libraries(rmm-lib-libc) 83 84# 85# Build the MbedTLS we package in the source tree, and import the targets from 86# it so that we can model the library dependency properly. 87# 88 89include("cmake/BuildMbedTLS.cmake") 90 91set(MbedTLS_ROOT "${MbedTLS_INSTALL_DIR}") 92find_package(MbedTLS COMPONENTS Crypto REQUIRED) 93 94target_link_libraries(MbedTLS 95 INTERFACE rmm-lib-libc) 96 97# 98# Build and link QCBOR 99# 100include("cmake/BuildQCBOR.cmake") 101 102# 103# Recurse into the various component subdirectories 104# 105add_subdirectory("lib") 106add_subdirectory("runtime") 107 108if(RMM_DOCS) 109 add_subdirectory("docs") 110endif() 111 112# 113# Create the flat binary using whatever tool comes with the toolchain. 114# 115 116if(CMAKE_OBJCOPY) 117 add_custom_command( 118 COMMAND "${CMAKE_OBJCOPY}" -O binary "$<TARGET_FILE:rmm-runtime>" rmm.img 119 OUTPUT rmm.img 120 DEPENDS rmm-runtime) 121endif() 122 123# 124# Create the dump file using whatever tool comes with the toolchain. 125# 126 127if(CMAKE_OBJDUMP) 128 add_custom_command( 129 COMMAND "${CMAKE_OBJDUMP}" -dx "$<TARGET_FILE:rmm-runtime>" > rmm.dump 130 OUTPUT rmm.dump 131 DEPENDS rmm-runtime) 132endif() 133 134# 135# Copy 'rmm-runtime' executable to 'build\rmm.elf'. 136# 137 138add_custom_command( 139 COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>" rmm.elf 140 OUTPUT rmm.elf 141 DEPENDS rmm-runtime) 142 143# 144# Copy 'rmm-runtime.map' to 'build\rmm.map' 145# 146 147add_custom_command( 148 COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>.map" rmm.map 149 OUTPUT rmm.map 150 DEPENDS rmm-runtime) 151 152add_custom_target(rmm ALL DEPENDS rmm.img rmm.dump rmm.elf rmm.map) 153 154# 155# Set up additional tooling. 156# 157 158add_subdirectory("tools") 159 160# 161# Rules for checkpatch 162# 163 164add_custom_target(checkcodebase 165 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 166 COMMAND ${CMAKE_COMMAND} -DCHECKCODEBASE_RUN=1 -P ${CMAKE_SOURCE_DIR}/tools/checkpatch/CheckPatch.cmake 167 ) 168 169add_custom_target(checkpatch 170 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 171 COMMAND ${CMAKE_COMMAND} -DCHECKPATCH_RUN=1 -P ${CMAKE_SOURCE_DIR}/tools/checkpatch/CheckPatch.cmake 172 ) 173 174# 175# Rules for checking license and copyright headers 176# 177add_custom_target(checkspdx-codebase 178 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 179 COMMAND ${CMAKE_COMMAND} -DCHECKSPDX_CODEBASE=1 -P ${CMAKE_SOURCE_DIR}/tools/checkspdx/CheckSPDX.cmake 180 ) 181 182add_custom_target(checkspdx-patch 183 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 184 COMMAND ${CMAKE_COMMAND} -DCHECKSPDX_PATCH=1 -P ${CMAKE_SOURCE_DIR}/tools/checkspdx/CheckSPDX.cmake 185 ) 186 187# 188# Rules for checking header files include order 189# 190add_custom_target(checkincludes-codebase 191 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 192 COMMAND ${CMAKE_COMMAND} -DCHECKINCLUDES_CODEBASE=1 -P ${CMAKE_SOURCE_DIR}/tools/checkincludes/CheckIncludes.cmake 193 ) 194 195add_custom_target(checkincludes-patch 196 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 197 COMMAND ${CMAKE_COMMAND} -DCHECKINCLUDES_PATCH=1 -P ${CMAKE_SOURCE_DIR}/tools/checkincludes/CheckIncludes.cmake 198 ) 199