Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
Gyorgy Szing | 28bca0b | 2023-02-15 11:17:07 +0100 | [diff] [blame] | 2 | # Copyright (c) 2021-2023, Arm Limited and Contributors. All rights reserved. |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | # t_cose is a library for signing CBOR tokens using COSE_Sign1 |
| 7 | #------------------------------------------------------------------------------- |
| 8 | |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 9 | set(T_COSE_URL "https://github.com/laurencelundblade/t_cose.git" CACHE STRING "t_cose repository URL") |
Julian Hall | c74f243 | 2022-01-11 09:43:52 +0000 | [diff] [blame] | 10 | set(T_COSE_REFSPEC "fc3a4b2c7196ff582e8242de8bd4a1bc4eec577f" CACHE STRING "t_cose git refspec") |
Gyorgy Szing | 9666994 | 2021-12-08 04:19:50 +0100 | [diff] [blame] | 11 | set(T_COSE_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/t_cose-src" CACHE PATH "t_cose installation directory") |
| 12 | set(T_COSE_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/t_cose_install" CACHE PATH "t_cose installation directory") |
Gyorgy Szing | 34aaf21 | 2022-10-20 07:26:23 +0200 | [diff] [blame] | 13 | set(T_COSE_BUILD_TYPE "Release" CACHE STRING "t_cose build type") |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 14 | |
Gyorgy Szing | 9666994 | 2021-12-08 04:19:50 +0100 | [diff] [blame] | 15 | set(GIT_OPTIONS |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 16 | GIT_REPOSITORY ${T_COSE_URL} |
| 17 | GIT_TAG ${T_COSE_REFSPEC} |
Julian Hall | a628af3 | 2022-04-01 10:08:18 +0100 | [diff] [blame] | 18 | GIT_SHALLOW FALSE |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 19 | |
| 20 | PATCH_COMMAND git stash |
Gyorgy Szing | 9666994 | 2021-12-08 04:19:50 +0100 | [diff] [blame] | 21 | COMMAND git branch -f bf-patch |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 22 | COMMAND git am ${CMAKE_CURRENT_LIST_DIR}/0001-add-install-definition.patch |
Gyorgy Szing | d6fcffd | 2022-03-05 03:04:22 +0000 | [diff] [blame] | 23 | ${CMAKE_CURRENT_LIST_DIR}/0002-Fix-stop-overriding-C_FLAGS-from-environment.patch |
Gyorgy Szing | 9666994 | 2021-12-08 04:19:50 +0100 | [diff] [blame] | 24 | COMMAND git reset bf-patch |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 25 | ) |
| 26 | |
Gyorgy Szing | d6fcffd | 2022-03-05 03:04:22 +0000 | [diff] [blame] | 27 | include(${TS_ROOT}/tools/cmake/common/PropertyCopy.cmake) |
| 28 | |
| 29 | # Only pass libc settings to t-cose if needed. For environments where the standard |
| 30 | # library is not overridden, this is not needed. |
| 31 | if(TARGET stdlib::c) |
| 32 | # Save libc settings |
| 33 | save_interface_target_properties(TGT stdlib::c PREFIX LIBC) |
| 34 | # Translate libc settings to cmake code fragment. Will be inserted into |
| 35 | # t_cose-init-cache.cmake.in when LazyFetch configures the file. |
| 36 | translate_interface_target_properties(PREFIX LIBC RES _cmake_fragment) |
| 37 | unset_saved_properties(LIBC) |
| 38 | endif() |
| 39 | |
Gyorgy Szing | 2247d24 | 2021-09-03 16:17:25 +0200 | [diff] [blame] | 40 | # Prepare include paths for dependencies that t_codse has on external components |
Gyorgy Szing | d6fcffd | 2022-03-05 03:04:22 +0000 | [diff] [blame] | 41 | save_interface_target_properties(TGT qcbor PREFIX QCBOR) |
| 42 | translate_interface_target_properties(PREFIX QCBOR RES _cmake_fragment1) |
| 43 | unset_saved_properties(QCBOR) |
| 44 | string(APPEND _cmake_fragment "\n${_cmake_fragment1}") |
| 45 | unset(_cmake_fragment1) |
| 46 | |
Gyorgy Szing | 8ac8a6a | 2022-07-19 12:24:42 +0000 | [diff] [blame] | 47 | if (NOT DEFINED PSA_CRYPTO_API_INCLUDE) |
| 48 | string(CONCAT _msg "Mandatory parameter PSA_CRYPTO_API_INCLUDE is not defined. Please include a component which" |
| 49 | " sets this variable or pass -DPSA_CRYPTO_API_INCLUDE=<path> where <path> is the location of" |
| 50 | " PSA API headers.") |
| 51 | message(FATAL_ERROR ${_msg} ) |
| 52 | endif() |
| 53 | |
Gyorgy Szing | d6fcffd | 2022-03-05 03:04:22 +0000 | [diff] [blame] | 54 | translate_value_as_property(VALUE "${PSA_CRYPTO_API_INCLUDE}" |
| 55 | PROPERTY INTERFACE_INCLUDE_DIRECTORIES |
| 56 | RES _cmake_fragment1) |
| 57 | string(APPEND _cmake_fragment "\n${_cmake_fragment1}") |
| 58 | unset(_cmake_fragment1) |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 59 | |
Gyorgy Szing | 9666994 | 2021-12-08 04:19:50 +0100 | [diff] [blame] | 60 | include(${TS_ROOT}/tools/cmake/common/LazyFetch.cmake REQUIRED) |
| 61 | LazyFetch_MakeAvailable(DEP_NAME t_cose |
| 62 | FETCH_OPTIONS "${GIT_OPTIONS}" |
| 63 | INSTALL_DIR ${T_COSE_INSTALL_DIR} |
| 64 | CACHE_FILE "${CMAKE_CURRENT_LIST_DIR}/t_cose-init-cache.cmake.in" |
| 65 | SOURCE_DIR "${T_COSE_SOURCE_DIR}" |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 66 | ) |
Gyorgy Szing | d6fcffd | 2022-03-05 03:04:22 +0000 | [diff] [blame] | 67 | unset(_cmake_fragment) |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 68 | |
| 69 | # Create an imported target to have clean abstraction in the build-system. |
| 70 | add_library(t_cose STATIC IMPORTED) |
Gyorgy Szing | 9666994 | 2021-12-08 04:19:50 +0100 | [diff] [blame] | 71 | target_link_libraries(t_cose INTERFACE qcbor) |
| 72 | set_property(TARGET t_cose PROPERTY IMPORTED_LOCATION "${T_COSE_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}t_cose${CMAKE_STATIC_LIBRARY_SUFFIX}") |
| 73 | set_property(TARGET t_cose PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${T_COSE_INSTALL_DIR}/include") |
Gyorgy Szing | 28bca0b | 2023-02-15 11:17:07 +0100 | [diff] [blame] | 74 | if(TARGET stdlib::c) |
| 75 | target_link_libraries(t_cose INTERFACE stdlib::c) |
| 76 | endif() |
Gyorgy Szing | 9666994 | 2021-12-08 04:19:50 +0100 | [diff] [blame] | 77 | set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${T_COSE_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}t_cose${CMAKE_STATIC_LIBRARY_SUFFIX}") |