blob: cda78711cc3f3ee0383f9531e9f008e5d37b3e5b [file] [log] [blame]
Julian Hall827d4472021-05-11 11:31:37 +01001#-------------------------------------------------------------------------------
2# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6# t_cose is a library for signing CBOR tokens using COSE_Sign1
7#-------------------------------------------------------------------------------
8
9# External component details
10set(T_COSE_URL "https://github.com/laurencelundblade/t_cose.git" CACHE STRING "t_cose repository URL")
11set(T_COSE_REFSPEC "master" CACHE STRING "t_cose git refspec")
12set(T_COSE_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/t_cose_install" CACHE PATH "t_cose installation directory")
13set(T_COSE_PACKAGE_PATH "${T_COSE_INSTALL_PATH}/libt_cose/cmake" CACHE PATH "t_cose CMake package directory")
14
15include(FetchContent)
16
17# Checking git
18find_program(GIT_COMMAND "git")
19if (NOT GIT_COMMAND)
20 message(FATAL_ERROR "Please install git")
21endif()
22
23# Fetching t_cose
24FetchContent_Declare(
25 t_cose
26 GIT_REPOSITORY ${T_COSE_URL}
27 GIT_TAG ${T_COSE_REFSPEC}
28 GIT_SHALLOW TRUE
29
30 PATCH_COMMAND git stash
31 COMMAND git am ${CMAKE_CURRENT_LIST_DIR}/0001-add-install-definition.patch
32 COMMAND git reset HEAD~1
33
34)
35
36# FetchContent_GetProperties exports t_cose_SOURCE_DIR and t_cose_BINARY_DIR variables
37FetchContent_GetProperties(t_cose)
38if(NOT t_cose_POPULATED)
39 message(STATUS "Fetching t_cose")
40 FetchContent_Populate(t_cose)
41endif()
42
43# Prepare include paths for dependencie that t_codse has on external components
44get_target_property(_qcbor_inc qcbor INTERFACE_INCLUDE_DIRECTORIES)
45set(_ext_inc_paths
46 ${_qcbor_inc}
47 ${PSA_CRYPTO_API_INCLUDE})
48
Andrew Beggs97a00d42021-06-15 15:45:46 +000049if (NOT TCOSE_EXTERNAL_INCLUDE_PATHS STREQUAL "")
50 list(APPEND _ext_inc_paths "${TCOSE_EXTERNAL_INCLUDE_PATHS}")
51 unset(TCOSE_EXTERNAL_INCLUDE_PATHS)
52endif()
53
Julian Hall827d4472021-05-11 11:31:37 +010054string(REPLACE ";" "\\;" _ext_inc_paths "${_ext_inc_paths}")
55
56# Configure the t_cose library
57execute_process(COMMAND
58${CMAKE_COMMAND}
59 -DCMAKE_TOOLCHAIN_FILE=${TS_EXTERNAL_LIB_TOOLCHAIN_FILE}
60 -Dthirdparty_inc=${_ext_inc_paths}
61 -DCMAKE_INSTALL_PREFIX=${T_COSE_INSTALL_PATH}
62 -DMBEDTLS=On
63 -GUnix\ Makefiles
64 ${t_cose_SOURCE_DIR}
65WORKING_DIRECTORY
66 ${t_cose_BINARY_DIR}
67)
68
69# Build the library
70execute_process(COMMAND
71 ${CMAKE_COMMAND} --build ${t_cose_BINARY_DIR} -j8
72 RESULT_VARIABLE _exec_error
73 )
74if (_exec_error)
75 message(FATAL_ERROR "Build step of t_cose failed with ${_exec_error}.")
76endif()
77
78execute_process(COMMAND
79 ${CMAKE_COMMAND} --install ${t_cose_BINARY_DIR}
80 RESULT_VARIABLE _exec_error
81 )
82if (_exec_error)
83 message(FATAL_ERROR "Build step of t_cose failed with ${_exec_error}.")
84endif()
85
86# Create an imported target to have clean abstraction in the build-system.
87add_library(t_cose STATIC IMPORTED)
88set_property(TARGET t_cose PROPERTY IMPORTED_LOCATION "${T_COSE_INSTALL_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}t_cose${CMAKE_STATIC_LIBRARY_SUFFIX}")
89set_property(TARGET t_cose PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${T_COSE_INSTALL_PATH}/include")