blob: 7e001be1589bbfb282e4bdbd9d44c051825d3b84 [file] [log] [blame]
Julian Hall201ce462021-04-29 11:05:34 +01001#-------------------------------------------------------------------------------
2# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6# QCBOR is a library for encoding and decodingg CBOR objects, as per RFC8949
7#-------------------------------------------------------------------------------
8
9# External component details
10set(QCBOR_URL "https://github.com/laurencelundblade/QCBOR.git" CACHE STRING "qcbor repository URL")
11set(QCBOR_REFSPEC "master" CACHE STRING "qcbor git refspec")
12set(QCBOR_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/qcbor_install" CACHE PATH "qcbor installation directory")
13set(QCBOR_PACKAGE_PATH "${QCBOR_INSTALL_PATH}/libqcbor/cmake" CACHE PATH "qcbor 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 qcbor
24FetchContent_Declare(
25 qcbor
26 GIT_REPOSITORY ${QCBOR_URL}
27 GIT_TAG ${QCBOR_REFSPEC}
28 GIT_SHALLOW TRUE
Julian Hallcaa4af82021-05-19 12:02:36 +010029
30 PATCH_COMMAND git stash
31 COMMAND git branch -f bf-patch
32 COMMAND git am ${CMAKE_CURRENT_LIST_DIR}/0001-Add-3rd-party-settings.patch ${CMAKE_CURRENT_LIST_DIR}/0002-Add-install-definition.patch
33 COMMAND git reset bf-patch
Julian Hall201ce462021-04-29 11:05:34 +010034)
35
36# FetchContent_GetProperties exports qcbor_SOURCE_DIR and qcbor_BINARY_DIR variables
37FetchContent_GetProperties(qcbor)
38if(NOT qcbor_POPULATED)
39 message(STATUS "Fetching qcbor")
40 FetchContent_Populate(qcbor)
41endif()
42
Julian Hallcaa4af82021-05-19 12:02:36 +010043# Determine floating point configuration
44if (TS_NO_FLOAT_HW)
45 set(_thirdparty_def -DQCBOR_DISABLE_FLOAT_HW_USE)
46endif()
47
Julian Hall201ce462021-04-29 11:05:34 +010048# Configure the qcbor library
49execute_process(COMMAND
50${CMAKE_COMMAND}
51 -DCMAKE_TOOLCHAIN_FILE=${TS_EXTERNAL_LIB_TOOLCHAIN_FILE}
52 -GUnix\ Makefiles
Julian Hallcaa4af82021-05-19 12:02:36 +010053 -Dthirdparty_def=${_thirdparty_def}
54 -DCMAKE_INSTALL_PREFIX=${QCBOR_INSTALL_PATH}
Julian Hall201ce462021-04-29 11:05:34 +010055 ${qcbor_SOURCE_DIR}
56WORKING_DIRECTORY
57 ${qcbor_BINARY_DIR}
58)
59
60# Build the library
61execute_process(COMMAND
62 ${CMAKE_COMMAND} --build ${qcbor_BINARY_DIR} -j8
63 RESULT_VARIABLE _exec_error
64 )
65if (_exec_error)
66 message(FATAL_ERROR "Build step of qcbor failed with ${_exec_error}.")
67endif()
68
Julian Hallcaa4af82021-05-19 12:02:36 +010069execute_process(COMMAND
70 ${CMAKE_COMMAND} --install ${qcbor_BINARY_DIR}
71 RESULT_VARIABLE _exec_error
72 )
73if (_exec_error)
74 message(FATAL_ERROR "Build step of qcbor failed with ${_exec_error}.")
75endif()
76
Julian Hall201ce462021-04-29 11:05:34 +010077# Create an imported target to have clean abstraction in the build-system.
78add_library(qcbor STATIC IMPORTED)
Julian Hallcaa4af82021-05-19 12:02:36 +010079set_property(TARGET qcbor PROPERTY IMPORTED_LOCATION "${QCBOR_INSTALL_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}qcbor${CMAKE_STATIC_LIBRARY_SUFFIX}")
80set_property(TARGET qcbor PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${QCBOR_INSTALL_PATH}/include")