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 |
Andrew Beggs | 97a00d4 | 2021-06-15 15:45:46 +0000 | [diff] [blame^] | 49 | if (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) |
| 53 | else() |
| 54 | set(QCBOR_EXTRA_OPTION "") |
| 55 | endif() |
| 56 | |
Julian Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 57 | execute_process(COMMAND |
Andrew Beggs | 97a00d4 | 2021-06-15 15:45:46 +0000 | [diff] [blame^] | 58 | ${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 Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 67 | ) |
Andrew Beggs | 97a00d4 | 2021-06-15 15:45:46 +0000 | [diff] [blame^] | 68 | unset(QCBOR_EXTRA_OPTION) |
Julian Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 69 | |
| 70 | # Build the library |
| 71 | execute_process(COMMAND |
| 72 | ${CMAKE_COMMAND} --build ${qcbor_BINARY_DIR} -j8 |
| 73 | RESULT_VARIABLE _exec_error |
| 74 | ) |
| 75 | if (_exec_error) |
| 76 | message(FATAL_ERROR "Build step of qcbor failed with ${_exec_error}.") |
| 77 | endif() |
| 78 | |
Julian Hall | caa4af8 | 2021-05-19 12:02:36 +0100 | [diff] [blame] | 79 | execute_process(COMMAND |
| 80 | ${CMAKE_COMMAND} --install ${qcbor_BINARY_DIR} |
| 81 | RESULT_VARIABLE _exec_error |
| 82 | ) |
| 83 | if (_exec_error) |
| 84 | message(FATAL_ERROR "Build step of qcbor failed with ${_exec_error}.") |
| 85 | endif() |
| 86 | |
Julian Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 87 | # Create an imported target to have clean abstraction in the build-system. |
| 88 | add_library(qcbor STATIC IMPORTED) |
Julian Hall | caa4af8 | 2021-05-19 12:02:36 +0100 | [diff] [blame] | 89 | set_property(TARGET qcbor PROPERTY IMPORTED_LOCATION "${QCBOR_INSTALL_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}qcbor${CMAKE_STATIC_LIBRARY_SUFFIX}") |
| 90 | set_property(TARGET qcbor PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${QCBOR_INSTALL_PATH}/include") |