From e147c5c5558fbb1a6a704173a9a7c71848893ab0 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 1 Apr 2014 12:12:52 +0200 Subject: UseSWIG: Detect module name from interface file (#10080) If no SWIG_MODULE_NAME is specified explicitly and the .i file exists, scan it for the module name declaration. --- Modules/UseSWIG.cmake | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index 11ca205..b694c40 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -86,7 +86,30 @@ macro(SWIG_GET_EXTRA_OUTPUT_FILES language outfiles generatedpath infile) get_source_file_property(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename ${infile} SWIG_MODULE_NAME) if(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename STREQUAL "NOTFOUND") - get_filename_component(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename "${infile}" NAME_WE) + + # try to get module name from "%module foo" syntax + if ( EXISTS ${infile} ) + file ( STRINGS ${infile} _MODULE_NAME REGEX "[ ]*%module[ ]*[a-zA-Z0-9_]+.*" ) + endif () + if ( _MODULE_NAME ) + string ( REGEX REPLACE "[ ]*%module[ ]*([a-zA-Z0-9_]+).*" "\\1" _MODULE_NAME "${_MODULE_NAME}" ) + set(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename "${_MODULE_NAME}") + + else () + # try to get module name from "%module (options=...) foo" syntax + if ( EXISTS ${infile} ) + file ( STRINGS ${infile} _MODULE_NAME REGEX "[ ]*%module[ ]*\\(.*\\)[ ]*[a-zA-Z0-9_]+.*" ) + endif () + if ( _MODULE_NAME ) + string ( REGEX REPLACE "[ ]*%module[ ]*\\(.*\\)[ ]*([a-zA-Z0-9_]+).*" "\\1" _MODULE_NAME "${_MODULE_NAME}" ) + set(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename "${_MODULE_NAME}") + + else () + # fallback to file basename + get_filename_component(SWIG_GET_EXTRA_OUTPUT_FILES_module_basename ${infile} NAME_WE) + endif () + endif () + endif() foreach(it ${SWIG_${language}_EXTRA_FILE_EXTENSION}) set(${outfiles} ${${outfiles}} -- cgit v0.12