Commit d6048bd1 authored by Marc Chevrier's avatar Marc Chevrier

UseSWIG: Re-work test framework

parent d8701485
......@@ -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 "")
......
......@@ -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
......
cmake_minimum_required(VERSION 2.8.4)
project(${RunCMake_TEST} CXX)
include(${RunCMake_TEST}.cmake)
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")
......
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})
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})
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)
......@@ -7,4 +7,3 @@
/* Let's just grab the original header file here */
%include "example.h"
......@@ -54,4 +54,3 @@ examplec::delete_Shape($s);
print $examplec::Shape_nshapes," shapes remain\n";
print "Goodbye\n";
......@@ -3,19 +3,21 @@
# This file illustrates the shadow-class C++ interface generated
# by SWIG.
from __future__ import print_function
import example
# ----- Object creation -----
print "Creating some objects:"
print ("Creating some objects:")
c = example.Circle(10)
print " Created circle", c
print (" Created circle", c)
s = example.Square(10)
print " Created square", s
print (" Created square", s)
# ----- Access a static member -----
print "\nA total of", example.cvar.Shape_nshapes,"shapes were created"
print ("\nA total of", example.cvar.Shape_nshapes,"shapes were created")
# ----- Member data access -----
......@@ -27,25 +29,24 @@ 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)
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:"
print ("\nHere are some properties of the shapes:")
for o in [c,s]:
print " ", o
print " area = ", o.area()
print " perimeter = ", o.perimeter()
print (" ", o)
print (" area = ", o.area())
print (" perimeter = ", o.perimeter())
print "\nGuess I'll clean up now"
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"
print (example.cvar.Shape_nshapes,"shapes remain")
print ("Goodbye")
......@@ -47,4 +47,3 @@ rename s ""
puts "$Shape_nshapes shapes remain"
puts "Goodbye"
......@@ -67,4 +67,3 @@ delete_Shape $s
puts "$Shape_nshapes shapes remain"
puts "Goodbye"
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