Using nanopb in configurable library outside of application folder #77494
Replies: 5 comments 4 replies
-
@pdgendt Maybe you can give me some help, I see you have some experience with the nanopb targets! |
Beta Was this translation helpful? Give feedback.
-
@pdgendt Thanks for your response.. From what I see, that example doesn't match what I'm trying to create. I have multiple application folders. I also have multiple library folders with .proto files For maintainability, the code is structured with lib, boards, drivers folders outside of the application folder. This is based on the zephyr example_application: https://github.com/zephyrproject-rtos/example-application I'm trying to create a structure like this; lib/CMakeLIsts.txt The application directories are parallel to the lib/schema folders: applications/mfg_app/CMakeLists.txt The application/prj.conf would only have a single additional line: How do I add proto targets to generate the .c and .h files in the lib/schemas/schema1/CMakeLists.txt? Perhaps we could make a PR to add a nanopb library to the example_application repo? a* |
Beta Was this translation helpful? Give feedback.
-
@pdgendt This is helping, I made some progress but not quite there yet. I did have to make a change, the library name from zephyr_library is complicated but its available from a variable $ZEPHYR_CURRENT_LIBRARY. I put this is the lib/schema1/CMakeLists.txt:
I also put this in the app/CMakeLists.txt
I didn't put the CONFIG_SCHEMA1 in the app directory since that is included from lib\CMakeLists.txt based on a Kconfig from lib\schema1\Kconfig However I still have a problem. I have an additional library we'll call it lib1, which provides functions using schema1. Its header file lib1.h includes schema1.pb.h.. When I compile main.c which include lib1.h and schema1.h In file included from XXX/app/src/main.c:16: It seems like main.c is compiled before hud_control.pb.h is generated or possibly the include directory is not setup correctly. I did find the schema1.pb.h is generated in the build directory Any ideas? |
Beta Was this translation helpful? Give feedback.
-
I think I have it working now. In the lib/schema1/CMakeLists.txt I have:
In my previous code I had forgotten the braces around CMAKE_CURRENT_BINARY_DIR |
Beta Was this translation helpful? Give feedback.
-
I have it working, thanks for the help! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am working on a project with multiple build variations off a common code base. All of the build variations use protobuf with nanopb but some of the protobuf files do not apply to some of the build variations. As an example there are multiple boards supported, each with multiple applications such as a manufacturing test application, and various customer-focused applications for different markets.
The general approach has been to place all these configurable library/modules into a folder where the CmakeLists.txt is conditionally included based on a Kconfig boolean flag such as CONFIG_LIB_OPTIONAL_PROTOBUF_COMPONENT1 Each of these conditional directories builds its files in a zephyr library, so the cmake usually has:
zephyr_include_directories(include)
zephyr_library()
zephyr_library_sources(library_source_file1.c)
The nanopb integration seems to be focused solely on protobuf files found directly in the application folder. This doesn't work in my application because the .proto files are share across multiple applications. In addition, they are actually placed into a submodule so the proto files can be shared with the mobile app developers.
I'm looking for advise on how to craft the configurable library's cmake file to:
Also what should I have in the application cmake to trigger building the common nanopb files, although there are not any application specific protobuf files.
thanks for any help!
Beta Was this translation helpful? Give feedback.
All reactions