summaryrefslogtreecommitdiff
path: root/gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake
diff options
context:
space:
mode:
authorJosh Blum2011-10-08 11:56:02 -0700
committerJosh Blum2011-10-08 11:56:02 -0700
commit7a2d39f425f6bc5df6a4f7206d3fa10f8e1e67c3 (patch)
treec0f3b142d6c288a7d214d82bb885c8797d3d2587 /gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake
parentb06328b4adee941fe62f12a848cc903097711bdd (diff)
parentf29a49a40a3f706ae14d7d69c536d87eff3b53db (diff)
downloadgnuradio-7a2d39f425f6bc5df6a4f7206d3fa10f8e1e67c3.tar.gz
gnuradio-7a2d39f425f6bc5df6a4f7206d3fa10f8e1e67c3.tar.bz2
gnuradio-7a2d39f425f6bc5df6a4f7206d3fa10f8e1e67c3.zip
Merge branch 'next' into digital
Diffstat (limited to 'gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake')
-rw-r--r--gr-howto-write-a-block-cmake/cmake/Modules/GrSwig.cmake48
1 files changed, 47 insertions, 1 deletions
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)))
+")