Skip to content

Commit

Permalink
chore(cmake): dependency to ensure pb files are generated (#39)
Browse files Browse the repository at this point in the history
see nanopb.cmake in zephyr 4+, specifically custom target
`nanopb_generated_headers` which has a new dependency: the custom target
 used to generate proto files

Signed-off-by: Cyril Fougeray <[email protected]>
  • Loading branch information
fouge authored Jan 31, 2025
1 parent 3dffed6 commit 62bb55b
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@
set(TARGET ORB_MCU_MESSAGING_LIB)

if (CONFIG_ORB_MCU_MESSAGING_LIB)
# check that the proto compiler is installed
find_program(PROTOC protoc)
if (NOT PROTOC)
message(FATAL_ERROR "'protoc' not found, please ensure protoc is installed\
and in path. See https://docs.zephyrproject.org/latest/samples/modules/nanopb/README.html")
endif ()

# import nanopb function from the library itself
if (NOT DEFINED WORKSPACE_DIR)
get_filename_component(WORKSPACE_DIR ${ZEPHYR_BASE} DIRECTORY)
endif ()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${WORKSPACE_DIR}/modules/lib/nanopb/extra)
find_package(Nanopb REQUIRED)
# include nanopb to perform checks, see nanopb.cmake
list(APPEND CMAKE_MODULE_PATH ${ZEPHYR_BASE}/modules/nanopb)
include(nanopb)

set(NANOPB_OPTIONS "-I${CMAKE_CURRENT_SOURCE_DIR}/../messages/")

Expand Down Expand Up @@ -48,16 +38,13 @@ if (CONFIG_ORB_MCU_MESSAGING_LIB)
${proto_headers}
)

zephyr_interface_library_named(${TARGET})
# see nanopb.cmake
add_dependencies(nanopb_generated_headers generate_proto_files)

target_include_directories(${TARGET} INTERFACE
${CMAKE_CURRENT_BINARY_DIR}
)

zephyr_library()
zephyr_interface_library_named(${TARGET})
zephyr_include_directories(${CMAKE_CURRENT_BINARY_DIR})
zephyr_library_sources(
${SRC_FILES}
)
zephyr_library_link_libraries(${TARGET})
target_link_libraries(${TARGET} INTERFACE zephyr_interface)
zephyr_link_libraries_ifdef(CONFIG_ORB_MCU_MESSAGING_LIB ${TARGET})
endif ()

0 comments on commit 62bb55b

Please sign in to comment.