diff options
-rw-r--r-- | cmake/Modules/GrSwig.cmake | 48 | ||||
-rw-r--r-- | gnuradio-core/src/lib/swig/CMakeLists.txt | 32 | ||||
-rw-r--r-- | gnuradio-core/src/lib/swig/gnuradio.i | 18 | ||||
-rw-r--r-- | gr-audio/swig/audio_swig.i | 18 | ||||
-rw-r--r-- | gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake | 48 | ||||
-rw-r--r-- | gr-trellis/src/lib/CMakeLists.txt | 15 | ||||
-rw-r--r-- | gr-uhd/swig/uhd_swig.i | 18 | ||||
-rw-r--r-- | gruel/src/swig/pmt_swig.i | 18 |
8 files changed, 139 insertions, 76 deletions
diff --git a/cmake/Modules/GrSwig.cmake b/cmake/Modules/GrSwig.cmake index 9fca29a4f..0d4cce2b3 100644 --- a/cmake/Modules/GrSwig.cmake +++ b/cmake/Modules/GrSwig.cmake @@ -22,6 +22,8 @@ IF(DEFINED __INCLUDED_GR_SWIG_CMAKE) ENDIF() SET(__INCLUDED_GR_SWIG_CMAKE TRUE) +INCLUDE(GrPython) + ######################################################################## # Build a swig target for the common gnuradio use case. Usage: # GR_SWIG_MAKE(target ifile ifile ifile...) @@ -36,8 +38,18 @@ SET(__INCLUDED_GR_SWIG_CMAKE TRUE) MACRO(GR_SWIG_MAKE name) SET(ifiles ${ARGN}) + #determine include dependencies for swig file + EXECUTE_PROCESS( + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_BINARY_DIR}/get_swig_deps.py + "${ifiles}" "${GR_SWIG_INCLUDE_DIRS}" + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE SWIG_MODULE_${name}_EXTRA_DEPS + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + #append the specified include directories INCLUDE_DIRECTORIES(${GR_SWIG_INCLUDE_DIRS}) - SET(SWIG_MODULE_${name}_EXTRA_DEPS ${GR_SWIG_SOURCE_DEPS}) + LIST(APPEND SWIG_MODULE_${name}_EXTRA_DEPS ${GR_SWIG_SOURCE_DEPS}) FIND_PACKAGE(PythonLibs) INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS}) @@ -88,3 +100,37 @@ MACRO(GR_SWIG_INSTALL) ENDFOREACH(name) ENDMACRO(GR_SWIG_INSTALL) + +######################################################################## +# Generate a python file that can determine swig dependencies. +# Used by the make macro above to determine extra dependencies. +# When you build C++, CMake figures out the header dependencies. +# This code essentially performs that logic for swig includes. +######################################################################## +FILE(WRITE ${CMAKE_BINARY_DIR}/get_swig_deps.py " + +import os, sys, re + +include_matcher = re.compile('[#|%]include\\s*[<|\"](.*)[>|\"]') +include_dirs = sys.argv[2].split(';') + +def get_swig_incs(file_path): + file_contents = open(file_path, 'r').read() + return include_matcher.findall(file_contents, re.MULTILINE) + +def get_swig_deps(file_path, level): + deps = [file_path] + if level == 0: return deps + for inc_file in get_swig_incs(file_path): + for inc_dir in include_dirs: + inc_path = os.path.join(inc_dir, inc_file) + if not os.path.exists(inc_path): continue + deps.extend(get_swig_deps(inc_path, level-1)) + return deps + +if __name__ == '__main__': + ifiles = sys.argv[1].split(';') + deps = sum([get_swig_deps(ifile, 3) for ifile in ifiles], []) + #sys.stderr.write(';'.join(set(deps)) + '\\n\\n') + print(';'.join(set(deps))) +") diff --git a/gnuradio-core/src/lib/swig/CMakeLists.txt b/gnuradio-core/src/lib/swig/CMakeLists.txt index 0d10245bf..9c7a75b4f 100644 --- a/gnuradio-core/src/lib/swig/CMakeLists.txt +++ b/gnuradio-core/src/lib/swig/CMakeLists.txt @@ -42,41 +42,15 @@ SET(GR_SWIG_LIBRARIES gnuradio-core) # smaller pieces for the compiler to digest. prior to this change, on # X86_64, g++'s resident set size was 650MB! # ---------------------------------------------------------------- -FILE(GLOB GR_SWIG_SOURCE_DEPS - "${CMAKE_SOURCE_DIR}/gnuradio-core/src/lib/runtime/*.i" - "${CMAKE_SOURCE_DIR}/gnuradio-core/src/lib/runtime/*.h" -) -GR_SWIG_MAKE(gnuradio_core_runtime gnuradio_core_runtime.i) -UNSET(GR_SWIG_SOURCE_DEPS) -FILE(GLOB GR_SWIG_SOURCE_DEPS - "${CMAKE_SOURCE_DIR}/gnuradio-core/src/lib/general/*.i" - "${CMAKE_SOURCE_DIR}/gnuradio-core/src/lib/general/*.h" -) -GR_SWIG_MAKE(gnuradio_core_general gnuradio_core_general.i) -UNSET(GR_SWIG_SOURCE_DEPS) +SET(GR_SWIG_TARGET_DEPS gengen_generated filter_generated) -SET(GR_SWIG_TARGET_DEPS gengen_generated) +GR_SWIG_MAKE(gnuradio_core_runtime gnuradio_core_runtime.i) +GR_SWIG_MAKE(gnuradio_core_general gnuradio_core_general.i) GR_SWIG_MAKE(gnuradio_core_gengen gnuradio_core_gengen.i) -UNSET(GR_SWIG_TARGET_DEPS) - -SET(GR_SWIG_TARGET_DEPS filter_generated) GR_SWIG_MAKE(gnuradio_core_filter gnuradio_core_filter.i) -UNSET(GR_SWIG_TARGET_DEPS) - -FILE(GLOB GR_SWIG_SOURCE_DEPS - "${CMAKE_SOURCE_DIR}/gnuradio-core/src/lib/io/*.i" - "${CMAKE_SOURCE_DIR}/gnuradio-core/src/lib/io/*.h" -) GR_SWIG_MAKE(gnuradio_core_io gnuradio_core_io.i) -UNSET(GR_SWIG_SOURCE_DEPS) - -FILE(GLOB GR_SWIG_SOURCE_DEPS - "${CMAKE_SOURCE_DIR}/gnuradio-core/src/lib/hier/*.i" - "${CMAKE_SOURCE_DIR}/gnuradio-core/src/lib/hier/*.h" -) GR_SWIG_MAKE(gnuradio_core_hier gnuradio_core_hier.i) -UNSET(GR_SWIG_SOURCE_DEPS) GR_SWIG_INSTALL(TARGETS gnuradio_core_runtime diff --git a/gnuradio-core/src/lib/swig/gnuradio.i b/gnuradio-core/src/lib/swig/gnuradio.i index 1856d5007..e365aeac7 100644 --- a/gnuradio-core/src/lib/swig/gnuradio.i +++ b/gnuradio-core/src/lib/swig/gnuradio.i @@ -26,6 +26,24 @@ //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// +// Language independent exception handler +//////////////////////////////////////////////////////////////////////// +%include exception.i + +%exception { + try { + $action + } + catch(std::exception &e) { + SWIG_exception(SWIG_RuntimeError, e.what()); + } + catch(...) { + SWIG_exception(SWIG_RuntimeError, "Unknown exception"); + } + +} + +//////////////////////////////////////////////////////////////////////// // Headers %{ diff --git a/gr-audio/swig/audio_swig.i b/gr-audio/swig/audio_swig.i index 612e96d23..1e3cca299 100644 --- a/gr-audio/swig/audio_swig.i +++ b/gr-audio/swig/audio_swig.i @@ -23,24 +23,6 @@ #define GR_AUDIO_API //////////////////////////////////////////////////////////////////////// -// Language independent exception handler -//////////////////////////////////////////////////////////////////////// -%include exception.i - -%exception { - try { - $action - } - catch(std::exception &e) { - SWIG_exception(SWIG_RuntimeError, e.what()); - } - catch(...) { - SWIG_exception(SWIG_RuntimeError, "Unknown exception"); - } - -} - -//////////////////////////////////////////////////////////////////////// // standard includes //////////////////////////////////////////////////////////////////////// %include "gnuradio.i" diff --git a/gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake b/gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake index 9fca29a4f..0d4cce2b3 100644 --- a/gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake +++ b/gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake @@ -22,6 +22,8 @@ IF(DEFINED __INCLUDED_GR_SWIG_CMAKE) ENDIF() SET(__INCLUDED_GR_SWIG_CMAKE TRUE) +INCLUDE(GrPython) + ######################################################################## # Build a swig target for the common gnuradio use case. Usage: # GR_SWIG_MAKE(target ifile ifile ifile...) @@ -36,8 +38,18 @@ SET(__INCLUDED_GR_SWIG_CMAKE TRUE) MACRO(GR_SWIG_MAKE name) SET(ifiles ${ARGN}) + #determine include dependencies for swig file + EXECUTE_PROCESS( + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_BINARY_DIR}/get_swig_deps.py + "${ifiles}" "${GR_SWIG_INCLUDE_DIRS}" + OUTPUT_STRIP_TRAILING_WHITESPACE + OUTPUT_VARIABLE SWIG_MODULE_${name}_EXTRA_DEPS + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + + #append the specified include directories INCLUDE_DIRECTORIES(${GR_SWIG_INCLUDE_DIRS}) - SET(SWIG_MODULE_${name}_EXTRA_DEPS ${GR_SWIG_SOURCE_DEPS}) + LIST(APPEND SWIG_MODULE_${name}_EXTRA_DEPS ${GR_SWIG_SOURCE_DEPS}) FIND_PACKAGE(PythonLibs) INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS}) @@ -88,3 +100,37 @@ MACRO(GR_SWIG_INSTALL) ENDFOREACH(name) ENDMACRO(GR_SWIG_INSTALL) + +######################################################################## +# Generate a python file that can determine swig dependencies. +# Used by the make macro above to determine extra dependencies. +# When you build C++, CMake figures out the header dependencies. +# This code essentially performs that logic for swig includes. +######################################################################## +FILE(WRITE ${CMAKE_BINARY_DIR}/get_swig_deps.py " + +import os, sys, re + +include_matcher = re.compile('[#|%]include\\s*[<|\"](.*)[>|\"]') +include_dirs = sys.argv[2].split(';') + +def get_swig_incs(file_path): + file_contents = open(file_path, 'r').read() + return include_matcher.findall(file_contents, re.MULTILINE) + +def get_swig_deps(file_path, level): + deps = [file_path] + if level == 0: return deps + for inc_file in get_swig_incs(file_path): + for inc_dir in include_dirs: + inc_path = os.path.join(inc_dir, inc_file) + if not os.path.exists(inc_path): continue + deps.extend(get_swig_deps(inc_path, level-1)) + return deps + +if __name__ == '__main__': + ifiles = sys.argv[1].split(';') + deps = sum([get_swig_deps(ifile, 3) for ifile in ifiles], []) + #sys.stderr.write(';'.join(set(deps)) + '\\n\\n') + print(';'.join(set(deps))) +") diff --git a/gr-trellis/src/lib/CMakeLists.txt b/gr-trellis/src/lib/CMakeLists.txt index e9222b5fd..3e449bcf8 100644 --- a/gr-trellis/src/lib/CMakeLists.txt +++ b/gr-trellis/src/lib/CMakeLists.txt @@ -100,6 +100,11 @@ expand_h_cc_i(trellis_sccc_decoder_combined_XX fb fs fi cb cs ci) expand_h_cc_i(trellis_pccc_decoder_X b s i) expand_h_cc_i(trellis_pccc_decoder_combined_XX fb fs fi cb cs ci) +ADD_CUSTOM_TARGET(trellis_generated DEPENDS + ${generated_trellis_includes} + ${generated_trellis_swigs} +) + ######################################################################## # Create the master trellis swig include files ######################################################################## @@ -195,21 +200,13 @@ IF(ENABLE_PYTHON) INCLUDE(GrPython) INCLUDE(GrSwig) +SET(GR_SWIG_TARGET_DEPS gengen_generated trellis_generated) SET(GR_SWIG_INCLUDE_DIRS ${GR_TRELLIS_INCLUDE_DIRS} ${GNURADIO_CORE_SWIG_INCLUDE_DIRS} ${GR_DIGITAL_SWIG_INCLUDE_DIRS} ) - SET(GR_SWIG_LIBRARIES gnuradio-trellis) -FILE(GLOB GR_SWIG_SOURCE_DEPS - "${CMAKE_CURRENT_SOURCE_DIR}/*.i" - "${CMAKE_CURRENT_SOURCE_DIR}/*.h" -) -LIST(APPEND GR_SWIG_SOURCE_DEPS - ${generated_trellis_swigs} - ${generated_trellis_includes} -) GR_SWIG_MAKE(trellis trellis.i) GR_SWIG_INSTALL( diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i index b58fe9e18..93bf5bfbe 100644 --- a/gr-uhd/swig/uhd_swig.i +++ b/gr-uhd/swig/uhd_swig.i @@ -27,24 +27,6 @@ #define GR_UHD_API //////////////////////////////////////////////////////////////////////// -// Language independent exception handler -//////////////////////////////////////////////////////////////////////// -%include exception.i - -%exception { - try { - $action - } - catch(std::exception &e) { - SWIG_exception(SWIG_RuntimeError, e.what()); - } - catch(...) { - SWIG_exception(SWIG_RuntimeError, "Unknown exception"); - } - -} - -//////////////////////////////////////////////////////////////////////// // standard includes //////////////////////////////////////////////////////////////////////// %include "gnuradio.i" diff --git a/gruel/src/swig/pmt_swig.i b/gruel/src/swig/pmt_swig.i index 3b0eb45c8..34c7d4b7c 100644 --- a/gruel/src/swig/pmt_swig.i +++ b/gruel/src/swig/pmt_swig.i @@ -36,6 +36,24 @@ using namespace pmt; %} +//////////////////////////////////////////////////////////////////////// +// Language independent exception handler +//////////////////////////////////////////////////////////////////////// +%include exception.i + +%exception { + try { + $action + } + catch(std::exception &e) { + SWIG_exception(SWIG_RuntimeError, e.what()); + } + catch(...) { + SWIG_exception(SWIG_RuntimeError, "Unknown exception"); + } + +} + // Template intrusive_ptr for Swig to avoid dereferencing issues class pmt_base; //%import <intrusive_ptr.i> |