blob: 0d94f41238eb69060d3a2e6ca7d3db2cda99b178 [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#
Soby Mathewb4c6df42022-11-09 11:13:29 +000014list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
Soby Mathewb5a29752024-11-14 14:26:11 +000015include(GitUtils)
Soby Mathewb4c6df42022-11-09 11:13:29 +000016
17#
18# Include any dependencies.
19#
Soby Mathewb4c6df42022-11-09 11:13:29 +000020include(ArmConfigOption)
21include(ArmConfigOptionOverride)
22
23#
Soby Mathewb5a29752024-11-14 14:26:11 +000024# Update the Submodules
25#
26Git_Update_Submodule()
27
28#
Soby Mathewb4c6df42022-11-09 11:13:29 +000029# Run preliminary setup scripts.
30#
31set(RMM_CONFIG_FILE "${CMAKE_SOURCE_DIR}/configs/${RMM_CONFIG}.cmake")
32if(NOT EXISTS ${RMM_CONFIG_FILE})
33 message(FATAL_ERROR "Please provide config ${RMM_CONFIG_FILE}")
34endif()
35
36include("${RMM_CONFIG_FILE}")
37
38#
39# Set the target build Architecture before we proceed further.
40# Default is aarch64.
41#
42arm_config_option(
43 NAME RMM_ARCH
44 HELP "Target Architecture for RMM build."
45 STRINGS "aarch64" "fake_host")
46
47include("cmake/Toolchains.cmake")
48include("cmake/BuildType.cmake")
49
50#
51# Initialize the project. Note that this is where the toolchain file is loaded,
52# and also where the project directory and version variables are set up.
53#
54
Soby Mathewef1aa482024-11-18 16:44:11 +000055project(RMM VERSION 0.6.0 LANGUAGES C CXX ASM)
Soby Mathewb4c6df42022-11-09 11:13:29 +000056
57#
58# Set global flags.
59#
60
61set(CMAKE_C_STANDARD 11)
62set(CMAKE_C_STANDARD_REQUIRED TRUE)
Soby Mathewe558fa32024-12-31 11:59:11 +000063set(CMAKE_CXX_STANDARD 11)
64set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
Soby Mathewb4c6df42022-11-09 11:13:29 +000065set(CMAKE_C_EXTENSIONS TRUE)
66
67if(RMM_STATIC_ANALYSIS_CPPCHECK)
68 set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
69endif()
Javier Almansa Sobrino576071e2022-09-09 16:01:17 +010070
Soby Mathewb4c6df42022-11-09 11:13:29 +000071#
AlexeiFedorov0f300ac2024-03-05 15:55:06 +000072# Set march compiler option
73#
74detect_and_set_march()
75
76#
Soby Mathewb4c6df42022-11-09 11:13:29 +000077# Include the platform makefile
78#
79include("cmake/Platforms.cmake")
80
81#
Javier Almansa Sobrino576071e2022-09-09 16:01:17 +010082# Include Coverage report framework
83#
84include("cmake/CoverageReport.cmake")
85
86#
Javier Almansa Sobrinoc4ad5b02022-07-05 19:05:14 +010087# Include the Unit Test Framework
88#
89include(UnitTestFramework)
90
91#
Soby Mathewb4c6df42022-11-09 11:13:29 +000092# Include the common configuration options
93#
94include("cmake/CommonConfigs.cmake")
95
96#
97# Load in our C standard library and link it to any targets created after this
98# point. This will automatically transition these targets away from the standard
99# library provided by the toolchain, and towards our libc.
100#
101
102add_subdirectory("lib/libc")
103
104link_libraries(rmm-lib-libc)
105
106#
Soby Mathewb4c6df42022-11-09 11:13:29 +0000107# Recurse into the various component subdirectories
108#
109add_subdirectory("lib")
110add_subdirectory("runtime")
111
112if(RMM_DOCS)
113 add_subdirectory("docs")
114endif()
115
116#
Soby Mathewa6fd3802023-01-25 14:43:08 +0000117# Copy 'rmm-runtime' executable to 'build/$<CONFIG>/rmm.elf'.
118#
119
120set(ARTEFACT_DIR "${CMAKE_BINARY_DIR}/$<CONFIG>")
121add_custom_command(
122 COMMAND ${CMAKE_COMMAND} -E make_directory "${ARTEFACT_DIR}"
123 COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>" "${ARTEFACT_DIR}/rmm.elf"
124 OUTPUT rmm.elf
125 DEPENDS rmm-runtime)
126
127#
Soby Mathewb4c6df42022-11-09 11:13:29 +0000128# Create the flat binary using whatever tool comes with the toolchain.
129#
130
131if(CMAKE_OBJCOPY)
132 add_custom_command(
Soby Mathewa6fd3802023-01-25 14:43:08 +0000133 COMMAND "${CMAKE_OBJCOPY}" -O binary "${ARTEFACT_DIR}/rmm.elf" "${ARTEFACT_DIR}/rmm.img"
Soby Mathewb4c6df42022-11-09 11:13:29 +0000134 OUTPUT rmm.img
Soby Mathewa6fd3802023-01-25 14:43:08 +0000135 DEPENDS rmm.elf)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000136endif()
137
138#
139# Create the dump file using whatever tool comes with the toolchain.
140#
141
142if(CMAKE_OBJDUMP)
143 add_custom_command(
AlexeiFedorovdf16e652023-10-26 13:19:53 +0100144 COMMAND "${CMAKE_OBJDUMP}" -dxS "${ARTEFACT_DIR}/rmm.elf" > "${ARTEFACT_DIR}/rmm.dump"
Soby Mathewb4c6df42022-11-09 11:13:29 +0000145 OUTPUT rmm.dump
Soby Mathewa6fd3802023-01-25 14:43:08 +0000146 DEPENDS rmm.elf)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000147endif()
148
149#
Soby Mathewa6fd3802023-01-25 14:43:08 +0000150# Copy 'rmm-runtime.map' to 'build/$<CONFIG>/rmm.map'
Soby Mathewb4c6df42022-11-09 11:13:29 +0000151#
152
153add_custom_command(
Soby Mathewa6fd3802023-01-25 14:43:08 +0000154 COMMAND "${CMAKE_COMMAND}" -E copy_if_different "$<TARGET_FILE:rmm-runtime>.map" "${ARTEFACT_DIR}/rmm.map"
Soby Mathewb4c6df42022-11-09 11:13:29 +0000155 OUTPUT rmm.map
156 DEPENDS rmm-runtime)
157
158add_custom_target(rmm ALL DEPENDS rmm.img rmm.dump rmm.elf rmm.map)
159
160#
161# Set up additional tooling.
162#
163
164add_subdirectory("tools")