Commits

Vertexwahn  committed dc4fe94

Added a demo that shows how to use boost python.

  • Participants
  • Parent commits 4e611f5

Comments (0)

Files changed (4)

File BoostPython/CMakeLists.txt

+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
+PROJECT(BoostPythonTest)
+
+set_property(GLOBAL PROPERTY USE_FOLDERS ON)
+
+SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/build/)
+
+#SET(CMAKE_DEBUG_POSTFIX  "d")
+
+set(Boost_USE_STATIC_LIBS   ON)
+FIND_PACKAGE(Boost COMPONENTS filesystem system	python REQUIRED)
+
+find_package(PythonLibs REQUIRED)
+include_directories(${PYTHON_INCLUDE_DIRS})
+link_directories(${PYTHON_LIBRARIES})
+
+# Unicode rules!
+ADD_DEFINITIONS(-D_UNICODE -DBOOST_PYTHON_STATIC_LIB)
+
+include_directories(
+	${Boost_INCLUDE_DIR}
+)
+	
+LINK_DIRECTORIES(	
+	${Boost_LIBRARY_DIRS}
+	${PYTHON_LIBRARIES}
+)
+  	
+file(GLOB BoostPython_SOURCES src/*.*)
+
+# Create a target for the library
+ADD_LIBRARY(hello_ext SHARED
+	${BoostPython_SOURCES})
+	
+target_link_libraries(hello_ext 
+        ${Boost_LIBRARIES}
+        ${PYTHON_LIBRARIES}
+)				
+
+add_custom_target(BoostCopyBinaries
+	COMMAND	${CMAKE_COMMAND} -E copy ${Boost_INCLUDE_DIR}/stage/lib/boost_filesystem-vc110-mt-gd-1_54.dll 	${CMAKE_BINARY_DIR}/Debug
+	COMMAND	${CMAKE_COMMAND} -E copy ${Boost_INCLUDE_DIR}/stage/lib/boost_system-vc110-mt-gd-1_54.dll 		${CMAKE_BINARY_DIR}/Debug
+	COMMAND	${CMAKE_COMMAND} -E copy ${Boost_INCLUDE_DIR}/stage/lib/boost_signals-vc110-mt-gd-1_54.dll 		${CMAKE_BINARY_DIR}/Debug
+	COMMAND	${CMAKE_COMMAND} -E copy ${Boost_INCLUDE_DIR}/stage/lib/boost_python-vc110-mt-gd-1_54.dll 		${CMAKE_BINARY_DIR}/Debug
+	COMMAND	${CMAKE_COMMAND} -E copy ${Boost_INCLUDE_DIR}/stage/lib/boost_filesystem-vc110-mt-1_54.dll 		${CMAKE_BINARY_DIR}/Release
+	COMMAND	${CMAKE_COMMAND} -E copy ${Boost_INCLUDE_DIR}/stage/lib/boost_system-vc110-mt-1_54.dll 			${CMAKE_BINARY_DIR}/Release
+	COMMAND	${CMAKE_COMMAND} -E copy ${Boost_INCLUDE_DIR}/stage/lib/boost_signals-vc110-mt-1_54.dll 		${CMAKE_BINARY_DIR}/Release
+
+	COMMENT "Copying boost_filesystem-vc110-mt-gd-1_53.dll	from '${Boost_INCLUDE_DIR}/lib/stage' to '${CMAKE_BINARY_DIR}/Debug'" VERBATIM
+	COMMENT "Copying boost_system-vc110-mt-gd-1_53.dll		from '${Boost_INCLUDE_DIR}/stage/lib' to '${CMAKE_BINARY_DIR}/Debug'" VERBATIM
+	COMMENT "Copying boost_signals-vc110-mt-gd-1_53.dll		from '${Boost_INCLUDE_DIR}/stage/lib' to '${CMAKE_BINARY_DIR}/Debug'" VERBATIM
+	COMMENT "Copying boost_system-vc110-mt-gd-1_53.dll		from '${Boost_INCLUDE_DIR}/stage/lib' to '${CMAKE_BINARY_DIR}/Debug'" VERBATIM
+	COMMENT "Copying boost_signals-vc110-mt-1_53.dll		from '${Boost_INCLUDE_DIR}/stage/lib' to '${CMAKE_BINARY_DIR}/Debug'" VERBATIM
+)

File BoostPython/python/hello_ext.pyd

Binary file added.

File BoostPython/python/test.py

+import hello_ext
+print( hello_ext.greet() )

File BoostPython/src/main.cpp

+#include <iostream>
+#include <boost/python.hpp>
+
+char const* greet()
+{
+	return "hello world";
+}
+
+BOOST_PYTHON_MODULE(hello_ext)
+{
+	using namespace boost::python;
+	def("greet", greet);
+}