Merge topic 'SWIG'

dff28141dc UseSWIG: add management of SWIG option -module
7b3d4799f8 Help: update policy 0078 documentation

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2669
This commit is contained in:
Brad King
2018-12-10 13:23:34 +00:00
committed by Kitware Robot
21 changed files with 233 additions and 4 deletions
+1 -1
View File
@@ -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)
@@ -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.$
@@ -1,4 +1,6 @@
cmake_policy(SET CMP0086 NEW)
set(SWIG_EXECUTABLE "swig")
set(SWIG_DIR "/swig")
include(UseSWIG)
@@ -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()
+2
View File
@@ -0,0 +1,2 @@
cmake_policy(SET CMP0086 NEW)
include(CMP0086-common.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()
+2
View File
@@ -0,0 +1,2 @@
cmake_policy(SET CMP0086 OLD)
include(CMP0086-common.cmake)
@@ -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\.$
@@ -0,0 +1 @@
include(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)
+20
View File
@@ -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()
+13 -1
View File
@@ -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>
)
+42
View File
@@ -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")
+9
View File
@@ -0,0 +1,9 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Let's just grab the original header file here */
%include "example.h"
+52
View File
@@ -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")