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 | # |
Gyorgy Szing | 2247d24 | 2021-09-03 16:17:25 +0200 | [diff] [blame^] | 6 | # QCBOR is a library for encoding and decoding CBOR objects, as per RFC8949 |
Julian Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 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 | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 17 | # External component details |
| 18 | set(QCBOR_URL "https://github.com/laurencelundblade/QCBOR.git" CACHE STRING "qcbor repository URL") |
| 19 | set(QCBOR_REFSPEC "master" CACHE STRING "qcbor git refspec") |
| 20 | set(QCBOR_INSTALL_PATH "${CMAKE_CURRENT_BINARY_DIR}/qcbor_install" CACHE PATH "qcbor installation directory") |
| 21 | set(QCBOR_PACKAGE_PATH "${QCBOR_INSTALL_PATH}/libqcbor/cmake" CACHE PATH "qcbor 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 qcbor |
| 32 | FetchContent_Declare( |
| 33 | qcbor |
| 34 | GIT_REPOSITORY ${QCBOR_URL} |
| 35 | GIT_TAG ${QCBOR_REFSPEC} |
| 36 | GIT_SHALLOW TRUE |
Julian Hall | caa4af8 | 2021-05-19 12:02:36 +0100 | [diff] [blame] | 37 | |
| 38 | PATCH_COMMAND git stash |
| 39 | COMMAND git branch -f bf-patch |
| 40 | COMMAND git am ${CMAKE_CURRENT_LIST_DIR}/0001-Add-3rd-party-settings.patch ${CMAKE_CURRENT_LIST_DIR}/0002-Add-install-definition.patch |
| 41 | COMMAND git reset bf-patch |
Julian Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 42 | ) |
| 43 | |
| 44 | # FetchContent_GetProperties exports qcbor_SOURCE_DIR and qcbor_BINARY_DIR variables |
| 45 | FetchContent_GetProperties(qcbor) |
| 46 | if(NOT qcbor_POPULATED) |
| 47 | message(STATUS "Fetching qcbor") |
| 48 | FetchContent_Populate(qcbor) |
| 49 | endif() |
| 50 | |
Julian Hall | caa4af8 | 2021-05-19 12:02:36 +0100 | [diff] [blame] | 51 | # Determine floating point configuration |
| 52 | if (TS_NO_FLOAT_HW) |
| 53 | set(_thirdparty_def -DQCBOR_DISABLE_FLOAT_HW_USE) |
| 54 | endif() |
| 55 | |
Julian Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 56 | # Configure the qcbor library |
Andrew Beggs | 97a00d4 | 2021-06-15 15:45:46 +0000 | [diff] [blame] | 57 | if (NOT "${QCBOR_EXTERNAL_INCLUDE_PATHS}" STREQUAL "") |
| 58 | string(REPLACE ";" "\\;" QCBOR_EXTERNAL_INCLUDE_PATHS "${QCBOR_EXTERNAL_INCLUDE_PATHS}") |
| 59 | set(QCBOR_EXTRA_OPTION -Dthirdparty_inc=${QCBOR_EXTERNAL_INCLUDE_PATHS}) |
| 60 | unset(QCBOR_EXTERNAL_INCLUDE_PATHS) |
| 61 | else() |
| 62 | set(QCBOR_EXTRA_OPTION "") |
| 63 | endif() |
| 64 | |
Julian Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 65 | execute_process(COMMAND |
Andrew Beggs | 97a00d4 | 2021-06-15 15:45:46 +0000 | [diff] [blame] | 66 | ${CMAKE_COMMAND} |
| 67 | -DCMAKE_TOOLCHAIN_FILE=${TS_EXTERNAL_LIB_TOOLCHAIN_FILE} |
| 68 | -GUnix\ Makefiles |
| 69 | -Dthirdparty_def=${_thirdparty_def} |
| 70 | -DCMAKE_INSTALL_PREFIX=${QCBOR_INSTALL_PATH} |
| 71 | ${QCBOR_EXTRA_OPTION} |
| 72 | ${qcbor_SOURCE_DIR} |
| 73 | WORKING_DIRECTORY |
| 74 | ${qcbor_BINARY_DIR} |
Julian Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 75 | ) |
Andrew Beggs | 97a00d4 | 2021-06-15 15:45:46 +0000 | [diff] [blame] | 76 | unset(QCBOR_EXTRA_OPTION) |
Julian Hall | 201ce46 | 2021-04-29 11:05:34 +0100 | [diff] [blame] | 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 ${qcbor_BINARY_DIR} --parallel ${PROCESSOR_COUNT} --target install |
Julian Hall | caa4af8 | 2021-05-19 12:02:36 +0100 | [diff] [blame] | 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") |