From 66c349c22240a9ab8f3f72ee0ae3e87e4b479693 Mon Sep 17 00:00:00 2001 From: Toshiki Teramura Date: Thu, 20 Nov 2014 22:27:15 +0900 Subject: [PATCH 1/2] Append python version detector --- CMakeLists.txt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cdba6a1..1bc0391 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,12 +31,17 @@ find_package(NumPy REQUIRED) # set(Boost_USE_STATIC_LIBS ON) # set(Boost_USE_MULTITHREADED ON) # set(Boost_USE_STATIC_RUNTIME ON) -FIND_PACKAGE(Boost COMPONENTS python REQUIRED) +if(${PYTHON_VERSION_STRING} GREATER 3.0) + message(STATUS "Use Python3") + find_package(Boost COMPONENTS python3 REQUIRED) +else() + message(STATUS "Use Python2") + find_package(Boost COMPONENTS python REQUIRED) +endif() -message( STATUS "found boost:" - "\nINCLUDE: ${Boost_INCLUDE_DIRS}" - "\nLIB: ${Boost_LIBRARIES}" -) +message( STATUS "Paths of Boost:") +message( STATUS "Include : " ${Boost_INCLUDE_DIRS}) +message( STATUS "Libraries: " ${Boost_LIBRARIES}) # add_definitions( -DBOOST_ALL_NO_LIB ) # In some cases, you may need to explicitly specify that a dynamic Boost is used; if so use: From 4fed85152336700544b2b62d294014200ec53394 Mon Sep 17 00:00:00 2001 From: Toshiki Teramura Date: Thu, 20 Nov 2014 22:31:29 +0900 Subject: [PATCH 2/2] Revise example/wrap.cpp for python3 --- libs/numpy/example/wrap.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/numpy/example/wrap.cpp b/libs/numpy/example/wrap.cpp index 06a8d55..5d2027e 100644 --- a/libs/numpy/example/wrap.cpp +++ b/libs/numpy/example/wrap.cpp @@ -111,8 +111,11 @@ BOOST_PYTHON_MODULE(example) { int main(int argc, char **argv) { // This line makes our module available to the embedded Python intepreter. - PyImport_AppendInittab("example", &initexample); - +# if PY_VERSION_HEX >= 0x03000000 + PyImport_AppendInittab("example", &PyInit_example); +# else + PyImport_AppendInittab("example", &initexample); +# endif // Initialize the Python runtime. Py_Initialize();