blob: a793590448bdc58895fda7938148f72b58ce1425 [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()
64#
65# Include the platform makefile
66#
67include("cmake/Platforms.cmake")
68
69#
Javier Almansa Sobrinoc4ad5b02022-07-05 19:05:14 +010070# Include the Unit Test Framework
71#
72include(UnitTestFramework)
73
74#
Soby Mathewb4c6df42022-11-09 11:13:29 +000075# Include the common configuration options
76#
77include("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
85add_subdirectory("lib/libc")
86
87link_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
94include("cmake/BuildMbedTLS.cmake")
95
96set(MbedTLS_ROOT "${MbedTLS_INSTALL_DIR}")
97find_package(MbedTLS COMPONENTS Crypto REQUIRED)
98
99target_link_libraries(MbedTLS
100 INTERFACE rmm-lib-libc)
101
102#
103# Build and link QCBOR
104#
105include("cmake/BuildQCBOR.cmake")
106
107#
108# Recurse into the various component subdirectories
109#
110add_subdirectory("lib")
111add_subdirectory("runtime")
112
113if(RMM_DOCS)
114 add_subdirectory("docs")
115endif()
116
117#
118# Create the flat binary using whatever tool comes with the toolchain.
119#
120
121if(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)
126endif()
127
128#
129# Create the dump file using whatever tool comes with the toolchain.
130#
131
132if(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)
137endif()
138
139#
140# Copy 'rmm-runtime' executable to 'build\rmm.elf'.
141#
142
143add_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
152add_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
157add_custom_target(rmm ALL DEPENDS rmm.img rmm.dump rmm.elf rmm.map)
158
159#
160# Set up additional tooling.
161#
162
163add_subdirectory("tools")
164
165#
166# Rules for checkpatch
167#
168
169add_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
174add_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#
182add_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
187add_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#
195add_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
200add_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 )