blob: 1c7e081f993708ad1eef5956594a06367a174cba [file] [log] [blame]
Dávid Vincze92d3f892023-01-05 23:54:22 +01001#-------------------------------------------------------------------------------
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 Vincze306cfc22022-12-19 20:02:39 +01009cmake_minimum_required(VERSION 3.15)
10
Hannes Tschofenigac5763d2021-04-20 21:12:07 +020011project(qcbor
Dávid Vincze306cfc22022-12-19 20:02:39 +010012 DESCRIPTION "QCBOR"
13 LANGUAGES C
Laurence Lundbladeb74ebf92024-11-04 19:57:16 -080014 VERSION 1.5.0
Dávid Vincze306cfc22022-12-19 20:02:39 +010015)
Hannes Tschofenigac5763d2021-04-20 21:12:07 +020016
Dávid Vincze306cfc22022-12-19 20:02:39 +010017set(BUILD_QCBOR_TEST "OFF" CACHE STRING "Build QCBOR test suite [OFF, LIB, APP]")
18set(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.
23set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries instead of static ones")
Hannes Tschofenigac5763d2021-04-20 21:12:07 +020024
Dávid Vincze92d3f892023-01-05 23:54:22 +010025# Configuration:
26# Floating-point support (see README.md for more information)
27set(QCBOR_OPT_DISABLE_FLOAT_HW_USE OFF CACHE BOOL "Eliminate dependency on FP hardware and FP instructions")
28set(QCBOR_OPT_DISABLE_FLOAT_PREFERRED OFF CACHE BOOL "Eliminate support for half-precision and CBOR preferred serialization")
29set(QCBOR_OPT_DISABLE_FLOAT_ALL OFF CACHE BOOL "Eliminate floating-point support completely")
30
Dávid Vincze306cfc22022-12-19 20:02:39 +010031if (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)
34endif()
Hannes Tschofenigac5763d2021-04-20 21:12:07 +020035
Dávid Vincze306cfc22022-12-19 20:02:39 +010036add_library(qcbor)
rvanputten165ecfb2022-03-04 20:54:04 +010037
Dávid Vincze306cfc22022-12-19 20:02:39 +010038target_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
47target_include_directories(qcbor
48 PUBLIC
49 inc
50 PRIVATE
51 src
52)
53
Dávid Vincze92d3f892023-01-05 23:54:22 +010054target_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 Vincze306cfc22022-12-19 20:02:39 +010061if (BUILD_SHARED_LIBS)
62 target_compile_options(qcbor PRIVATE -Os -fPIC)
63endif()
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 Vincze92d3f892023-01-05 23:54:22 +010067if (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 )
73endif()
Dávid Vincze306cfc22022-12-19 20:02:39 +010074
Brian Sipos3e0bdc52024-05-30 05:40:30 -040075set(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)
84set_target_properties(
85 qcbor PROPERTIES
Brian Siposb05c2c12024-10-28 14:03:36 -040086 VERSION ${PROJECT_VERSION}
87 SOVERSION ${PROJECT_VERSION_MAJOR}
88 PUBLIC_HEADER "${HEADERS}"
Brian Sipos3e0bdc52024-05-30 05:40:30 -040089)
90include(GNUInstallDirs)
91install(
92 TARGETS qcbor
93 PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/qcbor"
94)
95
Dávid Vincze306cfc22022-12-19 20:02:39 +010096if (NOT BUILD_QCBOR_TEST STREQUAL "OFF")
97 add_subdirectory(test)
98endif()