Akira Okumura Akira Okumura - 2 months ago 16
Python Question

`make install` with CMake + SWIG + Python

I am writing a C++ library which can be used from both C++ and Python on Mac and Linux. So I have decided to use CMake and SWIG for my project.

As well described in the SWIG 2.0 documentation, combination of SWIG and CMake also works fine on my Mac.
http://www.swig.org/Doc2.0/SWIGDocumentation.html#Introduction_build_system

But I have a question about

make install
.

After typing
cmake .
and
make
,
_example.so
was successfully generated. But
make install
does not work, because the auto-generated Makefile does not have
install
target. I would like to know how I can add
install
target in the Makefile. I would like
_example.so
to be installed under
site-packages
directory on each system.

I would very appreciate it if anyone could tell me how to modify the CMake example written in the above link.

Answer

The CMake interface to make install is the CMake command install(). In your example, you could add an installation rule like this:

install(
  TARGETS ${SWIG_MODULE_example_REAL_NAME} 
  # ... add other arguments to install() as necessary
)

Once there are any install() commands in a CMakeList, CMake will generate an install target callable as make install.

Comments