UseSWIG: Interface argument to swig breaks build
In CMake 3.12 my project builds successfully but breaks in CMake 3.16. I believe it is related to a change in 3.15: "UseSWIG module learned to manage alternate library names by passing -interface <library_name> for python language"
I'm using swig_add_library similarly to:
swig_add_library(mylib TYPE SHARED LANGUAGE python SOURCES ${SWIG_FILES} ${CMAKE_SWIG_OUTDIR}/mylib.cc)
Where SWIG_FILES contains multiple interface files (.i)
In 3.16, the swig invocation generated by CMake adds the "-interface mylib" argument, which causes the #define for SWIG_init to be set to PyInit__mylib and SWIG_name defined to "_mylib" in each and every wrapper generated for the files in SWIG_FILES. This causes duplicate symbols on linking.
Under 3.12, no "-interface" argument is passed to swig and swig uses the passed -module argument to set PyInit__<module_name> as the value for SWIG_init and _<module_name> as the value for SWIG_name. This results in a successful compilation.
As far as I could find, there isn't a policy to preserve the old behavior (i.e. not passing -interface argument) even though this seems like a change that may cause breakage.
Any suggestions for a fix or is there any additional information I might provide to troubleshoot this?