[Bf-blender-cvs] [4560570] master: Fix for building blender as a Python module

Campbell Barton noreply at git.blender.org
Tue Mar 24 07:06:23 CET 2015


Commit: 4560570f8ac91b7ce349c8c1079caaf1f21848bf
Author: Campbell Barton
Date:   Tue Mar 24 17:02:34 2015 +1100
Branches: master
https://developer.blender.org/rB4560570f8ac91b7ce349c8c1079caaf1f21848bf

Fix for building blender as a Python module

Installation didn't work on debian distro's
now install into PYTHON_SITE_PACKAGES (which is detected and can be configured).

===================================================================

M	CMakeLists.txt
M	build_files/cmake/Modules/FindPythonLibsUnix.cmake
M	source/creator/CMakeLists.txt

===================================================================

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21efa66..100d00b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -201,7 +201,7 @@ set(WITH_PYTHON_SECURITY ON CACHE BOOL "ON" FORCE) # temp force on.
 
 option(WITH_PYTHON_SAFETY "Enable internal API error checking to track invalid data to prevent crash on access (at the expense of some effeciency, only enable for development)." OFF)
 mark_as_advanced(WITH_PYTHON_SAFETY)
-option(WITH_PYTHON_MODULE "Enable building as a python module which runs without a user interface, like running regular blender in background mode (experimental, only enable for development)" OFF)
+option(WITH_PYTHON_MODULE "Enable building as a python module which runs without a user interface, like running regular blender in background mode (experimental, only enable for development), installs to PYTHON_SITE_PACKAGES" OFF)
 if(APPLE)
 	option(WITH_PYTHON_FRAMEWORK "Enable building using the Python available in the framework (OSX only)" OFF)
 endif()
@@ -617,6 +617,8 @@ endif()
 # may as well build python module without a UI
 if(WITH_PYTHON_MODULE)
 	set(WITH_HEADLESS ON)
+	# building as a Python module wont use /usr/shared
+	set(WITH_INSTALL_PORTABLE ON)
 endif()
 
 if(NOT WITH_PYTHON)
diff --git a/build_files/cmake/Modules/FindPythonLibsUnix.cmake b/build_files/cmake/Modules/FindPythonLibsUnix.cmake
index 1fb27e7..555ca4c 100644
--- a/build_files/cmake/Modules/FindPythonLibsUnix.cmake
+++ b/build_files/cmake/Modules/FindPythonLibsUnix.cmake
@@ -14,6 +14,7 @@
 #  PYTHON_INCLUDE_CONFIG_DIRS
 #  PYTHON_LIBRARIES
 #  PYTHON_LIBPATH, Used for installation
+#  PYTHON_SITE_PACKAGES, Used for installation (as a Python module)
 #  PYTHON_LINKFLAGS
 #  PYTHON_ROOT_DIR, The base directory to search for Python.
 #                   This can also be an environment variable.
@@ -187,6 +188,15 @@ IF(PYTHONLIBSUNIX_FOUND)
   SET(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIR} ${PYTHON_INCLUDE_CONFIG_DIR})
   SET(PYTHON_LIBRARIES ${PYTHON_LIBRARY})
 
+  FIND_FILE(PYTHON_SITE_PACKAGES
+    NAMES
+      # debian specific
+      dist-packages
+      site-packages
+    HINTS
+      ${PYTHON_LIBPATH}/python${PYTHON_VERSION}
+  )
+
   # we need this for installation
   # XXX No more valid with debian-like py3.4 packages...
 #  GET_FILENAME_COMPONENT(PYTHON_LIBPATH ${PYTHON_LIBRARY} PATH)
@@ -200,4 +210,5 @@ MARK_AS_ADVANCED(
   PYTHON_INCLUDE_CONFIG_DIR
   PYTHON_LIBRARY
   PYTHON_LIBPATH
+  PYTHON_SITE_PACKAGES
 )
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt
index 1557cc0..b9044e6 100644
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -261,11 +261,11 @@ endif()
 # Platform Specific Var: TARGETDIR_VER
 
 if(UNIX AND NOT APPLE)
-	if(WITH_INSTALL_PORTABLE)
-		set(TARGETDIR_VER ${BLENDER_VERSION})
+	if(WITH_PYTHON_MODULE)
+		set(TARGETDIR_VER ${PYTHON_SITE_PACKAGES}/${BLENDER_VERSION})
 	else()
-		if(WITH_PYTHON_MODULE)
-			set(TARGETDIR_VER ${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages/${BLENDER_VERSION})
+		if(WITH_INSTALL_PORTABLE)
+			set(TARGETDIR_VER ${BLENDER_VERSION})
 		else()
 			set(TARGETDIR_VER share/blender/${BLENDER_VERSION})
 		endif()
@@ -407,22 +407,24 @@ if(UNIX AND NOT APPLE)
 	endif()
 
 	# there are a few differences between portable and system install
-	if(WITH_INSTALL_PORTABLE)
-		if(WITH_PYTHON_MODULE)
-			# pass
-		else()
-			if(WITH_DOC_MANPAGE)
-				install(
-					FILES ${CMAKE_CURRENT_BINARY_DIR}/blender.1
-					DESTINATION "."
-				)
-			endif()
-		endif()
+	if(WITH_PYTHON_MODULE)
+		install(
+			TARGETS blender
+			LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES}
+		)
+		# none of the other files are needed currently
+	elseif(WITH_INSTALL_PORTABLE)
 		install(
 			TARGETS blender
 			DESTINATION "."
 		)
 
+		if(WITH_DOC_MANPAGE)
+			install(
+				FILES ${CMAKE_CURRENT_BINARY_DIR}/blender.1
+				DESTINATION "."
+			)
+		endif()
 		install(
 			FILES
 				${CMAKE_SOURCE_DIR}/release/freedesktop/blender.desktop
@@ -437,26 +439,18 @@ if(UNIX AND NOT APPLE)
 		)
 
 		set(BLENDER_TEXT_FILES_DESTINATION ".")
-
 	else()
 		# main blender binary
-		if(WITH_PYTHON_MODULE)
-			install(
-				TARGETS blender
-				LIBRARY	DESTINATION ${PYTHON_LIBPATH}/python${PYTHON_VERSION}/site-packages
-			)
-		else()
+		install(
+			TARGETS blender
+			DESTINATION bin
+		)
+		if(WITH_DOC_MANPAGE)
+			# manpage only with 'blender' binary
 			install(
-				TARGETS blender
-				DESTINATION bin
+				FILES ${CMAKE_CURRENT_BINARY_DIR}/blender.1
+				DESTINATION share/man/man1
 			)
-			if(WITH_DOC_MANPAGE)
-				# manpage only with 'blender' binary
-				install(
-					FILES ${CMAKE_CURRENT_BINARY_DIR}/blender.1
-					DESTINATION share/man/man1
-				)
-			endif()
 		endif()
 
 		# misc files




More information about the Bf-blender-cvs mailing list