summaryrefslogtreecommitdiffstats
path: root/Modules/UseSWIG.cmake
diff options
context:
space:
mode:
authorDaniele E. Domenichelli <daniele.domenichelli@iit.it>2016-11-10 15:49:46 (GMT)
committerDaniele E. Domenichelli <daniele.domenichelli@iit.it>2016-11-11 07:13:47 (GMT)
commitd0a9d8bbe60edfb7cf7569fe8162b17bba294182 (patch)
treeee1f3f236011548653e44667f967861af8a33873 /Modules/UseSWIG.cmake
parenta21f74767c61c36308ede4b35f69a342cb60c129 (diff)
downloadCMake-d0a9d8bbe60edfb7cf7569fe8162b17bba294182.zip
CMake-d0a9d8bbe60edfb7cf7569fe8162b17bba294182.tar.gz
CMake-d0a9d8bbe60edfb7cf7569fe8162b17bba294182.tar.bz2
UseSWIG: Add swig_add_library macro.
swig_add_module does not allow to set the type for the library and instead always create the library as MODULE. This patch adds the new swig_add_library command with this signature: SWIG_ADD_LIBRARY(<name> [TYPE <SHARED|MODULE|STATIC>] LANGUAGE <language> SOURCES <file>... ) The swig_add_module is deprecated in favour of swig_add_library. Closes: #16415
Diffstat (limited to 'Modules/UseSWIG.cmake')
-rw-r--r--Modules/UseSWIG.cmake48
1 files changed, 41 insertions, 7 deletions
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake
index 2df0011..fe80938 100644
--- a/Modules/UseSWIG.cmake
+++ b/Modules/UseSWIG.cmake
@@ -9,18 +9,22 @@
#
# ::
#
-# SWIG_ADD_MODULE(name language [ files ])
+# SWIG_ADD_LIBRARY(<name>
+# [TYPE <SHARED|MODULE|STATIC>]
+# LANGUAGE <language>
+# SOURCES <file>...
+# )
# - Define swig module with given name and specified language
# SWIG_LINK_LIBRARIES(name [ libraries ])
# - Link libraries to swig module
#
# Source files properties on module files can be set before the invocation
-# of the SWIG_ADD_MODULE macro to specify special behavior of SWIG.
+# of the SWIG_ADD_LIBRARY macro to specify special behavior of SWIG.
#
# The source file property CPLUSPLUS calls SWIG in c++ mode, e.g.::
#
# set_property(SOURCE mymod.i PROPERTY CPLUSPLUS ON)
-# swig_add_module(mymod python mymod.i)
+# swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
#
# The source file property SWIG_FLAGS adds custom flags to the SWIG executable.
#
@@ -217,10 +221,40 @@ endmacro()
# Create Swig module
#
macro(SWIG_ADD_MODULE name language)
- SWIG_MODULE_INITIALIZE(${name} ${language})
+ message(DEPRECATION "SWIG_ADD_MODULE is deprecated. Use SWIG_ADD_LIBRARY instead.")
+ swig_add_library(${name}
+ LANGUAGE ${language}
+ TYPE MODULE
+ SOURCES ${ARGN})
+endmacro()
+
+
+macro(SWIG_ADD_LIBRARY name)
+
+ include(CMakeParseArguments)
+ set(options "")
+ set(oneValueArgs LANGUAGE
+ TYPE)
+ set(multiValueArgs SOURCES)
+ cmake_parse_arguments(_SAM "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ if(NOT DEFINED _SAM_LANGUAGE)
+ message(FATAL_ERROR "SWIG_ADD_LIBRARY: Missing LANGUAGE argument")
+ endif()
+
+ if(NOT DEFINED _SAM_SOURCES)
+ message(FATAL_ERROR "SWIG_ADD_LIBRARY: Missing SOURCES argument")
+ endif()
+
+ if(NOT DEFINED _SAM_TYPE)
+ set(_SAM_TYPE MODULE)
+ endif()
+
+ swig_module_initialize(${name} ${_SAM_LANGUAGE})
+
set(swig_dot_i_sources)
set(swig_other_sources)
- foreach(it ${ARGN})
+ foreach(it ${_SAM_SOURCES})
if(${it} MATCHES "\\.i$")
set(swig_dot_i_sources ${swig_dot_i_sources} "${it}")
else()
@@ -237,11 +271,11 @@ macro(SWIG_ADD_MODULE name language)
set_directory_properties(PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES "${swig_extra_clean_files};${swig_generated_sources}")
add_library(${SWIG_MODULE_${name}_REAL_NAME}
- MODULE
+ ${_SAM_TYPE}
${swig_generated_sources}
${swig_other_sources})
set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES NO_SONAME ON)
- string(TOLOWER "${language}" swig_lowercase_language)
+ string(TOLOWER "${_SAM_LANGUAGE}" swig_lowercase_language)
if ("${swig_lowercase_language}" STREQUAL "octave")
set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "")
set_target_properties(${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".oct")