Skip to content

Conversation

@benedekkupper
Copy link

These changes make the protobuf code generation and build steps all managed by cmake, no additional steps are necessary. Dependent projects can

  1. add this as a subdirectory, or use FetchContent
  2. link to EmbeddedProto static library
  3. generate and include the protobuf headers (e.g. as done in the ./CMakeLists.txt file) with generate_embedded_proto
  4. define custom target, which depends on these headers, and add the dependency to your project

These changes make the protobuf code generation and build
steps all managed by cmake, no additional steps are necessary.
@BartHertog
Copy link
Contributor

Hello @benedekkupper,

Thank you for your effort in sending in this pull request. I will look at this later in the week.

Best regards,

Bart

@BartHertog
Copy link
Contributor

Hello @benedekkupper,
I took some time to look at your pull request. The reason is that similar functionality is already implemented in the develop-v4 branch. Development of version 4 is taking longer than hoped, so I am considering if it is beneficial for all users to include this. On the other hand, this is only required for the development of Embedded Proto unless the CMake functions can be called from a different CMake file to build Embedded Proto as a library.

How are you using this code now?

@benedekkupper
Copy link
Author

I'm using this modification to completely automate the build of EmbeddedProto. With these changes I only need to check out the repo and run build_test.sh to get everything built. In the project itself, the integration is also easy. Since I'm using a west workspace (known from zephyr RTOS) with multiple projects, I cannot just add this library as a submodule, I use FetchContent_Declare(EmbeddedProto SOURCE_DIR [...]) and FetchContent_MakeAvailable(EmbeddedProto). After this library is fetched, I can call generate_embedded_proto without any further include needed. The rest is just like in the main cmake file, use add_custom_target() to link the generated files to a target, then add_dependencies to link this target to the target which needs these generated header files. In my case:

    generate_embedded_proto(PROTO_HEADERS
        OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto
        INCLUDE_DIRS
            .
        PROTO_FILES
            ${PROTO_FILES}
    )
    add_custom_target(my_proto_gen_files DEPENDS ${PROTO_HEADERS})
    add_library(                my_protobuf INTERFACE)
    target_include_directories( my_protobuf INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/proto)
    target_link_libraries(      my_protobuf INTERFACE EmbeddedProto)
    add_dependencies(           my_protobuf my_proto_gen_files)

This way the generated files can be used in multiple project builds at the same time. I checked which example project of yours I could easily update as an illustration, but cmake is barely used anywhere, which is strange in these days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants