blob: 4bb3eb05b4a7230d54e91df9ad768b368e9be9d2 [file] [log] [blame]
Brian Waters13d96012017-12-08 16:53:31 -06001# The dbg_interactive extension
2PROJECT("Interactive debug facility based on SWIG" C)
3
4
5# This module is using Python
6SET(Python_ADDITIONAL_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
7FIND_PACKAGE(PythonLibs)
8INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
9
10#####
11# Wrapper to fD in python
12FIND_PACKAGE(SWIG REQUIRED)
13INCLUDE(${SWIG_USE_FILE})
14SET(CMAKE_SWIG_FLAGS -castmode -threads)
15
16# Add the dependencies for re-swig-ing the file
17SET(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 )
34SET_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
37SWIG_MODULE_INITIALIZE(fDpy python)
38SWIG_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.
43FIND_PROGRAM(XXD_EXECUTABLE xxd)
44# To avoid the dependency, simply compile it if not provided
45if (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)
49endif (NOT XXD_EXECUTABLE)
50# And now the magic command
51ADD_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
61GET_DIRECTORY_PROPERTY(swig_extra_clean_files ADDITIONAL_MAKE_CLEAN_FILES)
62SET_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
68FD_ADD_EXTENSION(dbg_interactive dbg_interactive.c ${swig_generated_sources} fDpy-inc.c)
69TARGET_LINK_LIBRARIES(dbg_interactive ${PYTHON_LIBRARIES})
70
71
72####
73## INSTALL section ##
74
75INSTALL(TARGETS dbg_interactive
76 LIBRARY DESTINATION ${INSTALL_EXTENSIONS_SUFFIX}
77 COMPONENT freeDiameter-debug-tools)