blob: f3bedd2c8c401adcb62623a9ec68d583824475ed [file] [log] [blame]
Dávid Vincze92d3f892023-01-05 23:54:22 +01001#-------------------------------------------------------------------------------
2# Copyright (c) 2022-2023, Arm Limited. All rights reserved.
Laurence Lundblade721b56e2024-10-22 03:02:04 -07003# Copyright (c) 2024, Laurence Lundblade. All rights reserved.
Dávid Vincze92d3f892023-01-05 23:54:22 +01004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7# See BSD-3-Clause license in README.md
8#-------------------------------------------------------------------------------
9
Dávid Vincze306cfc22022-12-19 20:02:39 +010010cmake_minimum_required(VERSION 3.15)
11
Hannes Tschofenigac5763d2021-04-20 21:12:07 +020012project(qcbor
Dávid Vincze306cfc22022-12-19 20:02:39 +010013 DESCRIPTION "QCBOR"
14 LANGUAGES C
15 VERSION 1.1.0
16)
Hannes Tschofenigac5763d2021-04-20 21:12:07 +020017
Dávid Vincze306cfc22022-12-19 20:02:39 +010018set(BUILD_QCBOR_TEST "OFF" CACHE STRING "Build QCBOR test suite [OFF, LIB, APP]")
19set(BUILD_QCBOR_WARN OFF CACHE BOOL "Compile with the warning flags used in the QCBOR release process")
20# BUILD_SHARED_LIBS is a built-in global CMake flag
21# The shared library is not made by default because of platform
22# variability For example MacOS and Linux behave differently and some
23# IoT OS's don't support them at all.
24set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries instead of static ones")
Hannes Tschofenigac5763d2021-04-20 21:12:07 +020025
Dávid Vincze92d3f892023-01-05 23:54:22 +010026# Configuration:
27# Floating-point support (see README.md for more information)
28set(QCBOR_OPT_DISABLE_FLOAT_HW_USE OFF CACHE BOOL "Eliminate dependency on FP hardware and FP instructions")
29set(QCBOR_OPT_DISABLE_FLOAT_PREFERRED OFF CACHE BOOL "Eliminate support for half-precision and CBOR preferred serialization")
30set(QCBOR_OPT_DISABLE_FLOAT_ALL OFF CACHE BOOL "Eliminate floating-point support completely")
31
Dávid Vincze306cfc22022-12-19 20:02:39 +010032if (BUILD_QCBOR_WARN)
33 # Compile options applying to all targets in current directory and below
34 add_compile_options(-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wcast-qual)
35endif()
Hannes Tschofenigac5763d2021-04-20 21:12:07 +020036
Dávid Vincze306cfc22022-12-19 20:02:39 +010037add_library(qcbor)
rvanputten165ecfb2022-03-04 20:54:04 +010038
Dávid Vincze306cfc22022-12-19 20:02:39 +010039target_sources(qcbor
40 PRIVATE
41 src/ieee754.c
42 src/qcbor_decode.c
Laurence Lundblade721b56e2024-10-22 03:02:04 -070043 src/qcbor_tag_decode.c
Dávid Vincze306cfc22022-12-19 20:02:39 +010044 src/qcbor_encode.c
45 src/qcbor_err_to_str.c
46 src/UsefulBuf.c
47)
48
49target_include_directories(qcbor
50 PUBLIC
51 inc
52 PRIVATE
53 src
54)
55
Dávid Vincze92d3f892023-01-05 23:54:22 +010056target_compile_definitions(qcbor
57 PRIVATE
58 $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>:QCBOR_DISABLE_FLOAT_HW_USE>
59 $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_PREFERRED}>:QCBOR_DISABLE_PREFERRED_FLOAT>
60 $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_ALL}>:USEFULBUF_DISABLE_ALL_FLOAT>
61)
62
Dávid Vincze306cfc22022-12-19 20:02:39 +010063if (BUILD_SHARED_LIBS)
64 target_compile_options(qcbor PRIVATE -Os -fPIC)
65endif()
66
67# The math library is needed for floating-point support.
68# To avoid need for it #define QCBOR_DISABLE_FLOAT_HW_USE
Dávid Vincze92d3f892023-01-05 23:54:22 +010069if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
70 # Using GCC
71 target_link_libraries(qcbor
72 PRIVATE
73 $<$<NOT:$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>>:m>
74 )
75endif()
Dávid Vincze306cfc22022-12-19 20:02:39 +010076
Brian Sipos3e0bdc52024-05-30 05:40:30 -040077set(HEADERS
78 inc/qcbor/qcbor.h
79 inc/qcbor/qcbor_common.h
80 inc/qcbor/qcbor_private.h
81 inc/qcbor/qcbor_encode.h
82 inc/qcbor/qcbor_decode.h
Laurence Lundblade721b56e2024-10-22 03:02:04 -070083 inc/qcbor/qcbor_tag_decode.h
Brian Sipos3e0bdc52024-05-30 05:40:30 -040084 inc/qcbor/qcbor_spiffy_decode.h
85 inc/qcbor/UsefulBuf.h
86)
87set_target_properties(
88 qcbor PROPERTIES
Brian Siposb05c2c12024-10-28 14:03:36 -040089 VERSION ${PROJECT_VERSION}
90 SOVERSION ${PROJECT_VERSION_MAJOR}
91 PUBLIC_HEADER "${HEADERS}"
Brian Sipos3e0bdc52024-05-30 05:40:30 -040092)
93include(GNUInstallDirs)
94install(
95 TARGETS qcbor
96 PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/qcbor"
97)
98
Dávid Vincze306cfc22022-12-19 20:02:39 +010099if (NOT BUILD_QCBOR_TEST STREQUAL "OFF")
100 add_subdirectory(test)
101endif()