Resolve "Modernize CMake and Swig"
Closes #5 (closed)
Remark
SWIG_ADD_LIBRARY
cmake command does not support multi-configurations that can be done with Visual Studio, Xcode or Ninja Multi-Config.
For example, let us consider a swig module dummy
. When using multi-config, we cannot ensure by default that both python module dummy.py
and the wrapped library _dummy.so
stand in the same directory. Using Release config for instance, we would have the following:
PATH_TO_MODULE/dummy.py
PATH_TO_MODLUE/Release/_dummy.so
In this case, the python module dummy.py
is unable to load the wrapped library _dummy.so
because it looks for it in the same folder. It is not possible to tell the module where to find the library via the options of the command SWIG_ADD_LIBRARY
.
The solution is to use generator expression
of cmake so as to enforce both the module and the library to be at the same place. Considering the previous example, one has to write in the CMakeLists.txt
the following code:
set_target_properties(dummy PROPERTIES
LIBRARY_OUTPUT_DIRECTORY $<PATH:APPEND,${PATH_TO_MODULE},>)
It results the following structure whatever the config type:
PATH_TO_MODULE/dummy.py
PATH_TO_MODLUE/_dummy.so