blob: 6d69d903fe81019987e1376a0b35f2c24f262424 [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
Andrew Beggs97a00d42021-06-15 15:45:46 +000049if (NOT "${QCBOR_EXTERNAL_INCLUDE_PATHS}" STREQUAL "")
50 string(REPLACE ";" "\\;" QCBOR_EXTERNAL_INCLUDE_PATHS "${QCBOR_EXTERNAL_INCLUDE_PATHS}")
51 set(QCBOR_EXTRA_OPTION -Dthirdparty_inc=${QCBOR_EXTERNAL_INCLUDE_PATHS})
52 unset(QCBOR_EXTERNAL_INCLUDE_PATHS)
53else()
54 set(QCBOR_EXTRA_OPTION "")
55endif()
56
Julian Hall201ce462021-04-29 11:05:34 +010057execute_process(COMMAND
Andrew Beggs97a00d42021-06-15 15:45:46 +000058 ${CMAKE_COMMAND}
59 -DCMAKE_TOOLCHAIN_FILE=${TS_EXTERNAL_LIB_TOOLCHAIN_FILE}
60 -GUnix\ Makefiles
61 -Dthirdparty_def=${_thirdparty_def}
62 -DCMAKE_INSTALL_PREFIX=${QCBOR_INSTALL_PATH}
63 ${QCBOR_EXTRA_OPTION}
64 ${qcbor_SOURCE_DIR}
65 WORKING_DIRECTORY
66 ${qcbor_BINARY_DIR}
Julian Hall201ce462021-04-29 11:05:34 +010067)
Andrew Beggs97a00d42021-06-15 15:45:46 +000068unset(QCBOR_EXTRA_OPTION)
Julian Hall201ce462021-04-29 11:05:34 +010069
70# Build the library
71execute_process(COMMAND
72 ${CMAKE_COMMAND} --build ${qcbor_BINARY_DIR} -j8
73 RESULT_VARIABLE _exec_error
74 )
75if (_exec_error)
76 message(FATAL_ERROR "Build step of qcbor failed with ${_exec_error}.")
77endif()
78
Julian Hallcaa4af82021-05-19 12:02:36 +010079execute_process(COMMAND
80 ${CMAKE_COMMAND} --install ${qcbor_BINARY_DIR}
81 RESULT_VARIABLE _exec_error
82 )
83if (_exec_error)
84 message(FATAL_ERROR "Build step of qcbor failed with ${_exec_error}.")
85endif()
86
Julian Hall201ce462021-04-29 11:05:34 +010087# Create an imported target to have clean abstraction in the build-system.
88add_library(qcbor STATIC IMPORTED)
Julian Hallcaa4af82021-05-19 12:02:36 +010089set_property(TARGET qcbor PROPERTY IMPORTED_LOCATION "${QCBOR_INSTALL_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}qcbor${CMAKE_STATIC_LIBRARY_SUFFIX}")
90set_property(TARGET qcbor PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${QCBOR_INSTALL_PATH}/include")