From 438429d6fe04164b7ed70bda872e291d0df1a9e3 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Tue, 27 Mar 2018 10:17:35 +0200 Subject: UseSWIG: Rework tests --- Tests/CMakeLists.txt | 4 ++ Tests/RunCMake/CMakeLists.txt | 5 -- Tests/RunCMake/UseSWIG/BasicConfiguration.cmake | 67 ---------------------- Tests/RunCMake/UseSWIG/BasicPerl.cmake | 18 ------ Tests/RunCMake/UseSWIG/BasicPython.cmake | 9 --- Tests/RunCMake/UseSWIG/CMakeLists.txt | 3 - Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake | 60 -------------------- Tests/RunCMake/UseSWIG/LegacyPerl.cmake | 18 ------ Tests/RunCMake/UseSWIG/LegacyPython.cmake | 9 --- Tests/RunCMake/UseSWIG/MultipleModules.cmake | 30 ---------- Tests/RunCMake/UseSWIG/MultiplePython.cmake | 26 --------- Tests/RunCMake/UseSWIG/RunCMakeTest.cmake | 27 --------- Tests/RunCMake/UseSWIG/example.cxx | 33 ----------- Tests/RunCMake/UseSWIG/example.h | 37 ------------ Tests/RunCMake/UseSWIG/example.i | 9 --- Tests/RunCMake/UseSWIG/runme.php4 | 58 ------------------- Tests/RunCMake/UseSWIG/runme.pike | 53 ----------------- Tests/RunCMake/UseSWIG/runme.pl | 56 ------------------ Tests/RunCMake/UseSWIG/runme.py | 52 ----------------- Tests/RunCMake/UseSWIG/runme.rb | 49 ---------------- Tests/RunCMake/UseSWIG/runme.tcl | 49 ---------------- Tests/RunCMake/UseSWIG/runme2.tcl | 69 ----------------------- Tests/UseSWIG/BasicConfiguration.cmake | 72 ++++++++++++++++++++++++ Tests/UseSWIG/BasicPerl/CMakeLists.txt | 22 ++++++++ Tests/UseSWIG/BasicPython/CMakeLists.txt | 13 +++++ Tests/UseSWIG/CMakeLists.txt | 62 ++++++++++++++++++++ Tests/UseSWIG/LegacyConfiguration.cmake | 61 ++++++++++++++++++++ Tests/UseSWIG/LegacyPerl/CMakeLists.txt | 22 ++++++++ Tests/UseSWIG/LegacyPython/CMakeLists.txt | 13 +++++ Tests/UseSWIG/MultipleModules/CMakeLists.txt | 38 +++++++++++++ Tests/UseSWIG/MultiplePython/CMakeLists.txt | 32 +++++++++++ Tests/UseSWIG/example.cxx | 33 +++++++++++ Tests/UseSWIG/example.h | 37 ++++++++++++ Tests/UseSWIG/example.i | 9 +++ Tests/UseSWIG/runme.php4 | 58 +++++++++++++++++++ Tests/UseSWIG/runme.pike | 53 +++++++++++++++++ Tests/UseSWIG/runme.pl | 56 ++++++++++++++++++ Tests/UseSWIG/runme.py | 52 +++++++++++++++++ Tests/UseSWIG/runme.rb | 49 ++++++++++++++++ Tests/UseSWIG/runme.tcl | 49 ++++++++++++++++ Tests/UseSWIG/runme2.tcl | 69 +++++++++++++++++++++++ 41 files changed, 804 insertions(+), 737 deletions(-) delete mode 100644 Tests/RunCMake/UseSWIG/BasicConfiguration.cmake delete mode 100644 Tests/RunCMake/UseSWIG/BasicPerl.cmake delete mode 100644 Tests/RunCMake/UseSWIG/BasicPython.cmake delete mode 100644 Tests/RunCMake/UseSWIG/CMakeLists.txt delete mode 100644 Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake delete mode 100644 Tests/RunCMake/UseSWIG/LegacyPerl.cmake delete mode 100644 Tests/RunCMake/UseSWIG/LegacyPython.cmake delete mode 100644 Tests/RunCMake/UseSWIG/MultipleModules.cmake delete mode 100644 Tests/RunCMake/UseSWIG/MultiplePython.cmake delete mode 100644 Tests/RunCMake/UseSWIG/RunCMakeTest.cmake delete mode 100644 Tests/RunCMake/UseSWIG/example.cxx delete mode 100644 Tests/RunCMake/UseSWIG/example.h delete mode 100644 Tests/RunCMake/UseSWIG/example.i delete mode 100644 Tests/RunCMake/UseSWIG/runme.php4 delete mode 100644 Tests/RunCMake/UseSWIG/runme.pike delete mode 100644 Tests/RunCMake/UseSWIG/runme.pl delete mode 100644 Tests/RunCMake/UseSWIG/runme.py delete mode 100644 Tests/RunCMake/UseSWIG/runme.rb delete mode 100644 Tests/RunCMake/UseSWIG/runme.tcl delete mode 100644 Tests/RunCMake/UseSWIG/runme2.tcl create mode 100644 Tests/UseSWIG/BasicConfiguration.cmake create mode 100644 Tests/UseSWIG/BasicPerl/CMakeLists.txt create mode 100644 Tests/UseSWIG/BasicPython/CMakeLists.txt create mode 100644 Tests/UseSWIG/CMakeLists.txt create mode 100644 Tests/UseSWIG/LegacyConfiguration.cmake create mode 100644 Tests/UseSWIG/LegacyPerl/CMakeLists.txt create mode 100644 Tests/UseSWIG/LegacyPython/CMakeLists.txt create mode 100644 Tests/UseSWIG/MultipleModules/CMakeLists.txt create mode 100644 Tests/UseSWIG/MultiplePython/CMakeLists.txt create mode 100644 Tests/UseSWIG/example.cxx create mode 100644 Tests/UseSWIG/example.h create mode 100644 Tests/UseSWIG/example.i create mode 100644 Tests/UseSWIG/runme.php4 create mode 100644 Tests/UseSWIG/runme.pike create mode 100644 Tests/UseSWIG/runme.pl create mode 100644 Tests/UseSWIG/runme.py create mode 100644 Tests/UseSWIG/runme.rb create mode 100644 Tests/UseSWIG/runme.tcl create mode 100644 Tests/UseSWIG/runme2.tcl diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 1344692..1309c42 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1431,6 +1431,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release add_subdirectory(FindPython) endif() + if(CMake_TEST_UseSWIG) + add_subdirectory(UseSWIG) + endif() + add_subdirectory(FindThreads) # Matlab module diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index ff4a80e..c0c361e 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -362,11 +362,6 @@ 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/BasicConfiguration.cmake b/Tests/RunCMake/UseSWIG/BasicConfiguration.cmake deleted file mode 100644 index 2f46d63..0000000 --- a/Tests/RunCMake/UseSWIG/BasicConfiguration.cmake +++ /dev/null @@ -1,67 +0,0 @@ - -find_package(SWIG REQUIRED) -include(${SWIG_USE_FILE}) - -unset(SWIG_LANG_TYPE) -unset(SWIG_LANG_INCLUDE_DIRECTORIES) -unset(SWIG_LANG_DEFINITIONS) -unset(SWIG_LANG_OPTIONS) -unset(SWIG_LANG_LIBRARIES) - -if(${language} MATCHES python) - find_package(Python REQUIRED COMPONENTS Interpreter Development) - set(SWIG_LANG_INCLUDE_DIRECTORIES ${Python_INCLUDE_DIRS}) - set(SWIG_LANG_LIBRARIES ${Python_LIBRARIES}) -endif() -if(${language} MATCHES perl) - find_package(Perl REQUIRED) - find_package(PerlLibs REQUIRED) - set(SWIG_LANG_INCLUDE_DIRECTORIES ${PERL_INCLUDE_PATH}) - separate_arguments(c_flags UNIX_COMMAND "${PERL_EXTRA_C_FLAGS}") - set(SWIG_LANG_OPTIONS ${c_flags}) - set(SWIG_LANG_LIBRARIES ${PERL_LIBRARY}) -endif() -if(${language} MATCHES tcl) - find_package(TCL REQUIRED) - set(SWIG_LANG_INCLUDE_DIRECTORIES ${TCL_INCLUDE_PATH}) - set(SWIG_LANG_LIBRARIES ${TCL_LIBRARY}) -endif() -if(${language} MATCHES ruby) - find_package(Ruby REQUIRED) - set(SWIG_LANG_INCLUDE_DIRECTORIES ${RUBY_INCLUDE_PATH}) - set(SWIG_LANG_LIBRARIES ${RUBY_LIBRARY}) -endif() -if(${language} MATCHES php4) - find_package(PHP4 REQUIRED) - set(SWIG_LANG_INCLUDE_DIRECTORIES ${PHP4_INCLUDE_PATH}) - set(SWIG_LANG_LIBRARIES ${PHP4_LIBRARY}) -endif() -if(${language} MATCHES pike) - find_package(Pike REQUIRED) - set(SWIG_LANG_INCLUDE_DIRECTORIES ${PIKE_INCLUDE_PATH}) - set(SWIG_LANG_LIBRARIES ${PIKE_LIBRARY}) -endif() -if(${language} MATCHES lua) - find_package(Lua REQUIRED) - set(SWIG_LANG_INCLUDE_DIRECTORIES ${LUA_INCLUDE_DIR}) - set(SWIG_LANG_TYPE TYPE SHARED) - set(SWIG_LANG_LIBRARIES ${LUA_LIBRARIES}) -endif() - -unset(CMAKE_SWIG_FLAGS) - -set (CMAKE_INCLUDE_CURRENT_DIR ON) - -set_property(SOURCE example.i PROPERTY CPLUSPLUS ON) -set_property(SOURCE example.i PROPERTY COMPILE_OPTIONS -includeall) - -set_property(SOURCE example.i PROPERTY GENERATED_INCLUDE_DIRECTORIES ${SWIG_LANG_INCLUDE_DIRECTORIES}) -set_property(SOURCE example.i PROPERTY GENERATED_COMPILE_DEFINITIONS ${SWIG_LANG_DEFINITIONS}) -set_property(SOURCE example.i PROPERTY GENERATED_COMPILE_OPTIONS ${SWIG_LANG_OPTIONS}) - - -SWIG_ADD_LIBRARY(example - LANGUAGE "${language}" - ${SWIG_LANG_TYPE} - SOURCES example.i example.cxx) -TARGET_LINK_LIBRARIES(example PRIVATE ${SWIG_LANG_LIBRARIES}) diff --git a/Tests/RunCMake/UseSWIG/BasicPerl.cmake b/Tests/RunCMake/UseSWIG/BasicPerl.cmake deleted file mode 100644 index 67ad6bc..0000000 --- a/Tests/RunCMake/UseSWIG/BasicPerl.cmake +++ /dev/null @@ -1,18 +0,0 @@ - -set(language "perl") - -include (BasicConfiguration.cmake) - -if (WIN32) - file (TO_CMAKE_PATH "$ENV{PATH}" perl_path) - string (REPLACE ";" "$" perl_path "${perl_path}") - set (perl_env "PATH=$$${perl_path}") -else() - set (perl_env "LD_LIBRARY_PATH=$") -endif() - -add_custom_target (RunTest - COMMAND "${CMAKE_COMMAND}" -E env "${perl_env}" - "${PERL_EXECUTABLE}" "-I$" - "${CMAKE_CURRENT_SOURCE_DIR}/runme.pl" - DEPENDS example) diff --git a/Tests/RunCMake/UseSWIG/BasicPython.cmake b/Tests/RunCMake/UseSWIG/BasicPython.cmake deleted file mode 100644 index 873dbe9..0000000 --- a/Tests/RunCMake/UseSWIG/BasicPython.cmake +++ /dev/null @@ -1,9 +0,0 @@ - -set(language "python") - -include (BasicConfiguration.cmake) - -add_custom_target (RunTest - COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$" - "${Python_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/runme.py" - DEPENDS example) diff --git a/Tests/RunCMake/UseSWIG/CMakeLists.txt b/Tests/RunCMake/UseSWIG/CMakeLists.txt deleted file mode 100644 index 2d75985..0000000 --- a/Tests/RunCMake/UseSWIG/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -cmake_minimum_required(VERSION 3.1) -project(${RunCMake_TEST} CXX) -include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake b/Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake deleted file mode 100644 index 3ce0790..0000000 --- a/Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake +++ /dev/null @@ -1,60 +0,0 @@ - -# Prevent deprecated warnings from new UseSWIG module -set (CMAKE_WARN_DEPRECATED FALSE) - -find_package(SWIG REQUIRED) -include(${SWIG_USE_FILE}) - -unset(SWIG_LANG_TYPE) -if(${language} MATCHES python) - 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(Perl REQUIRED) - find_package(PerlLibs REQUIRED) - include_directories(${PERL_INCLUDE_PATH}) - 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 REQUIRED) - include_directories(${TCL_INCLUDE_PATH}) - set(SWIG_LANG_LIBRARIES ${TCL_LIBRARY}) -endif() -if(${language} MATCHES ruby) - find_package(Ruby REQUIRED) - include_directories(${RUBY_INCLUDE_PATH}) - set(SWIG_LANG_LIBRARIES ${RUBY_LIBRARY}) -endif() -if(${language} MATCHES php4) - find_package(PHP4 REQUIRED) - include_directories(${PHP4_INCLUDE_PATH}) - set(SWIG_LANG_LIBRARIES ${PHP4_LIBRARY}) -endif() -if(${language} MATCHES pike) - find_package(Pike REQUIRED) - include_directories(${PIKE_INCLUDE_PATH}) - set(SWIG_LANG_LIBRARIES ${PIKE_LIBRARY}) -endif() -if(${language} MATCHES lua) - find_package(Lua REQUIRED) - include_directories(${LUA_INCLUDE_DIR}) - set(SWIG_LANG_TYPE TYPE SHARED) - set(SWIG_LANG_LIBRARIES ${LUA_LIBRARIES}) -endif() - -unset(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") -SWIG_ADD_LIBRARY(example - LANGUAGE "${language}" - ${SWIG_LANG_TYPE} - SOURCES example.i example.cxx) -SWIG_LINK_LIBRARIES(example ${SWIG_LANG_LIBRARIES}) diff --git a/Tests/RunCMake/UseSWIG/LegacyPerl.cmake b/Tests/RunCMake/UseSWIG/LegacyPerl.cmake deleted file mode 100644 index 3428c46..0000000 --- a/Tests/RunCMake/UseSWIG/LegacyPerl.cmake +++ /dev/null @@ -1,18 +0,0 @@ - -set(language "perl") - -include (LegacyConfiguration.cmake) - -if (WIN32) - file (TO_CMAKE_PATH "$ENV{PATH}" perl_path) - string (REPLACE ";" "$" perl_path "${perl_path}") - set (perl_env "PATH=$$${perl_path}") -else() - set (perl_env "LD_LIBRARY_PATH=$") -endif() - -add_custom_target (RunTest - COMMAND "${CMAKE_COMMAND}" -E env "${perl_env}" - "${PERL_EXECUTABLE}" "-I$" - "${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 deleted file mode 100644 index 8b47aa2..0000000 --- a/Tests/RunCMake/UseSWIG/LegacyPython.cmake +++ /dev/null @@ -1,9 +0,0 @@ - -set(language "python") - -include (LegacyConfiguration.cmake) - -add_custom_target (RunTest - COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$" - "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/runme.py" - DEPENDS ${SWIG_MODULE_example_REAL_NAME}) diff --git a/Tests/RunCMake/UseSWIG/MultipleModules.cmake b/Tests/RunCMake/UseSWIG/MultipleModules.cmake deleted file mode 100644 index e3d579f..0000000 --- a/Tests/RunCMake/UseSWIG/MultipleModules.cmake +++ /dev/null @@ -1,30 +0,0 @@ - -find_package(SWIG REQUIRED) -include(${SWIG_USE_FILE}) - -find_package(PythonLibs REQUIRED) -find_package(PerlLibs REQUIRED) - -unset(CMAKE_SWIG_FLAGS) - -set (CMAKE_INCLUDE_CURRENT_DIR ON) - -set_property(SOURCE example.i PROPERTY CPLUSPLUS ON) -set_property(SOURCE example.i PROPERTY COMPILE_OPTIONS -includeall) - -set_property(SOURCE example.i PROPERTY GENERATED_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_PATH}) - -swig_add_library(example1 - LANGUAGE python - SOURCES example.i example.cxx) -target_link_libraries(example1 PRIVATE ${PYTHON_LIBRARIES}) - -# re-use sample interface file for another plugin -set_property(SOURCE example.i PROPERTY GENERATED_INCLUDE_DIRECTORIES ${PERL_INCLUDE_PATH}) -separate_arguments(c_flags UNIX_COMMAND "${PERL_EXTRA_C_FLAGS}") -set_property(SOURCE example.i PROPERTY GENERATED_COMPILE_OPTIONS ${c_flags}) - -swig_add_library(example2 - LANGUAGE perl - SOURCES example.i example.cxx) -target_link_libraries(example2 PRIVATE ${PERL_LIBRARY}) diff --git a/Tests/RunCMake/UseSWIG/MultiplePython.cmake b/Tests/RunCMake/UseSWIG/MultiplePython.cmake deleted file mode 100644 index 3804bdd..0000000 --- a/Tests/RunCMake/UseSWIG/MultiplePython.cmake +++ /dev/null @@ -1,26 +0,0 @@ - -find_package(SWIG REQUIRED) -include(${SWIG_USE_FILE}) - -find_package(Python2 REQUIRED COMPONENTS Development) -find_package(Python3 REQUIRED COMPONENTS Development) - -unset(CMAKE_SWIG_FLAGS) - -set (CMAKE_INCLUDE_CURRENT_DIR ON) - -set_property(SOURCE example.i PROPERTY CPLUSPLUS ON) -set_property(SOURCE example.i PROPERTY COMPILE_OPTIONS -includeall) - -swig_add_library(example1 - LANGUAGE python - OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python2" - SOURCES example.i example.cxx) -target_link_libraries(example1 PRIVATE Python2::Python) - -# re-use sample interface file for another plugin -swig_add_library(example2 - LANGUAGE python - OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python3" - SOURCES example.i example.cxx) -target_link_libraries(example2 PRIVATE Python3::Python) diff --git a/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake b/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake deleted file mode 100644 index cded22f..0000000 --- a/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake +++ /dev/null @@ -1,27 +0,0 @@ -include(RunCMake) - -function(run_SWIG test) - cmake_parse_arguments(_SWIG_TEST "" "TARGET" "" ${ARGN}) - if (_SWIG_TEST_TARGET) - list (INSERT _SWIG_TEST_TARGET 0 --target) - endif() - - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build) - set(RunCMake_TEST_NO_CLEAN 1) - file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") - file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") - if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) - set (RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Release) - endif() - run_cmake(${test}) - run_cmake_command(${test}-test ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR} --config Release ${_SWIG_TEST_TARGET}) -endfunction() - -run_SWIG(LegacyPython TARGET RunTest) -run_SWIG(LegacyPerl TARGET RunTest) - -run_SWIG(BasicPython TARGET RunTest) -run_SWIG(BasicPerl TARGET RunTest) - -run_SWIG(MultipleModules) -run_SWIG(MultiplePython) diff --git a/Tests/RunCMake/UseSWIG/example.cxx b/Tests/RunCMake/UseSWIG/example.cxx deleted file mode 100644 index 961d6dd..0000000 --- a/Tests/RunCMake/UseSWIG/example.cxx +++ /dev/null @@ -1,33 +0,0 @@ -/* File : example.c */ - -#include "example.h" -#define M_PI 3.14159265358979323846 - -/* Move the shape to a new location */ -void Shape::move(double dx, double dy) -{ - x += dx; - y += dy; -} - -int Shape::nshapes = 0; - -double Circle::area(void) -{ - return M_PI * radius * radius; -} - -double Circle::perimeter(void) -{ - return 2 * M_PI * radius; -} - -double Square::area(void) -{ - return width * width; -} - -double Square::perimeter(void) -{ - return 4 * width; -} diff --git a/Tests/RunCMake/UseSWIG/example.h b/Tests/RunCMake/UseSWIG/example.h deleted file mode 100644 index 366deb0..0000000 --- a/Tests/RunCMake/UseSWIG/example.h +++ /dev/null @@ -1,37 +0,0 @@ -/* File : example.h */ - -class Shape -{ -public: - Shape() { nshapes++; } - virtual ~Shape() { nshapes--; }; - double x, y; - void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; - static int nshapes; -}; - -class Circle : public Shape -{ -private: - double radius; - -public: - Circle(double r) - : radius(r){}; - virtual double area(void); - virtual double perimeter(void); -}; - -class Square : public Shape -{ -private: - double width; - -public: - Square(double w) - : width(w){}; - virtual double area(void); - virtual double perimeter(void); -}; diff --git a/Tests/RunCMake/UseSWIG/example.i b/Tests/RunCMake/UseSWIG/example.i deleted file mode 100644 index fbdf724..0000000 --- a/Tests/RunCMake/UseSWIG/example.i +++ /dev/null @@ -1,9 +0,0 @@ -/* File : example.i */ -%module example - -%{ -#include "example.h" -%} - -/* Let's just grab the original header file here */ -%include "example.h" diff --git a/Tests/RunCMake/UseSWIG/runme.php4 b/Tests/RunCMake/UseSWIG/runme.php4 deleted file mode 100644 index 653ced2..0000000 --- a/Tests/RunCMake/UseSWIG/runme.php4 +++ /dev/null @@ -1,58 +0,0 @@ - diff --git a/Tests/RunCMake/UseSWIG/runme.pike b/Tests/RunCMake/UseSWIG/runme.pike deleted file mode 100644 index ec28dd7..0000000 --- a/Tests/RunCMake/UseSWIG/runme.pike +++ /dev/null @@ -1,53 +0,0 @@ -import .example; - -int main() -{ - // ----- Object creation ----- - - write("Creating some objects:\n"); - Circle c = Circle(10.0); - write(" Created circle.\n"); - Square s = Square(10.0); - write(" Created square.\n"); - - // ----- Access a static member ----- - - write("\nA total of " + Shape_nshapes_get() + " shapes were created\n"); - - // ----- Member data access ----- - - // Set the location of the object - - c->x_set(20.0); - c->y_set(30.0); - - s->x_set(-10.0); - s->y_set(5.0); - - write("\nHere is their current position:\n"); - write(" Circle = (%f, %f)\n", c->x_get(), c->y_get()); - write(" Square = (%f, %f)\n", s->x_get(), s->y_get()); - - // ----- Call some methods ----- - - write("\nHere are some properties of the shapes:\n"); - write(" The circle:\n"); - write(" area = %f.\n", c->area()); - write(" perimeter = %f.\n", c->perimeter()); - write(" The square:\n"); - write(" area = %f.\n", s->area()); - write(" perimeter = %f.\n", s->perimeter()); - - write("\nGuess I'll clean up now\n"); - - /* See if we can force 's' to be garbage-collected */ - s = 0; - - /* Now we should be down to only 1 shape */ - write("%d shapes remain\n", Shape_nshapes_get()); - - /* Done */ - write("Goodbye\n"); - - return 0; -} diff --git a/Tests/RunCMake/UseSWIG/runme.pl b/Tests/RunCMake/UseSWIG/runme.pl deleted file mode 100644 index 965e063..0000000 --- a/Tests/RunCMake/UseSWIG/runme.pl +++ /dev/null @@ -1,56 +0,0 @@ -# file: runme.pl - -# This file illustrates the low-level C++ interface -# created by SWIG. In this case, all of our C++ classes -# get converted into function calls. - -use example; - -# ----- Object creation ----- - -print "Creating some objects:\n"; -$c = examplec::new_Circle(10); -print " Created circle $c\n"; -$s = examplec::new_Square(10); -print " Created square $s\n"; - -# ----- Access a static member ----- - -print "\nA total of $examplec::Shape_nshapes shapes were created\n"; - -# ----- Member data access ----- - -# Set the location of the object. -# Note: methods in the base class Shape are used since -# x and y are defined there. - -examplec::Shape_x_set($c, 20); -examplec::Shape_y_set($c, 30); -examplec::Shape_x_set($s,-10); -examplec::Shape_y_set($s,5); - -print "\nHere is their current position:\n"; -print " Circle = (",examplec::Shape_x_get($c),",", examplec::Shape_y_get($c),")\n"; -print " Square = (",examplec::Shape_x_get($s),",", examplec::Shape_y_get($s),")\n"; - -# ----- Call some methods ----- - -print "\nHere are some properties of the shapes:\n"; -foreach $o ($c,$s) { - print " $o\n"; - print " area = ", examplec::Shape_area($o), "\n"; - print " perimeter = ", examplec::Shape_perimeter($o), "\n"; - } -# Notice how the Shape_area() and Shape_perimeter() functions really -# invoke the appropriate virtual method on each object. - -# ----- Delete everything ----- - -print "\nGuess I'll clean up now\n"; - -# Note: this invokes the virtual destructor -examplec::delete_Shape($c); -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 deleted file mode 100644 index af5e07d..0000000 --- a/Tests/RunCMake/UseSWIG/runme.py +++ /dev/null @@ -1,52 +0,0 @@ -# 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/RunCMake/UseSWIG/runme.rb b/Tests/RunCMake/UseSWIG/runme.rb deleted file mode 100644 index de73bcd..0000000 --- a/Tests/RunCMake/UseSWIG/runme.rb +++ /dev/null @@ -1,49 +0,0 @@ -# file: runme.rb - -# This file illustrates the C++ interface created by SWIG. -# All of our C++ classes get converted into Ruby classes. - -require 'example' - -# ----- Object creation ----- - -print "Creating some objects:\n" -c = Example::Circle.new(10) -print " Created circle #{c}\n" -s = Example::Square.new(10) -print " Created square #{s}\n" - -# ----- Access a static member ----- - -print "\nA total of #{Example::Shape.nshapes} shapes were created\n" - -# ----- Member data access ----- - -# Set the location of the object - -# Notice how we can do this using functions specific to -# the 'Circle' class. -c.x = 20 -c.y = 30 - -# Now use the same functions in the base class -s.x = -10 -s.y = 5 - -print "\nHere is their current position:\n" -print " Circle = (", c.x, ",", c.y, ")\n" -print " Square = (", s.x, ",", s.y, ")\n" - -# ----- Call some methods ----- - -print "\nHere are some properties of the shapes:\n" -for o in [c, s] - print " #{o}\n" - print " area = ", o.area, "\n" - print " perimeter = ", o.perimeter, "\n" -end -# Notice how the Shape#area() and Shape#perimeter() functions really -# invoke the appropriate virtual method on each object. - -print "\n", Example::Shape.nshapes," shapes remain\n" -print "Goodbye\n" diff --git a/Tests/RunCMake/UseSWIG/runme.tcl b/Tests/RunCMake/UseSWIG/runme.tcl deleted file mode 100644 index 6055cf6..0000000 --- a/Tests/RunCMake/UseSWIG/runme.tcl +++ /dev/null @@ -1,49 +0,0 @@ -# file: runme.tcl - -# This file illustrates the high level C++ interface. -# In this case C++ classes work kind of like Tk widgets - -catch { load ./example[info sharedlibextension] example} - -# ----- Object creation ----- - -puts "Creating some objects:" -Circle c 10 -puts " Created circle [c cget -this]" -Square s 10 -puts " Created square [s cget -this]" - -# ----- Access a static member ----- - -puts "\nA total of $Shape_nshapes shapes were created" - -# ----- Member data access ----- - -# Set the location of the object - -c configure -x 20 -y 30 -s configure -x -10 -y 5 - -puts "\nHere is their current position:" -puts " Circle = ([c cget -x], [c cget -y])" -puts " Square = ([s cget -x], [s cget -y])" - -# ----- Call some methods ----- - -puts "\nHere are some properties of the shapes:" -foreach o "c s" { - puts " [$o cget -this]" - puts " area = [$o area]" - puts " perimeter = [$o perimeter]" -} - -# ----- Delete everything ----- - -puts "\nGuess I'll clean up now" - -# Note: this invokes the virtual destructor -rename c "" -rename s "" - -puts "$Shape_nshapes shapes remain" -puts "Goodbye" diff --git a/Tests/RunCMake/UseSWIG/runme2.tcl b/Tests/RunCMake/UseSWIG/runme2.tcl deleted file mode 100644 index d0b5c21..0000000 --- a/Tests/RunCMake/UseSWIG/runme2.tcl +++ /dev/null @@ -1,69 +0,0 @@ -# file: runme2.tcl - -# This file illustrates the low-level C++ interface -# created by SWIG. In this case, all of our C++ classes -# get converted into function calls. - -catch { load ./example[info sharedlibextension] example} - -# ----- Object creation ----- - -puts "Creating some objects:" -set c [new_Circle 10] -puts " Created circle $c" -set s [new_Square 10] -puts " Created square $s" - -# ----- Access a static member ----- - -puts "\nA total of $Shape_nshapes shapes were created" - -# ----- Member data access ----- - -# Set the location of the object -# Note: the base class must be used since that's where x and y -# were declared. - -Shape_x_set $c 20 -Shape_y_set $c 30 -Shape_x_set $s -10 -Shape_y_set $s 5 - -puts "\nHere is their current position:" -puts " Circle = ([Shape_x_get $c], [Shape_y_get $c])" -puts " Square = ([Shape_x_get $s], [Shape_y_get $s])" - -# ----- Call some methods ----- - -puts "\nHere are some properties of the shapes:" -foreach o "$c $s" { - puts " $o" - puts " area = [Shape_area $o]" - puts " perimeter = [Shape_perimeter $o]" -} -# Notice how the Shape_area() and Shape_perimeter() functions really -# invoke the appropriate virtual method on each object. - -# ----- Try to cause a type error ----- - -puts "\nI'm going to try and break the type system" - -if { [catch { - # Bad script! - Square_area $c # Try to invoke Square method on a Circle - puts " Bad bad SWIG!" - -}]} { - puts " Well, it didn't work. Good SWIG." -} - -# ----- Delete everything ----- - -puts "\nGuess I'll clean up now" - -# Note: this invokes the virtual destructor -delete_Shape $c -delete_Shape $s - -puts "$Shape_nshapes shapes remain" -puts "Goodbye" diff --git a/Tests/UseSWIG/BasicConfiguration.cmake b/Tests/UseSWIG/BasicConfiguration.cmake new file mode 100644 index 0000000..73298567 --- /dev/null +++ b/Tests/UseSWIG/BasicConfiguration.cmake @@ -0,0 +1,72 @@ + +find_package(SWIG REQUIRED) +include(${SWIG_USE_FILE}) + +unset(SWIG_LANG_TYPE) +unset(SWIG_LANG_INCLUDE_DIRECTORIES) +unset(SWIG_LANG_DEFINITIONS) +unset(SWIG_LANG_OPTIONS) +unset(SWIG_LANG_LIBRARIES) + +if(${language} MATCHES python) + find_package(Python REQUIRED COMPONENTS Interpreter Development) + set(SWIG_LANG_INCLUDE_DIRECTORIES ${Python_INCLUDE_DIRS}) + set(SWIG_LANG_LIBRARIES ${Python_LIBRARIES}) +endif() +if(${language} MATCHES perl) + find_package(Perl REQUIRED) + find_package(PerlLibs REQUIRED) + set(SWIG_LANG_INCLUDE_DIRECTORIES ${PERL_INCLUDE_PATH}) + separate_arguments(c_flags UNIX_COMMAND "${PERL_EXTRA_C_FLAGS}") + set(SWIG_LANG_OPTIONS ${c_flags}) + set(SWIG_LANG_LIBRARIES ${PERL_LIBRARY}) +endif() +if(${language} MATCHES tcl) + find_package(TCL REQUIRED) + set(SWIG_LANG_INCLUDE_DIRECTORIES ${TCL_INCLUDE_PATH}) + set(SWIG_LANG_LIBRARIES ${TCL_LIBRARY}) +endif() +if(${language} MATCHES ruby) + find_package(Ruby REQUIRED) + set(SWIG_LANG_INCLUDE_DIRECTORIES ${RUBY_INCLUDE_PATH}) + set(SWIG_LANG_LIBRARIES ${RUBY_LIBRARY}) +endif() +if(${language} MATCHES php4) + find_package(PHP4 REQUIRED) + set(SWIG_LANG_INCLUDE_DIRECTORIES ${PHP4_INCLUDE_PATH}) + set(SWIG_LANG_LIBRARIES ${PHP4_LIBRARY}) +endif() +if(${language} MATCHES pike) + find_package(Pike REQUIRED) + set(SWIG_LANG_INCLUDE_DIRECTORIES ${PIKE_INCLUDE_PATH}) + set(SWIG_LANG_LIBRARIES ${PIKE_LIBRARY}) +endif() +if(${language} MATCHES lua) + find_package(Lua REQUIRED) + set(SWIG_LANG_INCLUDE_DIRECTORIES ${LUA_INCLUDE_DIR}) + set(SWIG_LANG_TYPE TYPE SHARED) + set(SWIG_LANG_LIBRARIES ${LUA_LIBRARIES}) +endif() + +unset(CMAKE_SWIG_FLAGS) + +set (CMAKE_INCLUDE_CURRENT_DIR ON) + +set_property(SOURCE "${CMAKE_CURRENT_LIST_DIR}/example.i" PROPERTY CPLUSPLUS ON) +set_property(SOURCE "${CMAKE_CURRENT_LIST_DIR}/example.i" PROPERTY COMPILE_OPTIONS -includeall) + +set_property(SOURCE "${CMAKE_CURRENT_LIST_DIR}/example.i" + PROPERTY GENERATED_INCLUDE_DIRECTORIES ${SWIG_LANG_INCLUDE_DIRECTORIES} + "${CMAKE_CURRENT_LIST_DIR}") +set_property(SOURCE "${CMAKE_CURRENT_LIST_DIR}/example.i" + PROPERTY GENERATED_COMPILE_DEFINITIONS ${SWIG_LANG_DEFINITIONS}) +set_property(SOURCE "${CMAKE_CURRENT_LIST_DIR}/example.i" + PROPERTY GENERATED_COMPILE_OPTIONS ${SWIG_LANG_OPTIONS}) + + +SWIG_ADD_LIBRARY(example + LANGUAGE "${language}" + ${SWIG_LANG_TYPE} + SOURCES "${CMAKE_CURRENT_LIST_DIR}/example.i" + "${CMAKE_CURRENT_LIST_DIR}/example.cxx") +TARGET_LINK_LIBRARIES(example PRIVATE ${SWIG_LANG_LIBRARIES}) diff --git a/Tests/UseSWIG/BasicPerl/CMakeLists.txt b/Tests/UseSWIG/BasicPerl/CMakeLists.txt new file mode 100644 index 0000000..10c1cd8 --- /dev/null +++ b/Tests/UseSWIG/BasicPerl/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.1) + +project(TestBasicPerl CXX) + +include(CTest) + +set(language "perl") + +include (../BasicConfiguration.cmake) + +if (WIN32) + file (TO_CMAKE_PATH "$ENV{PATH}" perl_path) + string (REPLACE ";" "$" perl_path "${perl_path}") + set (perl_env "PATH=$$${perl_path}") +else() + set (perl_env "LD_LIBRARY_PATH=$") +endif() + +add_test (NAME BasicPerl + COMMAND "${CMAKE_COMMAND}" -E env "${perl_env}" + "${PERL_EXECUTABLE}" "-I$" + "${CMAKE_CURRENT_SOURCE_DIR}/../runme.pl") diff --git a/Tests/UseSWIG/BasicPython/CMakeLists.txt b/Tests/UseSWIG/BasicPython/CMakeLists.txt new file mode 100644 index 0000000..1ca4e25 --- /dev/null +++ b/Tests/UseSWIG/BasicPython/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.1) + +project(TestBasicPython CXX) + +include(CTest) + +set(language "python") + +include (../BasicConfiguration.cmake) + +add_test (NAME BasicPython + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$" + "${Python_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py") diff --git a/Tests/UseSWIG/CMakeLists.txt b/Tests/UseSWIG/CMakeLists.txt new file mode 100644 index 0000000..f7516e6 --- /dev/null +++ b/Tests/UseSWIG/CMakeLists.txt @@ -0,0 +1,62 @@ +add_test(NAME UseSWIG.LegacyPython COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/UseSWIG/LegacyPython" + "${CMake_BINARY_DIR}/Tests/UseSWIG/LegacyPython" + ${build_generator_args} + --build-project TestLegacyPython + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) +add_test(NAME UseSWIG.LegacyPerl COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/UseSWIG/LegacyPerl" + "${CMake_BINARY_DIR}/Tests/UseSWIG/LegacyPerl" + ${build_generator_args} + --build-project TestLegacyPerl + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) + + +add_test(NAME UseSWIG.BasicPython COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/UseSWIG/BasicPython" + "${CMake_BINARY_DIR}/Tests/UseSWIG/BasicPython" + ${build_generator_args} + --build-project TestBasicPython + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) +add_test(NAME UseSWIG.BasicPerl COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/UseSWIG/BasicPerl" + "${CMake_BINARY_DIR}/Tests/UseSWIG/BasicPerl" + ${build_generator_args} + --build-project TestBasicPerl + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) + + +add_test(NAME UseSWIG.MultipleModules COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/UseSWIG/MultipleModules" + "${CMake_BINARY_DIR}/Tests/UseSWIG/MultipleModules" + ${build_generator_args} + --build-project TestMultipleModules + --build-options ${build_options} + ) +add_test(NAME UseSWIG.MultiplePython COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/UseSWIG/MultiplePython" + "${CMake_BINARY_DIR}/Tests/UseSWIG/MultiplePython" + ${build_generator_args} + --build-project TestMultiplePython + --build-options ${build_options} + ) diff --git a/Tests/UseSWIG/LegacyConfiguration.cmake b/Tests/UseSWIG/LegacyConfiguration.cmake new file mode 100644 index 0000000..640c713 --- /dev/null +++ b/Tests/UseSWIG/LegacyConfiguration.cmake @@ -0,0 +1,61 @@ + +# Prevent deprecated warnings from new UseSWIG module +set (CMAKE_WARN_DEPRECATED FALSE) + +find_package(SWIG REQUIRED) +include(${SWIG_USE_FILE}) + +unset(SWIG_LANG_TYPE) +if(${language} MATCHES python) + 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(Perl REQUIRED) + find_package(PerlLibs REQUIRED) + include_directories(${PERL_INCLUDE_PATH}) + 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 REQUIRED) + include_directories(${TCL_INCLUDE_PATH}) + set(SWIG_LANG_LIBRARIES ${TCL_LIBRARY}) +endif() +if(${language} MATCHES ruby) + find_package(Ruby REQUIRED) + include_directories(${RUBY_INCLUDE_PATH}) + set(SWIG_LANG_LIBRARIES ${RUBY_LIBRARY}) +endif() +if(${language} MATCHES php4) + find_package(PHP4 REQUIRED) + include_directories(${PHP4_INCLUDE_PATH}) + set(SWIG_LANG_LIBRARIES ${PHP4_LIBRARY}) +endif() +if(${language} MATCHES pike) + find_package(Pike REQUIRED) + include_directories(${PIKE_INCLUDE_PATH}) + set(SWIG_LANG_LIBRARIES ${PIKE_LIBRARY}) +endif() +if(${language} MATCHES lua) + find_package(Lua REQUIRED) + include_directories(${LUA_INCLUDE_DIR}) + set(SWIG_LANG_TYPE TYPE SHARED) + set(SWIG_LANG_LIBRARIES ${LUA_LIBRARIES}) +endif() + +unset(CMAKE_SWIG_FLAGS) + +include_directories(${CMAKE_CURRENT_LIST_DIR}) + +set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/example.i" PROPERTIES CPLUSPLUS ON) +set_source_files_properties("${CMAKE_CURRENT_LIST_DIR}/example.i" PROPERTIES SWIG_FLAGS "-includeall") +SWIG_ADD_LIBRARY(example + LANGUAGE "${language}" + ${SWIG_LANG_TYPE} + SOURCES "${CMAKE_CURRENT_LIST_DIR}/example.i" + "${CMAKE_CURRENT_LIST_DIR}/example.cxx") +SWIG_LINK_LIBRARIES(example ${SWIG_LANG_LIBRARIES}) diff --git a/Tests/UseSWIG/LegacyPerl/CMakeLists.txt b/Tests/UseSWIG/LegacyPerl/CMakeLists.txt new file mode 100644 index 0000000..0def5f5 --- /dev/null +++ b/Tests/UseSWIG/LegacyPerl/CMakeLists.txt @@ -0,0 +1,22 @@ +cmake_minimum_required(VERSION 3.1) + +project(TestLegacyPerl CXX) + +include(CTest) + +set(language "perl") + +include (../LegacyConfiguration.cmake) + +if (WIN32) + file (TO_CMAKE_PATH "$ENV{PATH}" perl_path) + string (REPLACE ";" "$" perl_path "${perl_path}") + set (perl_env "PATH=$$${perl_path}") +else() + set (perl_env "LD_LIBRARY_PATH=$") +endif() + +add_test (NAME LegacyPerl + COMMAND "${CMAKE_COMMAND}" -E env "${perl_env}" + "${PERL_EXECUTABLE}" "-I$" + "${CMAKE_CURRENT_SOURCE_DIR}/../runme.pl") diff --git a/Tests/UseSWIG/LegacyPython/CMakeLists.txt b/Tests/UseSWIG/LegacyPython/CMakeLists.txt new file mode 100644 index 0000000..11a0d28 --- /dev/null +++ b/Tests/UseSWIG/LegacyPython/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.1) + +project(TestLegacyPython CXX) + +include(CTest) + +set(language "python") + +include (../LegacyConfiguration.cmake) + +add_test (NAME LegacyPython + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$" + "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py") diff --git a/Tests/UseSWIG/MultipleModules/CMakeLists.txt b/Tests/UseSWIG/MultipleModules/CMakeLists.txt new file mode 100644 index 0000000..0f4ae75 --- /dev/null +++ b/Tests/UseSWIG/MultipleModules/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.1) + +project(TestMultipleModules CXX) + +include(CTest) + +find_package(SWIG REQUIRED) +include(${SWIG_USE_FILE}) + +find_package(Python REQUIRED COMPONENTS Development) + +find_package(PerlLibs REQUIRED) + +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 GENERATED_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/..") + +swig_add_library(example1 + LANGUAGE python + OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python" + SOURCES ../example.i ../example.cxx) +target_link_libraries(example1 PRIVATE Python::Python) + +# re-use sample interface file for another plugin +set_property(SOURCE "../example.i" APPEND PROPERTY + GENERATED_INCLUDE_DIRECTORIES ${PERL_INCLUDE_PATH}) +separate_arguments(c_flags UNIX_COMMAND "${PERL_EXTRA_C_FLAGS}") +set_property(SOURCE "../example.i" PROPERTY GENERATED_COMPILE_OPTIONS ${c_flags}) + +swig_add_library(example2 + LANGUAGE perl + OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Perl" + SOURCES ../example.i ../example.cxx) +target_link_libraries(example2 PRIVATE ${PERL_LIBRARY}) diff --git a/Tests/UseSWIG/MultiplePython/CMakeLists.txt b/Tests/UseSWIG/MultiplePython/CMakeLists.txt new file mode 100644 index 0000000..f1ae42a --- /dev/null +++ b/Tests/UseSWIG/MultiplePython/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.1) + +project(TestMultiplePython CXX) + +include(CTest) + +find_package(SWIG REQUIRED) +include(${SWIG_USE_FILE}) + +find_package(Python2 REQUIRED COMPONENTS Development) +find_package(Python3 REQUIRED COMPONENTS Development) + +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 GENERATED_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/..") + +swig_add_library(example1 + LANGUAGE python + OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python2" + SOURCES ../example.i ../example.cxx) +target_link_libraries(example1 PRIVATE Python2::Python) + +# re-use sample interface file for another plugin +swig_add_library(example2 + LANGUAGE python + OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python3" + SOURCES ../example.i ../example.cxx) +target_link_libraries(example2 PRIVATE Python3::Python) diff --git a/Tests/UseSWIG/example.cxx b/Tests/UseSWIG/example.cxx new file mode 100644 index 0000000..961d6dd --- /dev/null +++ b/Tests/UseSWIG/example.cxx @@ -0,0 +1,33 @@ +/* File : example.c */ + +#include "example.h" +#define M_PI 3.14159265358979323846 + +/* Move the shape to a new location */ +void Shape::move(double dx, double dy) +{ + x += dx; + y += dy; +} + +int Shape::nshapes = 0; + +double Circle::area(void) +{ + return M_PI * radius * radius; +} + +double Circle::perimeter(void) +{ + return 2 * M_PI * radius; +} + +double Square::area(void) +{ + return width * width; +} + +double Square::perimeter(void) +{ + return 4 * width; +} diff --git a/Tests/UseSWIG/example.h b/Tests/UseSWIG/example.h new file mode 100644 index 0000000..366deb0 --- /dev/null +++ b/Tests/UseSWIG/example.h @@ -0,0 +1,37 @@ +/* File : example.h */ + +class Shape +{ +public: + Shape() { nshapes++; } + virtual ~Shape() { nshapes--; }; + double x, y; + void move(double dx, double dy); + virtual double area(void) = 0; + virtual double perimeter(void) = 0; + static int nshapes; +}; + +class Circle : public Shape +{ +private: + double radius; + +public: + Circle(double r) + : radius(r){}; + virtual double area(void); + virtual double perimeter(void); +}; + +class Square : public Shape +{ +private: + double width; + +public: + Square(double w) + : width(w){}; + virtual double area(void); + virtual double perimeter(void); +}; diff --git a/Tests/UseSWIG/example.i b/Tests/UseSWIG/example.i new file mode 100644 index 0000000..fbdf724 --- /dev/null +++ b/Tests/UseSWIG/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/runme.php4 b/Tests/UseSWIG/runme.php4 new file mode 100644 index 0000000..653ced2 --- /dev/null +++ b/Tests/UseSWIG/runme.php4 @@ -0,0 +1,58 @@ + diff --git a/Tests/UseSWIG/runme.pike b/Tests/UseSWIG/runme.pike new file mode 100644 index 0000000..ec28dd7 --- /dev/null +++ b/Tests/UseSWIG/runme.pike @@ -0,0 +1,53 @@ +import .example; + +int main() +{ + // ----- Object creation ----- + + write("Creating some objects:\n"); + Circle c = Circle(10.0); + write(" Created circle.\n"); + Square s = Square(10.0); + write(" Created square.\n"); + + // ----- Access a static member ----- + + write("\nA total of " + Shape_nshapes_get() + " shapes were created\n"); + + // ----- Member data access ----- + + // Set the location of the object + + c->x_set(20.0); + c->y_set(30.0); + + s->x_set(-10.0); + s->y_set(5.0); + + write("\nHere is their current position:\n"); + write(" Circle = (%f, %f)\n", c->x_get(), c->y_get()); + write(" Square = (%f, %f)\n", s->x_get(), s->y_get()); + + // ----- Call some methods ----- + + write("\nHere are some properties of the shapes:\n"); + write(" The circle:\n"); + write(" area = %f.\n", c->area()); + write(" perimeter = %f.\n", c->perimeter()); + write(" The square:\n"); + write(" area = %f.\n", s->area()); + write(" perimeter = %f.\n", s->perimeter()); + + write("\nGuess I'll clean up now\n"); + + /* See if we can force 's' to be garbage-collected */ + s = 0; + + /* Now we should be down to only 1 shape */ + write("%d shapes remain\n", Shape_nshapes_get()); + + /* Done */ + write("Goodbye\n"); + + return 0; +} diff --git a/Tests/UseSWIG/runme.pl b/Tests/UseSWIG/runme.pl new file mode 100644 index 0000000..965e063 --- /dev/null +++ b/Tests/UseSWIG/runme.pl @@ -0,0 +1,56 @@ +# file: runme.pl + +# This file illustrates the low-level C++ interface +# created by SWIG. In this case, all of our C++ classes +# get converted into function calls. + +use example; + +# ----- Object creation ----- + +print "Creating some objects:\n"; +$c = examplec::new_Circle(10); +print " Created circle $c\n"; +$s = examplec::new_Square(10); +print " Created square $s\n"; + +# ----- Access a static member ----- + +print "\nA total of $examplec::Shape_nshapes shapes were created\n"; + +# ----- Member data access ----- + +# Set the location of the object. +# Note: methods in the base class Shape are used since +# x and y are defined there. + +examplec::Shape_x_set($c, 20); +examplec::Shape_y_set($c, 30); +examplec::Shape_x_set($s,-10); +examplec::Shape_y_set($s,5); + +print "\nHere is their current position:\n"; +print " Circle = (",examplec::Shape_x_get($c),",", examplec::Shape_y_get($c),")\n"; +print " Square = (",examplec::Shape_x_get($s),",", examplec::Shape_y_get($s),")\n"; + +# ----- Call some methods ----- + +print "\nHere are some properties of the shapes:\n"; +foreach $o ($c,$s) { + print " $o\n"; + print " area = ", examplec::Shape_area($o), "\n"; + print " perimeter = ", examplec::Shape_perimeter($o), "\n"; + } +# Notice how the Shape_area() and Shape_perimeter() functions really +# invoke the appropriate virtual method on each object. + +# ----- Delete everything ----- + +print "\nGuess I'll clean up now\n"; + +# Note: this invokes the virtual destructor +examplec::delete_Shape($c); +examplec::delete_Shape($s); + +print $examplec::Shape_nshapes," shapes remain\n"; +print "Goodbye\n"; diff --git a/Tests/UseSWIG/runme.py b/Tests/UseSWIG/runme.py new file mode 100644 index 0000000..af5e07d --- /dev/null +++ b/Tests/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/UseSWIG/runme.rb b/Tests/UseSWIG/runme.rb new file mode 100644 index 0000000..de73bcd --- /dev/null +++ b/Tests/UseSWIG/runme.rb @@ -0,0 +1,49 @@ +# file: runme.rb + +# This file illustrates the C++ interface created by SWIG. +# All of our C++ classes get converted into Ruby classes. + +require 'example' + +# ----- Object creation ----- + +print "Creating some objects:\n" +c = Example::Circle.new(10) +print " Created circle #{c}\n" +s = Example::Square.new(10) +print " Created square #{s}\n" + +# ----- Access a static member ----- + +print "\nA total of #{Example::Shape.nshapes} shapes were created\n" + +# ----- Member data access ----- + +# Set the location of the object + +# Notice how we can do this using functions specific to +# the 'Circle' class. +c.x = 20 +c.y = 30 + +# Now use the same functions in the base class +s.x = -10 +s.y = 5 + +print "\nHere is their current position:\n" +print " Circle = (", c.x, ",", c.y, ")\n" +print " Square = (", s.x, ",", s.y, ")\n" + +# ----- Call some methods ----- + +print "\nHere are some properties of the shapes:\n" +for o in [c, s] + print " #{o}\n" + print " area = ", o.area, "\n" + print " perimeter = ", o.perimeter, "\n" +end +# Notice how the Shape#area() and Shape#perimeter() functions really +# invoke the appropriate virtual method on each object. + +print "\n", Example::Shape.nshapes," shapes remain\n" +print "Goodbye\n" diff --git a/Tests/UseSWIG/runme.tcl b/Tests/UseSWIG/runme.tcl new file mode 100644 index 0000000..6055cf6 --- /dev/null +++ b/Tests/UseSWIG/runme.tcl @@ -0,0 +1,49 @@ +# file: runme.tcl + +# This file illustrates the high level C++ interface. +# In this case C++ classes work kind of like Tk widgets + +catch { load ./example[info sharedlibextension] example} + +# ----- Object creation ----- + +puts "Creating some objects:" +Circle c 10 +puts " Created circle [c cget -this]" +Square s 10 +puts " Created square [s cget -this]" + +# ----- Access a static member ----- + +puts "\nA total of $Shape_nshapes shapes were created" + +# ----- Member data access ----- + +# Set the location of the object + +c configure -x 20 -y 30 +s configure -x -10 -y 5 + +puts "\nHere is their current position:" +puts " Circle = ([c cget -x], [c cget -y])" +puts " Square = ([s cget -x], [s cget -y])" + +# ----- Call some methods ----- + +puts "\nHere are some properties of the shapes:" +foreach o "c s" { + puts " [$o cget -this]" + puts " area = [$o area]" + puts " perimeter = [$o perimeter]" +} + +# ----- Delete everything ----- + +puts "\nGuess I'll clean up now" + +# Note: this invokes the virtual destructor +rename c "" +rename s "" + +puts "$Shape_nshapes shapes remain" +puts "Goodbye" diff --git a/Tests/UseSWIG/runme2.tcl b/Tests/UseSWIG/runme2.tcl new file mode 100644 index 0000000..d0b5c21 --- /dev/null +++ b/Tests/UseSWIG/runme2.tcl @@ -0,0 +1,69 @@ +# file: runme2.tcl + +# This file illustrates the low-level C++ interface +# created by SWIG. In this case, all of our C++ classes +# get converted into function calls. + +catch { load ./example[info sharedlibextension] example} + +# ----- Object creation ----- + +puts "Creating some objects:" +set c [new_Circle 10] +puts " Created circle $c" +set s [new_Square 10] +puts " Created square $s" + +# ----- Access a static member ----- + +puts "\nA total of $Shape_nshapes shapes were created" + +# ----- Member data access ----- + +# Set the location of the object +# Note: the base class must be used since that's where x and y +# were declared. + +Shape_x_set $c 20 +Shape_y_set $c 30 +Shape_x_set $s -10 +Shape_y_set $s 5 + +puts "\nHere is their current position:" +puts " Circle = ([Shape_x_get $c], [Shape_y_get $c])" +puts " Square = ([Shape_x_get $s], [Shape_y_get $s])" + +# ----- Call some methods ----- + +puts "\nHere are some properties of the shapes:" +foreach o "$c $s" { + puts " $o" + puts " area = [Shape_area $o]" + puts " perimeter = [Shape_perimeter $o]" +} +# Notice how the Shape_area() and Shape_perimeter() functions really +# invoke the appropriate virtual method on each object. + +# ----- Try to cause a type error ----- + +puts "\nI'm going to try and break the type system" + +if { [catch { + # Bad script! + Square_area $c # Try to invoke Square method on a Circle + puts " Bad bad SWIG!" + +}]} { + puts " Well, it didn't work. Good SWIG." +} + +# ----- Delete everything ----- + +puts "\nGuess I'll clean up now" + +# Note: this invokes the virtual destructor +delete_Shape $c +delete_Shape $s + +puts "$Shape_nshapes shapes remain" +puts "Goodbye" -- cgit v0.12 From 8ab4e38373352c43fcedf4ac91b41114d8e31dc0 Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Tue, 27 Mar 2018 16:49:58 +0200 Subject: UseSWIG: Add new behavior for better support files management fixes: #17840 --- Help/release/dev/UseSWIG-Multiple-Behaviors.rst | 6 + Modules/UseSWIG.cmake | 155 ++++++++++++++++++------ Tests/UseSWIG/CMakeLists.txt | 14 +++ Tests/UseSWIG/ModuleVersion2/CMakeLists.txt | 56 +++++++++ Tests/UseSWIG/MultipleModules/CMakeLists.txt | 33 ++++- Tests/UseSWIG/MultiplePython/CMakeLists.txt | 24 +++- 6 files changed, 245 insertions(+), 43 deletions(-) create mode 100644 Help/release/dev/UseSWIG-Multiple-Behaviors.rst create mode 100644 Tests/UseSWIG/ModuleVersion2/CMakeLists.txt diff --git a/Help/release/dev/UseSWIG-Multiple-Behaviors.rst b/Help/release/dev/UseSWIG-Multiple-Behaviors.rst new file mode 100644 index 0000000..043ba50 --- /dev/null +++ b/Help/release/dev/UseSWIG-Multiple-Behaviors.rst @@ -0,0 +1,6 @@ +UseSWIG-multiple-behaviors +-------------------------- + +* The :module:`UseSWIG` module learned to manage multiple behaviors through + ``UseSWIG_MODULE_VERSION`` variable to ensure legacy support as well as more + robust handling of ``SWIG`` advanced features (like ``%template``). diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index 8e7ca41..5f9afc1 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -5,7 +5,10 @@ UseSWIG ------- -Defines the following command for use with SWIG: +This file provides support for ``SWIG``. It is assumed that :module:`FindSWIG` +module has already been loaded. + +Defines the following command for use with ``SWIG``: .. command:: swig_add_library @@ -20,17 +23,19 @@ Defines the following command for use with SWIG: SOURCES ... ) - Targets created with command ``swig_add_library`` have the same capabilities as targets - created with command :command:`add_library`, so can be used with any command accepting a target - especially command :command:`target_link_libraries`. + Targets created with the ``swig_add_library`` command have the same + capabilities as targets created with the :command:`add_library` command, so + those targets can be used with any command expecting a target (e.g. + :command:`target_link_libraries`). The arguments are: ``TYPE`` - ``SHARED``, ``MODULE`` and ``STATIC`` have same semantic as command :command:`add_library`. - if ``USE_BUILD_SHARED_LIBS`` is specified, library type will be ``STATIC`` or ``SHARED`` - based on whether the current value of the variable :variable:`BUILD_SHARED_LIBS` is ``ON``. - If none is specified, ``MODULE`` will be used. + ``SHARED``, ``MODULE`` and ``STATIC`` have the same semantic as for the + :command:`add_library` command. If ``USE_BUILD_SHARED_LIBS`` is specified, + the library type will be ``STATIC`` or ``SHARED`` based on whether the + current value of the :variable:`BUILD_SHARED_LIBS` variable is ``ON``. If + no type is specified, ``MODULE`` will be used. ``LANGUAGE`` Specify the target language. @@ -39,22 +44,40 @@ Defines the following command for use with SWIG: Prevent the generation of the wrapper layer (swig ``-noproxy`` option). ``OUTPUT_DIR`` - Specify where to write the language specific files (swig ``-outdir`` option). - If not specified, variable ``CMAKE_SWIG_OUTDIR`` will be used. If none is specified, - :variable:`CMAKE_CURRENT_BINARY_DIR` is used. + Specify where to write the language specific files (swig ``-outdir`` + option). If not given, the ``CMAKE_SWIG_OUTDIR`` variable will be used. + If neither is specified, the default depends on the value of the + ``UseSWIG_MODULE_VERSION`` variable as follows: + + * If ``UseSWIG_MODULE_VERSION`` is 1 or is undefined, output is written to + the :variable:`CMAKE_CURRENT_BINARY_DIR` directory. + * If ``UseSWIG_MODULE_VERSION`` is 2, a dedicated directory will be used. + The path of this directory can be retrieved from the + ``SWIG_SUPPORT_FILES_DIRECTORY`` target property. ``OUTFILE_DIR`` - Specify an output directory name where the generated source file will be placed - (swig -o option). If not specified, variable ``SWIG_OUTFILE_DIR`` will be used. - If none is specified, option ``OUTPUT_DIR`` or variable ``CMAKE_SWIG_OUTDIR`` is used. + Specify an output directory name where the generated source file will be + placed (swig -o option). If not specified, the ``SWIG_OUTFILE_DIR`` variable + will be used. If neither is specified, ``OUTPUT_DIR`` or + ``CMAKE_SWIG_OUTDIR`` is used instead. ``SOURCES`` - List of sources for the library. Files with extension ``.i`` will be identified as sources - for ``SWIG`` tool. Other files will be handled in the standard way. + List of sources for the library. Files with extension ``.i`` will be + identified as sources for the ``SWIG`` tool. Other files will be handled in + the standard way. + +.. note:: -Source files properties on module files **must** be set before the invocation -of the ``swig_add_library`` command to specify special behavior of SWIG and ensure -generated files will receive required settings. + If ``UseSWIG_MODULE_VERSION`` is set to 2, it is **strongly** recommended + to use a dedicated directory unique to the target when either the + ``OUTPUT_DIR`` option or the ``CMAKE_SWIG_OUTDIR`` variable are specified. + The output directory contents are erased as part of the target build, so + to prevent interference between targets or losing other important files, each + target should have its own dedicated output directory. + +Source file properties on module files **must** be set before the invocation +of the ``swig_add_library`` command to specify special behavior of SWIG and +ensure generated files will receive the required settings. ``CPLUSPLUS`` Call SWIG in c++ mode. For example: @@ -66,7 +89,8 @@ generated files will receive required settings. ``INCLUDE_DIRECTORIES``, ``COMPILE_DEFINITIONS`` and ``COMPILE_OPTIONS`` Add custom flags to SWIG compiler and have same semantic as properties - :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and :prop_sf:`COMPILE_OPTIONS`. + :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and + :prop_sf:`COMPILE_OPTIONS`. ``GENERATED_INCLUDE_DIRECTORIES``, ``GENERATED_COMPILE_DEFINITIONS`` and ``GENERATED_COMPILE_OPTIONS`` Add custom flags to the C/C++ generated source. They will fill, respectively, @@ -85,12 +109,13 @@ generated files will receive required settings. set_property(SOURCE mymod.i PROPERTY SWIG_MODULE_NAME mymod_realname) -Target library properties can be set to apply same configuration to all SWIG input files. +Target library properties can be set to apply same configuration to all SWIG +input files. ``SWIG_INCLUDE_DIRECTORIES``, ``SWIG_COMPILE_DEFINITIONS`` and ``SWIG_COMPILE_OPTIONS`` - These properties will be applied to all SWIG input files and have same semantic as - target properties :prop_tgt:`INCLUDE_DIRECTORIES`, :prop_tgt:`COMPILE_DEFINITIONS` and - :prop_tgt:`COMPILE_OPTIONS`. + These properties will be applied to all SWIG input files and have same + semantic as target properties :prop_tgt:`INCLUDE_DIRECTORIES`, + :prop_tgt:`COMPILE_DEFINITIONS` and :prop_tgt:`COMPILE_OPTIONS`. .. code-block:: cmake @@ -99,12 +124,16 @@ Target library properties can be set to apply same configuration to all SWIG inp set_property(TARGET mymod PROPERTY SWIG_COMPILE_OPTIONS -bla -blb) ``SWIG_GENERATED_INCLUDE_DIRECTORIES``, ``SWIG_GENERATED_COMPILE_DEFINITIONS`` and ``SWIG_GENERATED_COMPILE_OPTIONS`` - These properties will populate, respectively, properties :prop_sf:`INCLUDE_DIRECTORIES`, - :prop_sf:`COMPILE_DEFINITIONS` and :prop_sf:`COMPILE_FLAGS` of all generated C/C++ files. + These properties will populate, respectively, properties + :prop_sf:`INCLUDE_DIRECTORIES`, :prop_sf:`COMPILE_DEFINITIONS` and + :prop_sf:`COMPILE_FLAGS` of all generated C/C++ files. ``SWIG_DEPENDS`` Add dependencies to all SWIG input files. +The following target properties are output properties and can be used to get +information about support files generated by ``SWIG`` interface compilation. + ``SWIG_SUPPORT_FILES`` This output property list of wrapper files generated during SWIG compilation. @@ -113,7 +142,26 @@ Target library properties can be set to apply same configuration to all SWIG inp swig_add_library(mymod LANGUAGE python SOURCES mymod.i) get_property(support_files TARGET mymod PROPERTY SWIG_SUPPORT_FILES) -Some variables can be set to specify special behavior of SWIG: + .. note:: + + Only most principal support files are listed. In case some advanced + features of ``SWIG`` are used (for example ``%template``), associated + support files may not be listed. Prefer to use the + ``SWIG_SUPPORT_FILES_DIRECTORY`` property to handle support files. + +``SWIG_SUPPORT_FILES_DIRECTORY`` + This output property specifies the directory where support files will be + generated. + +Some variables can be set to customize the behavior of ``swig_add_library`` +as well as ``SWIG``: + +``UseSWIG_MODULE_VERSION`` + Specify different behaviors for ``UseSWIG`` module. + + * Set to 1 or undefined: Legacy behavior is applied. + * Set to 2: A new strategy is applied regarding support files: the output + directory of support files is erased before ``SWIG`` interface compilation. ``CMAKE_SWIG_FLAGS`` Add flags to all swig calls. @@ -158,7 +206,6 @@ macro(SWIG_MODULE_INITIALIZE name language) string(TOUPPER "${language}" SWIG_MODULE_${name}_LANGUAGE) string(TOLOWER "${language}" SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG) - set(SWIG_MODULE_${name}_NAME "${name}") set(SWIG_MODULE_${name}_EXTRA_FLAGS) if (NOT DEFINED SWIG_MODULE_${name}_NOPROXY) set (SWIG_MODULE_${name}_NOPROXY FALSE) @@ -172,11 +219,6 @@ macro(SWIG_MODULE_INITIALIZE name language) endif() if(SWIG_MODULE_${name}_LANGUAGE STREQUAL "UNKNOWN") message(FATAL_ERROR "SWIG Error: Language \"${language}\" not found") - elseif(SWIG_MODULE_${name}_LANGUAGE STREQUAL "PYTHON" AND NOT SWIG_MODULE_${name}_NOPROXY) - # swig will produce a module.py containing an 'import _modulename' statement, - # which implies having a corresponding _modulename.so (*NIX), _modulename.pyd (Win32), - # unless the -noproxy flag is used - set(SWIG_MODULE_${name}_NAME "_${name}") elseif(SWIG_MODULE_${name}_LANGUAGE STREQUAL "PERL") list(APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-shadow") endif() @@ -332,6 +374,14 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) list (APPEND swig_dependencies ${file_depends}) endif() + if (UseSWIG_MODULE_VERSION VERSION_EQUAL 2) + # as part of custom command, start by removing old generated files + # to ensure obsolete files do not stay + set (swig_cleanup_command COMMAND "${CMAKE_COMMAND}" -E remove_directory "${outdir}") + else() + unset (swig_cleanup_command) + endif() + # IMPLICIT_DEPENDS below can not handle situations where a dependent file is # removed. We need an extra step with timestamp and custom target, see #16830 # As this is needed only for Makefile generator do it conditionally @@ -352,10 +402,11 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) add_custom_command( OUTPUT ${swig_custom_output} ${swig_custom_products} + ${swig_cleanup_command} # Let's create the ${outdir} at execution time, in case dir contains $(OutDir) COMMAND "${CMAKE_COMMAND}" -E make_directory ${outdir} ${outfiledir} ${swig_timestamp_command} - COMMAND "${SWIG_EXECUTABLE}" + COMMAND "${CMAKE_COMMAND}" -E env "SWIG_LIB=${SWIG_DIR}" "${SWIG_EXECUTABLE}" "-${SWIG_MODULE_${name}_SWIG_LANGUAGE_FLAG}" "${swig_source_file_flags}" -outdir "${outdir}" @@ -434,6 +485,12 @@ function(SWIG_ADD_LIBRARY name) unset(_SAM_TYPE) endif() + if (NOT DEFINED UseSWIG_MODULE_VERSION) + set (UseSWIG_MODULE_VERSION 1) + elseif (NOT UseSWIG_MODULE_VERSION MATCHES "^(1|2)$") + message (FATAL_ERROR "UseSWIG_MODULE_VERSION: ${UseSWIG_MODULE_VERSION}: invalid value. 1 or 2 is expected.") + endif() + set (workingdir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${name}.dir") # set special variable to pass extra information to command SWIG_ADD_SOURCE_TO_MODULE # which cannot be changed due to legacy compatibility @@ -444,7 +501,11 @@ function(SWIG_ADD_LIBRARY name) if (CMAKE_SWIG_OUTDIR) set (outputdir "${CMAKE_SWIG_OUTDIR}") else() - set (outputdir "${CMAKE_CURRENT_BINARY_DIR}") + if (UseSWIG_MODULE_VERSION VERSION_EQUAL 2) + set (outputdir "${workingdir}/${_SAM_LANGUAGE}.files") + else() + set (outputdir "${CMAKE_CURRENT_BINARY_DIR}") + endif() endif() endif() @@ -470,6 +531,9 @@ function(SWIG_ADD_LIBRARY name) set(swig_dot_i_sources ${_SAM_SOURCES}) list(FILTER swig_dot_i_sources INCLUDE REGEX "\\.i$") + if (NOT swig_dot_i_sources) + message(FATAL_ERROR "SWIG_ADD_LIBRARY: no SWIG interface files specified") + endif() set(swig_other_sources ${_SAM_SOURCES}) list(REMOVE_ITEM swig_other_sources ${swig_dot_i_sources}) @@ -486,12 +550,14 @@ function(SWIG_ADD_LIBRARY name) endforeach() set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${swig_generated_sources} ${swig_generated_timestamps}) + if (UseSWIG_MODULE_VERSION VERSION_EQUAL 2) + set_property (DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${outputdir}") + endif() add_library(${name} ${_SAM_TYPE} ${swig_generated_sources} ${swig_other_sources}) - set_target_properties(${name} PROPERTIES OUTPUT_NAME "${SWIG_MODULE_${name}_NAME}") if(CMAKE_GENERATOR MATCHES "Make") # see IMPLICIT_DEPENDS above add_custom_target(${name}_swig_compilation DEPENDS ${swig_generated_timestamps}) @@ -524,8 +590,14 @@ function(SWIG_ADD_LIBRARY name) set_target_properties(${name} PROPERTIES PREFIX "") endif() elseif (swig_lowercase_language STREQUAL "python") - # this is only needed for the python case where a _modulename.so is generated - set_target_properties(${name} PROPERTIES PREFIX "") + if (SWIG_MODULE_${name}_NOPROXY) + set_target_properties(${name} PROPERTIES PREFIX "") + else() + # swig will produce a module.py containing an 'import _modulename' statement, + # which implies having a corresponding _modulename.so (*NIX), _modulename.pyd (Win32), + # unless the -noproxy flag is used + set_target_properties(${name} PROPERTIES PREFIX "_") + endif() # Python extension modules on Windows must have the extension ".pyd" # instead of ".dll" as of Python 2.5. Older python versions do support # this suffix. @@ -560,7 +632,10 @@ function(SWIG_ADD_LIBRARY name) # assume empty prefix because we expect the module to be dynamically loaded set_target_properties (${name} PROPERTIES PREFIX "") endif () - # target property SWIG_SUPPORT_FILES lists proxy support files + + # target property SWIG_SUPPORT_FILES_DIRECTORY specify output directory of support files + set_property (TARGET ${name} PROPERTY SWIG_SUPPORT_FILES_DIRECTORY "${outputdir}") + # target property SWIG_SUPPORT_FILES lists principal proxy support files if (NOT SWIG_MODULE_${name}_NOPROXY) string(TOUPPER "${_SAM_LANGUAGE}" swig_uppercase_language) set(swig_all_support_files) @@ -572,7 +647,7 @@ function(SWIG_ADD_LIBRARY name) if (swig_all_support_files) list(REMOVE_DUPLICATES swig_all_support_files) endif() - set_property (TARGET ${name} APPEND PROPERTY SWIG_SUPPORT_FILES ${swig_all_support_files}) + set_property (TARGET ${name} PROPERTY SWIG_SUPPORT_FILES ${swig_all_support_files}) endif() # to ensure legacy behavior, export some variables diff --git a/Tests/UseSWIG/CMakeLists.txt b/Tests/UseSWIG/CMakeLists.txt index f7516e6..0c4ec8a 100644 --- a/Tests/UseSWIG/CMakeLists.txt +++ b/Tests/UseSWIG/CMakeLists.txt @@ -50,6 +50,7 @@ add_test(NAME UseSWIG.MultipleModules COMMAND ${build_generator_args} --build-project TestMultipleModules --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ ) add_test(NAME UseSWIG.MultiplePython COMMAND ${CMAKE_CTEST_COMMAND} -C $ @@ -59,4 +60,17 @@ add_test(NAME UseSWIG.MultiplePython COMMAND ${build_generator_args} --build-project TestMultiplePython --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ + ) + + +add_test(NAME UseSWIG.ModuleVersion2 COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/UseSWIG/ModuleVersion2" + "${CMake_BINARY_DIR}/Tests/UseSWIG/ModuleVersion2" + ${build_generator_args} + --build-project TestModuleVersion2 + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ ) diff --git a/Tests/UseSWIG/ModuleVersion2/CMakeLists.txt b/Tests/UseSWIG/ModuleVersion2/CMakeLists.txt new file mode 100644 index 0000000..92cbcd3 --- /dev/null +++ b/Tests/UseSWIG/ModuleVersion2/CMakeLists.txt @@ -0,0 +1,56 @@ +cmake_minimum_required(VERSION 3.1) + +project(TestModuleVersion2 CXX) + +include(CTest) + +find_package(SWIG REQUIRED) +include(${SWIG_USE_FILE}) + +find_package(Python2 REQUIRED COMPONENTS Interpreter Development) +find_package(Python3 REQUIRED COMPONENTS Interpreter Development) + +set (UseSWIG_MODULE_VERSION 2) +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 GENERATED_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/..") + +swig_add_library(example1 + LANGUAGE python + SOURCES ../example.i ../example.cxx) +set_target_properties (example1 PROPERTIES + OUTPUT_NAME example + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2") +target_link_libraries(example1 PRIVATE Python2::Python) + +# re-use sample interface file for another plugin +swig_add_library(example2 + LANGUAGE python + SOURCES ../example.i ../example.cxx) +set_target_properties (example2 PROPERTIES + OUTPUT_NAME example + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3") +target_link_libraries(example2 PRIVATE Python3::Python) + + +if (WIN32) + set (PS $) +else() + set (PS ":") +endif() + +add_test (NAME ModuleVersion2.example1 + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$${PS}$" + "${Python2_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py") + +add_test (NAME ModuleVersion2.example2 + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$${PS}$" + "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py") diff --git a/Tests/UseSWIG/MultipleModules/CMakeLists.txt b/Tests/UseSWIG/MultipleModules/CMakeLists.txt index 0f4ae75..d495007 100644 --- a/Tests/UseSWIG/MultipleModules/CMakeLists.txt +++ b/Tests/UseSWIG/MultipleModules/CMakeLists.txt @@ -7,8 +7,9 @@ include(CTest) find_package(SWIG REQUIRED) include(${SWIG_USE_FILE}) -find_package(Python REQUIRED COMPONENTS Development) +find_package(Python REQUIRED COMPONENTS Interpreter Development) +find_package(Perl REQUIRED) find_package(PerlLibs REQUIRED) unset(CMAKE_SWIG_FLAGS) @@ -23,6 +24,11 @@ swig_add_library(example1 LANGUAGE python OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python" SOURCES ../example.i ../example.cxx) +set_target_properties (example1 PROPERTIES + OUTPUT_NAME example + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python") target_link_libraries(example1 PRIVATE Python::Python) # re-use sample interface file for another plugin @@ -35,4 +41,29 @@ swig_add_library(example2 LANGUAGE perl OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Perl" SOURCES ../example.i ../example.cxx) +set_target_properties (example2 PROPERTIES + OUTPUT_NAME example + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Perl" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Perl" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Perl") target_link_libraries(example2 PRIVATE ${PERL_LIBRARY}) + + + +add_test (NAME MultipleModules.Python + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$" + "${Python_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py") + + +if (WIN32) + file (TO_CMAKE_PATH "$ENV{PATH}" perl_path) + string (REPLACE ";" "$" perl_path "${perl_path}") + set (perl_env "PATH=$$${perl_path}") +else() + set (perl_env "LD_LIBRARY_PATH=$") +endif() + +add_test (NAME MultipleModules.Perl + COMMAND "${CMAKE_COMMAND}" -E env "${perl_env}" + "${PERL_EXECUTABLE}" "-I$" + "${CMAKE_CURRENT_SOURCE_DIR}/../runme.pl") diff --git a/Tests/UseSWIG/MultiplePython/CMakeLists.txt b/Tests/UseSWIG/MultiplePython/CMakeLists.txt index f1ae42a..260a382 100644 --- a/Tests/UseSWIG/MultiplePython/CMakeLists.txt +++ b/Tests/UseSWIG/MultiplePython/CMakeLists.txt @@ -7,8 +7,8 @@ include(CTest) find_package(SWIG REQUIRED) include(${SWIG_USE_FILE}) -find_package(Python2 REQUIRED COMPONENTS Development) -find_package(Python3 REQUIRED COMPONENTS Development) +find_package(Python2 REQUIRED COMPONENTS Interpreter Development) +find_package(Python3 REQUIRED COMPONENTS Interpreter Development) unset(CMAKE_SWIG_FLAGS) @@ -22,6 +22,11 @@ swig_add_library(example1 LANGUAGE python OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python2" SOURCES ../example.i ../example.cxx) +set_target_properties (example1 PROPERTIES + OUTPUT_NAME example + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python2") target_link_libraries(example1 PRIVATE Python2::Python) # re-use sample interface file for another plugin @@ -29,4 +34,19 @@ swig_add_library(example2 LANGUAGE python OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/Python3" SOURCES ../example.i ../example.cxx) +set_target_properties (example2 PROPERTIES + OUTPUT_NAME example + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3" + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Python3") target_link_libraries(example2 PRIVATE Python3::Python) + + + +add_test (NAME MultiplePython.example1 + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$" + "${Python2_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py") + +add_test (NAME MultiplePython.example2 + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$" + "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py") -- cgit v0.12