Commit 8ab4e383 authored by Marc Chevrier's avatar Marc Chevrier

UseSWIG: Add new behavior for better support files management

fixes: #17840
parent 438429d6
UseSWIG-multiple-behaviors
--------------------------
* The :module:`UseSWIG` module learned to manage multiple behaviors through
``UseSWIG_MODULE_VERSION`` variable to ensure legacy support as well as more
robust handling of ``SWIG`` advanced features (like ``%template``).
This diff is collapsed.
......@@ -50,6 +50,7 @@ add_test(NAME UseSWIG.MultipleModules COMMAND
${build_generator_args}
--build-project TestMultipleModules
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
add_test(NAME UseSWIG.MultiplePython COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
......@@ -59,4 +60,17 @@ add_test(NAME UseSWIG.MultiplePython COMMAND
${build_generator_args}
--build-project TestMultiplePython
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
add_test(NAME UseSWIG.ModuleVersion2 COMMAND
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
--build-and-test
"${CMake_SOURCE_DIR}/Tests/UseSWIG/ModuleVersion2"
"${CMake_BINARY_DIR}/Tests/UseSWIG/ModuleVersion2"
${build_generator_args}
--build-project TestModuleVersion2
--build-options ${build_options}
--test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
)
cmake_minimum_required(VERSION 3.1)
project(TestModuleVersion2 CXX)
include(CTest)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(Python2 REQUIRED COMPONENTS Interpreter Development)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
set (UseSWIG_MODULE_VERSION 2)
unset(CMAKE_SWIG_FLAGS)
set_property(SOURCE "../example.i" PROPERTY CPLUSPLUS ON)
set_property(SOURCE "../example.i" PROPERTY COMPILE_OPTIONS -includeall)
set_property(SOURCE "../example.i"
PROPERTY GENERATED_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/..")
swig_add_library(example1
LANGUAGE python
SOURCES ../example.i ../example.cxx)
set_target_properties (example1 PROPERTIES
OUTPUT_NAME example
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2")
target_link_libraries(example1 PRIVATE Python2::Python)
# re-use sample interface file for another plugin
swig_add_library(example2
LANGUAGE python
SOURCES ../example.i ../example.cxx)
set_target_properties (example2 PROPERTIES
OUTPUT_NAME example
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3")
target_link_libraries(example2 PRIVATE Python3::Python)
if (WIN32)
set (PS $<SEMICOLON>)
else()
set (PS ":")
endif()
add_test (NAME ModuleVersion2.example1
COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_PROPERTY:example1,SWIG_SUPPORT_FILES_DIRECTORY>${PS}$<TARGET_FILE_DIR:example1>"
"${Python2_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py")
add_test (NAME ModuleVersion2.example2
COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_PROPERTY:example2,SWIG_SUPPORT_FILES_DIRECTORY>${PS}$<TARGET_FILE_DIR:example2>"
"${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py")
......@@ -7,8 +7,9 @@ include(CTest)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(Python REQUIRED COMPONENTS Development)
find_package(Python REQUIRED COMPONENTS Interpreter Development)
find_package(Perl REQUIRED)
find_package(PerlLibs REQUIRED)
unset(CMAKE_SWIG_FLAGS)
......@@ -23,6 +24,11 @@ swig_add_library(example1
LANGUAGE python
OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python"
SOURCES ../example.i ../example.cxx)
set_target_properties (example1 PROPERTIES
OUTPUT_NAME example
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python")
target_link_libraries(example1 PRIVATE Python::Python)
# re-use sample interface file for another plugin
......@@ -35,4 +41,29 @@ swig_add_library(example2
LANGUAGE perl
OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Perl"
SOURCES ../example.i ../example.cxx)
set_target_properties (example2 PROPERTIES
OUTPUT_NAME example
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Perl"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Perl"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Perl")
target_link_libraries(example2 PRIVATE ${PERL_LIBRARY})
add_test (NAME MultipleModules.Python
COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:example1>"
"${Python_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py")
if (WIN32)
file (TO_CMAKE_PATH "$ENV{PATH}" perl_path)
string (REPLACE ";" "$<SEMICOLON>" perl_path "${perl_path}")
set (perl_env "PATH=$<TARGET_FILE_DIR:example2>$<SEMICOLON>${perl_path}")
else()
set (perl_env "LD_LIBRARY_PATH=$<TARGET_FILE_DIR:example2>")
endif()
add_test (NAME MultipleModules.Perl
COMMAND "${CMAKE_COMMAND}" -E env "${perl_env}"
"${PERL_EXECUTABLE}" "-I$<TARGET_FILE_DIR:example2>"
"${CMAKE_CURRENT_SOURCE_DIR}/../runme.pl")
......@@ -7,8 +7,8 @@ include(CTest)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(Python2 REQUIRED COMPONENTS Development)
find_package(Python3 REQUIRED COMPONENTS Development)
find_package(Python2 REQUIRED COMPONENTS Interpreter Development)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
unset(CMAKE_SWIG_FLAGS)
......@@ -22,6 +22,11 @@ swig_add_library(example1
LANGUAGE python
OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python2"
SOURCES ../example.i ../example.cxx)
set_target_properties (example1 PROPERTIES
OUTPUT_NAME example
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2")
target_link_libraries(example1 PRIVATE Python2::Python)
# re-use sample interface file for another plugin
......@@ -29,4 +34,19 @@ swig_add_library(example2
LANGUAGE python
OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python3"
SOURCES ../example.i ../example.cxx)
set_target_properties (example2 PROPERTIES
OUTPUT_NAME example
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3")
target_link_libraries(example2 PRIVATE Python3::Python)
add_test (NAME MultiplePython.example1
COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:example1>"
"${Python2_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py")
add_test (NAME MultiplePython.example2
COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:example2>"
"${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment