Brian Waters | 13d9601 | 2017-12-08 16:53:31 -0600 | [diff] [blame] | 1 | # The dbg_interactive extension |
| 2 | PROJECT("Interactive debug facility based on SWIG" C) |
| 3 | |
| 4 | |
| 5 | # This module is using Python |
| 6 | SET(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0) |
| 7 | FIND_PACKAGE(PythonLibs) |
| 8 | INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) |
| 9 | |
| 10 | ##### |
| 11 | # Wrapper to fD in python |
| 12 | FIND_PACKAGE(SWIG REQUIRED) |
| 13 | INCLUDE(${SWIG_USE_FILE}) |
| 14 | SET(CMAKE_SWIG_FLAGS -castmode -threads) |
| 15 | |
| 16 | # Add the dependencies for re-swig-ing the file |
| 17 | SET(SWIG_MODULE_fDpy_EXTRA_DEPS |
| 18 | ${CMAKE_BINARY_DIR}/include/freeDiameter/freeDiameter-host.h |
| 19 | ${CMAKE_SOURCE_DIR}/include/freeDiameter/libfdcore.h |
| 20 | ${CMAKE_SOURCE_DIR}/include/freeDiameter/libfdproto.h |
| 21 | lists.i |
| 22 | dictionary.i |
| 23 | sessions.i |
| 24 | routing.i |
| 25 | messages.i |
| 26 | dispatch.i |
| 27 | queues.i |
| 28 | peers.i |
| 29 | events.i |
| 30 | endpoints.i |
| 31 | posix.i |
| 32 | hooks.i |
| 33 | ) |
| 34 | SET_SOURCE_FILES_PROPERTIES(dbg_interactive.i PROPERTIES SWIG_MODULE_NAME fDpy) |
| 35 | |
| 36 | # The following code is inspired from SWIG_ADD_MODULE, but we do only what we need |
| 37 | SWIG_MODULE_INITIALIZE(fDpy python) |
| 38 | SWIG_ADD_SOURCE_TO_MODULE(fDpy swig_generated_sources "dbg_interactive.i") |
| 39 | |
| 40 | # In order to avoid shipping the python file that contains the shadow class definitions, |
| 41 | # we transform this file in a C-style string and compile it within our software. |
| 42 | # We use for this purpose xxd tool provided with vim package. |
| 43 | FIND_PROGRAM(XXD_EXECUTABLE xxd) |
| 44 | # To avoid the dependency, simply compile it if not provided |
| 45 | if (NOT XXD_EXECUTABLE) |
| 46 | SET_SOURCE_FILES_PROPERTIES(helper/xxd.c PROPERTIES COMPILE_DEFINITIONS UNIX) |
| 47 | ADD_EXECUTABLE(xxd helper/xxd.c) |
| 48 | SET(XXD_EXECUTABLE xxd) |
| 49 | endif (NOT XXD_EXECUTABLE) |
| 50 | # And now the magic command |
| 51 | ADD_CUSTOM_COMMAND( |
| 52 | OUTPUT "fDpy-inc.c" |
| 53 | COMMAND "${XXD_EXECUTABLE}" |
| 54 | ARGS "-i" |
| 55 | "fDpy.py" |
| 56 | "fDpy-inc.c" |
| 57 | MAIN_DEPENDENCY "${swig_extra_generated_files}" |
| 58 | COMMENT "Shadow definitions") |
| 59 | |
| 60 | # Ensure that the generated source files are removed |
| 61 | GET_DIRECTORY_PROPERTY(swig_extra_clean_files ADDITIONAL_MAKE_CLEAN_FILES) |
| 62 | SET_DIRECTORY_PROPERTIES(PROPERTIES |
| 63 | ADDITIONAL_MAKE_CLEAN_FILES "${swig_extra_clean_files};${swig_generated_sources};fDpy-inc.c") |
| 64 | |
| 65 | |
| 66 | ##### |
| 67 | # Extension that embeds the python interpreter |
| 68 | FD_ADD_EXTENSION(dbg_interactive dbg_interactive.c ${swig_generated_sources} fDpy-inc.c) |
| 69 | TARGET_LINK_LIBRARIES(dbg_interactive ${PYTHON_LIBRARIES}) |
| 70 | |
| 71 | |
| 72 | #### |
| 73 | ## INSTALL section ## |
| 74 | |
| 75 | INSTALL(TARGETS dbg_interactive |
| 76 | LIBRARY DESTINATION ${INSTALL_EXTENSIONS_SUFFIX} |
| 77 | COMPONENT freeDiameter-debug-tools) |