Skip to content

Commit 30aa9bf

Browse files
dl1ksvmormj
authored andcommitted
Make additional includes and defines available in the bind process
1 parent 85dd61c commit 30aa9bf

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

cmake/Modules/GrPybind.cmake

+5-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ foreach(file ${files})
209209
message(STATUS "Regenerating Bindings in-place for " ${header_filename})
210210

211211
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${file}.regen_status)
212-
# Automatically regenerate the bindings
212+
# Automatically regenerate the bindings
213+
string(REPLACE ";" "," extra_include_list "${extra_includes}") #Convert ';' separated extra_includes to ',' separated list format
214+
string(REPLACE ";" "," defines "${define_symbols}") #Convert ';' separated define_symbols to ',' separated list format
213215
add_custom_command(
214216
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}}/${file}
215217
COMMAND "${PYTHON_EXECUTABLE}"
@@ -222,7 +224,8 @@ foreach(file ${files})
222224
"--status" ${CMAKE_CURRENT_BINARY_DIR}/${file}.regen_status
223225
"--flag_automatic" ${flag_auto}
224226
"--flag_pygccxml" ${flag_pygccxml}
225-
# "--include" "$<INSTALL_INTERFACE:include>" #FIXME: Make the pygccxml generation use the source tree headers
227+
"--defines" ${defines} #Add preprocessor defines
228+
"--include" ${extra_include_list} #Some oots may require additional includes
226229
COMMENT "Automatic generation of pybind11 bindings for " ${header_full_path})
227230
add_custom_target(${file}_regen_bindings ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}}/${file})
228231
list(APPEND regen_targets ${file}_regen_bindings)

gr-utils/bindtool/core/generator.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class BindingGenerator:
2222

23-
def __init__(self, prefix, namespace, prefix_include_root, output_dir="", addl_includes="",
23+
def __init__(self, prefix, namespace, prefix_include_root, output_dir="", define_symbols=None, addl_includes= None,
2424
match_include_structure=False, catch_exceptions=True, write_json_output=False, status_output=None,
2525
flag_automatic=False, flag_pygccxml=False):
2626
"""Initialize BindingGenerator
@@ -31,13 +31,15 @@ def __init__(self, prefix, namespace, prefix_include_root, output_dir="", addl_i
3131
3232
Keyword arguments:
3333
output_dir -- path where bindings will be placed
34+
define_symbols -- comma separated tuple of defines
3435
addl_includes -- comma separated list of additional include directories (default "")
3536
match_include_structure --
3637
If set to False, a bindings/ dir will be placed directly under the specified output_dir
3738
If set to True, the directory structure under include/ will be mirrored
3839
"""
3940

4041
self.header_extensions = ['.h', '.hh', '.hpp']
42+
self.define_symbols=define_symbols
4143
self.addl_include = addl_includes
4244
self.prefix = prefix
4345
self.namespace = namespace
@@ -151,7 +153,7 @@ def gen_file_binding(self, file_to_process):
151153
include_paths = ','.join((include_paths, self.addl_include))
152154

153155
parser = GenericHeaderParser(
154-
include_paths=include_paths, file_path=file_to_process)
156+
define_symbols = self.define_symbols, include_paths=include_paths, file_path=file_to_process)
155157
try:
156158
header_info = parser.get_header_info(self.namespace)
157159

gr-utils/blocktool/core/parseheader_generic.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ class GenericHeaderParser(BlockTool):
4747
name = 'Block Parse Header'
4848
description = 'Create a parsed output from a block header file'
4949

50-
def __init__(self, file_path=None, blocktool_comments=False, include_paths=None, **kwargs):
50+
def __init__(self, file_path=None, blocktool_comments=False, define_symbols=None, include_paths=None, **kwargs):
5151
""" __init__ """
5252
BlockTool.__init__(self, **kwargs)
5353
self.parsed_data = {}
5454
self.addcomments = blocktool_comments
55+
self.define_symbols = ('BOOST_ATOMIC_DETAIL_EXTRA_BACKEND_GENERIC',)
56+
if(define_symbols):
57+
self.define_symbols += define_symbols
5558
self.include_paths = None
5659
if (include_paths):
5760
self.include_paths = [p.strip() for p in include_paths.split(',')]
@@ -270,7 +273,7 @@ def get_header_info(self, namespace_to_parse):
270273
module = self.modname.split('-')[-1]
271274
self.parsed_data['module_name'] = module
272275
self.parsed_data['filename'] = self.filename
273-
276+
274277
import hashlib
275278
hasher = hashlib.md5()
276279
with open(self.target_file, 'rb') as file_in:
@@ -322,11 +325,11 @@ def get_header_info(self, namespace_to_parse):
322325
include_paths=self.include_paths,
323326
compiler='gcc',
324327
undefine_symbols=['__PIE__'],
325-
#define_symbols=['BOOST_ATOMIC_DETAIL_EXTRA_BACKEND_GENERIC', '__PIC__'],
326-
define_symbols=['BOOST_ATOMIC_DETAIL_EXTRA_BACKEND_GENERIC'],
328+
define_symbols=self.define_symbols,
327329
cflags='-std=c++11 -fPIC')
328330
decls = parser.parse(
329331
[self.target_file], xml_generator_config)
332+
330333
global_namespace = declarations.get_global_namespace(decls)
331334

332335
# namespace

gr-utils/modtool/cli/bind.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727

2828
@click.command('bind', short_help=ModToolGenBindings.description)
2929
@click.option('-o', '--output', is_flag=True,
30-
help='If given, a file with desired output format will be generated')
31-
@click.option('--addl_includes',default ="",
32-
help = 'comma separated list of additional include directories (default "")')
30+
help = 'If given, a file with desired output format will be generated')
31+
@click.option('--addl_includes', default = None,
32+
help = 'Comma separated list of additional include directories (default None)')
33+
@click.option('-D', '--define_symbols', multiple=True, default=None,
34+
help = 'Set precompiler defines')
3335
@common_params
3436
@block_name
3537
def cli(**kwargs):

gr-utils/modtool/core/bind.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, blockname=None, **kwargs):
3838
ModTool.__init__(self, blockname, **kwargs)
3939
self.info['pattern'] = blockname
4040
self.info['addl_includes'] = kwargs['addl_includes']
41+
self.info['define_symbols'] = kwargs['define_symbols']
4142

4243
def validate(self):
4344
""" Validates the arguments """
@@ -58,6 +59,8 @@ def run(self):
5859
with warnings.catch_warnings():
5960
warnings.filterwarnings("ignore", category=DeprecationWarning)
6061
file_to_process = os.path.join(self.dir, self.info['includedir'], self.info['blockname'] + '.h')
62+
6163
bg = BindingGenerator(prefix=gr.prefix(), namespace=[
62-
'gr', self.info['modname']], prefix_include_root=self.info['modname'], output_dir=os.path.join(self.dir, 'python'), addl_includes=self.info['addl_includes'])
64+
'gr', self.info['modname']], prefix_include_root=self.info['modname'], output_dir=os.path.join(self.dir, 'python'),
65+
define_symbols=self.info['define_symbols'], addl_includes=self.info['addl_includes'])
6366
bg.gen_file_binding(file_to_process)

gr-utils/modtool/templates/gr-newmod/python/bindings/bind_oot_file.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
'--filename', help="File to be parsed")
2020

2121
parser.add_argument(
22-
'--include', help='Additional Include Dirs, separated', default=(), nargs='+')
22+
'--defines', help='Set additional defines for precompiler',default=(), nargs='*')
23+
parser.add_argument(
24+
'--include', help='Additional Include Dirs, separated', default=(), nargs='*')
2325

2426
parser.add_argument(
2527
'--status', help='Location of output file for general status (used during cmake)', default=None
@@ -35,7 +37,8 @@
3537

3638
prefix = args.prefix
3739
output_dir = args.output_dir
38-
includes = args.include
40+
defines = tuple(','.join(args.defines).split(','))
41+
includes = ','.join(args.include)
3942
name = args.module
4043

4144
namespace = ['gr', name]
@@ -46,7 +49,8 @@
4649
warnings.filterwarnings("ignore", category=DeprecationWarning)
4750

4851
bg = BindingGenerator(prefix, namespace,
49-
prefix_include_root, output_dir, addl_includes=','.join(args.include), catch_exceptions=False, write_json_output=False, status_output=args.status,
52+
prefix_include_root, output_dir, define_symbols=defines, addl_includes=includes,
53+
catch_exceptions=False, write_json_output=False, status_output=args.status,
5054
flag_automatic=True if args.flag_automatic.lower() in [
5155
'1', 'true'] else False,
5256
flag_pygccxml=True if args.flag_pygccxml.lower() in ['1', 'true'] else False)

0 commit comments

Comments
 (0)