Skip to content

Commit

Permalink
pybind11: Switch from SWIG to PyBind11
Browse files Browse the repository at this point in the history
This is a rather large commit to move this module from SWIG to PyBind11
for Python bindings. Use with care.
  • Loading branch information
jdemel committed Jun 23, 2020
1 parent 026e230 commit 77cc2b0
Show file tree
Hide file tree
Showing 49 changed files with 905 additions and 584 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"terminal.integrated.env.linux": {
"PATH": "${env:HOME}/prefix/gnuradio/bin:${env:PATH}",
"PYBOMBS_PREFIX": "${env:HOME}/prefix/pybind",
"PATH": "${env:PYBOMBS_PREFIX}/bin:${env:PATH}",
"PYTHONPATH": "${env:HOME}/prefix/gnuradio/lib/python3.8/site-packages:${env:HOME}/prefix/gnuradio/lib/python3/dist-packages:${env:PYTHONPATH}",
"LD_LIBRARY_PATH": "${env:HOME}/prefix/gnuradio/lib:${env:LD_LIBRARY_PATH}",
"LIBRARY_PATH": "${env:HOME}/prefix/gnuradio/lib:${env:LIBRARY_PATH}",
"PKG_CONFIG_PATH": "${env:HOME}/prefix/gnuradio/lib/pkgconfig:${env:PKG_CONFIG_PATH}",
"PYBOMBS_PREFIX": "${env:HOME}/prefix/gnuradio",
},
"telemetry.enableTelemetry": false,
"terminal.integrated.shell.linux": "zsh",
Expand Down
99 changes: 56 additions & 43 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
# Copyright 2011,2012,2014,2016 Free Software Foundation, Inc.
# Copyright 2011, 2012, 2014, 2016, 2018 Free Software Foundation, Inc.
#
# This file was generated by gr_modtool, a tool from the GNU Radio framework
# This file is part of XFDMSync
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# SPDX-License-Identifier: GPL-3.0-or-later
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.

########################################################################
# Project setup
Expand All @@ -24,66 +13,82 @@ cmake_minimum_required(VERSION 3.8)
project(gr-xfdm_sync CXX C)
enable_testing()

#install to PyBOMBS target prefix if defined
# Install to PyBOMBS target prefix if defined
if(DEFINED ENV{PYBOMBS_PREFIX})
set(CMAKE_INSTALL_PREFIX $ENV{PYBOMBS_PREFIX})
message(STATUS "PyBOMBS installed GNU Radio. Setting CMAKE_INSTALL_PREFIX to $ENV{PYBOMBS_PREFIX}")
endif()

#select the release build type by default to get optimization flags
# Select the release build type by default to get optimization flags
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
message(STATUS "Build type not specified: defaulting to release.")
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")

#make sure our local CMake Modules path comes first
# Make sure our local CMake Modules path comes first
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/Modules)

# Set the version information here
set(VERSION_INFO_MAJOR_VERSION 1)
set(VERSION_INFO_API_COMPAT 0)
set(VERSION_INFO_MINOR_VERSION 0)
set(VERSION_INFO_MAINT_VERSION git)
set(VERSION_MAJOR 1)
set(VERSION_API 0)
set(VERSION_ABI 0)
set(VERSION_PATCH git)

cmake_policy(SET CMP0011 NEW)

# Enable generation of compile_commands.json for code completion engines
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

########################################################################
# Compiler specific setup
########################################################################
if(CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32)
if((CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR
CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
AND NOT WIN32)
#http://gcc.gnu.org/wiki/Visibility
add_definitions(-fvisibility=hidden)
add_definitions(-Wno-psabi)
endif()

find_package(Gnuradio "3.9" REQUIRED FFT)
include(GrVersion)
endif()

IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
SET(CMAKE_CXX_STANDARD 14)
ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
SET(CMAKE_CXX_STANDARD 14)
ELSEIF(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
SET(CMAKE_CXX_STANDARD 14)
ELSE()
message(WARNING "C++ standard could not be set because compiler is not GNU, Clang or MSVC.")
ENDIF()

IF(CMAKE_C_COMPILER_ID STREQUAL "GNU")
SET(CMAKE_C_STANDARD 11)
ELSEIF(CMAKE_C_COMPILER_ID MATCHES "Clang")
SET(CMAKE_C_STANDARD 11)
ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
SET(CMAKE_C_STANDARD 11)
ELSE()
message(WARNING "C standard could not be set because compiler is not GNU, Clang or MSVC.")
ENDIF()

########################################################################
# Install directories
########################################################################

find_package(Gnuradio "3.9" REQUIRED FFT)
include(GrVersion)

include(GrPlatform) #define LIB_SUFFIX

if(NOT CMAKE_MODULES_DIR)
set(CMAKE_MODULES_DIR lib${LIB_SUFFIX}/cmake)
endif(NOT CMAKE_MODULES_DIR)
set(GR_RUNTIME_DIR bin)
set(GR_LIBRARY_DIR lib${LIB_SUFFIX})

set(GR_INCLUDE_DIR include/xfdm_sync)
set(GR_DATA_DIR share)
set(GR_CMAKE_DIR ${CMAKE_MODULES_DIR}/xfdm_sync)
set(GR_PKG_DATA_DIR ${GR_DATA_DIR}/${CMAKE_PROJECT_NAME})
set(GR_DOC_DIR ${GR_DATA_DIR}/doc)
set(GR_PKG_DOC_DIR ${GR_DOC_DIR}/${CMAKE_PROJECT_NAME})
set(GR_CONF_DIR etc)
set(GR_PKG_CONF_DIR ${GR_CONF_DIR}/${CMAKE_PROJECT_NAME}/conf.d)
set(GR_LIBEXEC_DIR libexec)
set(GR_PKG_LIBEXEC_DIR ${GR_LIBEXEC_DIR}/${CMAKE_PROJECT_NAME})
set(GRC_BLOCKS_DIR ${GR_PKG_DATA_DIR}/grc/blocks)
set(GR_CMAKE_DIR ${CMAKE_MODULES_DIR}/xfdm_sync)



########################################################################
# On Apple only, set install name and use rpath correctly, if not already set
Expand All @@ -110,14 +115,23 @@ endif(APPLE)
########################################################################
find_package(Doxygen)

########################################################################
# PyBind11 Related
########################################################################

find_package(pybind11 REQUIRED)
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"from __future__ import print_function\ntry:\n import numpy\n import os\n inc_path = numpy.get_include()\n if os.path.exists(os.path.join(inc_path, 'numpy', 'arrayobject.h')):\n print(inc_path, end='')\nexcept:\n pass"
OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR)

########################################################################
# Setup doxygen option
########################################################################
if(DOXYGEN_FOUND)
option(ENABLE_DOXYGEN "Build docs using Doxygen" ON)
option(ENABLE_DOXYGEN "Build docs using Doxygen" ON)
else(DOXYGEN_FOUND)
option(ENABLE_DOXYGEN "Build docs using Doxygen" OFF)
option(ENABLE_DOXYGEN "Build docs using Doxygen" OFF)
endif(DOXYGEN_FOUND)

########################################################################
Expand All @@ -130,18 +144,17 @@ configure_file(

add_custom_target(uninstall
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
)
)

########################################################################
# Add subdirectories
########################################################################
add_subdirectory(include/xfdm_sync)
add_subdirectory(lib)
add_subdirectory(swig)
add_subdirectory(python)
add_subdirectory(grc)
add_subdirectory(apps)
add_subdirectory(docs)
add_subdirectory(python)
add_subdirectory(grc)

########################################################################
# Install cmake search helper for this library
Expand Down
17 changes: 3 additions & 14 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
# Copyright 2011 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
# This file was generated by gr_modtool, a tool from the GNU Radio framework
# This file is a part of gr-dummy
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# SPDX-License-Identifier: GPL-3.0-or-later
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.

include(GrPython)

Expand Down
17 changes: 3 additions & 14 deletions docs/doxygen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
# Copyright 2011 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
# This file was generated by gr_modtool, a tool from the GNU Radio framework
# This file is a part of gr-dummy
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# SPDX-License-Identifier: GPL-3.0-or-later
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.

########################################################################
# Create the doxygen configuration file
Expand Down
14 changes: 0 additions & 14 deletions docs/doxygen/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1680,11 +1680,6 @@ EXTERNAL_GROUPS = YES

EXTERNAL_PAGES = YES

# The PERL_PATH should be the absolute path and name of the perl script
# interpreter (i.e. the result of `which perl').

PERL_PATH = /usr/bin/perl

#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
Expand All @@ -1697,15 +1692,6 @@ PERL_PATH = /usr/bin/perl

CLASS_DIAGRAMS = YES

# You can define message sequence charts within doxygen comments using the \msc
# command. Doxygen will then run the mscgen tool (see
# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the
# documentation. The MSCGEN_PATH tag allows you to specify the directory where
# the mscgen tool resides. If left empty the tool is assumed to be found in the
# default search path.

MSCGEN_PATH =

# If set to YES, the inheritance and collaboration graphs will hide
# inheritance and usage relations if the target is undocumented
# or is not a class.
Expand Down
19 changes: 4 additions & 15 deletions docs/doxygen/doxyxml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
#
# Copyright 2010 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
# This file was generated by gr_modtool, a tool from the GNU Radio framework
# This file is a part of XFDMSync
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# SPDX-License-Identifier: GPL-3.0-or-later
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
"""
Python interface to contents of doxygen xml documentation.
Expand Down Expand Up @@ -64,7 +53,7 @@
"""

from doxyindex import DoxyIndex, DoxyFunction, DoxyParam, DoxyClass, DoxyFile, DoxyNamespace, DoxyGroup, DoxyFriend, DoxyOther
from .doxyindex import DoxyIndex, DoxyFunction, DoxyParam, DoxyClass, DoxyFile, DoxyNamespace, DoxyGroup, DoxyFriend, DoxyOther

def _test():
import os
Expand Down
33 changes: 11 additions & 22 deletions docs/doxygen/doxyxml/base.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
#
# Copyright 2010 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
# This file was generated by gr_modtool, a tool from the GNU Radio framework
# This file is a part of XFDMSync
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# SPDX-License-Identifier: GPL-3.0-or-later
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
"""
A base class is created.
Expand All @@ -30,18 +19,18 @@

from xml.parsers.expat import ExpatError

from generated import compound
from .generated import compound


class Base(object):

class Duplicate(StandardError):
class Duplicate(Exception):
pass

class NoSuchMember(StandardError):
class NoSuchMember(Exception):
pass

class ParsingError(StandardError):
class ParsingError(Exception):
pass

def __init__(self, parse_data, top=None):
Expand Down Expand Up @@ -94,19 +83,19 @@ def get_cls(self, mem):
for cls in self.mem_classes:
if cls.can_parse(mem):
return cls
raise StandardError(("Did not find a class for object '%s'." \
raise Exception(("Did not find a class for object '%s'." \
% (mem.get_name())))

def convert_mem(self, mem):
try:
cls = self.get_cls(mem)
converted = cls.from_parse_data(mem, self.top)
if converted is None:
raise StandardError('No class matched this object.')
raise Exception('No class matched this object.')
self.add_ref(converted)
return converted
except StandardError, e:
print e
except Exception as e:
print(e)

@classmethod
def includes(cls, inst):
Expand Down
Loading

0 comments on commit 77cc2b0

Please sign in to comment.