Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame^] | 1 | # |
| 2 | # SPDX-License-Identifier: BSD-3-Clause |
| 3 | # SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | # |
| 5 | |
| 6 | add_subdirectory("ext/qcbor") |
| 7 | |
| 8 | # |
| 9 | # Set up qcbor using our own libc. This is done by getting certain properties |
| 10 | # from our libc target and applying them to qcbor - not ideal, but qcbor |
| 11 | # doesn't provide an interface library for us to use. |
| 12 | # |
| 13 | get_target_property(system_includes rmm-lib-libc |
| 14 | INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) |
| 15 | get_target_property(includes rmm-lib-libc |
| 16 | INTERFACE_INCLUDE_DIRECTORIES) |
| 17 | get_target_property(definitions rmm-lib-libc |
| 18 | INTERFACE_COMPILE_DEFINITIONS) |
| 19 | get_target_property(options rmm-lib-libc |
| 20 | INTERFACE_COMPILE_OPTIONS) |
| 21 | |
| 22 | # |
| 23 | # System include directories appear in both the `SYSTEM_INCLUDE_DIRECTORIES` and |
| 24 | # `INCLUDE_DIRECTORIES` properties, so filter them out of the latter. |
| 25 | # |
| 26 | list(REMOVE_ITEM includes ${system_includes}) |
| 27 | |
| 28 | # |
| 29 | # Target properties that are not set return `<PROPERTY>-NOTFOUND`. Clear any |
| 30 | # variables where this occurred. |
| 31 | # |
| 32 | foreach(set IN ITEMS system_includes includes definitions options) |
| 33 | if(NOT ${set}) |
| 34 | set(${set}) |
| 35 | endif() |
| 36 | endforeach() |
| 37 | |
| 38 | # QCBOR custom definitions |
| 39 | list(APPEND definitions "QCBOR_DISABLE_FLOAT_HW_USE") |
| 40 | list(APPEND definitions "USEFULBUF_DISABLE_ALL_FLOAT") |
| 41 | |
| 42 | # |
| 43 | # Create compiler flags from the libc properties we retrieved. |
| 44 | # |
| 45 | list(TRANSFORM definitions PREPEND " -D") |
| 46 | |
| 47 | foreach(set IN ITEMS options definitions) |
| 48 | string(REPLACE ";" " " ${set} "${${set}}") |
| 49 | endforeach() |
| 50 | |
| 51 | string(PREPEND qcbor_C_FLAGS "${definitions} ") |
| 52 | # Add the relevant build flags. TODO: Currently CBOR is only passed Release build flag |
| 53 | string(PREPEND qcbor_C_FLAGS "${options} ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE} ") |
| 54 | string(PREPEND qcbor_C_FLAGS "-Wno-maybe-uninitialized ") |
| 55 | |
| 56 | string(REPLACE " " ";" qcbor_C_FLAGS ${qcbor_C_FLAGS}) |
| 57 | |
| 58 | # |
| 59 | # qcbor's build system ignores and overwrites the flags we specify in our |
| 60 | # toolchain files. Un-overwrite them, because they're there for a good reason. |
| 61 | # |
| 62 | target_include_directories(qcbor |
| 63 | PUBLIC "${RMM_SOURCE_DIR}/ext/qcbor/inc" |
| 64 | ) |
| 65 | |
| 66 | target_include_directories(qcbor |
| 67 | PRIVATE |
| 68 | ${includes} |
| 69 | ${system_includes} |
| 70 | ) |
| 71 | |
| 72 | target_compile_options(qcbor |
| 73 | PRIVATE |
| 74 | ${qcbor_C_FLAGS} |
| 75 | ) |
| 76 | |
| 77 | target_link_libraries(qcbor |
| 78 | PRIVATE |
| 79 | rmm-lib-libc |
| 80 | ) |
| 81 | |
| 82 | link_libraries(qcbor) |