blob: d2d950a7079c8bceec1a29a7bb37a1854fda05d9 [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
Laurence Lundbladecf49acc2024-12-08 20:48:31 -070015 VERSION 2.0.0
Dávid Vincze306cfc22022-12-19 20:02:39 +010016)
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
Laurence Lundblade7596eef2024-12-21 10:08:32 -070041 src/qcbor_main_encode.c
42 src/qcbor_number_encode.c
Dávid Vincze306cfc22022-12-19 20:02:39 +010043 src/ieee754.c
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080044 src/qcbor_main_decode.c
Laurence Lundblade41e40d52024-12-01 10:29:33 -080045 src/qcbor_spiffy_decode.c
Laurence Lundblade721b56e2024-10-22 03:02:04 -070046 src/qcbor_tag_decode.c
Laurence Lundblade33ed26f2024-11-24 10:26:43 -080047 src/qcbor_number_decode.c
Dávid Vincze306cfc22022-12-19 20:02:39 +010048 src/qcbor_err_to_str.c
49 src/UsefulBuf.c
50)
51
52target_include_directories(qcbor
53 PUBLIC
54 inc
55 PRIVATE
56 src
57)
58
Dávid Vincze92d3f892023-01-05 23:54:22 +010059target_compile_definitions(qcbor
60 PRIVATE
61 $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>:QCBOR_DISABLE_FLOAT_HW_USE>
62 $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_PREFERRED}>:QCBOR_DISABLE_PREFERRED_FLOAT>
63 $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_ALL}>:USEFULBUF_DISABLE_ALL_FLOAT>
64)
65
Dávid Vincze306cfc22022-12-19 20:02:39 +010066if (BUILD_SHARED_LIBS)
67 target_compile_options(qcbor PRIVATE -Os -fPIC)
68endif()
69
70# The math library is needed for floating-point support.
71# To avoid need for it #define QCBOR_DISABLE_FLOAT_HW_USE
Dávid Vincze92d3f892023-01-05 23:54:22 +010072if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
73 # Using GCC
74 target_link_libraries(qcbor
75 PRIVATE
76 $<$<NOT:$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>>:m>
77 )
78endif()
Dávid Vincze306cfc22022-12-19 20:02:39 +010079
Brian Sipos3e0bdc52024-05-30 05:40:30 -040080set(HEADERS
81 inc/qcbor/qcbor.h
82 inc/qcbor/qcbor_common.h
83 inc/qcbor/qcbor_private.h
84 inc/qcbor/qcbor_encode.h
85 inc/qcbor/qcbor_decode.h
Laurence Lundbladecf49acc2024-12-08 20:48:31 -070086 inc/qcbor/qcbor_number_decode.h
87 inc/qcbor/qcbor_main_decode.h
Laurence Lundblade721b56e2024-10-22 03:02:04 -070088 inc/qcbor/qcbor_tag_decode.h
Brian Sipos3e0bdc52024-05-30 05:40:30 -040089 inc/qcbor/qcbor_spiffy_decode.h
90 inc/qcbor/UsefulBuf.h
91)
92set_target_properties(
93 qcbor PROPERTIES
Brian Siposb05c2c12024-10-28 14:03:36 -040094 VERSION ${PROJECT_VERSION}
95 SOVERSION ${PROJECT_VERSION_MAJOR}
96 PUBLIC_HEADER "${HEADERS}"
Brian Sipos3e0bdc52024-05-30 05:40:30 -040097)
98include(GNUInstallDirs)
99install(
100 TARGETS qcbor
101 PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/qcbor"
102)
103
Dávid Vincze306cfc22022-12-19 20:02:39 +0100104if (NOT BUILD_QCBOR_TEST STREQUAL "OFF")
105 add_subdirectory(test)
106endif()