[CMake] Finding PythonLibs using PythonInterp

Felipe Lema felipe.lema at alges.cl
Mon Nov 28 09:54:13 EST 2011


Hello, everyone

I was trying to use cmake to build python c++ extensions in win7, but
couldn't get cmake to detect PythonLibs. At least, not without editing the
windows registry. Since it could detect PythonInterp, I got it working
using the directories provided from methods inside the interpreter.

-- code snippet --
execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import sys;from
distutils.sysconfig import
get_python_inc;sys.stdout.write(get_python_inc())"
OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS
ERROR_VARIABLE ERROR_FINDING_INCLUDES)

execute_process(COMMAND "${PYTHON_EXECUTABLE}" -c "import sys;from
numpy.distutils.numpy_distribution import NumpyDistribution;from
numpy.distutils.command.build_ext import
build_ext;a=build_ext(NumpyDistribution());a.ensure_finalized();sys.stdout.write(';'.join(a.library_dirs))"
OUTPUT_VARIABLE PYTHON_LIBRARIES_DIR
ERROR_VARIABLE ERROR_FINDING_LIBRARIES)

  -- /code snippet --

These directories can be used later for finding the python .lib files and
version number, as cmake currently does (although using the directories
from the windows registry)

The only setback (at least for finding the python lib files) is that the
user must have numpy correctly installed with the found interpreter.
Haven't tried it, but there should be a way to get it to work without numpy
installed.

In spite of the latest, I still think that this code is very useful.

PS=Just in case, the python script embedded in the execute_process args
should be a single line
-- 

Felipe Lema Salas
Ingeniero Civil en Computación
Laboratorio ALGES
Departamento de Ingeniería en Minas
Universidad de Chile
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20111128/3edd8cc8/attachment.htm>


More information about the CMake mailing list