diff options
author | Marc Chevrier <marc.chevrier@sap.com> | 2018-01-29 08:46:51 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@sap.com> | 2018-02-14 07:35:04 (GMT) |
commit | d6048bd153979c268a2943b26fd71be7c5f11251 (patch) | |
tree | b45637ba609ca2e429249c7baa084a6839fde99b | |
parent | d870148537319da2e86237cbd8baf6815975e594 (diff) | |
download | CMake-d6048bd153979c268a2943b26fd71be7c5f11251.zip CMake-d6048bd153979c268a2943b26fd71be7c5f11251.tar.gz CMake-d6048bd153979c268a2943b26fd71be7c5f11251.tar.bz2 |
UseSWIG: Re-work test framework
-rw-r--r-- | Modules/UseSWIG.cmake | 6 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 5 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake (renamed from Tests/SwigTest/CMakeLists.txt) | 28 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/LegacyPerl.cmake | 18 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/LegacyPython.cmake | 9 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/RunCMakeTest.cmake | 13 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/example.cxx (renamed from Tests/SwigTest/example.cxx) | 0 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/example.h (renamed from Tests/SwigTest/example.h) | 0 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/example.i (renamed from Tests/SwigTest/example.i) | 1 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/runme.php4 (renamed from Tests/SwigTest/runme.php4) | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | Tests/RunCMake/UseSWIG/runme.pike (renamed from Tests/SwigTest/runme.pike) | 0 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/runme.pl (renamed from Tests/SwigTest/runme.pl) | 1 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/runme.py | 52 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/runme.rb (renamed from Tests/SwigTest/runme.rb) | 0 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/runme.tcl (renamed from Tests/SwigTest/runme.tcl) | 1 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/runme2.tcl (renamed from Tests/SwigTest/runme2.tcl) | 1 | ||||
-rw-r--r-- | Tests/SwigTest/runme.py | 51 |
18 files changed, 119 insertions, 70 deletions
diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index 959893f..cc30669 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -378,6 +378,12 @@ macro(SWIG_ADD_LIBRARY name) if (APPLE) set_target_properties (${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".bundle") endif () + elseif ("${swig_lowercase_language}" STREQUAL "perl") + # assume empty prefix because we expect the module to be dynamically loaded + set_target_properties (${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "") + if (APPLE) + set_target_properties (${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES SUFFIX ".dylib") + endif () else() # assume empty prefix because we expect the module to be dynamically loaded set_target_properties (${SWIG_MODULE_${name}_REAL_NAME} PROPERTIES PREFIX "") diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index d5bd297..31069fa 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -358,6 +358,11 @@ if(CMake_TEST_FindMatlab) add_RunCMake_test(FindMatlab) endif() +# UseSWIG related tests +if(CMake_TEST_UseSWIG) + add_RunCMake_test(UseSWIG) +endif() + add_executable(pseudo_emulator pseudo_emulator.c) add_executable(pseudo_emulator_custom_command pseudo_emulator_custom_command.c) add_RunCMake_test(CrosscompilingEmulator diff --git a/Tests/RunCMake/UseSWIG/CMakeLists.txt b/Tests/RunCMake/UseSWIG/CMakeLists.txt new file mode 100644 index 0000000..f452db1 --- /dev/null +++ b/Tests/RunCMake/UseSWIG/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 2.8.4) +project(${RunCMake_TEST} CXX) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/SwigTest/CMakeLists.txt b/Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake index 65f5c93..3f400bf 100644 --- a/Tests/SwigTest/CMakeLists.txt +++ b/Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake @@ -1,54 +1,52 @@ -set(language "python") - -cmake_minimum_required (VERSION 2.6) - -project(example_${language}_class) find_package(SWIG REQUIRED) include(${SWIG_USE_FILE}) unset(SWIG_LANG_TYPE) if(${language} MATCHES python) - find_package(PythonLibs) + find_package(PythonInterp REQUIRED) + find_package(PythonLibs REQUIRED) include_directories(${PYTHON_INCLUDE_PATH}) set(SWIG_LANG_LIBRARIES ${PYTHON_LIBRARIES}) endif() if(${language} MATCHES perl) - find_package(PerlLibs) + find_package(Perl REQUIRED) + find_package(PerlLibs REQUIRED) include_directories(${PERL_INCLUDE_PATH}) - add_definitions(${PERL_EXTRA_C_FLAGS}) + separate_arguments(c_flags UNIX_COMMAND "${PERL_EXTRA_C_FLAGS}") + add_compile_options(${c_flags}) set(SWIG_LANG_LIBRARIES ${PERL_LIBRARY}) endif() if(${language} MATCHES tcl) - find_package(TCL) + find_package(TCL REQUIRED) include_directories(${TCL_INCLUDE_PATH}) set(SWIG_LANG_LIBRARIES ${TCL_LIBRARY}) endif() if(${language} MATCHES ruby) - find_package(Ruby) + find_package(Ruby REQUIRED) include_directories(${RUBY_INCLUDE_PATH}) set(SWIG_LANG_LIBRARIES ${RUBY_LIBRARY}) endif() if(${language} MATCHES php4) - find_package(PHP4) + find_package(PHP4 REQUIRED) include_directories(${PHP4_INCLUDE_PATH}) set(SWIG_LANG_LIBRARIES ${PHP4_LIBRARY}) endif() if(${language} MATCHES pike) - find_package(Pike) + find_package(Pike REQUIRED) include_directories(${PIKE_INCLUDE_PATH}) set(SWIG_LANG_LIBRARIES ${PIKE_LIBRARY}) endif() if(${language} MATCHES lua) - find_package(Lua) + find_package(Lua REQUIRED) include_directories(${LUA_INCLUDE_DIR}) set(SWIG_LANG_TYPE TYPE SHARED) set(SWIG_LANG_LIBRARIES ${LUA_LIBRARIES}) endif() -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +unset(CMAKE_SWIG_FLAGS) -set(CMAKE_SWIG_FLAGS "") +include_directories(${CMAKE_CURRENT_LIST_DIR}) set_source_files_properties(example.i PROPERTIES CPLUSPLUS ON) set_source_files_properties(example.i PROPERTIES SWIG_FLAGS "-includeall") diff --git a/Tests/RunCMake/UseSWIG/LegacyPerl.cmake b/Tests/RunCMake/UseSWIG/LegacyPerl.cmake new file mode 100644 index 0000000..cfa8c53 --- /dev/null +++ b/Tests/RunCMake/UseSWIG/LegacyPerl.cmake @@ -0,0 +1,18 @@ + +set(language "perl") + +include (LegacyConfiguration.cmake) + +if (WIN32) + file (TO_CMAKE_PATH "$ENV{PATH}" perl_path) + string (REPLACE ";" "$<SEMICOLON>" perl_path "${perl_path}") + set (perl_env "PATH=$<TARGET_FILE_DIR:${SWIG_MODULE_example_REAL_NAME}>$<SEMICOLON>${perl_path}") +else() + set (perl_env "LD_LIBRARY_PATH=$<TARGET_FILE_DIR:${SWIG_MODULE_example_REAL_NAME}>") +endif() + +add_custom_target (RunPerl + COMMAND "${CMAKE_COMMAND}" -E env "${perl_env}" + "${PERL_EXECUTABLE}" "-I$<TARGET_FILE_DIR:${SWIG_MODULE_example_REAL_NAME}>" + "${CMAKE_CURRENT_SOURCE_DIR}/runme.pl" + DEPENDS ${SWIG_MODULE_example_REAL_NAME}) diff --git a/Tests/RunCMake/UseSWIG/LegacyPython.cmake b/Tests/RunCMake/UseSWIG/LegacyPython.cmake new file mode 100644 index 0000000..f3d9e2b --- /dev/null +++ b/Tests/RunCMake/UseSWIG/LegacyPython.cmake @@ -0,0 +1,9 @@ + +set(language "python") + +include (LegacyConfiguration.cmake) + +add_custom_target (RunPython + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:${SWIG_MODULE_example_REAL_NAME}>" + "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/runme.py" + DEPENDS ${SWIG_MODULE_example_REAL_NAME}) diff --git a/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake b/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake new file mode 100644 index 0000000..cbeba66 --- /dev/null +++ b/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake @@ -0,0 +1,13 @@ +include(RunCMake) + +function(run_SWIG group language) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${group}${language}-build) + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + run_cmake(${group}${language}) + run_cmake_command(${group}${language}-test ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR} --target Run${language}) +endfunction() + +run_SWIG(Legacy Python) +run_SWIG(Legacy Perl) diff --git a/Tests/SwigTest/example.cxx b/Tests/RunCMake/UseSWIG/example.cxx index 961d6dd..961d6dd 100644 --- a/Tests/SwigTest/example.cxx +++ b/Tests/RunCMake/UseSWIG/example.cxx diff --git a/Tests/SwigTest/example.h b/Tests/RunCMake/UseSWIG/example.h index 366deb0..366deb0 100644 --- a/Tests/SwigTest/example.h +++ b/Tests/RunCMake/UseSWIG/example.h diff --git a/Tests/SwigTest/example.i b/Tests/RunCMake/UseSWIG/example.i index 75700b3..fbdf724 100644 --- a/Tests/SwigTest/example.i +++ b/Tests/RunCMake/UseSWIG/example.i @@ -7,4 +7,3 @@ /* Let's just grab the original header file here */ %include "example.h" - diff --git a/Tests/SwigTest/runme.php4 b/Tests/RunCMake/UseSWIG/runme.php4 index 653ced2..653ced2 100644 --- a/Tests/SwigTest/runme.php4 +++ b/Tests/RunCMake/UseSWIG/runme.php4 diff --git a/Tests/SwigTest/runme.pike b/Tests/RunCMake/UseSWIG/runme.pike index ec28dd7..ec28dd7 100755..100644 --- a/Tests/SwigTest/runme.pike +++ b/Tests/RunCMake/UseSWIG/runme.pike diff --git a/Tests/SwigTest/runme.pl b/Tests/RunCMake/UseSWIG/runme.pl index 5bfb3d8..965e063 100644 --- a/Tests/SwigTest/runme.pl +++ b/Tests/RunCMake/UseSWIG/runme.pl @@ -54,4 +54,3 @@ examplec::delete_Shape($s); print $examplec::Shape_nshapes," shapes remain\n"; print "Goodbye\n"; - diff --git a/Tests/RunCMake/UseSWIG/runme.py b/Tests/RunCMake/UseSWIG/runme.py new file mode 100644 index 0000000..af5e07d --- /dev/null +++ b/Tests/RunCMake/UseSWIG/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 example + +# ----- Object creation ----- + +print ("Creating some objects:") +c = example.Circle(10) +print (" Created circle", c) +s = example.Square(10) +print (" Created square", s) + +# ----- Access a static member ----- + +print ("\nA total of", 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 (example.cvar.Shape_nshapes,"shapes remain") +print ("Goodbye") diff --git a/Tests/SwigTest/runme.rb b/Tests/RunCMake/UseSWIG/runme.rb index de73bcd..de73bcd 100644 --- a/Tests/SwigTest/runme.rb +++ b/Tests/RunCMake/UseSWIG/runme.rb diff --git a/Tests/SwigTest/runme.tcl b/Tests/RunCMake/UseSWIG/runme.tcl index c7f4725..6055cf6 100644 --- a/Tests/SwigTest/runme.tcl +++ b/Tests/RunCMake/UseSWIG/runme.tcl @@ -47,4 +47,3 @@ rename s "" puts "$Shape_nshapes shapes remain" puts "Goodbye" - diff --git a/Tests/SwigTest/runme2.tcl b/Tests/RunCMake/UseSWIG/runme2.tcl index 88ec2f6..d0b5c21 100644 --- a/Tests/SwigTest/runme2.tcl +++ b/Tests/RunCMake/UseSWIG/runme2.tcl @@ -67,4 +67,3 @@ delete_Shape $s puts "$Shape_nshapes shapes remain" puts "Goodbye" - diff --git a/Tests/SwigTest/runme.py b/Tests/SwigTest/runme.py deleted file mode 100644 index ed3909e..0000000 --- a/Tests/SwigTest/runme.py +++ /dev/null @@ -1,51 +0,0 @@ -# file: runme.py - -# This file illustrates the shadow-class C++ interface generated -# by SWIG. - -import example - -# ----- Object creation ----- - -print "Creating some objects:" -c = example.Circle(10) -print " Created circle", c -s = example.Square(10) -print " Created square", s - -# ----- Access a static member ----- - -print "\nA total of", 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 example.cvar.Shape_nshapes,"shapes remain" -print "Goodbye" - |