diff options
author | Marc Chevrier <marc.chevrier@gmail.com> | 2020-08-04 14:19:10 (GMT) |
---|---|---|
committer | Marc Chevrier <marc.chevrier@gmail.com> | 2020-08-04 14:19:10 (GMT) |
commit | 50e53eaed903e9a7b5e69eb7825a75073b44cfe9 (patch) | |
tree | dd2e5252c47f240d7d5b8f53c1070e3b18c253eb /Tests/UseSWIG | |
parent | 5becf28f9230eb70e4181b4aa669297781e7f6b1 (diff) | |
download | CMake-50e53eaed903e9a7b5e69eb7825a75073b44cfe9.zip CMake-50e53eaed903e9a7b5e69eb7825a75073b44cfe9.tar.gz CMake-50e53eaed903e9a7b5e69eb7825a75073b44cfe9.tar.bz2 |
UseSWIG: Take care of support files in sub-directories
Fixes: #20833
Diffstat (limited to 'Tests/UseSWIG')
-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 |
6 files changed, 84 insertions, 0 deletions
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" |