blob: c37cb38dbc0bf33a962fad196ea607e9af745fb5 [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
Laurence Lundblade33ed26f2024-11-24 10:26:43 -080044 src/qcbor_number_decode.c
Dávid Vincze306cfc22022-12-19 20:02:39 +010045 src/qcbor_encode.c
46 src/qcbor_err_to_str.c
47 src/UsefulBuf.c
48)
49
50target_include_directories(qcbor
51 PUBLIC
52 inc
53 PRIVATE
54 src
55)
56
Dávid Vincze92d3f892023-01-05 23:54:22 +010057target_compile_definitions(qcbor
58 PRIVATE
59 $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>:QCBOR_DISABLE_FLOAT_HW_USE>
60 $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_PREFERRED}>:QCBOR_DISABLE_PREFERRED_FLOAT>
61 $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_ALL}>:USEFULBUF_DISABLE_ALL_FLOAT>
62)
63
Dávid Vincze306cfc22022-12-19 20:02:39 +010064if (BUILD_SHARED_LIBS)
65 target_compile_options(qcbor PRIVATE -Os -fPIC)
66endif()
67
68# The math library is needed for floating-point support.
69# To avoid need for it #define QCBOR_DISABLE_FLOAT_HW_USE
Dávid Vincze92d3f892023-01-05 23:54:22 +010070if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
71 # Using GCC
72 target_link_libraries(qcbor
73 PRIVATE
74 $<$<NOT:$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>>:m>
75 )
76endif()
Dávid Vincze306cfc22022-12-19 20:02:39 +010077
Brian Sipos3e0bdc52024-05-30 05:40:30 -040078set(HEADERS
79 inc/qcbor/qcbor.h
80 inc/qcbor/qcbor_common.h
81 inc/qcbor/qcbor_private.h
82 inc/qcbor/qcbor_encode.h
83 inc/qcbor/qcbor_decode.h
Laurence Lundblade721b56e2024-10-22 03:02:04 -070084 inc/qcbor/qcbor_tag_decode.h
Brian Sipos3e0bdc52024-05-30 05:40:30 -040085 inc/qcbor/qcbor_spiffy_decode.h
86 inc/qcbor/UsefulBuf.h
87)
88set_target_properties(
89 qcbor PROPERTIES
Brian Siposb05c2c12024-10-28 14:03:36 -040090 VERSION ${PROJECT_VERSION}
91 SOVERSION ${PROJECT_VERSION_MAJOR}
92 PUBLIC_HEADER "${HEADERS}"
Brian Sipos3e0bdc52024-05-30 05:40:30 -040093)
94include(GNUInstallDirs)
95install(
96 TARGETS qcbor
97 PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/qcbor"
98)
99
Dávid Vincze306cfc22022-12-19 20:02:39 +0100100if (NOT BUILD_QCBOR_TEST STREQUAL "OFF")
101 add_subdirectory(test)
102endif()