blob: 3c439882ea2dd81a5072205a43e2aad6a86894cd [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
41 src/ieee754.c
Laurence Lundblade926ccfc2024-12-05 20:34:55 -080042 src/qcbor_main_decode.c
Laurence Lundblade41e40d52024-12-01 10:29:33 -080043 src/qcbor_spiffy_decode.c
Laurence Lundblade721b56e2024-10-22 03:02:04 -070044 src/qcbor_tag_decode.c
Laurence Lundblade33ed26f2024-11-24 10:26:43 -080045 src/qcbor_number_decode.c
Dávid Vincze306cfc22022-12-19 20:02:39 +010046 src/qcbor_encode.c
47 src/qcbor_err_to_str.c
48 src/UsefulBuf.c
49)
50
51target_include_directories(qcbor
52 PUBLIC
53 inc
54 PRIVATE
55 src
56)
57
Dávid Vincze92d3f892023-01-05 23:54:22 +010058target_compile_definitions(qcbor
59 PRIVATE
60 $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>:QCBOR_DISABLE_FLOAT_HW_USE>
61 $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_PREFERRED}>:QCBOR_DISABLE_PREFERRED_FLOAT>
62 $<$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_ALL}>:USEFULBUF_DISABLE_ALL_FLOAT>
63)
64
Dávid Vincze306cfc22022-12-19 20:02:39 +010065if (BUILD_SHARED_LIBS)
66 target_compile_options(qcbor PRIVATE -Os -fPIC)
67endif()
68
69# The math library is needed for floating-point support.
70# To avoid need for it #define QCBOR_DISABLE_FLOAT_HW_USE
Dávid Vincze92d3f892023-01-05 23:54:22 +010071if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
72 # Using GCC
73 target_link_libraries(qcbor
74 PRIVATE
75 $<$<NOT:$<BOOL:${QCBOR_OPT_DISABLE_FLOAT_HW_USE}>>:m>
76 )
77endif()
Dávid Vincze306cfc22022-12-19 20:02:39 +010078
Brian Sipos3e0bdc52024-05-30 05:40:30 -040079set(HEADERS
80 inc/qcbor/qcbor.h
81 inc/qcbor/qcbor_common.h
82 inc/qcbor/qcbor_private.h
83 inc/qcbor/qcbor_encode.h
84 inc/qcbor/qcbor_decode.h
Laurence Lundbladecf49acc2024-12-08 20:48:31 -070085 inc/qcbor/qcbor_number_decode.h
86 inc/qcbor/qcbor_main_decode.h
Laurence Lundblade721b56e2024-10-22 03:02:04 -070087 inc/qcbor/qcbor_tag_decode.h
Brian Sipos3e0bdc52024-05-30 05:40:30 -040088 inc/qcbor/qcbor_spiffy_decode.h
89 inc/qcbor/UsefulBuf.h
90)
91set_target_properties(
92 qcbor PROPERTIES
Brian Siposb05c2c12024-10-28 14:03:36 -040093 VERSION ${PROJECT_VERSION}
94 SOVERSION ${PROJECT_VERSION_MAJOR}
95 PUBLIC_HEADER "${HEADERS}"
Brian Sipos3e0bdc52024-05-30 05:40:30 -040096)
97include(GNUInstallDirs)
98install(
99 TARGETS qcbor
100 PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/qcbor"
101)
102
Dávid Vincze306cfc22022-12-19 20:02:39 +0100103if (NOT BUILD_QCBOR_TEST STREQUAL "OFF")
104 add_subdirectory(test)
105endif()