blob: 0e83302532cb9bf4d3a6655e873470d319aa3762 [file] [log] [blame]
Gyorgy Szing49091802020-11-24 00:33:09 +01001#-------------------------------------------------------------------------------
Gyorgy Szing28bca0b2023-02-15 11:17:07 +01002# Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.
Gyorgy Szing49091802020-11-24 00:33:09 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
Balint Dobszay047aea82022-05-16 14:20:53 +02007cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
Gyorgy Szing49091802020-11-24 00:33:09 +01008include(../../deployment.cmake REQUIRED)
9
10#-------------------------------------------------------------------------------
11# The CMakeLists.txt for building the libsp deployment for opteesp
12#
Gyorgy Szingb9596cd2022-03-03 01:10:23 +010013# Used for building the libsp library that provides FFA related functions
Gyorgy Szing49091802020-11-24 00:33:09 +010014# for applications deployed in a secure partition.
15#-------------------------------------------------------------------------------
16include(${TS_ROOT}/environments/opteesp/env.cmake)
17
Gyorgy Szing0afc4912022-07-20 06:26:25 +000018version_semver_read(FILE "${CMAKE_CURRENT_LIST_DIR}/version.txt"
19 MAJOR _major MINOR _minor PATCH _patch)
20set(LIBSP_VERSION "${_major}.${_minor}.${_patch}")
Gyorgy Szing49091802020-11-24 00:33:09 +010021project(trusted-services
22 VERSION
23 ${LIBSP_VERSION}
24 LANGUAGES
25 C ASM
26 )
Gyorgy Szing0afc4912022-07-20 06:26:25 +000027unset(_major)
28unset(_minor)
29unset(_patch)
Gyorgy Szing49091802020-11-24 00:33:09 +010030
31add_library(sp STATIC)
32
Gyorgy Szingb9596cd2022-03-03 01:10:23 +010033add_components(TARGET sp
Gyorgy Szing49091802020-11-24 00:33:09 +010034 BASE_DIR ${TS_ROOT}
35 COMPONENTS
36 components/messaging/ffa/libsp
37 components/common/utils
38)
39
Gyorgy Szingb9596cd2022-03-03 01:10:23 +010040# Include newlib into the build, but do no add SP executable specific files to libsp.
41# Use a dummy target which will never be built.
Gyorgy Szing63bf16a2022-10-20 08:55:52 +000042function(get_newlib_compile_flags)
43 # Environment specific files require this variable to be set.
44 # Set it to a dummy value as we are not going to build these anyways.
45 # The namespace of the function will ensure globas setting is not affected.
46 set(SP_HEAP_SIZE 4096)
47 add_library(dummy EXCLUDE_FROM_ALL)
48 add_components(TARGET dummy
49 BASE_DIR ${TS_ROOT}
50 COMPONENTS
51 environments/opteesp
52 )
53endfunction()
54
55get_newlib_compile_flags()
Gyorgy Szingb9596cd2022-03-03 01:10:23 +010056
57# Get libc specific settings from newlib.
Gyorgy Szing28bca0b2023-02-15 11:17:07 +010058target_link_libraries(sp PUBLIC stdlib::c)
Gyorgy Szingb9596cd2022-03-03 01:10:23 +010059
60target_compile_definitions(sp PRIVATE
Gyorgy Szing49091802020-11-24 00:33:09 +010061 ARM64=1
62)
63
64if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
Gyorgy Szingb9596cd2022-03-03 01:10:23 +010065 target_compile_options(sp PRIVATE
Andrew Beggs97a00d42021-06-15 15:45:46 +000066 -std=c99
Gyorgy Szing49091802020-11-24 00:33:09 +010067 )
68endif()
69
70######################################## install
71if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
72 set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE)
73endif()
74
75install(
76 TARGETS
77 sp
78 EXPORT
79 LibspTargets
80 ARCHIVE DESTINATION
Gyorgy Szingc31afbf2021-02-12 01:51:55 +010081 ${TS_ENV}/lib
Gyorgy Szing49091802020-11-24 00:33:09 +010082 PUBLIC_HEADER DESTINATION
Gyorgy Szingc31afbf2021-02-12 01:51:55 +010083 ${TS_ENV}/include
Gyorgy Szing49091802020-11-24 00:33:09 +010084 COMPONENT
85 libsp
86)
87
Gyorgy Szing49091802020-11-24 00:33:09 +010088### Create a config file package.
Gyorgy Szingc31afbf2021-02-12 01:51:55 +010089set(ConfigPackageLocation ${TS_ENV}/lib/cmake/libsp)
Gyorgy Szing49091802020-11-24 00:33:09 +010090
91include(CMakePackageConfigHelpers)
92write_basic_package_version_file(
93 "${CMAKE_CURRENT_BINARY_DIR}/LibspConfigVersion.cmake"
Gyorgy Szing0afc4912022-07-20 06:26:25 +000094 VERSION "${LIBSP_VERSION}"
Gyorgy Szing49091802020-11-24 00:33:09 +010095 COMPATIBILITY SameMajorVersion
96)
97
98# Create targets file.
99export(
100 EXPORT
101 LibspTargets
102 FILE
103 "${CMAKE_CURRENT_BINARY_DIR}/LibspTargets.cmake"
104 NAMESPACE
105 libsp::
106)
107
108# Finalize config file.
109configure_package_config_file(
110 LibspConfig.cmake.in
111 "${CMAKE_CURRENT_BINARY_DIR}/LibspConfig.cmake"
112 PATH_VARS
113
114 INSTALL_DESTINATION
115 ${ConfigPackageLocation}
116)
117
118install(
119 EXPORT
120 LibspTargets
121 FILE
122 LibspTargets.cmake
123 NAMESPACE
124 libsp::
125 DESTINATION
126 ${ConfigPackageLocation}
127 COMPONENT
128 libsp
129)
130
131# install config and version files
132install(
133 FILES
134 "${CMAKE_CURRENT_BINARY_DIR}/LibspConfig.cmake"
135 "${CMAKE_CURRENT_BINARY_DIR}/LibspConfigVersion.cmake"
Gyorgy Szing49091802020-11-24 00:33:09 +0100136 DESTINATION
137 ${ConfigPackageLocation}
138 COMPONENT
139 libsp
140)