Skip to content

Commit c552b57

Browse files
committed
Merge branch 'joshuroar-master'
2 parents a828221 + 6c5a316 commit c552b57

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

04-ClassMembers/member.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
m1 = member.SomeClass("Pavel")
66
print ("name =",m1.name)
7-
m1.name = "Günther"
7+
m1.name = "Gunther"
88
print ("name =",m1.name)
99

1010

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
cmake_minimum_required(VERSION 2.8.3)
22
FIND_PACKAGE(PythonInterp)
33
FIND_PACKAGE(PythonLibs)
4-
FIND_PACKAGE(Boost COMPONENTS python)
4+
if(APPLE AND ${PYTHON_VERSION_MAJOR} EQUAL 3)
5+
FIND_PACKAGE(Boost COMPONENTS python3)
6+
else()
7+
FIND_PACKAGE(Boost COMPONENTS python)
8+
endif()
59

610
ENABLE_TESTING()
711
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
@@ -20,4 +24,3 @@ ADD_SUBDIRECTORY(10-Embedding)
2024
ADD_SUBDIRECTORY(11-Iterators)
2125
ADD_SUBDIRECTORY(12-Exceptions)
2226
ADD_SUBDIRECTORY(13-AutoInstantiation)
23-

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ There is a special package needed called boost-python. The standard boost packag
2121

2222
+ `brew install cmake boost-python`
2323

24-
Furthermore, for the homebrew python lib to be used, unfortunately the full path has to be given:
24+
Furthermore, for the homebrew python lib to be used, its path must be provided to cmake. This is handled in the `build.sh` script, but for reference, or if any issues arise, that can be done manually as follows (substitute the path as appropriate for your Python version):
2525

2626
cmake -DPYTHON_LIBRARY=/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib ..
2727

@@ -39,7 +39,7 @@ All examples contain tests, but these only try to run the examples without check
3939

4040
## Python 3
4141

42-
The code works with PYthon3 both on Linux and on OS X. However, there is an astonishing number of loops to hop through.
42+
The code works with Python 3 both on Linux and on OS X. However, there are several caveats.
4343

4444
### Linux
4545

@@ -49,7 +49,12 @@ The code works with PYthon3 both on Linux and on OS X. However, there is an asto
4949

5050
### OS X (again with homebrew)
5151

52+
Some effort has been made to make Python 3 compilation automatic, by making modifications to `build.sh` and `CMakeLists.txt` that account for quirks on the Apple platform regarding cmake, paths, and naming conventions for python/python3. Having said that, if you use `build.sh`, then you will still need to do the following:
53+
5254
+ Build Boost::Python against Python 3 (needs at least version 1.56.0)
53-
+ make sure `python` resolves to python3 (e.g., by using a python3 VE)
55+
+ make sure `python` resolves to python3 (e.g., by using virtualenv)
56+
57+
If you are building without `build.sh`, then you will additionally need to:
58+
5459
+ run `cmake -DBOOST_ROOT=xxx -DPYTHON_LIBRARY=xxx -DPYTHON_INCLUDE_DIR=xxx ..`
55-
+ set DYLD_LIBRARY_PATH to the directory where the boost::python shared library resides before `make test`
60+
+ As of the time of this writing, the naming convention is that python2 is called "python" and python3 is called "python3" on the Apple platform. Therefore, in `CMakeLists.txt` verify that the line `FIND_PACKAGE(Boost COMPONENTS python)` is changed to `FIND_PACKAGE(Boost COMPONENTS python3)`.

build.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,25 @@ set -x
55
cd ${0%%$(basename $0)}
66
mkdir build
77
cd build
8-
cmake -DCMAKE_BUILD_TYPE=DEBUG .. && make && make test
8+
9+
if [[ "$OSTYPE" == "linux-gnu" ]]; then
10+
cmake -DCMAKE_BUILD_TYPE=DEBUG .. && make && make test
11+
elif [[ "$OSTYPE" == "darwin"* ]]; then
12+
PYTHON_VERSION=`python -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)";`
13+
PYTHON_LIBRARY=/usr/local/Frameworks/Python.framework/Versions/$PYTHON_VERSION/lib/libpython$PYTHON_VERSION.dylib
14+
PYTHON_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Versions/$PYTHON_VERSION/Headers/
15+
cmake -DPYTHON_LIBRARY=$PYTHON_LIBRARY -DPYTHON_INCLUDE_DIR=$PYTHON_INCLUDE_DIR -DCMAKE_BUILD_TYPE=DEBUG .. && make && make test
16+
elif [[ "$OSTYPE" == "cygwin" ]]; then
17+
: # POSIX compatibility layer and Linux environment emulation for Windows
18+
elif [[ "$OSTYPE" == "msys" ]]; then
19+
: # shell and GNU utilities compiled for Windows as part of MinGW
20+
elif [[ "$OSTYPE" == "win32" ]]; then
21+
: # good luck
22+
elif [[ "$OSTYPE" == "freebsd"* ]]; then
23+
: # ...
24+
else
25+
: # Unknown.
26+
fi
27+
28+
929

0 commit comments

Comments
 (0)