From 330c94f1e26356b6bf670045b0c91449d67e387d Mon Sep 17 00:00:00 2001 From: Noel Eck Date: Fri, 8 Jun 2018 11:58:07 -0700 Subject: [PATCH] CMake: Expose *_regs.h to SWIG wrappers Some of the UPM libraries have a common C header with types used in both the C and C++ source. This commit adds these common header files to the SWIG modules. Signed-off-by: Noel Eck --- src/CMakeLists.txt | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 030218a3..e19cda23 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -248,11 +248,10 @@ function (_get_current_dot_i_file filePrefix varDotIFile) # This file will exist OUTSIDE the source tree set(${varDotIFile} "${CMAKE_CURRENT_BINARY_DIR}/${libname}.i") - # First, create the include variables - set(SWIG_HASH_INCLUDES) - foreach (_hpp ${module_hpp}) - set(SWIG_HASH_INCLUDES "#include \"${_hpp}\"") - endforeach() + # Create preprocessor include string for importing + string(REGEX REPLACE ";" "\"\n#include \"" SWIG_HASH_INCLUDES "${module_h_hpp}") + set(SWIG_HASH_INCLUDES "#include \"${SWIG_HASH_INCLUDES}\"") + # And the SWIG import string string(REPLACE "#" "%" SWIG_PERCENT_INCLUDES "${SWIG_HASH_INCLUDES}") # Write the interface file @@ -308,7 +307,7 @@ macro(_upm_swig_python) set (python_wrapper_target ${SWIG_MODULE_${python_wrapper_name}_REAL_NAME}) add_dependencies(${python_wrapper_target} ${libname}) - swig_link_libraries (${python_wrapper_name} ${PYTHON_LIBRARIES} ${libname}) + swig_link_libraries (${python_wrapper_name} ${PYTHON_LIBRARIES} ${libname} -Wl,--unresolved-symbols=report-all) target_include_directories (${python_wrapper_target} PUBLIC "${PYTHON_INCLUDE_PATH}" @@ -821,6 +820,16 @@ function(upm_module_init) # Don't SWIG C if (NOT IS_C_LIBRARY) + # When auto-generating a SWIG .i file, first include any C headers which + # end in *_regs.h. Then, include the C++ headers. + if (UPM_MIXED_MODULE_INIT_C_HDR AND UPM_MIXED_MODULE_INIT_CPP_WRAPS_C) + string(REGEX MATCHALL "[^;]*_regs.h" _regs "${UPM_MIXED_MODULE_INIT_C_HDR}") + if(_regs) + list(APPEND module_h_hpp "${_regs}") + endif() + endif () + list(APPEND module_h_hpp "${module_hpp}") + separate_arguments (module_h_hpp) if (BUILDSWIGPYTHON) upm_swig_python() endif (BUILDSWIGPYTHON)