From fddf79f1a3e5c7b09b472198f960a494b608ca82 Mon Sep 17 00:00:00 2001 From: Isaak Lim Date: Mon, 9 Mar 2015 16:39:11 +0000 Subject: [PATCH] Alexander Dielen: - updated the tutorial with further information on how to build the python bindings - updated the cmake file so that cmake finds boost python installations with the names python2 and python3 - fixed a cmake warning on os x (Policy CMP0042: MACOSX_RPATH) - fixed a bug in the unit test test_add_face.py git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@1237 fdac6126-5c0c-442c-9429-916003d36597 --- Doc/python_tutorial.docu | 22 ++++++++++++++++++-- src/Python/CMakeLists.txt | 30 ++++++++++++++------------- src/Python/Example/CMakeLists.txt | 3 +++ src/Python/Unittests/test_add_face.py | 5 +++-- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Doc/python_tutorial.docu b/Doc/python_tutorial.docu index 413ebe6e..8649d4f9 100644 --- a/Doc/python_tutorial.docu +++ b/Doc/python_tutorial.docu @@ -25,8 +25,26 @@ The Python Bindings depend on the following libraries: \note Make sure that your Boost Python and Python versions match, i.e. that Boost Python was linked against the correct Python version. -The Python Bindings are automatically build with %OpenMesh. For more information -on how to build %OpenMesh see \ref compiling. +The Python Bindings are automatically built with %OpenMesh. The generated files are written to the +Build/python subdirectory of the build tree. For more information on how to build %OpenMesh see +\ref compiling. + +If CMake does not find your Python installation (or finds the wrong one) you can +explicitly specify an installation by setting the following variables: + +\verbatim +PYTHON_LIBRARY - Path to the python library +PYTHON_INCLUDE_DIR - Path to where Python.h is found +\endverbatim + +Similarly, if CMake does not find your Boost Python installation, set the +following variables: + +\verbatim +BOOST_ROOT - Preferred installation prefix +BOOST_INCLUDEDIR - Preferred include directory e.g. /include +BOOST_LIBRARYDIR - Preferred library directory e.g. /lib +\endverbatim diff --git a/src/Python/CMakeLists.txt b/src/Python/CMakeLists.txt index ee28abeb..26979a49 100644 --- a/src/Python/CMakeLists.txt +++ b/src/Python/CMakeLists.txt @@ -12,27 +12,26 @@ ENDIF() IF(OPENMESH_BUILD_PYTHON_BINDINGS) # Look for the python libs - MESSAGE(STATUS "Looking for Python") + MESSAGE(STATUS "Looking for PythonLibs") FIND_PACKAGE(PythonLibs ${OPENMESH_PYTHON_VERSION} QUIET) IF(PYTHONLIBS_FOUND) - MESSAGE(STATUS "Looking for Python -- found") + MESSAGE(STATUS "Looking for PythonLibs -- found") # Determine the name of the python component - STRING(REGEX MATCH "^[0-9]+\\.[0-9]+" PYTHON_VERSION ${PYTHONLIBS_VERSION_STRING}) - STRING(REGEX REPLACE "\\." "" PYTHON_VERSION ${PYTHON_VERSION}) - - SET(BOOST_PYTHON_COMPONENT "python-py${PYTHON_VERSION}") + STRING(REGEX MATCH "^[0-9]+\\.[0-9]+" PYTHON_VERSION_MAJOR_MINOR ${PYTHONLIBS_VERSION_STRING}) + STRING(REGEX REPLACE "\\." "" PYTHON_VERSION_MAJOR_MINOR ${PYTHON_VERSION_MAJOR_MINOR}) + STRING(REGEX MATCH "^[0-9]" PYTHON_VERSION_MAJOR ${PYTHON_VERSION_MAJOR_MINOR}) MESSAGE(STATUS "Looking for Boost Python") - # Look for version specific python component - FIND_PACKAGE(Boost QUIET COMPONENTS ${BOOST_PYTHON_COMPONENT}) - - # Look for any other python component - IF(NOT Boost_FOUND) - FIND_PACKAGE(Boost QUIET COMPONENTS python) - ENDIF() + SET(BOOST_PYTHON_COMPONENT_NAMES "python-py${PYTHON_VERSION_MAJOR_MINOR}" "python${PYTHON_VERSION_MAJOR}" "python") + + FOREACH(NAME ${BOOST_PYTHON_COMPONENT_NAMES}) + IF(NOT Boost_FOUND) + FIND_PACKAGE(Boost QUIET COMPONENTS ${NAME}) + ENDIF() + ENDFOREACH() IF(Boost_FOUND) MESSAGE(STATUS "Looking for Boost Python -- found") @@ -111,6 +110,9 @@ IF(OPENMESH_BUILD_PYTHON_BINDINGS) IF(APPLE) SET_TARGET_PROPERTIES(openmesh PROPERTIES SUFFIX ".so") + IF (NOT (CMAKE_MAJOR_VERSION LESS 3)) + SET_TARGET_PROPERTIES(openmesh PROPERTIES MACOSX_RPATH TRUE) + ENDIF() ENDIF() IF(WIN32) @@ -191,6 +193,6 @@ IF(OPENMESH_BUILD_PYTHON_BINDINGS) MESSAGE("Boost Python not found! Skipping Python Bindings.") ENDIF() ELSE() - MESSAGE("Python not found! Skipping Python Bindings.") + MESSAGE("PythonLibs not found! Skipping Python Bindings.") ENDIF() ENDIF() diff --git a/src/Python/Example/CMakeLists.txt b/src/Python/Example/CMakeLists.txt index 53ae0b64..10b99d0f 100644 --- a/src/Python/Example/CMakeLists.txt +++ b/src/Python/Example/CMakeLists.txt @@ -19,6 +19,9 @@ SET_TARGET_PROPERTIES( IF(APPLE) SET_TARGET_PROPERTIES(example PROPERTIES SUFFIX ".so") + IF (NOT (CMAKE_MAJOR_VERSION LESS 3)) + SET_TARGET_PROPERTIES(example PROPERTIES MACOSX_RPATH TRUE) + ENDIF() ENDIF() IF(WIN32) diff --git a/src/Python/Unittests/test_add_face.py b/src/Python/Unittests/test_add_face.py index faeadea1..f6a6fb20 100644 --- a/src/Python/Unittests/test_add_face.py +++ b/src/Python/Unittests/test_add_face.py @@ -216,11 +216,12 @@ class AddFace(unittest.TestCase): self.mesh.add_face(self.vhandle[0], self.vhandle[5], self.vhandle[6]) # non-manifold! - self.mesh.add_face(self.vhandle[3], self.vhandle[0], self.vhandle[4]) + invalid_fh = self.mesh.add_face(self.vhandle[3], self.vhandle[0], self.vhandle[4]) # Check setup self.assertEqual(self.mesh.n_vertices(), 7) - self.assertEqual(self.mesh.n_faces(), 4) + self.assertEqual(self.mesh.n_faces(), 3) + self.assertEqual(invalid_fh, openmesh.TriMesh.InvalidFaceHandle) def test_add_quad_to_polymesh(self): self.mesh = openmesh.PolyMesh()