diff options
author | Brad King <brad.king@kitware.com> | 2020-08-06 14:53:28 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-08-06 14:53:36 (GMT) |
commit | fdcb7483d11030fe597208843437ad6cce71ff50 (patch) | |
tree | 104cd36ae823b5f6c50e9ae875fd4cffe2acc224 | |
parent | 5c56aaa2848fe674e7fcdc255d72b2ea9f088d48 (diff) | |
parent | 50e53eaed903e9a7b5e69eb7825a75073b44cfe9 (diff) | |
download | CMake-fdcb7483d11030fe597208843437ad6cce71ff50.zip CMake-fdcb7483d11030fe597208843437ad6cce71ff50.tar.gz CMake-fdcb7483d11030fe597208843437ad6cce71ff50.tar.bz2 |
Merge topic 'UseSWIG-support-files-in-subdirectories'
50e53eaed9 UseSWIG: Take care of support files in sub-directories
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5097
-rw-r--r-- | Modules/UseSWIG/ManageSupportFiles.cmake | 4 | ||||
-rw-r--r-- | Tests/UseSWIG/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Tests/UseSWIG/NamespaceCsharp/CMakeLists.txt | 25 | ||||
-rw-r--r-- | Tests/UseSWIG/NamespaceCsharp/ValidateSupportFiles.cmake | 8 | ||||
-rw-r--r-- | Tests/UseSWIG/NamespaceCsharp/ns_example.cpp | 14 | ||||
-rw-r--r-- | Tests/UseSWIG/NamespaceCsharp/ns_example.hpp | 19 | ||||
-rw-r--r-- | Tests/UseSWIG/NamespaceCsharp/ns_example.i | 8 |
7 files changed, 86 insertions, 2 deletions
diff --git a/Modules/UseSWIG/ManageSupportFiles.cmake b/Modules/UseSWIG/ManageSupportFiles.cmake index 4a03900..6618fd5 100644 --- a/Modules/UseSWIG/ManageSupportFiles.cmake +++ b/Modules/UseSWIG/ManageSupportFiles.cmake @@ -4,7 +4,7 @@ if (ACTION STREQUAL "CLEAN") # Collect current list of generated files - file (GLOB files LIST_DIRECTORIES FALSE RELATIVE "${SUPPORT_FILES_WORKING_DIRECTORY}" "${SUPPORT_FILES_WORKING_DIRECTORY}/*") + file (GLOB_RECURSE files LIST_DIRECTORIES TRUE RELATIVE "${SUPPORT_FILES_WORKING_DIRECTORY}" "${SUPPORT_FILES_WORKING_DIRECTORY}/*") if (files) # clean-up the output directory @@ -22,7 +22,7 @@ endif() if (ACTION STREQUAL "COPY") # Collect current list of generated files - file (GLOB files LIST_DIRECTORIES FALSE "${SUPPORT_FILES_WORKING_DIRECTORY}/*") + file (GLOB files LIST_DIRECTORIES TRUE "${SUPPORT_FILES_WORKING_DIRECTORY}/*") if (files) # copy files to the output directory diff --git a/Tests/UseSWIG/CMakeLists.txt b/Tests/UseSWIG/CMakeLists.txt index d102846..7046fab 100644 --- a/Tests/UseSWIG/CMakeLists.txt +++ b/Tests/UseSWIG/CMakeLists.txt @@ -33,6 +33,16 @@ if (CMAKE_CSharp_COMPILER) --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) endif() +add_test(NAME UseSWIG.NamespaceCsharp COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/UseSWIG/NamespaceCsharp" + "${CMake_BINARY_DIR}/Tests/UseSWIG/NamespaceCsharp" + ${build_generator_args} + --build-project TestNamespaceCsharp + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) add_test(NAME UseSWIG.BasicPython COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> diff --git a/Tests/UseSWIG/NamespaceCsharp/CMakeLists.txt b/Tests/UseSWIG/NamespaceCsharp/CMakeLists.txt new file mode 100644 index 0000000..39566a8 --- /dev/null +++ b/Tests/UseSWIG/NamespaceCsharp/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.12...3.13) + +project(TestNamsespaceCsharp CXX) + +include(CTest) + +find_package(SWIG REQUIRED) +include(${SWIG_USE_FILE}) + +set(UseSWIG_MODULE_VERSION 2) + + +add_library(ns_example STATIC ns_example.cpp) +target_include_directories(ns_example PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") + +set_property(SOURCE ns_example.i PROPERTY CPLUSPLUS ON) + +swig_add_library(ns_csharp TYPE SHARED LANGUAGE csharp SOURCES ns_example.i) +set_target_properties(ns_csharp PROPERTIES SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE) + +target_link_libraries(ns_csharp PRIVATE ns_example) + +get_target_property(NS_CSHARP_SUPPORT_FILES_DIR ns_csharp SWIG_SUPPORT_FILES_DIRECTORY) + +add_test(NAME NamespaceCsharp COMMAND "${CMAKE_COMMAND}" "-DSUPPORT_FILES_DIRECTORY=${NS_CSHARP_SUPPORT_FILES_DIR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/ValidateSupportFiles.cmake") diff --git a/Tests/UseSWIG/NamespaceCsharp/ValidateSupportFiles.cmake b/Tests/UseSWIG/NamespaceCsharp/ValidateSupportFiles.cmake new file mode 100644 index 0000000..828d54c --- /dev/null +++ b/Tests/UseSWIG/NamespaceCsharp/ValidateSupportFiles.cmake @@ -0,0 +1,8 @@ + +file (GLOB_RECURSE files LIST_DIRECTORIES TRUE RELATIVE "${SUPPORT_FILES_DIRECTORY}" "${SUPPORT_FILES_DIRECTORY}/*") + +list(SORT files) + +if (NOT files STREQUAL "NSExample.cs;NSExamplePINVOKE.cs;ns;ns/my_class_in_namespace.cs") + message (FATAL_ERROR "Support files not correctly collected.") +endif() diff --git a/Tests/UseSWIG/NamespaceCsharp/ns_example.cpp b/Tests/UseSWIG/NamespaceCsharp/ns_example.cpp new file mode 100644 index 0000000..a03dbad --- /dev/null +++ b/Tests/UseSWIG/NamespaceCsharp/ns_example.cpp @@ -0,0 +1,14 @@ +#include "ns_example.hpp" + +namespace ns { + +void my_class_in_namespace::add(int value) +{ + Sum += value; +} + +int my_class_in_namespace::get_sum() const +{ + return Sum; +} +} diff --git a/Tests/UseSWIG/NamespaceCsharp/ns_example.hpp b/Tests/UseSWIG/NamespaceCsharp/ns_example.hpp new file mode 100644 index 0000000..65b9ab5 --- /dev/null +++ b/Tests/UseSWIG/NamespaceCsharp/ns_example.hpp @@ -0,0 +1,19 @@ +#pragma once + +namespace ns { + +class my_class_in_namespace +{ +public: + my_class_in_namespace() + : Sum(0) + { + } + + void add(int value); + int get_sum() const; + +private: + int Sum; +}; +} diff --git a/Tests/UseSWIG/NamespaceCsharp/ns_example.i b/Tests/UseSWIG/NamespaceCsharp/ns_example.i new file mode 100644 index 0000000..036f7ca --- /dev/null +++ b/Tests/UseSWIG/NamespaceCsharp/ns_example.i @@ -0,0 +1,8 @@ +%module NSExample + +%{ +#include "ns_example.hpp" +%} + +%nspace ns::my_class_in_namespace; +%include "ns_example.hpp" |