diff options
author | Brad King <brad.king@kitware.com> | 2019-05-06 13:18:21 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-05-06 13:19:38 (GMT) |
commit | 1820c7e780e827a509a340835229d7075f5d1d1e (patch) | |
tree | be99d854ba51794b5cc2f7acf89b860c35c5b845 | |
parent | b9ee95fe5e621037f415de675eb378504170a056 (diff) | |
parent | e3919bae17d3442e18b5ec1f4a1ae994c87c455b (diff) | |
download | CMake-1820c7e780e827a509a340835229d7075f5d1d1e.zip CMake-1820c7e780e827a509a340835229d7075f5d1d1e.tar.gz CMake-1820c7e780e827a509a340835229d7075f5d1d1e.tar.bz2 |
Merge topic 'SWIG'
e3919bae17 UseSWIG: Manage alternate library name
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3241
-rw-r--r-- | Help/release/dev/UseSWIG-alternate-library-name.rst | 7 | ||||
-rw-r--r-- | Modules/UseSWIG.cmake | 9 | ||||
-rw-r--r-- | Tests/UseSWIG/AlternateLibraryName/CMakeLists.txt | 35 | ||||
-rw-r--r-- | Tests/UseSWIG/CMakeLists.txt | 12 |
4 files changed, 62 insertions, 1 deletions
diff --git a/Help/release/dev/UseSWIG-alternate-library-name.rst b/Help/release/dev/UseSWIG-alternate-library-name.rst new file mode 100644 index 0000000..8e58b8d --- /dev/null +++ b/Help/release/dev/UseSWIG-alternate-library-name.rst @@ -0,0 +1,7 @@ +UseSWIG-alternate-library-name +------------------------------ + +* The :module:`UseSWIG` module learned to manage alternate library names by + passing ``-interface <library_name>`` for ``python`` language or + ``-dllimport <library_name>`` for ``CSharp`` language to the ``SWIG`` + compiler. diff --git a/Modules/UseSWIG.cmake b/Modules/UseSWIG.cmake index 18ea55c..c136b05 100644 --- a/Modules/UseSWIG.cmake +++ b/Modules/UseSWIG.cmake @@ -466,7 +466,14 @@ function(SWIG_ADD_SOURCE_TO_MODULE name outfiles infile) if(NOT ("-dllimport" IN_LIST swig_source_file_flags OR "-dllimport" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS)) # This makes sure that the name used in the generated DllImport # matches the library name created by CMake - list (APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-dllimport" "${name}") + list (APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-dllimport" "$<TARGET_FILE_PREFIX:${target_name}>$<TARGET_FILE_BASE_NAME:${target_name}>") + endif() + endif() + if (SWIG_MODULE_${name}_LANGUAGE STREQUAL "PYTHON" AND NOT SWIG_MODULE_${name}_NOPROXY) + if(NOT ("-interface" IN_LIST swig_source_file_flags OR "-interface" IN_LIST SWIG_MODULE_${name}_EXTRA_FLAGS)) + # This makes sure that the name used in the proxy code + # matches the library name created by CMake + list (APPEND SWIG_MODULE_${name}_EXTRA_FLAGS "-interface" "$<TARGET_FILE_PREFIX:${target_name}>$<TARGET_FILE_BASE_NAME:${target_name}>") endif() endif() list (APPEND swig_extra_flags ${SWIG_MODULE_${name}_EXTRA_FLAGS}) diff --git a/Tests/UseSWIG/AlternateLibraryName/CMakeLists.txt b/Tests/UseSWIG/AlternateLibraryName/CMakeLists.txt new file mode 100644 index 0000000..a2c239c --- /dev/null +++ b/Tests/UseSWIG/AlternateLibraryName/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.14...3.15) + +project(TestAlternateLibraryName CXX) + +include(CTest) + +find_package(SWIG REQUIRED) +include(${SWIG_USE_FILE}) + +find_package(Python2 REQUIRED COMPONENTS Interpreter Development) + +# Path separator +if (WIN32) + set (PS "$<SEMICOLON>") +else() + set (PS ":") +endif() + +unset(CMAKE_SWIG_FLAGS) + +set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/../example.i" PROPERTY CPLUSPLUS ON) +set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/../example.i" PROPERTY COMPILE_OPTIONS -includeall) + +swig_add_library(example_python + LANGUAGE python + SOURCES ../example.i ../example.cxx) +set_target_properties (example_python PROPERTIES + INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/.." + SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE) +target_link_libraries(example_python PRIVATE Python2::Python) + + +add_test (NAME AlternateLibraryName.example1 + COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}${PS}$<TARGET_FILE_DIR:example_python>" + "${Python2_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/../runme.py") diff --git a/Tests/UseSWIG/CMakeLists.txt b/Tests/UseSWIG/CMakeLists.txt index 434895e..3cc910f 100644 --- a/Tests/UseSWIG/CMakeLists.txt +++ b/Tests/UseSWIG/CMakeLists.txt @@ -123,3 +123,15 @@ add_test(NAME UseSWIG.SwigSrcFileExtension COMMAND --build-options ${build_options} --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) + + +add_test(NAME UseSWIG.AlternateLibraryName COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/UseSWIG/AlternateLibraryName" + "${CMake_BINARY_DIR}/Tests/UseSWIG/AlternateLibraryName" + ${build_generator_args} + --build-project TestAlternateLibraryName + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) |