[CMake] Various problems deploying a python module

Michael Hertling mhertling at online.de
Fri Jun 18 02:29:25 EDT 2010


On 06/17/2010 04:23 PM, Janosch Peters wrote:
> Hi list,
> 
> I try to write a cmake script for a python module.  Its finally working 
> now, but the solution I came up with is not very nice.
> 
> 1. Finding the correct python environment:
> 
> I have two python frameworks on my mac: Python2.5 which comes with OS 
> X, and python2.6 from macports. If I just use 
> FIND_PACKAGE(PythonInterp) and FIND_PACKAGE(PythonLibs) I end up 
> getting the python2.6 interpreter from macports but the python2.5 libs 
> from OS X.
> 
> I "solved" it by manually setting the path to python2.6 libraries and 
> headers in INCLUDE_DIRECTORIES and TARGET_LINK_LIBRARIES but this is 
> quite ugly because it may break on another system wit a different path 
> prefix for macports.
> 
> Is there any way to set the desired python version for PythonInterp and 
> PythonLibs in cmake?

There has been several disussions of such an issue, e.g.

<http://www.mail-archive.com/cmake@cmake.org/msg19031.html>
<http://www.mail-archive.com/cmake@cmake.org/msg25197.html>

and perhaps

<http://www.mail-archive.com/cmake@cmake.org/msg27324.html>

which raises hope for a well elaborated FindPython.cmake. ;)

Have you already tried variables like CMAKE_PREFIX_PATH et al. to
direct the find functions to your preferred python installation? On
*nix, e.g., with a python 2.6 installed aside the usual locations but
with the interpreter in the PATH and a system's python 2.5 there would
be a version mismatch since FindPythonInterp.cmake follows the PATH to
2.6 while FindPythonLibs.cmake ignores the PATH and finds 2.5 through
CMAKE_SYSTEM_PREFIX_PATH, so the use of CMAKE_PREFIX_PATH or the like
is needed to find the 2.6 libraries as well. However, because the two
FindPython modules use hardcoded version specifications in a hardcoded
order you shouldn't rely on their capability to find a certain version,
cf. <http://www.mail-archive.com/cmake@cmake.org/msg28878.html>, i.e.
in the above-mentioned *nix scenario, e.g., one couldn't force the
FindPythonInterp.cmake to find 2.5 if 2.6 can be found, too.

> 2. Renaming the library file:
> 
> This is probably very simple, but I startet wih cmake today: How do I 
> change the filename of my library/module? The module is called 
> libvlfeat.so, however python expects C modules to be named _<name>.so. 
> (In my case _vlfeat.so).
> 
> How do I do that?

SET_TARGET_PROPERTIES(vlfeat PROPERTIES PREFIX "_")

'hope that helps.

Regards,

Michael


More information about the CMake mailing list