blob: 46458f174fdd09dcb4c9e11bcfa2f19ddb466964 [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#
AlexeiFedorov0f300ac2024-03-05 15:55:06 +000066# Set march compiler option
67#
68detect_and_set_march()
69
70#
Soby Mathewb4c6df42022-11-09 11:13:29 +000071# Include the platform makefile
72#
73include("cmake/Platforms.cmake")
74
75#
Javier Almansa Sobrino576071e2022-09-09 16:01:17 +010076# Include Coverage report framework
77#
78include("cmake/CoverageReport.cmake")
79
80#
Javier Almansa Sobrinoc4ad5b02022-07-05 19:05:14 +010081# Include the Unit Test Framework
82#
83include(UnitTestFramework)
84
85#
Soby Mathewb4c6df42022-11-09 11:13:29 +000086# Include the common configuration options
87#
88include("cmake/CommonConfigs.cmake")
89
90#
91# Load in our C standard library and link it to any targets created after this
92# point. This will automatically transition these targets away from the standard
93# library provided by the toolchain, and towards our libc.
94#
95
96add_subdirectory("lib/libc")
97
98link_libraries(rmm-lib-libc)
99
100#
Soby Mathewb4c6df42022-11-09 11:13:29 +0000101# Recurse into the various component subdirectories
102#
103add_subdirectory("lib")
104add_subdirectory("runtime")
105
106if(RMM_DOCS)
107 add_subdirectory("docs")
108endif()
109
110#
Soby Mathewa6fd3802023-01-25 14:43:08 +0000111# Copy 'rmm-runtime' executable to 'build/$<CONFIG>/rmm.elf'.
112#
113
114set(ARTEFACT_DIR "${CMAKE_BINARY_DIR}/$<CONFIG>")
115add_custom_command(
116 COMMAND ${CMAKE_COMMAND} -E make_directory "${ARTEFACT_DIR}"
117 COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>" "${ARTEFACT_DIR}/rmm.elf"
118 OUTPUT rmm.elf
119 DEPENDS rmm-runtime)
120
121#
Soby Mathewb4c6df42022-11-09 11:13:29 +0000122# Create the flat binary using whatever tool comes with the toolchain.
123#
124
125if(CMAKE_OBJCOPY)
126 add_custom_command(
Soby Mathewa6fd3802023-01-25 14:43:08 +0000127 COMMAND "${CMAKE_OBJCOPY}" -O binary "${ARTEFACT_DIR}/rmm.elf" "${ARTEFACT_DIR}/rmm.img"
Soby Mathewb4c6df42022-11-09 11:13:29 +0000128 OUTPUT rmm.img
Soby Mathewa6fd3802023-01-25 14:43:08 +0000129 DEPENDS rmm.elf)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000130endif()
131
132#
133# Create the dump file using whatever tool comes with the toolchain.
134#
135
136if(CMAKE_OBJDUMP)
137 add_custom_command(
AlexeiFedorovdf16e652023-10-26 13:19:53 +0100138 COMMAND "${CMAKE_OBJDUMP}" -dxS "${ARTEFACT_DIR}/rmm.elf" > "${ARTEFACT_DIR}/rmm.dump"
Soby Mathewb4c6df42022-11-09 11:13:29 +0000139 OUTPUT rmm.dump
Soby Mathewa6fd3802023-01-25 14:43:08 +0000140 DEPENDS rmm.elf)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000141endif()
142
143#
Soby Mathewa6fd3802023-01-25 14:43:08 +0000144# Copy 'rmm-runtime.map' to 'build/$<CONFIG>/rmm.map'
Soby Mathewb4c6df42022-11-09 11:13:29 +0000145#
146
147add_custom_command(
Soby Mathewa6fd3802023-01-25 14:43:08 +0000148 COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>.map" "${ARTEFACT_DIR}/rmm.map"
Soby Mathewb4c6df42022-11-09 11:13:29 +0000149 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")