1# Copyright (c) 2021, Basalte bv 2# 3# SPDX-License-Identifier: Apache-2.0 4 5if(CONFIG_NANOPB) 6 7 set(NANOPB_DIR ${ZEPHYR_CURRENT_MODULE_DIR}) 8 9 find_program(PROTOC protoc) 10 if(NOT PROTOC) 11 message(FATAL_ERROR "'protoc' not found, please ensure protoc is installed\ 12 and in path. See https://docs.zephyrproject.org/latest/samples/modules/nanopb/README.html") 13 endif() 14 15 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${NANOPB_DIR}/extra) 16 find_package(Nanopb REQUIRED) 17 18 zephyr_library() 19 20 zephyr_include_directories(${NANOPB_DIR}) 21 22 zephyr_library_sources( 23 ${NANOPB_DIR}/pb_common.c 24 ${NANOPB_DIR}/pb_encode.c 25 ${NANOPB_DIR}/pb_decode.c 26 ) 27 28 zephyr_compile_definitions( 29 PB_MAX_REQUIRED_FIELDS=${CONFIG_NANOPB_MAX_REQUIRED_FIELDS}) 30 31 zephyr_compile_definitions_ifdef( 32 CONFIG_NANOPB_ENABLE_MALLOC 33 PB_ENABLE_MALLOC 34 ) 35 36 zephyr_compile_definitions_ifdef( 37 CONFIG_NANOPB_NO_ERRMSG 38 PB_NO_ERRMSG 39 ) 40 41 zephyr_compile_definitions_ifdef( 42 CONFIG_NANOPB_BUFFER_ONLY 43 PB_BUFFER_ONLY 44 ) 45 46 zephyr_compile_definitions_ifdef( 47 CONFIG_NANOPB_WITHOUT_64BIT 48 PB_WITHOUT_64BIT 49 ) 50 51 zephyr_compile_definitions_ifdef( 52 CONFIG_NANOPB_ENCODE_ARRAYS_UNPACKED 53 PB_ENCODE_ARRAYS_UNPACKED 54 ) 55 56 zephyr_compile_definitions_ifdef( 57 CONFIG_NANOPB_VALIDATE_UTF8 58 PB_VALIDATE_UTF8 59 ) 60 61endif() 62