UseSWIG - Module name not passed to SWIG command
Looks like the module name is not being passed to the swig
command even if the user sets the module name through SWIG_MODULE_NAME
property on the source .i
file. This is useful when %module <name>
is not declared in .i
files.
Here's a minimally viable example
CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(SwigModule C)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(Python2 COMPONENTS Development REQUIRED)
set(UseSWIG_TARGET_NAME_PREFERENCE STANDARD)
set_property(SOURCE my_swig_module.i PROPERTY SWIG_MODULE_NAME my_swig_module)
swig_add_library(my_swig_module
LANGUAGE python
SOURCES my_swig_module.i my_swig_module.c)
target_link_libraries(my_swig_module Python2::Python)
my_swig_module.i
// Notice no %module here
%{
int add(int a, int b);
%}
int add(int a, int b);
my_swig_module.c
int add(int a, int b)
{
return a + b;
}
But if I set the module name by using compile options, it works.
set_property(SOURCE "my_swig_module.i" PROPERTY COMPILE_OPTIONS -module my_swig_module)