aboutsummaryrefslogtreecommitdiffstats
path: root/grc
diff options
context:
space:
mode:
authorVolker Schroer <3470424+dl1ksv@users.noreply.github.com>2021-07-31 17:14:12 +0200
committermormj <34754695+mormj@users.noreply.github.com>2021-09-02 08:29:16 -0400
commitb417716a0a6e686d189596ffdaab1e4b8e9679b7 (patch)
treed83dce3bbfe94b42de62f0620a895092666ee5a2 /grc
parentgr-digital: fix gfsk documentation (diff)
downloadgnuradio-b417716a0a6e686d189596ffdaab1e4b8e9679b7.tar.xz
gnuradio-b417716a0a6e686d189596ffdaab1e4b8e9679b7.zip
grc cpp generation: Establish the possibility to add find packages
Flowgraphs may use oot modules. When generating cpp code an oot module may require a package that is not provided by gnuradio. So I propose to add an additional entry parameters in the cpp template to provide a list of package names. Signed-off-by: Volker Schroer <3470424+dl1ksv@users.noreply.github.com>
Diffstat (limited to 'grc')
-rw-r--r--grc/core/blocks/_build.py1
-rw-r--r--grc/core/generator/FlowGraphProxy.py9
-rw-r--r--grc/core/generator/cpp_templates/CMakeLists.txt.mako6
-rw-r--r--grc/core/generator/cpp_top_block.py14
-rw-r--r--grc/core/schema_checker/block.py1
5 files changed, 29 insertions, 2 deletions
diff --git a/grc/core/blocks/_build.py b/grc/core/blocks/_build.py
index c360416b9..40155fc84 100644
--- a/grc/core/blocks/_build.py
+++ b/grc/core/blocks/_build.py
@@ -57,6 +57,7 @@ def build(id, label='', category='', flags='', documentation='',
callbacks=cpp_templates.get('callbacks', []),
var_make=cpp_templates.get('var_make', ''),
link=cpp_templates.get('link', []),
+ packages=cpp_templates.get('packages', []),
translations=cpp_templates.get('translations', []),
declarations=cpp_templates.get('declarations', ''),
)
diff --git a/grc/core/generator/FlowGraphProxy.py b/grc/core/generator/FlowGraphProxy.py
index f39f25d8f..38d44e5b1 100644
--- a/grc/core/generator/FlowGraphProxy.py
+++ b/grc/core/generator/FlowGraphProxy.py
@@ -148,6 +148,15 @@ class FlowGraphProxy(object): # TODO: move this in a refactored Generator
"""
return [block.cpp_templates.render('link') for block in self.iter_enabled_blocks() if not (block.is_virtual_sink() or block.is_virtual_source())]
+ def packages(self):
+ """
+ Get a set of all packages to find (C++) ( especially for oot modules ) in this flow graph namespace.
+
+ Returns:
+ a list of required packages
+ """
+ return [block.cpp_templates.render('packages') for block in self.iter_enabled_blocks() if not (block.is_virtual_sink() or block.is_virtual_source())]
+
def get_hier_block_io(flow_graph, direction, domain=None):
"""
Get a list of io ports for this flow graph.
diff --git a/grc/core/generator/cpp_templates/CMakeLists.txt.mako b/grc/core/generator/cpp_templates/CMakeLists.txt.mako
index 263f470e4..e7705530d 100644
--- a/grc/core/generator/cpp_templates/CMakeLists.txt.mako
+++ b/grc/core/generator/cpp_templates/CMakeLists.txt.mako
@@ -22,7 +22,6 @@ set(CMAKE_CXX_STANDARD 14)
project(${class_name})
-
find_package(Gnuradio "${short_version}" COMPONENTS
% for component in config.enabled_components.split(";"):
% if component.startswith("gr-"):
@@ -50,6 +49,11 @@ set(CMAKE_EXE_LINKER_FLAGS " -static")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
% endif
+% for package in packages:
+% if package:
+find_package(${package})
+% endif
+% endfor
add_executable(${class_name} ${class_name}.cpp)
target_link_libraries(${class_name}
gnuradio::gnuradio-blocks
diff --git a/grc/core/generator/cpp_top_block.py b/grc/core/generator/cpp_top_block.py
index d0bc4c172..f0da138bb 100644
--- a/grc/core/generator/cpp_top_block.py
+++ b/grc/core/generator/cpp_top_block.py
@@ -175,6 +175,7 @@ class CppTopBlockGenerator(TopBlockGenerator):
connections=self._connections(),
links=self._links(),
cmake_tuples=cmake_tuples,
+ packages=self._packages(),
**self.namespace
)
# strip trailing white-space
@@ -187,7 +188,6 @@ class CppTopBlockGenerator(TopBlockGenerator):
fg = self._flow_graph
links = fg.links()
seen = set()
- output = []
for link_list in links:
if link_list:
@@ -196,6 +196,18 @@ class CppTopBlockGenerator(TopBlockGenerator):
return list(seen)
+ def _packages(self):
+ fg = self._flow_graph
+ packages = fg.packages()
+ seen = set()
+
+ for package_list in packages:
+ if package_list:
+ for package in package_list:
+ seen.add(package)
+
+ return list(seen)
+
def _includes(self):
fg = self._flow_graph
includes = fg.includes()
diff --git a/grc/core/schema_checker/block.py b/grc/core/schema_checker/block.py
index eee1e29ea..f336fc4fd 100644
--- a/grc/core/schema_checker/block.py
+++ b/grc/core/schema_checker/block.py
@@ -42,6 +42,7 @@ CPP_TEMPLATES_SCHEME = expand(
var_make=str,
callbacks=list,
link=list,
+ packages=list,
translations=dict,
)
BLOCK_SCHEME = expand(