3
3
# Author: Pavel Kirienko <[email protected] >
4
4
5
5
cmake_minimum_required (VERSION 3.17 )
6
- project (differential_pressure_sensor C CXX )
7
- set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR} /cmake/modules" )
6
+ project (differential_pressure_sensor C )
8
7
9
- set (submodules "${CMAKE_SOURCE_DIR} /../submodules" )
8
+ set (submodules "${CMAKE_CURRENT_SOURCE_DIR} /../submodules" )
9
+ set (CMAKE_PREFIX_PATH "${submodules} /nunavut" )
10
10
11
11
set (CMAKE_C_STANDARD 11 )
12
12
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -pedantic -fstrict-aliasing" )
@@ -17,7 +17,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-conversion -Wcast-align -Wmissing-dec
17
17
# Forward the revision information to the compiler so that we could expose it at runtime. This is entirely optional.
18
18
execute_process (
19
19
COMMAND git rev-parse --short=16 HEAD
20
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR }
20
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR }
21
21
OUTPUT_VARIABLE vcs_revision_id
22
22
OUTPUT_STRIP_TRAILING_WHITESPACE
23
23
)
@@ -29,39 +29,32 @@ add_definitions(
29
29
-DNODE_NAME= "org.opencyphal.demos.differential_pressure"
30
30
)
31
31
32
- # Transpile DSDL into C using Nunavut. Install Nunavut as follows: pip install nunavut.
33
- # Alternatively, you can invoke the transpiler manually or use https://nunaweb.opencyphal.org.
34
- find_package (nnvg REQUIRED )
35
- create_dsdl_target ( # Generate the support library for generated C headers, which is "nunavut.h".
36
- "nunavut_support"
37
- c
38
- ${CMAKE_BINARY_DIR} /transpiled
39
- ""
40
- OFF
41
- little
42
- "only"
32
+ ## Transpile DSDL into C using Nunavut. This uses this repo's built-in submodules to setup Nunavut. See
33
+ # CMAKE_PREFIX_PATH above for how this is resolved to the local submodules.
34
+ find_package (Nunavut 3.0 REQUIRED )
35
+
36
+ set (LOCAL_PUBLIC_TYPES
37
+ uavcan/node/430.GetInfo.1.0.dsdl
38
+ uavcan/node/435.ExecuteCommand.1.1.dsdl
39
+ uavcan/node/7509.Heartbeat.1.0.dsdl
40
+ uavcan/node/port/7510.List.0.1.dsdl
41
+ uavcan/pnp/8165.NodeIDAllocationData.2.0.dsdl
42
+ uavcan/register/384.Access.1.0.dsdl
43
+ uavcan/register/385.List.1.0.dsdl
44
+ uavcan/si/unit/pressure/Scalar.1.0.dsdl
45
+ uavcan/si/unit/temperature/Scalar.1.0.dsdl
43
46
)
44
- set (dsdl_root_namespace_dirs # List all DSDL root namespaces to transpile here.
45
- ${submodules} /public_regulated_data_types/uavcan
46
- ${submodules} /public_regulated_data_types/reg
47
+
48
+ add_cyphal_library (
49
+ NAME dsdl_uavcan
50
+ EXACT_NAME
51
+ LANGUAGE c
52
+ LANGUAGE_STANDARD c${CMAKE_C_STANDARD}
53
+ DSDL_FILES ${LOCAL_PUBLIC_TYPES}
54
+ SERIALIZATION_ASSERT assert
55
+ EXPORT_MANIFEST
56
+ OUT_LIBRARY_TARGET LOCAL_TYPES_C_LIBRARY
47
57
)
48
- foreach (ns_dir ${dsdl_root_namespace_dirs} )
49
- get_filename_component (ns ${ns_dir} NAME )
50
- message (STATUS "DSDL namespace ${ns} at ${ns_dir} " )
51
- create_dsdl_target (
52
- "dsdl_${ns} " # CMake target name
53
- c # Target language to transpile into
54
- ${CMAKE_BINARY_DIR} /transpiled # Destination directory (add it to the includes)
55
- ${ns_dir} # Source directory
56
- OFF # Disable variable array capacity override
57
- little # Endianness of the target platform (alternatives: "big", "any")
58
- "never" # Support files are generated once in the nunavut_support target (above)
59
- ${dsdl_root_namespace_dirs} # Look-up DSDL namespaces
60
- )
61
- add_dependencies ("dsdl_${ns} " nunavut_support )
62
- endforeach ()
63
- include_directories (SYSTEM ${CMAKE_BINARY_DIR} /transpiled ) # Make the transpiled headers available for inclusion.
64
- add_definitions (-DNUNAVUT_ASSERT=assert )
65
58
66
59
# Build libcanard.
67
60
add_library (canard STATIC ${submodules} /libcanard/libcanard/canard.c )
@@ -71,12 +64,21 @@ include_directories(SYSTEM ${submodules}/libcanard/libcanard)
71
64
add_library (o1heap STATIC ${submodules} /o1heap/o1heap/o1heap.c )
72
65
include_directories (SYSTEM ${submodules} /o1heap/o1heap/ )
73
66
74
- include (${CMAKE_SOURCE_DIR} /../shared/register/register.cmake )
75
- include (${CMAKE_SOURCE_DIR} /../shared/socketcan/socketcan.cmake )
67
+ include (${CMAKE_CURRENT_SOURCE_DIR} /../shared/register/register.cmake )
68
+ target_link_libraries (shared_register
69
+ PRIVATE ${LOCAL_TYPES_C_LIBRARY}
70
+ )
71
+
72
+ include (${CMAKE_CURRENT_SOURCE_DIR} /../shared/socketcan/socketcan.cmake )
76
73
77
74
# Build the application.
78
75
add_executable (differential_pressure_sensor
79
76
src/main.c
80
77
)
81
- add_dependencies (differential_pressure_sensor dsdl_uavcan dsdl_reg )
82
- target_link_libraries (differential_pressure_sensor canard o1heap shared_register shared_socketcan )
78
+ target_link_libraries (differential_pressure_sensor
79
+ ${LOCAL_TYPES_C_LIBRARY}
80
+ canard
81
+ o1heap
82
+ shared_register
83
+ shared_socketcan
84
+ )
0 commit comments