[CMake] Calling Python Setuptools (setup.py) from CMake.

Alan W. Irwin irwin at beluga.phys.uvic.ca
Sat Feb 21 03:25:29 EST 2009


On 2009-02-21 16:12+1100 Nima Talebi wrote:

> Hi All,
> I've been using CMake for a little while now, but not with python.
> 
> I have something like this in my CMakeLists.txt file...
> 
> message(STATUS " ${III} Loading FUNCWIRE_MINION...")
> 
> if(ENABLE_FUNCWIRE_MINION)
>   message(STATUS "   ${GGG} Python build...")
>   execute_process(COMMAND cd ${CMAKE_SOURCE_DIR}/funcwire-minion/ &&
> ${PYTHON} setup.py build)
> endif(ENABLE_FUNCWIRE_MINION)
> 
> install(CODE "EXECUTE_PROCESS(COMMAND cd
> ${CMAKE_SOURCE_DIR}/funcwire-minion/ && ${PYTHON} setup.py install)")
> 
> ...however it doesn't quite work, before putting too much work into finding
> what the problem is, could someone point out if I'm even on the right track,
> or if there is a better way to do this?

I rarely have used the python setup.py build system so I will just confine
my comments to the overview.

One issue that might be confusing you is setup.py build is running at the
time you run cmake, rather than the time you run make.  You might want to
try using a custom command for that intead (which will set up the Makefiles
generated by cmake so that "python setup.py build" is run at make time).

I suspect the install(CODE...) part is okay if you have the syntax right.
That fragment of CMake code should run at "make install" time which I think
is what you want.  (EXECUTE_PROCESS there is running at "make install" time
because that is the rather special action that is done by install(CODE...
for the single cmake command within the quotes while the previous
EXECUTE_PROCESS runs at cmake time as I noted above.)

An unrelated but important issue is the problem of messing up your source
tree with the setup.py build.  Is there a way to run python setup.py build
from a different directory, specifically
${CMAKE_BINARY_DIR}/funcwire-minion/?  That would be more compatible with
the spirit of cmake which likes to make strong distinctions between the
build tree (which is often separate from the source tree) and the source
tree.  (You can also lump the two together with cmake, but it is not advised
since a clean source tree is nice to have.)

I hope this overview helps.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list