This file provides support for SWIG
. It is assumed that FindSWIG
module has already been loaded.
Defines the following command for use with SWIG
:
swig_add_library
Define swig module with given name and specified language:
swig_add_library(<name> [TYPE <SHARED|MODULE|STATIC|USE_BUILD_SHARED_LIBS>] LANGUAGE <language> [NO_PROXY] [OUTPUT_DIR <directory>] [OUTFILE_DIR <directory>] SOURCES <file>... )
Targets created with the swig_add_library
command have the same capabilities as targets created with the add_library()
command, so those targets can be used with any command expecting a target (e.g. target_link_libraries()
).
Note
The variable SWIG_MODULE_<name>_REAL_NAME
will be set to the name of the swig module target library. This variable is useless if variable UseSWIG_TARGET_NAME_PREFERENCE
is set to STANDARD
.
Note
For multi-config generators, this module does not support configuration-specific files generated by SWIG
. All build configurations must result in the same generated source file.
TYPE
SHARED
, MODULE
and STATIC
have the same semantic as for the add_library()
command. If USE_BUILD_SHARED_LIBS
is specified, the library type will be STATIC
or SHARED
based on whether the current value of the BUILD_SHARED_LIBS
variable is ON
. If no type is specified, MODULE
will be used.LANGUAGE
NO_PROXY
-noproxy
option).OUTPUT_DIR
Specify where to write the language specific files (swig -outdir
option). If not given, the CMAKE_SWIG_OUTDIR
variable will be used. If neither is specified, the default depends on the value of the UseSWIG_MODULE_VERSION
variable as follows:
UseSWIG_MODULE_VERSION
is 1 or is undefined, output is written to the CMAKE_CURRENT_BINARY_DIR
directory.UseSWIG_MODULE_VERSION
is 2, a dedicated directory will be used. The path of this directory can be retrieved from the SWIG_SUPPORT_FILES_DIRECTORY
target property.OUTFILE_DIR
SWIG_OUTFILE_DIR
variable will be used. If neither is specified, OUTPUT_DIR
or CMAKE_SWIG_OUTDIR
is used instead.SOURCES
.i
will be identified as sources for the SWIG
tool. Other files will be handled in the standard way.Note
If UseSWIG_MODULE_VERSION
is set to 2, it is strongly recommended to use a dedicated directory unique to the target when either the OUTPUT_DIR
option or the CMAKE_SWIG_OUTDIR
variable are specified. The output directory contents are erased as part of the target build, so to prevent interference between targets or losing other important files, each target should have its own dedicated output directory.
swig_link_libraries
Link libraries to swig module:
swig_link_libraries(<name> <item>...)
This command has same capabilities as target_link_libraries()
command.
Note
If variable UseSWIG_TARGET_NAME_PREFERENCE
is set to STANDARD
, this command is deprecated and target_link_libraries()
command must be used instead.
Source file properties on module files must be set before the invocation of the swig_add_library
command to specify special behavior of SWIG and ensure generated files will receive the required settings.
CPLUSPLUS
Call SWIG in c++ mode. For example:
set_property(SOURCE mymod.i PROPERTY CPLUSPLUS ON) swig_add_library(mymod LANGUAGE python SOURCES mymod.i)
INCLUDE_DIRECTORIES, COMPILE_DEFINITIONS and COMPILE_OPTIONS
INCLUDE_DIRECTORIES
, COMPILE_DEFINITIONS
and COMPILE_OPTIONS
.GENERATED_INCLUDE_DIRECTORIES, GENERATED_COMPILE_DEFINITIONS and GENERATED_COMPILE_OPTIONS
INCLUDE_DIRECTORIES
, COMPILE_DEFINITIONS
and COMPILE_OPTIONS
of generated C/C++ file.DEPENDS
SWIG_MODULE_NAME
Specify the actual import name of the module in the target language. This is required if it cannot be scanned automatically from source or different from the module file basename. For example:
set_property(SOURCE mymod.i PROPERTY SWIG_MODULE_NAME mymod_realname)
Target library properties can be set to apply same configuration to all SWIG input files.
SWIG_INCLUDE_DIRECTORIES, SWIG_COMPILE_DEFINITIONS and SWIG_COMPILE_OPTIONS
These properties will be applied to all SWIG input files and have same semantic as target properties INCLUDE_DIRECTORIES
, COMPILE_DEFINITIONS
and COMPILE_OPTIONS
.
set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD) swig_add_library(mymod LANGUAGE python SOURCES mymod.i) set_property(TARGET mymod PROPERTY SWIG_COMPILE_DEFINITIONS MY_DEF1 MY_DEF2) set_property(TARGET mymod PROPERTY SWIG_COMPILE_OPTIONS -bla -blb)
SWIG_GENERATED_INCLUDE_DIRECTORIES, SWIG_GENERATED_COMPILE_DEFINITIONS and SWIG_GENERATED_COMPILE_OPTIONS
INCLUDE_DIRECTORIES
, COMPILE_DEFINITIONS
and COMPILE_FLAGS
of all generated C/C++ files.SWIG_DEPENDS
The following target properties are output properties and can be used to get information about support files generated by SWIG
interface compilation.
SWIG_SUPPORT_FILES
This output property list of wrapper files generated during SWIG compilation.
set (UseSWIG_TARGET_NAME_PREFERENCE STANDARD) swig_add_library(mymod LANGUAGE python SOURCES mymod.i) get_property(support_files TARGET mymod PROPERTY SWIG_SUPPORT_FILES)
Note
Only most principal support files are listed. In case some advanced features of SWIG
are used (for example %template
), associated support files may not be listed. Prefer to use the SWIG_SUPPORT_FILES_DIRECTORY
property to handle support files.
SWIG_SUPPORT_FILES_DIRECTORY
Some variables can be set to customize the behavior of swig_add_library
as well as SWIG
:
UseSWIG_TARGET_NAME_PREFERENCE
Specify target name strategy.
LEGACY
or undefined: legacy strategy is applied. Variable SWIG_MODULE_<name>_REAL_NAME
must be used to get real target name.STANDARD
: target name matches specified name.UseSWIG_MODULE_VERSION
Specify different behaviors for UseSWIG
module.
SWIG
interface compilation.CMAKE_SWIG_FLAGS
CMAKE_SWIG_OUTDIR
-outdir
option).SWIG_OUTFILE_DIR
CMAKE_SWIG_OUTDIR
is used.SWIG_MODULE_<name>_EXTRA_DEPS
<name>
.
© 2000–2018 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.
https://cmake.org/cmake/help/v3.12/module/UseSWIG.html