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