blob: 6c51e17b2ccf6cb109a8155722fba99e52b29863 [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")