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