Skip to content
Snippets Groups Projects
Commit d264685b authored by Marc Chevrier's avatar Marc Chevrier
Browse files

UseSWIG: Update option -interface usage

Option -interface must not be used if multiple SWIG files are part
of the same library.

Fixes: #21134
parent f2a22ecd
No related branches found
No related tags found
No related merge requests found
......@@ -496,7 +496,8 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile)
endif()
endif()
if (SWIG_MODULE_${name}_LANGUAGE STREQUAL "PYTHON" AND NOT SWIG_MODULE_${name}_NOPROXY)
if(NOT ("-interface" IN_LIST swig_source_file_flags OR "-interface" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS))
if(SWIG_USE_INTERFACE AND
NOT ("-interface" IN_LIST swig_source_file_flags OR "-interface" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS))
# This makes sure that the name used in the proxy code
# matches the library name created by CMake
list (APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-interface" "$<TARGET_FILE_PREFIX:${target_name}>$<TARGET_FILE_BASE_NAME:${target_name}>")
......@@ -724,6 +725,13 @@ function(SWIG_ADD_LIBRARY name)
set(swig_generated_sources)
set(swig_generated_timestamps)
list(LENGTH swig_dot_i_sources swig_sources_count)
if (swig_sources_count GREATER "1")
# option -interface cannot be used
set(SWIG_USE_INTERFACE FALSE)
else()
set(SWIG_USE_INTERFACE TRUE)
endif()
foreach(swig_it IN LISTS swig_dot_i_sources)
SWIG_ADD_SOURCE_TO_MODULE(${name} swig_generated_source "${swig_it}")
list (APPEND swig_generated_sources "${swig_generated_source}")
......
......@@ -91,6 +91,15 @@ add_test(NAME UseSWIG.MultiplePython COMMAND
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
add_test(NAME UseSWIG.MultipleFiles COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/UseSWIG/MultipleFiles"
"${CMake_BINARY_DIR}/Tests/UseSWIG/MultipleFiles"
${build_generator_args}
--build-project TestMultipleFiles
--build-options ${build_options}
)
add_test(NAME UseSWIG.ModuleVersion2 COMMAND
......
cmake_minimum_required(VERSION 3.18)
project(TestMultipleFiles CXX)
find_package(SWIG REQUIRED)
include(UseSWIG)
unset(SWIG_LANG_TYPE)
unset(SWIG_LANG_INCLUDE_DIRECTORIES)
unset(SWIG_LANG_DEFINITIONS)
unset(SWIG_LANG_OPTIONS)
unset(SWIG_LANG_LIBRARIES)
find_package(Python3 REQUIRED COMPONENTS Development)
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/add.i" PROPERTY CPLUSPLUS ON)
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/sub.i" PROPERTY CPLUSPLUS ON)
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/add.i" PROPERTY SWIG_MODULE_NAME _add)
set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/sub.i" PROPERTY SWIG_MODULE_NAME _sub)
swig_add_library(example
LANGUAGE python
TYPE MODULE
SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/add.i"
"${CMAKE_CURRENT_SOURCE_DIR}/sub.i"
"${CMAKE_CURRENT_SOURCE_DIR}/add.cxx"
"${CMAKE_CURRENT_SOURCE_DIR}/sub.cxx")
target_include_directories(example PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(example PRIVATE Python3::Module)
#include "add.h"
int add(int a, int b)
{
return a + b;
}
int add(int a, int b);
%{
#include "add.h"
%}
%include "add.h"
#include "sub.h"
int sub(int a, int b)
{
return a - b;
}
int sub(int a, int b);
%{
#include "sub.h"
%}
%include "sub.h"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment