Julian Hall | 201ce46 | 2021-04-29 11:05:34 +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 | # QCBOR is a library for encoding and decodingg CBOR objects, as per RFC8949 |
| 7 | #------------------------------------------------------------------------------- |
| 8 | |
| 9 | # External component details |
| 10 | set(QCBOR_URL "https://github.com/laurencelundblade/QCBOR.git" CACHE STRING "qcbor repository URL") |
| 11 | set(QCBOR_REFSPEC "master" CACHE STRING "qcbor git refspec") |
| 12 | set(QCBOR_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/qcbor_install" CACHE PATH "qcbor installation directory") |
| 13 | set(QCBOR_PACKAGE_PATH "${QCBOR_INSTALL_PATH}/libqcbor/cmake" CACHE PATH "qcbor CMake package directory") |
| 14 | |
| 15 | include(FetchContent) |
| 16 | |
| 17 | # Checking git |
| 18 | find_program(GIT_COMMAND "git") |
| 19 | if (NOT GIT_COMMAND) |
| 20 | message(FATAL_ERROR "Please install git") |
| 21 | endif() |
| 22 | |
| 23 | # Fetching qcbor |
| 24 | FetchContent_Declare( |
| 25 | qcbor |
| 26 | GIT_REPOSITORY ${QCBOR_URL} |
| 27 | GIT_TAG ${QCBOR_REFSPEC} |
| 28 | GIT_SHALLOW TRUE |
Julian Hall | caa4af8 | 2021-05-19 12:02:36 +0100 | [diff] [blame^] | 29 | |
| 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 Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 34 | ) |
| 35 | |
| 36 | # FetchContent_GetProperties exports qcbor_SOURCE_DIR and qcbor_BINARY_DIR variables |
| 37 | FetchContent_GetProperties(qcbor) |
| 38 | if(NOT qcbor_POPULATED) |
| 39 | message(STATUS "Fetching qcbor") |
| 40 | FetchContent_Populate(qcbor) |
| 41 | endif() |
| 42 | |
Julian Hall | caa4af8 | 2021-05-19 12:02:36 +0100 | [diff] [blame^] | 43 | # Determine floating point configuration |
| 44 | if (TS_NO_FLOAT_HW) |
| 45 | set(_thirdparty_def -DQCBOR_DISABLE_FLOAT_HW_USE) |
| 46 | endif() |
| 47 | |
Julian Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 48 | # Configure the qcbor library |
| 49 | execute_process(COMMAND |
| 50 | ${CMAKE_COMMAND} |
| 51 | -DCMAKE_TOOLCHAIN_FILE=${TS_EXTERNAL_LIB_TOOLCHAIN_FILE} |
| 52 | -GUnix\ Makefiles |
Julian Hall | caa4af8 | 2021-05-19 12:02:36 +0100 | [diff] [blame^] | 53 | -Dthirdparty_def=${_thirdparty_def} |
| 54 | -DCMAKE_INSTALL_PREFIX=${QCBOR_INSTALL_PATH} |
Julian Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 55 | ${qcbor_SOURCE_DIR} |
| 56 | WORKING_DIRECTORY |
| 57 | ${qcbor_BINARY_DIR} |
| 58 | ) |
| 59 | |
| 60 | # Build the library |
| 61 | execute_process(COMMAND |
| 62 | ${CMAKE_COMMAND} --build ${qcbor_BINARY_DIR} -j8 |
| 63 | RESULT_VARIABLE _exec_error |
| 64 | ) |
| 65 | if (_exec_error) |
| 66 | message(FATAL_ERROR "Build step of qcbor failed with ${_exec_error}.") |
| 67 | endif() |
| 68 | |
Julian Hall | caa4af8 | 2021-05-19 12:02:36 +0100 | [diff] [blame^] | 69 | execute_process(COMMAND |
| 70 | ${CMAKE_COMMAND} --install ${qcbor_BINARY_DIR} |
| 71 | RESULT_VARIABLE _exec_error |
| 72 | ) |
| 73 | if (_exec_error) |
| 74 | message(FATAL_ERROR "Build step of qcbor failed with ${_exec_error}.") |
| 75 | endif() |
| 76 | |
Julian Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 77 | # Create an imported target to have clean abstraction in the build-system. |
| 78 | add_library(qcbor STATIC IMPORTED) |
Julian Hall | caa4af8 | 2021-05-19 12:02:36 +0100 | [diff] [blame^] | 79 | set_property(TARGET qcbor PROPERTY IMPORTED_LOCATION "${QCBOR_INSTALL_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}qcbor${CMAKE_STATIC_LIBRARY_SUFFIX}") |
| 80 | set_property(TARGET qcbor PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${QCBOR_INSTALL_PATH}/include") |