diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2018-11-27 14:10:32 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2018-12-07 17:51:57 (GMT) |
commit | dff28141dcddd90b0bb95740d66b8f698cc8da6a (patch) | |
tree | 0a6a26af46a22a672f7e12a53550b7f691559dcb /Tests/UseSWIG | |
parent | 7b3d4799f8c03162d537e65effd3dd8d56fc3386 (diff) | |
download | CMake-dff28141dcddd90b0bb95740d66b8f698cc8da6a.zip CMake-dff28141dcddd90b0bb95740d66b8f698cc8da6a.tar.gz CMake-dff28141dcddd90b0bb95740d66b8f698cc8da6a.tar.bz2 |
UseSWIG: add management of SWIG option -module
When file property SWIG_MODULE_NAME is specified, provide option -module
to SWIG compiler.
Fixes: #18374
Diffstat (limited to 'Tests/UseSWIG')
-rw-r--r-- | Tests/UseSWIG/CMakeLists.txt | 14 | ||||
-rw-r--r-- | Tests/UseSWIG/ModuleName/CMakeLists.txt | 42 | ||||
-rw-r--r-- | Tests/UseSWIG/ModuleName/example.i | 9 | ||||
-rw-r--r-- | Tests/UseSWIG/ModuleName/runme.py | 52 |
4 files changed, 116 insertions, 1 deletions
diff --git a/Tests/UseSWIG/CMakeLists.txt b/Tests/UseSWIG/CMakeLists.txt index 4c3d901..f79cda6 100644 --- a/Tests/UseSWIG/CMakeLists.txt +++ b/Tests/UseSWIG/CMakeLists.txt @@ -96,6 +96,18 @@ add_test(NAME UseSWIG.UseTargetINCLUDE_DIRECTORIES COMMAND "${CMake_SOURCE_DIR}/Tests/UseSWIG/UseTargetINCLUDE_DIRECTORIES" "${CMake_BINARY_DIR}/Tests/UseSWIG/UseTargetINCLUDE_DIRECTORIES" ${build_generator_args} - --build-project TestModuleVersion2 + --build-project TestUseTargetINCLUDE_DIRECTORIES --build-options ${build_options} ) + + +add_test(NAME UseSWIG.ModuleName COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/UseSWIG/ModuleName" + "${CMake_BINARY_DIR}/Tests/UseSWIG/ModuleName" + ${build_generator_args} + --build-project TestModuleName + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) diff --git a/Tests/UseSWIG/ModuleName/CMakeLists.txt b/Tests/UseSWIG/ModuleName/CMakeLists.txt new file mode 100644 index 0000000..de63883 --- /dev/null +++ b/Tests/UseSWIG/ModuleName/CMakeLists.txt @@ -0,0 +1,42 @@ +cmake_minimum_required(VERSION 3.1...3.14) + +project(TestModuleName CXX) + +include(CTest) + +find_package(SWIG REQUIRED) +cmake_policy(SET CMP0086 NEW) +include(${SWIG_USE_FILE}) + +find_package(Python2 REQUIRED COMPONENTS Interpreter Development) + +# Path separator +if (WIN32) + set (PS "$<SEMICOLON>") +else() + set (PS ":") +endif() + +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 SWIG_MODULE_NAME new_example) + +swig_add_library(example1 + LANGUAGE python + OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/example1" + SOURCES example.i ../example.cxx) +set_target_properties (example1 PROPERTIES + INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/.." + SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE + OUTPUT_NAME new_example + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/example1" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/example1" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/example1") +target_link_libraries(example1 PRIVATE Python2::Python) + + +add_test (NAME ModuleName.example1 + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}/Python2${PS}$<TARGET_FILE_DIR:example1>" + "${Python2_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/runme.py") diff --git a/Tests/UseSWIG/ModuleName/example.i b/Tests/UseSWIG/ModuleName/example.i new file mode 100644 index 0000000..fbdf724 --- /dev/null +++ b/Tests/UseSWIG/ModuleName/example.i @@ -0,0 +1,9 @@ +/* File : example.i */ +%module example + +%{ +#include "example.h" +%} + +/* Let's just grab the original header file here */ +%include "example.h" diff --git a/Tests/UseSWIG/ModuleName/runme.py b/Tests/UseSWIG/ModuleName/runme.py new file mode 100644 index 0000000..c37e4a7 --- /dev/null +++ b/Tests/UseSWIG/ModuleName/runme.py @@ -0,0 +1,52 @@ +# file: runme.py + +# This file illustrates the shadow-class C++ interface generated +# by SWIG. + +from __future__ import print_function + +import new_example + +# ----- Object creation ----- + +print ("Creating some objects:") +c = new_example.Circle(10) +print (" Created circle", c) +s = new_example.Square(10) +print (" Created square", s) + +# ----- Access a static member ----- + +print ("\nA total of", new_example.cvar.Shape_nshapes,"shapes were created") + +# ----- Member data access ----- + +# Set the location of the object + +c.x = 20 +c.y = 30 + +s.x = -10 +s.y = 5 + +print ("\nHere is their current position:") +print (" Circle = (%f, %f)" % (c.x,c.y)) +print (" Square = (%f, %f)" % (s.x,s.y)) + +# ----- Call some methods ----- + +print ("\nHere are some properties of the shapes:") +for o in [c,s]: + print (" ", o) + print (" area = ", o.area()) + print (" perimeter = ", o.perimeter()) + +print ("\nGuess I'll clean up now") + +# Note: this invokes the virtual destructor +del c +del s + +s = 3 +print (new_example.cvar.Shape_nshapes,"shapes remain") +print ("Goodbye") |