1# 2# Copyright (c) 2022 Nordic Semiconductor ASA 3# 4# SPDX-License-Identifier: Apache-2.0 5# 6 7cmake_minimum_required(VERSION 3.13.3) 8project (sample_pet) 9 10# The zcbor-generated files can be regenerated by calling this file with -DREGENERATE_ZCBOR=Y 11# This will call zcbor to regenerate the files, and then build like usual. 12if (REGENERATE_ZCBOR) 13 set (zcbor_command 14 zcbor code # Invoke code generation 15 --decode --encode # Generate both encoding and decoding code 16 --short-names # Attempt to make generated symbol names shorter (at the risk of collision) 17 -c ${CMAKE_CURRENT_LIST_DIR}/../../tests/cases/pet.cddl # Generate code for the data structures in pet.cddl 18 -t Pet # Create a public API for decoding/encoding the "Pet" type from pet.cddl 19 --output-cmake ${CMAKE_CURRENT_LIST_DIR}/pet.cmake # The generated cmake file will be placed here 20 # This also causes the c code to be placed in 21 # ${CMAKE_CURRENT_LIST_DIR}/src and ${CMAKE_CURRENT_LIST_DIR}/include) 22 --file-header "Copyright (c) 2022 Nordic Semiconductor ASA\n\nSPDX-License-Identifier: Apache-2.0" 23 ) 24 execute_process(COMMAND ${zcbor_command}) 25endif() 26 27# Convert the data in the pet1.yml file to CBOR and put the data in a header 28# file as a C array. 29set(py_command_convert_pet1 30 zcbor convert -c ${CMAKE_CURRENT_LIST_DIR}/../../tests/cases/pet.cddl -t Pet 31 -i ${CMAKE_CURRENT_LIST_DIR}/pet1.yml 32 -o ${PROJECT_BINARY_DIR}/include/pet1.h --c-code-var-name pet1 33 --yaml-compatibility 34 ) 35add_custom_target(pet1_yaml 36 COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/include 37 COMMAND ${py_command_convert_pet1} 38 ) 39 40# Include the cmake file generated by the regenerate_zcbor.sh file. It adds the 41# generated code and the necessary zcbor C code files. 42include(${CMAKE_CURRENT_LIST_DIR}/pet.cmake) 43 44add_executable(app src/main.c) 45 46# Link the library from pet.cmake 47target_link_libraries(app PRIVATE pet) 48add_dependencies(app pet1_yaml) 49 50# Add the directory containing pet1.h 51target_include_directories(app PRIVATE ${PROJECT_BINARY_DIR}/include) 52