blob: bddf80162436c60ce51daab71b972d50ea70641b [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
Soby Mathewe400b532023-11-21 14:21:00 +000051project(RMM VERSION 0.4.0 LANGUAGES C CXX ASM)
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#
Soby Mathewb4c6df42022-11-09 11:13:29 +000096# Recurse into the various component subdirectories
97#
98add_subdirectory("lib")
99add_subdirectory("runtime")
100
101if(RMM_DOCS)
102 add_subdirectory("docs")
103endif()
104
105#
Soby Mathewa6fd3802023-01-25 14:43:08 +0000106# Copy 'rmm-runtime' executable to 'build/$<CONFIG>/rmm.elf'.
107#
108
109set(ARTEFACT_DIR "${CMAKE_BINARY_DIR}/$<CONFIG>")
110add_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 Mathewb4c6df42022-11-09 11:13:29 +0000117# Create the flat binary using whatever tool comes with the toolchain.
118#
119
120if(CMAKE_OBJCOPY)
121 add_custom_command(
Soby Mathewa6fd3802023-01-25 14:43:08 +0000122 COMMAND "${CMAKE_OBJCOPY}" -O binary "${ARTEFACT_DIR}/rmm.elf" "${ARTEFACT_DIR}/rmm.img"
Soby Mathewb4c6df42022-11-09 11:13:29 +0000123 OUTPUT rmm.img
Soby Mathewa6fd3802023-01-25 14:43:08 +0000124 DEPENDS rmm.elf)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000125endif()
126
127#
128# Create the dump file using whatever tool comes with the toolchain.
129#
130
131if(CMAKE_OBJDUMP)
132 add_custom_command(
AlexeiFedorovdf16e652023-10-26 13:19:53 +0100133 COMMAND "${CMAKE_OBJDUMP}" -dxS "${ARTEFACT_DIR}/rmm.elf" > "${ARTEFACT_DIR}/rmm.dump"
Soby Mathewb4c6df42022-11-09 11:13:29 +0000134 OUTPUT rmm.dump
Soby Mathewa6fd3802023-01-25 14:43:08 +0000135 DEPENDS rmm.elf)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000136endif()
137
138#
Soby Mathewa6fd3802023-01-25 14:43:08 +0000139# Copy 'rmm-runtime.map' to 'build/$<CONFIG>/rmm.map'
Soby Mathewb4c6df42022-11-09 11:13:29 +0000140#
141
142add_custom_command(
Soby Mathewa6fd3802023-01-25 14:43:08 +0000143 COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>.map" "${ARTEFACT_DIR}/rmm.map"
Soby Mathewb4c6df42022-11-09 11:13:29 +0000144 OUTPUT rmm.map
145 DEPENDS rmm-runtime)
146
147add_custom_target(rmm ALL DEPENDS rmm.img rmm.dump rmm.elf rmm.map)
148
149#
150# Set up additional tooling.
151#
152
153add_subdirectory("tools")
154
155#
156# Rules for checkpatch
157#
158
159add_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
164add_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#
172add_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
177add_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#
185add_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
190add_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 Luo88c07192023-09-25 16:11:36 +0100194
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#
204add_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
212add_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-Pal83a45bd2023-09-01 11:17:19 +0200219