diff options
author | Julien Schueller <schueller@phimeca.com> | 2014-04-01 10:12:52 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-04-21 13:22:57 (GMT) |
commit | e147c5c5558fbb1a6a704173a9a7c71848893ab0 (patch) | |
tree | fff86b796c3c845cc5a512385437f4f9ba03c047 /Modules/UseSWIG.cmake | |
parent | e3e1ba3f781c621835dc5e46783fecb6ccaad127 (diff) | |
download | CMake-e147c5c5558fbb1a6a704173a9a7c71848893ab0.zip CMake-e147c5c5558fbb1a6a704173a9a7c71848893ab0.tar.gz CMake-e147c5c5558fbb1a6a704173a9a7c71848893ab0.tar.bz2 |
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.
Diffstat (limited to 'Modules/UseSWIG.cmake')
-rw-r--r-- | Modules/UseSWIG.cmake | 25 |
1 files changed, 24 insertions, 1 deletions
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}} |