Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2022-09-09 04:12:56 +0300
committerBrecht Van Lommel <brecht@blender.org>2022-09-10 14:47:48 +0300
commit2c23b4e0bff0ddd7219f4d23bcbe95d2da921fed (patch)
treef645ba1750f17ee387c8dc9f2ffd20cb59a245a5 /build_files/cmake
parent325eee2261b1c091ade52b08d7c8938168f80baf (diff)
Python: on macOS, stop requiring framework for building bpy module
Build against Python from precompiled libraries by default, instead of requiring framework from python.org package install. The resulting bpy module can still be used with any Python install of the same version. Use the same CMake find module as Linux. This simplifies code, and makes it possible to manually set PYTHON_* variables in CMake configuration. Remove WITH_PYTHON_FRAMEWORK option for regular Blender build, as this doesn't work well due to missing required Python packages. Advanced users can still set PYTHON_ROOT_DIR=/Library/Frameworks/Python.framework/Versions/3.10 for the same result.
Diffstat (limited to 'build_files/cmake')
-rw-r--r--build_files/cmake/Modules/FindPythonLibsUnix.cmake16
-rw-r--r--build_files/cmake/macros.cmake8
-rw-r--r--build_files/cmake/platform/platform_apple.cmake43
3 files changed, 21 insertions, 46 deletions
diff --git a/build_files/cmake/Modules/FindPythonLibsUnix.cmake b/build_files/cmake/Modules/FindPythonLibsUnix.cmake
index 1e88621303f..0afe1299330 100644
--- a/build_files/cmake/Modules/FindPythonLibsUnix.cmake
+++ b/build_files/cmake/Modules/FindPythonLibsUnix.cmake
@@ -34,11 +34,17 @@ SET(PYTHON_VERSION 3.10 CACHE STRING "Python Version (major and minor only)")
MARK_AS_ADVANCED(PYTHON_VERSION)
-# See: http://docs.python.org/extending/embedding.html#linking-requirements
-# for why this is needed
-SET(PYTHON_LINKFLAGS "-Xlinker -export-dynamic" CACHE STRING "Linker flags for python")
-MARK_AS_ADVANCED(PYTHON_LINKFLAGS)
-
+if(APPLE)
+ if(WITH_PYTHON_MODULE)
+ set(PYTHON_LINKFLAGS "-undefined dynamic_lookup")
+ else()
+ set(PYTHON_LINKFLAGS)
+ endif()
+else()
+ # See: http://docs.python.org/extending/embedding.html#linking-requirements
+ SET(PYTHON_LINKFLAGS "-Xlinker -export-dynamic" CACHE STRING "Linker flags for python")
+ MARK_AS_ADVANCED(PYTHON_LINKFLAGS)
+endif()
# if the user passes these defines as args, we don't want to overwrite
SET(_IS_INC_DEF OFF)
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index 5508e8f2104..d271d8f216f 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -1208,16 +1208,8 @@ endmacro()
macro(without_system_libs_begin)
set(CMAKE_IGNORE_PATH "${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES};${CMAKE_SYSTEM_INCLUDE_PATH};${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES};${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}")
- if(APPLE)
- # Avoid searching for headers in frameworks (like Mono), and libraries in LIBDIR.
- set(CMAKE_FIND_FRAMEWORK NEVER)
- endif()
endmacro()
macro(without_system_libs_end)
unset(CMAKE_IGNORE_PATH)
- if(APPLE)
- # FIRST is the default.
- set(CMAKE_FIND_FRAMEWORK FIRST)
- endif()
endmacro()
diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake
index bc5baf43530..e428b2abab3 100644
--- a/build_files/cmake/platform/platform_apple.cmake
+++ b/build_files/cmake/platform/platform_apple.cmake
@@ -36,6 +36,9 @@ endmacro()
# ------------------------------------------------------------------------
# Find system provided libraries.
+# Avoid searching for headers in frameworks (like Mono), and libraries in LIBDIR.
+set(CMAKE_FIND_FRAMEWORK NEVER)
+
# Find system ZLIB, not the pre-compiled one supplied with OpenCollada.
set(ZLIB_ROOT /usr)
find_package(ZLIB REQUIRED)
@@ -75,6 +78,11 @@ if(NOT EXISTS "${LIBDIR}/")
message(FATAL_ERROR "Mac OSX requires pre-compiled libs at: '${LIBDIR}'")
endif()
+# Optionally use system Python if PYTHON_ROOT_DIR is specified.
+if(WITH_PYTHON AND (WITH_PYTHON_MODULE AND PYTHON_ROOT_DIR))
+ find_package(PythonLibsUnix REQUIRED)
+endif()
+
# Prefer lib directory paths
file(GLOB LIB_SUBDIRS ${LIBDIR}/*)
set(CMAKE_PREFIX_PATH ${LIB_SUBDIRS})
@@ -123,34 +131,8 @@ if(WITH_CODEC_SNDFILE)
unset(_sndfile_VORBISENC_LIBRARY)
endif()
-if(WITH_PYTHON)
- # Use precompiled libraries by default.
- set(PYTHON_VERSION 3.10)
- if(NOT WITH_PYTHON_MODULE AND NOT WITH_PYTHON_FRAMEWORK)
- # Normally cached but not since we include them with blender.
- set(PYTHON_INCLUDE_DIR "${LIBDIR}/python/include/python${PYTHON_VERSION}")
- set(PYTHON_EXECUTABLE "${LIBDIR}/python/bin/python${PYTHON_VERSION}")
- set(PYTHON_LIBRARY ${LIBDIR}/python/lib/libpython${PYTHON_VERSION}.a)
- set(PYTHON_LIBPATH "${LIBDIR}/python/lib/python${PYTHON_VERSION}")
- else()
- # Module must be compiled against Python framework.
- set(_py_framework "/Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}")
- set(PYTHON_INCLUDE_DIR "${_py_framework}/include/python${PYTHON_VERSION}")
- set(PYTHON_EXECUTABLE "${_py_framework}/bin/python${PYTHON_VERSION}")
- set(PYTHON_LIBPATH "${_py_framework}/lib/python${PYTHON_VERSION}")
- unset(_py_framework)
- endif()
-
- # uncached vars
- set(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
- set(PYTHON_LIBRARIES "${PYTHON_LIBRARY}")
-
- # needed for Audaspace, numpy is installed into python site-packages
- set(PYTHON_NUMPY_INCLUDE_DIRS "${PYTHON_LIBPATH}/site-packages/numpy/core/include")
-
- if(NOT EXISTS "${PYTHON_EXECUTABLE}")
- message(FATAL_ERROR "Python executable missing: ${PYTHON_EXECUTABLE}")
- endif()
+if(WITH_PYTHON AND NOT (WITH_PYTHON_MODULE AND PYTHON_ROOT_DIR))
+ find_package(PythonLibsUnix REQUIRED)
endif()
if(WITH_FFTW3)
@@ -213,11 +195,6 @@ if(WITH_JACK)
string(APPEND PLATFORM_LINKFLAGS " -F/Library/Frameworks -weak_framework jackmp")
endif()
-if(WITH_PYTHON_MODULE OR WITH_PYTHON_FRAMEWORK)
- # force cmake to link right framework
- string(APPEND PLATFORM_LINKFLAGS " /Library/Frameworks/Python.framework/Versions/${PYTHON_VERSION}/Python")
-endif()
-
if(WITH_OPENCOLLADA)
find_package(OpenCOLLADA)
find_library(PCRE_LIBRARIES NAMES pcre HINTS ${LIBDIR}/opencollada/lib)