From 8c6785594c870ded9cb99d9bcecd6238e5324588 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Wed, 6 Feb 2013 19:24:40 -0800 Subject: [PATCH] CMake now invokes distutils correctly --- CMakeLists.txt | 22 +++++++++++++-------- python/README.md | 13 +++++-------- python/demo/interactive.py | 0 python/demo/main.py | 0 python/demo/shaders.py | 2 +- python/setup.py | 40 ++++++++++++++++++++++---------------- 6 files changed, 43 insertions(+), 34 deletions(-) mode change 100644 => 100755 python/demo/interactive.py mode change 100644 => 100755 python/demo/main.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 003760e8..40832fa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -337,19 +337,25 @@ if(PYTHONINTERP_FOUND AND SWIG_FOUND) if(NUMPY_ERR) message(WARNING "Unable to import numpy.") else() - message(STATUS "Numpy package has been located, Python bindings will be built.") + message(STATUS "Numpy package has been located.") + set(PYCMD ${PYTHON_EXECUTABLE} setup.py build ) + list(APPEND PYCMD --osddir=${LIBRARY_OUTPUT_PATH} ) + list(APPEND PYCMD --build-platlib=${PROJECT_BINARY_DIR}/python ) + list(APPEND PYCMD --build-temp=${PROJECT_BINARY_DIR}/temp ) add_custom_command( - OUTPUT ${PROJECT_BINARY_DIR}/python - COMMAND ${PYTHON_EXECUTABLE} setup.py build --osddir=${LIBRARY_OUTPUT_PATH} --build-base=${PROJECT_BINARY_DIR}/python - WORKING_DIRECTORY python + OUTPUT ${PROJECT_BINARY_DIR}/python/osd + COMMAND ${PYCMD} + WORKING_DIRECTORY ../python DEPENDS osd_static_cpu osd_dynamic_cpu COMMENT "Building Python bindings with distutils" ) add_custom_target(python ALL - DEPENDS ${PROJECT_BINARY_DIR}/python) - install(CODE "execute_process(" - "WORKING_DIRECTORY python " - "COMMAND ${PYTHON_EXECUTABLE} setup.py build --osddir=${LIBRARY_OUTPUT_PATH} --build-base=/home/prideout/git/OpenSubdiv/build/python install") + DEPENDS ${PROJECT_BINARY_DIR}/python/osd + ) + install(CODE "execute_process( + WORKING_DIRECTORY ../python + COMMAND ${PYCMD} install --user)" + ) endif() endif() diff --git a/python/README.md b/python/README.md index 429b8662..7d8dd22d 100644 --- a/python/README.md +++ b/python/README.md @@ -1,17 +1,13 @@ # Instructions The OpenSubdiv Python wrapper has been tested with Python 2.6 and Python 2.7. -Make sure you have the numpy module installed before you begin. +Make sure you install SWIG and numpy before you begin. -First, try building the extension with: +CMake builds the extension like this: - ./setup.py build osddir='../build/lib' + ./setup.py build --osddir='../build/lib' --build-platlib='../build/python' -You'll need to replace `../build/lib` with the folder that has `libosdCPU.a` et al. - -This creates a build folder with a platform-specific subfolder, such as: - - ./build/lib.macosx-10.8-intel-2.7 +If you invoke this manually, you'll need to replace `../build/lib` with the folder that has `libosdCPU.a`. Next, try out the unit tests: @@ -41,3 +37,4 @@ After installing the module, you can generate and view the Sphinx-generated docu - Instead of using OsdCpuVertexBuffer, create a "NumpyCpuVertexBuffer" that wraps a numpy array - Add an API that looks very similar to the RIB parameters for RiHierarchicalSubdiv - Remove all the caveats that are listed in the Sphinx docs :) +- Sphinx documentation should be CMake-ified. diff --git a/python/demo/interactive.py b/python/demo/interactive.py old mode 100644 new mode 100755 diff --git a/python/demo/main.py b/python/demo/main.py old mode 100644 new mode 100755 diff --git a/python/demo/shaders.py b/python/demo/shaders.py index 8d0853d9..7ea04554 100644 --- a/python/demo/shaders.py +++ b/python/demo/shaders.py @@ -57,7 +57,7 @@ from OpenGL.GL import * -ProgramFiles = ['demo/simple.glsl'] +ProgramFiles = ['simple.glsl'] Programs = { "BareBones" : { diff --git a/python/setup.py b/python/setup.py index 8b427373..c926ff04 100755 --- a/python/setup.py +++ b/python/setup.py @@ -66,23 +66,12 @@ import os, os.path np_include_dir = numpy.get_include() np_library_dir = os.path.join(np_include_dir, '../lib') osd_include_dirs = ['../opensubdiv', '../regression'] - -def import_build_folder(): - import sys, distutils.util, os.path - build_dir = "build/lib.{0}-{1}.{2}".format( - distutils.util.get_platform(), - *sys.version_info) - if not os.path.exists(build_dir): - print "Folder does not exist: " + build_dir - print "Perhaps you need to run:" - print " python setup.py build" - else: - sys.path.insert(0, build_dir) +osddir = '../build/lib' osd_shim = Extension( 'osd._shim', include_dirs = osd_include_dirs, - library_dirs = ['../build/lib', np_library_dir], + library_dirs = [osddir, np_library_dir], libraries = ['osdCPU', 'npymath'], swig_opts = ['-c++'], sources = [ @@ -95,6 +84,21 @@ osd_shim.extra_compile_args = \ os.environ['ARCHFLAGS'] = '-arch ' + os.uname()[4] +def setBuildFolder(folder): + osddir = folder + osd_shim.runtime_library_dirs = [folder] + osd_shim.library_dirs = [folder, np_library_dir] + +def importBuildFolder(): + import os.path + builddir = os.path.join(osddir, "../python") + if not os.path.exists(builddir): + print "Folder does not exist: " + builddir + print "Perhaps you need to run:" + print " python setup.py build" + else: + sys.path.insert(0, builddir) + class TestCommand(Command): description = "runs unit tests" user_options = [] @@ -103,7 +107,7 @@ class TestCommand(Command): def finalize_options(self): pass def run(self): - import_build_folder() + importBuildFolder() import unittest, test suite = unittest.defaultTestLoader.loadTestsFromModule(test) unittest.TextTestRunner(verbosity=2).run(suite) @@ -116,8 +120,9 @@ class DemoCommand(Command): def finalize_options(self): pass def run(self): - import_build_folder() + importBuildFolder() import demo + os.chdir('demo') demo.main() class InteractiveCommand(Command): @@ -128,8 +133,9 @@ class InteractiveCommand(Command): def finalize_options(self): pass def run(self): - import_build_folder() + importBuildFolder() import demo + os.chdir('demo') demo.interactive() class DocCommand(Command): @@ -156,7 +162,7 @@ class BuildCommand(build): build.finalize_options(self) if self.osddir is None: self.osddir = '../build/lib' - osd_shim.runtime_library_dirs = [self.osddir] + setBuildFolder(self.osddir) def run(self): build.run(self)