CyberRadio / gr-cyberradio

MIT License
5 stars 4 forks source link

Add C++ code generation GRC support (3.10) #10

Closed jwmelto closed 1 year ago

jwmelto commented 2 years ago

In the GNU Radio Companion (GRC), there is an option to generate code in either Python or C++, but the 3.10 YAML files lack the necessary support.

Specifically, for each block, add

flags: [ python, cpp ]

and then (for example)

cpp_templates:
  include: ['#include <CyberRadio/vita_udp_rx.h>']
  declarations: 'CyberRadio::vita_udp_rx::sptr ${id};'
  make: 'this->${id} = CyberRadio::vita_udp_rx::make();'

I'm still playing but these seem to be the minmal required changes to support C++ code generation. Of course, these portions need to be added for all supported blocks (vita_udp_rx was just chosen for illustration).

jwmelto commented 2 years ago

Could you either change or add an overload to the block make function that passes std::string? That's what the GRC code generator generates. I'm getting compilation errors with a generated flowgraph

crs-bs commented 2 years ago

Commit: 10ff67a should switch this back to std::string I believe my problem was not using "s in the GRC that was causing issues with C++ generation.

jwmelto commented 1 year ago

A couple more things. The C++ template needs

link: ['gnuradio::gnuradio-CyberRadio']
packages: ['gnuradio-CyberRadio']

The C++ code generation iterates over all the defined blocks and pulls out these values for use in generating the project/flowgraph CMakeLists.txt file.

The values in the link list are added as libraries for any projects that include the block. For reasons I cannot explain, simply having gnuradio-CyberRadio doesn't work; it generates a link error -lgnuradio-CyberRadio not found, even though libgnuradio-CyberRadio.so is in my installed lib directory (and known to ldconfig). However, if instead the CMake config is loaded, then the namespace-qualified target does work.

The packages list drives the CMake package process (basically, generates find_package(<var>) for each element in the list).

Combined, it finds the gnuradio-CyberRadio package, and then adds the appropriate target to the generated CMakeLists.txt.

crs-bs commented 1 year ago

See: Commit 94a7d98 should resolve the above.