[CMake] Installing Python Modules with CMake

Todd Gamblin tgamblin at llnl.gov
Mon Jan 3 12:23:05 EST 2011


On Jan 3, 2011, at 1:34 AM, Michael Wild wrote:

> 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...

That's kind of difficult because if I have just 'python', I don't have the version yet, so how am I supposed to find the Makefile?

Off the top of my head, the most portable way to do this would be to find the python-config (which you can get by appending -config to the exe path, even if it's just python and not pythonX.Y) and then:

	head -1 `which ${PYTHON_CONFIG}` | sed 's/.*\([0-9].[0-9]\)$/\1/'

Or the equivalent in CMake using string(REGEXP ...).

That will get you the version without running anything, and then you can go and find the Makefile.  In the non cross-compiled case, though, it would be nice to just have a module that gives you all the information from python-config.

-Todd


> 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...

I noticed you guys had a long discussion about finding Python 3.  Did you come to any conclusions on this?  It would be nice to have a python detection Find module that works if you *just* give it your python executable.  I don't mind writing something like this up if no one else is up for it, but if I'm going to write it I'd like to make something that people will use.

Thoughts?

-Todd





> 
> Michael
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list