Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 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 | |
Gyorgy Szing | 2247d24 | 2021-09-03 16:17:25 +0200 | [diff] [blame] | 9 | # Determine the number of processes to run while running parallel builds. |
| 10 | # Pass -DPROCESSOR_COUNT=<n> to cmake to override. |
| 11 | if(NOT DEFINED PROCESSOR_COUNT) |
| 12 | include(ProcessorCount) |
| 13 | ProcessorCount(PROCESSOR_COUNT) |
| 14 | set(PROCESSOR_COUNT ${PROCESSOR_COUNT} CACHE STRING "Number of cores to use for parallel builds.") |
| 15 | endif() |
| 16 | |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 17 | # External component details |
| 18 | set(T_COSE_URL "https://github.com/laurencelundblade/t_cose.git" CACHE STRING "t_cose repository URL") |
| 19 | set(T_COSE_REFSPEC "master" CACHE STRING "t_cose git refspec") |
| 20 | set(T_COSE_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/t_cose_install" CACHE PATH "t_cose installation directory") |
| 21 | set(T_COSE_PACKAGE_PATH "${T_COSE_INSTALL_PATH}/libt_cose/cmake" CACHE PATH "t_cose CMake package directory") |
| 22 | |
| 23 | include(FetchContent) |
| 24 | |
| 25 | # Checking git |
| 26 | find_program(GIT_COMMAND "git") |
| 27 | if (NOT GIT_COMMAND) |
| 28 | message(FATAL_ERROR "Please install git") |
| 29 | endif() |
| 30 | |
| 31 | # Fetching t_cose |
| 32 | FetchContent_Declare( |
| 33 | t_cose |
| 34 | GIT_REPOSITORY ${T_COSE_URL} |
| 35 | GIT_TAG ${T_COSE_REFSPEC} |
| 36 | GIT_SHALLOW TRUE |
| 37 | |
| 38 | PATCH_COMMAND git stash |
| 39 | COMMAND git am ${CMAKE_CURRENT_LIST_DIR}/0001-add-install-definition.patch |
Julian Hall | c635094 | 2021-07-21 12:08:09 +0100 | [diff] [blame^] | 40 | COMMAND git apply ${CMAKE_CURRENT_LIST_DIR}/0002-add-tls3_0_0-compatibility.patch |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 41 | COMMAND git reset HEAD~1 |
| 42 | |
| 43 | ) |
| 44 | |
| 45 | # FetchContent_GetProperties exports t_cose_SOURCE_DIR and t_cose_BINARY_DIR variables |
| 46 | FetchContent_GetProperties(t_cose) |
| 47 | if(NOT t_cose_POPULATED) |
| 48 | message(STATUS "Fetching t_cose") |
| 49 | FetchContent_Populate(t_cose) |
| 50 | endif() |
| 51 | |
Gyorgy Szing | 2247d24 | 2021-09-03 16:17:25 +0200 | [diff] [blame] | 52 | # Prepare include paths for dependencies that t_codse has on external components |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 53 | get_target_property(_qcbor_inc qcbor INTERFACE_INCLUDE_DIRECTORIES) |
| 54 | set(_ext_inc_paths |
| 55 | ${_qcbor_inc} |
| 56 | ${PSA_CRYPTO_API_INCLUDE}) |
| 57 | |
Andrew Beggs | 97a00d4 | 2021-06-15 15:45:46 +0000 | [diff] [blame] | 58 | if (NOT TCOSE_EXTERNAL_INCLUDE_PATHS STREQUAL "") |
| 59 | list(APPEND _ext_inc_paths "${TCOSE_EXTERNAL_INCLUDE_PATHS}") |
| 60 | unset(TCOSE_EXTERNAL_INCLUDE_PATHS) |
| 61 | endif() |
| 62 | |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 63 | string(REPLACE ";" "\\;" _ext_inc_paths "${_ext_inc_paths}") |
| 64 | |
| 65 | # Configure the t_cose library |
| 66 | execute_process(COMMAND |
| 67 | ${CMAKE_COMMAND} |
| 68 | -DCMAKE_TOOLCHAIN_FILE=${TS_EXTERNAL_LIB_TOOLCHAIN_FILE} |
| 69 | -Dthirdparty_inc=${_ext_inc_paths} |
| 70 | -DCMAKE_INSTALL_PREFIX=${T_COSE_INSTALL_PATH} |
| 71 | -DMBEDTLS=On |
| 72 | -GUnix\ Makefiles |
| 73 | ${t_cose_SOURCE_DIR} |
| 74 | WORKING_DIRECTORY |
| 75 | ${t_cose_BINARY_DIR} |
| 76 | ) |
| 77 | |
| 78 | # Build the library |
| 79 | execute_process(COMMAND |
Gyorgy Szing | 2247d24 | 2021-09-03 16:17:25 +0200 | [diff] [blame] | 80 | ${CMAKE_COMMAND} --build ${t_cose_BINARY_DIR} --parallel ${PROCESSOR_COUNT} --target install |
Julian Hall | 827d447 | 2021-05-11 11:31:37 +0100 | [diff] [blame] | 81 | RESULT_VARIABLE _exec_error |
| 82 | ) |
| 83 | if (_exec_error) |
| 84 | message(FATAL_ERROR "Build step of t_cose failed with ${_exec_error}.") |
| 85 | endif() |
| 86 | |
| 87 | # Create an imported target to have clean abstraction in the build-system. |
| 88 | add_library(t_cose STATIC IMPORTED) |
| 89 | set_property(TARGET t_cose PROPERTY IMPORTED_LOCATION "${T_COSE_INSTALL_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}t_cose${CMAKE_STATIC_LIBRARY_SUFFIX}") |
| 90 | set_property(TARGET t_cose PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${T_COSE_INSTALL_PATH}/include") |