Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.15) |
| 2 | |
Hannes Tschofenig | ac5763d | 2021-04-20 21:12:07 +0200 | [diff] [blame] | 3 | project(qcbor |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 4 | DESCRIPTION "QCBOR" |
| 5 | LANGUAGES C |
| 6 | VERSION 1.1.0 |
| 7 | ) |
Hannes Tschofenig | ac5763d | 2021-04-20 21:12:07 +0200 | [diff] [blame] | 8 | |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 9 | set(BUILD_QCBOR_TEST "OFF" CACHE STRING "Build QCBOR test suite [OFF, LIB, APP]") |
| 10 | set(BUILD_QCBOR_WARN OFF CACHE BOOL "Compile with the warning flags used in the QCBOR release process") |
| 11 | # BUILD_SHARED_LIBS is a built-in global CMake flag |
| 12 | # The shared library is not made by default because of platform |
| 13 | # variability For example MacOS and Linux behave differently and some |
| 14 | # IoT OS's don't support them at all. |
| 15 | set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries instead of static ones") |
Hannes Tschofenig | ac5763d | 2021-04-20 21:12:07 +0200 | [diff] [blame] | 16 | |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 17 | if (BUILD_QCBOR_WARN) |
| 18 | # Compile options applying to all targets in current directory and below |
| 19 | add_compile_options(-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wcast-qual) |
| 20 | endif() |
Hannes Tschofenig | ac5763d | 2021-04-20 21:12:07 +0200 | [diff] [blame] | 21 | |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 22 | add_library(qcbor) |
rvanputten | 165ecfb | 2022-03-04 20:54:04 +0100 | [diff] [blame] | 23 | |
Dávid Vincze | 306cfc2 | 2022-12-19 20:02:39 +0100 | [diff] [blame] | 24 | target_sources(qcbor |
| 25 | PRIVATE |
| 26 | src/ieee754.c |
| 27 | src/qcbor_decode.c |
| 28 | src/qcbor_encode.c |
| 29 | src/qcbor_err_to_str.c |
| 30 | src/UsefulBuf.c |
| 31 | ) |
| 32 | |
| 33 | target_include_directories(qcbor |
| 34 | PUBLIC |
| 35 | inc |
| 36 | PRIVATE |
| 37 | src |
| 38 | ) |
| 39 | |
| 40 | if (BUILD_SHARED_LIBS) |
| 41 | target_compile_options(qcbor PRIVATE -Os -fPIC) |
| 42 | endif() |
| 43 | |
| 44 | # The math library is needed for floating-point support. |
| 45 | # To avoid need for it #define QCBOR_DISABLE_FLOAT_HW_USE |
| 46 | target_link_libraries(qcbor PRIVATE m) |
| 47 | |
| 48 | if (NOT BUILD_QCBOR_TEST STREQUAL "OFF") |
| 49 | add_subdirectory(test) |
| 50 | endif() |