UseSWIG: Proxy classes not copied to SWIG_SUPPORT_FILES_DIRECTORY when using namespaces
I'm trying to generate a C# wrapper using SWIG for a C++ class in a namespace.
// mylib.hpp
#pragma once
namespace mylib {
class my_class_in_namespace {
public:
void add(int value);
int get_sum() const;
private:
int sum_ = 0;
};
} // namespace mylib
// mylib.i
%module MyLib
%{
#include <mylib.hpp>
%}
%nspace mylib::my_class_in_namespace;
%include <mylib.hpp>
In the CMakeLists.txt
file the UseSWIG_MODULE_VERSION
variable gets set to 2
. Other output variables are not modified.
For installing the project I retrieve the SWIG_SUPPORT_FILES_DIRECTORY
target property
get_target_property(
MYLIB_CSHARP_SUPPORT_FILES_DIR
mylib_csharp
SWIG_SUPPORT_FILES_DIRECTORY
)
and copy the content of this directory to the installation directory directory
install(
DIRECTORY ${MYLIB_CSHARP_SUPPORT_FILES_DIR}/
DESTINATION .
)
This partially works, but the C# proxy code for the mylib::my_class_in_namespace
class is missing from the installation directory. When building the library this code lives in the ${PROJECT_BINARY_DIR}/CMakeFiles/mylib_csharp.dir/mylib.files/mylib/my_class_in_namespace.cs
file, but it seems like only the files directly inside the ${PROJECT_BINARY_DIR}/CMakeFiles/mylib_csharp.dir/mylib.files
directory will get copied to SWIG_SUPPORT_FILES_DIRECTORY
(${PROJECT_BINARY_DIR}/CMakeFiles/mylib_csharp.dir/csharp.files
) during the build step.
A minimal example project can be found here:
https://github.com/mabuchner/cmake-use-swig-csharp-namespace
Tested on MacOS 10.15.4 with CMake 3.17.0, Swig 4.0.1 and using the Ninja generator.