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