diff options
author | Marc Chevrier <marc.chevrier@sap.com> | 2018-01-29 10:40:25 +0100 |
---|---|---|
committer | Marc Chevrier <marc.chevrier@sap.com> | 2018-02-14 08:35:04 +0100 |
commit | 0bef9eb410566aa10536331d086d4a3ee265a526 (patch) | |
tree | 98047f3821f494aaa2967733938ed6fd73c522bd /Tests/RunCMake/UseSWIG | |
parent | d6048bd153979c268a2943b26fd71be7c5f11251 (diff) | |
download | cmake-0bef9eb410566aa10536331d086d4a3ee265a526.tar.gz |
UseSWIG: modernize module
Diffstat (limited to 'Tests/RunCMake/UseSWIG')
-rw-r--r-- | Tests/RunCMake/UseSWIG/BasicConfiguration.cmake | 68 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/BasicPerl.cmake | 18 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/BasicPython.cmake | 9 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/LegacyPerl.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/LegacyPython.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/MultipleModules.cmake | 30 | ||||
-rw-r--r-- | Tests/RunCMake/UseSWIG/RunCMakeTest.cmake | 22 |
8 files changed, 146 insertions, 8 deletions
diff --git a/Tests/RunCMake/UseSWIG/BasicConfiguration.cmake b/Tests/RunCMake/UseSWIG/BasicConfiguration.cmake new file mode 100644 index 0000000000..94d8dd3b47 --- /dev/null +++ b/Tests/RunCMake/UseSWIG/BasicConfiguration.cmake @@ -0,0 +1,68 @@ + +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(PythonInterp REQUIRED) + find_package(PythonLibs REQUIRED) + set(SWIG_LANG_INCLUDE_DIRECTORIES ${PYTHON_INCLUDE_PATH}) + 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 new file mode 100644 index 0000000000..67ad6bc020 --- /dev/null +++ b/Tests/RunCMake/UseSWIG/BasicPerl.cmake @@ -0,0 +1,18 @@ + +set(language "perl") + +include (BasicConfiguration.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:example>$<SEMICOLON>${perl_path}") +else() + set (perl_env "LD_LIBRARY_PATH=$<TARGET_FILE_DIR:example>") +endif() + +add_custom_target (RunTest + COMMAND "${CMAKE_COMMAND}" -E env "${perl_env}" + "${PERL_EXECUTABLE}" "-I$<TARGET_FILE_DIR:example>" + "${CMAKE_CURRENT_SOURCE_DIR}/runme.pl" + DEPENDS example) diff --git a/Tests/RunCMake/UseSWIG/BasicPython.cmake b/Tests/RunCMake/UseSWIG/BasicPython.cmake new file mode 100644 index 0000000000..0d8c8242b9 --- /dev/null +++ b/Tests/RunCMake/UseSWIG/BasicPython.cmake @@ -0,0 +1,9 @@ + +set(language "python") + +include (BasicConfiguration.cmake) + +add_custom_target (RunTest + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=$<TARGET_FILE_DIR:example>" + "${PYTHON_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/runme.py" + DEPENDS example) diff --git a/Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake b/Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake index 3f400bf76d..3ce0790281 100644 --- a/Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake +++ b/Tests/RunCMake/UseSWIG/LegacyConfiguration.cmake @@ -1,4 +1,7 @@ +# Prevent deprecated warnings from new UseSWIG module +set (CMAKE_WARN_DEPRECATED FALSE) + find_package(SWIG REQUIRED) include(${SWIG_USE_FILE}) diff --git a/Tests/RunCMake/UseSWIG/LegacyPerl.cmake b/Tests/RunCMake/UseSWIG/LegacyPerl.cmake index cfa8c536ea..3428c464ed 100644 --- a/Tests/RunCMake/UseSWIG/LegacyPerl.cmake +++ b/Tests/RunCMake/UseSWIG/LegacyPerl.cmake @@ -11,7 +11,7 @@ else() set (perl_env "LD_LIBRARY_PATH=$<TARGET_FILE_DIR:${SWIG_MODULE_example_REAL_NAME}>") endif() -add_custom_target (RunPerl +add_custom_target (RunTest COMMAND "${CMAKE_COMMAND}" -E env "${perl_env}" "${PERL_EXECUTABLE}" "-I$<TARGET_FILE_DIR:${SWIG_MODULE_example_REAL_NAME}>" "${CMAKE_CURRENT_SOURCE_DIR}/runme.pl" diff --git a/Tests/RunCMake/UseSWIG/LegacyPython.cmake b/Tests/RunCMake/UseSWIG/LegacyPython.cmake index f3d9e2b2e8..8b47aa2aa8 100644 --- a/Tests/RunCMake/UseSWIG/LegacyPython.cmake +++ b/Tests/RunCMake/UseSWIG/LegacyPython.cmake @@ -3,7 +3,7 @@ set(language "python") include (LegacyConfiguration.cmake) -add_custom_target (RunPython +add_custom_target (RunTest 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/MultipleModules.cmake b/Tests/RunCMake/UseSWIG/MultipleModules.cmake new file mode 100644 index 0000000000..e3d579fd2f --- /dev/null +++ b/Tests/RunCMake/UseSWIG/MultipleModules.cmake @@ -0,0 +1,30 @@ + +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/RunCMakeTest.cmake b/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake index cbeba66f74..c63ff2e7de 100644 --- a/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake +++ b/Tests/RunCMake/UseSWIG/RunCMakeTest.cmake @@ -1,13 +1,23 @@ include(RunCMake) -function(run_SWIG group language) - set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${group}${language}-build) +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}") - run_cmake(${group}${language}) - run_cmake_command(${group}${language}-test ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR} --target Run${language}) + run_cmake(${test}) + run_cmake_command(${test}-test ${CMAKE_COMMAND} --build ${RunCMake_TEST_BINARY_DIR} ${_SWIG_TEST_TARGET}) endfunction() -run_SWIG(Legacy Python) -run_SWIG(Legacy Perl) +run_SWIG(LegacyPython TARGET RunTest) +run_SWIG(LegacyPerl TARGET RunTest) + +run_SWIG(BasicPython TARGET RunTest) +run_SWIG(BasicPerl TARGET RunTest) + +run_SWIG(MultipleModules) |