Skip to content

Refactor: add_goby_executable and add_goby_library CMake functions in GobyTarget.cmake, replace protobuf_generate_cpp_dccl#36

Draft
Copilot wants to merge 5 commits intocmake-cleanupfrom
copilot/refactor-add-executable-function
Draft

Refactor: add_goby_executable and add_goby_library CMake functions in GobyTarget.cmake, replace protobuf_generate_cpp_dccl#36
Copilot wants to merge 5 commits intocmake-cleanupfrom
copilot/refactor-add-executable-function

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

Summary

Introduces a new cmake/GobyTarget.cmake file with add_goby_executable and add_goby_library convenience functions that consolidate the repetitive boilerplate used for every binary and library target in the project. Replaces the custom protobuf_generate_cpp_dccl with direct add_custom_command calls replicating the same --cpp_out + --dccl_out protoc invocation, and removes FindProtobufLocal.cmake in favor of CMake's standard find_package(Protobuf REQUIRED).

Changes

New cmake/GobyTarget.cmake

Defines two public functions and one internal helper:

add_goby_executable — build a Goby application binary (linking against goby and installing to bin are both implied):

add_goby_executable(TARGET goby3_example_basic_udpm_interprocess_publisher
  SOURCES publisher.cpp
  PROTOS config.proto
  LINK_LIBRARIES goby3_example_messages)

add_goby_library — build a Goby library target (SHARED by default; pass STATIC or MODULE to change):

add_goby_library(TARGET goby3_example_messages
  PROTOS nav.proto nav_dccl.proto gps.proto state.proto init.proto
  PROTOC_OUT_DIR ${project_INC_DIR}/messages
  LINK_LIBRARIES ${Protobuf_LIBRARIES} dccl)

Both functions accept TARGET, SOURCES, PROTOS, LINK_LIBRARIES, PROTO_IMPORT_DIRS, and PROTOC_OUT_DIR. Proto files are compiled via an internal _goby_generate_protos helper that issues add_custom_command with:

protoc --cpp_out <dir> <proto> -I<dirs>... --dccl_out <dir>

This matches the original protobuf_generate_cpp_dccl invocation pattern exactly, ensuring DCCL's insertion-point mechanism works correctly across all supported distros. add_goby_executable also calls generate_interfaces() automatically when export_goby_interfaces is ON, and automatically installs the target to bin.

cmake/FindProtobufLocal.cmake

Replaced with a stub comment. All its custom functions (PROTOBUF_GENERATE_CPP_DCCL, PROTOBUF_INCLUDE_DIRS) are removed.

Root CMakeLists.txt

  • Bumped cmake_minimum_required to 3.13
  • Replaced find_package(ProtobufLocal) with find_package(Protobuf REQUIRED)
  • Added GOBY_PROTOBUF_IMPORT_DIRS variable (global protoc import paths used by both functions)
  • Added include(GobyTarget)
  • Simplified CMAKE_CXX_STANDARD guard to if(NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 17)

All binary CMakeLists.txt files (30+)

Every add_executable + proto codegen + target_link_libraries + install + generate_interfaces block replaced with a single add_goby_executable(...) call.

Library CMakeLists.txt files

src/messages/, src/components/acomms/modemdriver/pluggable_driver/, src/components/moos/gobyexample_protobuf/, and gps_moos_plugin updated to use add_goby_library.

Before / After Example

Before:

protobuf_generate_cpp_dccl(PROTO_SRCS PROTO_HDRS ${CMAKE_CURRENT_BINARY_DIR}
  config.proto)

add_executable(goby3_example_basic_udpm_interprocess_publisher
  publisher.cpp
  ${PROTO_SRCS} ${PROTO_HDRS})

target_link_libraries(goby3_example_basic_udpm_interprocess_publisher
  goby
  goby3_example_messages)

install(TARGETS goby3_example_basic_udpm_interprocess_publisher RUNTIME DESTINATION bin)

if(export_goby_interfaces)
  generate_interfaces(goby3_example_basic_udpm_interprocess_publisher)
endif()

After:

add_goby_executable(TARGET goby3_example_basic_udpm_interprocess_publisher
  SOURCES publisher.cpp
  PROTOS config.proto
  LINK_LIBRARIES goby3_example_messages)

Copilot AI and others added 2 commits April 8, 2026 08:02
…ariable name in gps_driver

Agent-Logs-Url: https://github.com/GobySoft/goby3-examples/sessions/1bb95bbd-d7a1-41b8-99ec-01bdd2fa1a1b

Co-authored-by: tsaubergine <732276+tsaubergine@users.noreply.github.com>
Copy link
Copy Markdown
Member

@tsaubergine tsaubergine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix failing build. Also do something similar for the libraries (add_goby_library function)

…, add add_goby_library

Agent-Logs-Url: https://github.com/GobySoft/goby3-examples/sessions/6a9e9ae6-5731-4b98-9887-cc0af1167fbd

Co-authored-by: tsaubergine <732276+tsaubergine@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 8, 2026

Please fix failing build. Also do something similar for the libraries (add_goby_library function)

Fixed in 7c90421.

Build failures: The root cause was protobuf_generate(LANGUAGE dccl ...) producing incompatible protoc invocations (insertion-point errors on jammy/bookworm; wrong output-path computation on noble). I replaced it with add_custom_command directly, replicating the exact --cpp_out ... --dccl_out pattern from the original protobuf_generate_cpp_dccl.

add_goby_library: Added to cmake/GobyApp.cmake alongside add_goby_executable. It takes TARGET, SOURCES, PROTOS, LINK_LIBRARIES, PROTO_IMPORT_DIRS, PROTOC_OUT_DIR, and optional STATIC/MODULE flags (defaults to SHARED). Updated src/messages, pluggable_driver, gobyexample_protobuf, and gps_moos_plugin to use it.

Copilot AI changed the title Refactor: add_goby_executable CMake function and replace protobuf_generate_cpp_dccl Refactor: add_goby_executable and add_goby_library CMake functions, replace protobuf_generate_cpp_dccl Apr 8, 2026
Copilot AI requested a review from tsaubergine April 8, 2026 09:20
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to GobyTarget.cmake

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8303e61cmake/GobyApp.cmake renamed to cmake/GobyTarget.cmake and the include(GobyApp) in the root updated to include(GobyTarget).

target_link_libraries(amac_simple goby ${Boost_LIBRARIES} ${PROTOBUF_LIBRARIES})
add_goby_executable(TARGET amac_simple
SOURCES amac_simple.cpp)
install(TARGETS amac_simple RUNTIME DESTINATION bin)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the install to the add_goby_executable function (for all excecutables)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8303e61install(TARGETS ${args_TARGET} RUNTIME DESTINATION bin) added to add_goby_executable, and the 9 individual install(...) lines removed from the per-target CMakeLists.txt files.

CMakeLists.txt Outdated
Comment on lines 6 to 10
@@ -9,20 +9,18 @@ if(((NOT DEFINED CMAKE_CXX_STANDARD) OR ("${CMAKE_CXX_STANDARD}" STREQUAL "03")
message ("Setting CMAKE_CXX_STANDARD to 17 as required by Goby. If you wish to use a newer standard, set CMAKE_CXX_STANDARD directly")
endif()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write this more concisely if possible

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8303e61 — simplified to:

if(NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 17)

…cutable, simplify CXX_STANDARD check

Agent-Logs-Url: https://github.com/GobySoft/goby3-examples/sessions/0063b641-6e58-4ecb-8477-a394964c9b24

Co-authored-by: tsaubergine <732276+tsaubergine@users.noreply.github.com>
Copilot AI changed the title Refactor: add_goby_executable and add_goby_library CMake functions, replace protobuf_generate_cpp_dccl Refactor: add_goby_executable and add_goby_library CMake functions in GobyTarget.cmake, replace protobuf_generate_cpp_dccl Apr 8, 2026
Copilot AI requested a review from tsaubergine April 8, 2026 11:40
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