Dávid Vincze | 92d3f89 | 2023-01-05 23:54:22 +0100 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2022-2023, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | # See BSD-3-Clause license in README.md |
| 7 | #------------------------------------------------------------------------------- |
| 8 | |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 9 | cmake_minimum_required(VERSION 3.15) |
| 10 | |
Hannes Tschofenig | ac5763d | 2021-04-20 21:12:07 +0200 | [diff] [blame] | 11 | project(qcbor |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 12 | DESCRIPTION "QCBOR" |
| 13 | LANGUAGES C |
| 14 | VERSION 1.1.0 |
| 15 | ) |
Hannes Tschofenig | ac5763d | 2021-04-20 21:12:07 +0200 | [diff] [blame] | 16 | |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 17 | set(BUILD_QCBOR_TEST "OFF" CACHE STRING "Build QCBOR test suite [OFF, LIB, APP]") |
| 18 | set(BUILD_QCBOR_WARN OFF CACHE BOOL "Compile with the warning flags used in the QCBOR release process") |
| 19 | # BUILD_SHARED_LIBS is a built-in global CMake flag |
| 20 | # The shared library is not made by default because of platform |
| 21 | # variability For example MacOS and Linux behave differently and some |
| 22 | # IoT OS's don't support them at all. |
| 23 | set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries instead of static ones") |
Hannes Tschofenig | ac5763d | 2021-04-20 21:12:07 +0200 | [diff] [blame] | 24 | |
Dávid Vincze | 92d3f89 | 2023-01-05 23:54:22 +0100 | [diff] [blame] | 25 | # Configuration: |
| 26 | # Floating-point support (see README.md for more information) |
| 27 | set(QCBOR_OPT_DISABLE_FLOAT_HW_USE OFF CACHE BOOL "Eliminate dependency on FP hardware and FP instructions") |
| 28 | set(QCBOR_OPT_DISABLE_FLOAT_PREFERRED OFF CACHE BOOL "Eliminate support for half-precision and CBOR preferred serialization") |
| 29 | set(QCBOR_OPT_DISABLE_FLOAT_ALL OFF CACHE BOOL "Eliminate floating-point support completely") |
| 30 | |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 31 | if (BUILD_QCBOR_WARN) |
| 32 | # Compile options applying to all targets in current directory and below |
| 33 | add_compile_options(-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wcast-qual) |
| 34 | endif() |
Hannes Tschofenig | ac5763d | 2021-04-20 21:12:07 +0200 | [diff] [blame] | 35 | |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 36 | add_library(qcbor) |
rvanputten | 165ecfb | 2022-03-04 20:54:04 +0100 | [diff] [blame] | 37 | |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 38 | target_sources(qcbor |
| 39 | PRIVATE |
| 40 | src/ieee754.c |
| 41 | src/qcbor_decode.c |
| 42 | src/qcbor_encode.c |
| 43 | src/qcbor_err_to_str.c |
| 44 | src/UsefulBuf.c |
| 45 | ) |
| 46 | |
| 47 | target_include_directories(qcbor |
| 48 | PUBLIC |
| 49 | inc |
| 50 | PRIVATE |
| 51 | src |
| 52 | ) |
| 53 | |
Dávid Vincze | 92d3f89 | 2023-01-05 23:54:22 +0100 | [diff] [blame] | 54 | target_compile_definitions(qcbor |
| 55 | PRIVATE |
| 56 | $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>:QCBOR_DISABLE_FLOAT_HW_USE> |
| 57 | $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_PREFERRED}>:QCBOR_DISABLE_PREFERRED_FLOAT> |
| 58 | $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_ALL}>:USEFULBUF_DISABLE_ALL_FLOAT> |
| 59 | ) |
| 60 | |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 61 | if (BUILD_SHARED_LIBS) |
| 62 | target_compile_options(qcbor PRIVATE -Os -fPIC) |
| 63 | endif() |
| 64 | |
| 65 | # The math library is needed for floating-point support. |
| 66 | # To avoid need for it #define QCBOR_DISABLE_FLOAT_HW_USE |
Dávid Vincze | 92d3f89 | 2023-01-05 23:54:22 +0100 | [diff] [blame] | 67 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU") |
| 68 | # Using GCC |
| 69 | target_link_libraries(qcbor |
| 70 | PRIVATE |
| 71 | $<$<NOT:$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>>:m> |
| 72 | ) |
| 73 | endif() |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 74 | |
Brian Sipos | 3e0bdc5 | 2024-05-30 05:40:30 -0400 | [diff] [blame] | 75 | set(HEADERS |
| 76 | inc/qcbor/qcbor.h |
| 77 | inc/qcbor/qcbor_common.h |
| 78 | inc/qcbor/qcbor_private.h |
| 79 | inc/qcbor/qcbor_encode.h |
| 80 | inc/qcbor/qcbor_decode.h |
| 81 | inc/qcbor/qcbor_spiffy_decode.h |
| 82 | inc/qcbor/UsefulBuf.h |
| 83 | ) |
| 84 | set_target_properties( |
| 85 | qcbor PROPERTIES |
| 86 | PUBLIC_HEADER "${HEADERS}" |
| 87 | ) |
| 88 | include(GNUInstallDirs) |
| 89 | install( |
| 90 | TARGETS qcbor |
| 91 | PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/qcbor" |
| 92 | ) |
| 93 | |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 94 | if (NOT BUILD_QCBOR_TEST STREQUAL "OFF") |
| 95 | add_subdirectory(test) |
| 96 | endif() |