summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorMarc Chevrier <marc.chevrier@gmail.com>2018-11-27 14:10:32 (GMT)
committerMarc Chevrier <marc.chevrier@gmail.com>2018-12-07 17:51:57 (GMT)
commitdff28141dcddd90b0bb95740d66b8f698cc8da6a (patch)
tree0a6a26af46a22a672f7e12a53550b7f691559dcb /Tests
parent7b3d4799f8c03162d537e65effd3dd8d56fc3386 (diff)
downloadCMake-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')
-rw-r--r--Tests/RunCMake/CMakeLists.txt2
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0078-WARN-stderr.txt2
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0078-common.cmake2
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0086-NEW-nuild-check.cmake4
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0086-NEW.cmake2
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0086-OLD-build-check.cmake4
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0086-OLD.cmake2
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0086-WARN-stderr.txt11
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0086-WARN.cmake1
-rw-r--r--Tests/RunCMake/UseSWIG/CMP0086-common.cmake11
-rw-r--r--Tests/RunCMake/UseSWIG/RunCMakeTest.cmake20
-rw-r--r--Tests/UseSWIG/CMakeLists.txt14
-rw-r--r--Tests/UseSWIG/ModuleName/CMakeLists.txt42
-rw-r--r--Tests/UseSWIG/ModuleName/example.i9
-rw-r--r--Tests/UseSWIG/ModuleName/runme.py52
15 files changed, 175 insertions, 3 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index b044757..5ff2538 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -159,7 +159,7 @@ add_RunCMake_test(FindBoost)
add_RunCMake_test(FindLua)
add_RunCMake_test(FindOpenGL)
if(CMake_TEST_UseSWIG)
- add_RunCMake_test(UseSWIG)
+ add_RunCMake_test(UseSWIG -DCMake_TEST_FindPython=${CMake_TEST_FindPython})
endif()
if(NOT CMAKE_C_COMPILER_ID MATCHES "Watcom")
add_RunCMake_test(GenerateExportHeader)
diff --git a/Tests/RunCMake/UseSWIG/CMP0078-WARN-stderr.txt b/Tests/RunCMake/UseSWIG/CMP0078-WARN-stderr.txt
index f0ed577..d89d174 100644
--- a/Tests/RunCMake/UseSWIG/CMP0078-WARN-stderr.txt
+++ b/Tests/RunCMake/UseSWIG/CMP0078-WARN-stderr.txt
@@ -4,7 +4,7 @@ CMake Warning \(dev\) at .*/Modules/UseSWIG\.cmake:[0-9]+ \(message\):
command to set the policy and suppress this warning\.
Call Stack \(most recent call first\):
- CMP0078-common\.cmake:6 \(swig_add_library\)
+ CMP0078-common\.cmake:8 \(swig_add_library\)
CMP0078-WARN\.cmake:1 \(include\)
CMakeLists\.txt:3 \(include\)
This warning is for project developers. Use -Wno-dev to suppress it.$
diff --git a/Tests/RunCMake/UseSWIG/CMP0078-common.cmake b/Tests/RunCMake/UseSWIG/CMP0078-common.cmake
index 6cf39dc..b13796b 100644
--- a/Tests/RunCMake/UseSWIG/CMP0078-common.cmake
+++ b/Tests/RunCMake/UseSWIG/CMP0078-common.cmake
@@ -1,4 +1,6 @@
+cmake_policy(SET CMP0086 NEW)
+
set(SWIG_EXECUTABLE "swig")
set(SWIG_DIR "/swig")
include(UseSWIG)
diff --git a/Tests/RunCMake/UseSWIG/CMP0086-NEW-nuild-check.cmake b/Tests/RunCMake/UseSWIG/CMP0086-NEW-nuild-check.cmake
new file mode 100644
index 0000000..ea8b2cd
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0086-NEW-nuild-check.cmake
@@ -0,0 +1,4 @@
+
+if (NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/new_example.py")
+ set (RunCMake_TEST_FAILED "Not found expected file: '${RunCMake_TEST_BINARY_DIR}/new_example.py'.")
+endif()
diff --git a/Tests/RunCMake/UseSWIG/CMP0086-NEW.cmake b/Tests/RunCMake/UseSWIG/CMP0086-NEW.cmake
new file mode 100644
index 0000000..b54338d
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0086-NEW.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0086 NEW)
+include(CMP0086-common.cmake)
diff --git a/Tests/RunCMake/UseSWIG/CMP0086-OLD-build-check.cmake b/Tests/RunCMake/UseSWIG/CMP0086-OLD-build-check.cmake
new file mode 100644
index 0000000..96b5295
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0086-OLD-build-check.cmake
@@ -0,0 +1,4 @@
+
+if (NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/example.py")
+ set (RunCMake_TEST_FAILED "Not found expected file: '${RunCMake_TEST_BINARY_DIR}/example.py'.")
+endif()
diff --git a/Tests/RunCMake/UseSWIG/CMP0086-OLD.cmake b/Tests/RunCMake/UseSWIG/CMP0086-OLD.cmake
new file mode 100644
index 0000000..6a63d4c
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0086-OLD.cmake
@@ -0,0 +1,2 @@
+cmake_policy(SET CMP0086 OLD)
+include(CMP0086-common.cmake)
diff --git a/Tests/RunCMake/UseSWIG/CMP0086-WARN-stderr.txt b/Tests/RunCMake/UseSWIG/CMP0086-WARN-stderr.txt
new file mode 100644
index 0000000..af41021
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0086-WARN-stderr.txt
@@ -0,0 +1,11 @@
+CMake Warning \(dev\) at .*/Modules/UseSWIG.cmake:[0-9]+ \(message\):
+ Policy CMP0086 is not set: UseSWIG honors SWIG_MODULE_NAME via -module
+ flag. Run "cmake --help-policy CMP0086" for policy details\. Use the
+ cmake_policy command to set the policy and suppress this warning\.
+
+Call Stack \(most recent call first\):
+ .*/Modules/UseSWIG.cmake:[0-9]+ \(SWIG_ADD_SOURCE_TO_MODULE\)
+ CMP0086-common\.cmake:[0-9]+ \(swig_add_library\)
+ CMP0086-WARN\.cmake:1 \(include\)
+ CMakeLists\.txt:3 \(include\)
+This warning is for project developers\. Use -Wno-dev to suppress it\.$
diff --git a/Tests/RunCMake/UseSWIG/CMP0086-WARN.cmake b/Tests/RunCMake/UseSWIG/CMP0086-WARN.cmake
new file mode 100644
index 0000000..69c2d9d
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0086-WARN.cmake
@@ -0,0 +1 @@
+include(CMP0086-common.cmake)
diff --git a/Tests/RunCMake/UseSWIG/CMP0086-common.cmake b/Tests/RunCMake/UseSWIG/CMP0086-common.cmake
new file mode 100644
index 0000000..c02592a
--- /dev/null
+++ b/Tests/RunCMake/UseSWIG/CMP0086-common.cmake
@@ -0,0 +1,11 @@
+
+cmake_policy(SET CMP0078 NEW)
+
+find_package(Python REQUIRED COMPONENTS Development)
+find_package (SWIG REQUIRED)
+include(UseSWIG)
+
+set_property (SOURCE example.i PROPERTY SWIG_MODULE_NAME "new_example")
+
+swig_add_library(example LANGUAGE python TYPE MODULE SOURCES example.i)
+target_link_libraries(example PRIVATE Python::Python)
diff --git a/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake b/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake
index b96622a..6acf719 100644
--- a/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake
+++ b/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake
@@ -3,3 +3,23 @@ include(RunCMake)
run_cmake(CMP0078-WARN)
run_cmake(CMP0078-OLD)
run_cmake(CMP0078-NEW)
+
+run_cmake(CMP0086-WARN)
+
+if (CMake_TEST_FindPython)
+
+ macro(run_cmake_target test subtest target)
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
+ set(RunCMake_TEST_NO_CLEAN 1)
+ run_cmake_command(${test}-${subtest} ${CMAKE_COMMAND} --build . --target ${target} ${ARGN})
+
+ unset(RunCMake_TEST_BINARY_DIR)
+ unset(RunCMake_TEST_NO_CLEAN)
+ endmacro()
+
+ run_cmake(CMP0086-OLD)
+ run_cmake_target(CMP0086-OLD build example)
+ run_cmake(CMP0086-NEW)
+ run_cmake_target(CMP0086-NEW build example)
+
+endif()
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")