blob: 3fd8061a48fc188b67b5539c2a501deb512ad940 [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
49string(REPLACE ";" "\\;" _ext_inc_paths "${_ext_inc_paths}")
50
51# Configure the t_cose library
52execute_process(COMMAND
53${CMAKE_COMMAND}
54 -DCMAKE_TOOLCHAIN_FILE=${TS_EXTERNAL_LIB_TOOLCHAIN_FILE}
55 -Dthirdparty_inc=${_ext_inc_paths}
56 -DCMAKE_INSTALL_PREFIX=${T_COSE_INSTALL_PATH}
57 -DMBEDTLS=On
58 -GUnix\ Makefiles
59 ${t_cose_SOURCE_DIR}
60WORKING_DIRECTORY
61 ${t_cose_BINARY_DIR}
62)
63
64# Build the library
65execute_process(COMMAND
66 ${CMAKE_COMMAND} --build ${t_cose_BINARY_DIR} -j8
67 RESULT_VARIABLE _exec_error
68 )
69if (_exec_error)
70 message(FATAL_ERROR "Build step of t_cose failed with ${_exec_error}.")
71endif()
72
73execute_process(COMMAND
74 ${CMAKE_COMMAND} --install ${t_cose_BINARY_DIR}
75 RESULT_VARIABLE _exec_error
76 )
77if (_exec_error)
78 message(FATAL_ERROR "Build step of t_cose failed with ${_exec_error}.")
79endif()
80
81# Create an imported target to have clean abstraction in the build-system.
82add_library(t_cose STATIC IMPORTED)
83set_property(TARGET t_cose PROPERTY IMPORTED_LOCATION "${T_COSE_INSTALL_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}t_cose${CMAKE_STATIC_LIBRARY_SUFFIX}")
84set_property(TARGET t_cose PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${T_COSE_INSTALL_PATH}/include")