[CMake] Installing Python Modules with CMake

Michael Wild themiwi at gmail.com
Mon Jan 3 04:34:30 EST 2011


On 01/03/2011 09:11 AM, Todd Gamblin wrote:
> Is there some standard way in CMake to get a project-local install destination for python libraries, e.g.:
> 
> 	${CMAKE_INSTALL_PREFIX}/lib/python2.6/site-packages
> 
> Is this something find modules typically provide?  I can construct this name easily enough myself, but it involves querying the python executable for its version then regexing that string, and I feel like FindPythonLibs should do stuff like that for me.  It would be nice to have something called, say, "CMAKE_PYTHON_INSTALL_PREFIX" set to this path in advance, so that I can just install python modules there.
> 
> Or am I missing something?  I couldn't fund much on installing python files in the docs.
> 
> -Todd
> 

I think you'll have to query Python yourself. Of course, this becomes
difficult if you're cross-compiling, in which case you would need to
parse the <prefix>/lib/pythonX.Y/config/Makefile file yourself and fetch
all the relevant variables (datarootdir, BINDIR, DESTSHARED, LIBDEST,
etc.) and then ask the user what prefix and exec_prefix he wants
(presumably CMAKE_INSTALL_PREFIX maps to prefix, and usually exec_prefix
is the same as prefix, but that's not always the case). Not sure how
that works on Windows, though...

I wouldn't rely too much on FindPythonLibs. The whole FindPython* is a
sorry mess (IMHO) and needs some serious overhaul, but that is some
major undertaking an apparently the suffering wasn't big enough so far
for somebody to take action...

Michael


More information about the CMake mailing list