2011-06-20 02:54:56 +00:00
|
|
|
# - Find Python libraries
|
|
|
|
# Find the native Python includes and library
|
2011-06-18 15:53:47 +00:00
|
|
|
#
|
2011-06-20 02:54:56 +00:00
|
|
|
# Note:, This is not _yet_ intended to be a general python module for other
|
|
|
|
# projects to use since its hard coded to python 3.2 as blender only supports
|
|
|
|
# a single python version.
|
|
|
|
# This is for blender/unix python only.
|
|
|
|
#
|
|
|
|
# This module defines
|
2011-06-18 15:53:47 +00:00
|
|
|
# PYTHON_VERSION
|
|
|
|
# PYTHON_INCLUDE_DIRS
|
2011-06-19 06:57:56 +00:00
|
|
|
# PYTHON_LIBRARIES
|
2011-06-19 11:04:15 +00:00
|
|
|
# PYTHON_LIBPATH, Used for installation
|
2011-06-18 15:53:47 +00:00
|
|
|
# PYTHON_LINKFLAGS
|
|
|
|
# PYTHON_ROOT_DIR, The base directory to search for Python.
|
|
|
|
# This can also be an environment variable.
|
2011-06-20 02:54:56 +00:00
|
|
|
#
|
|
|
|
# also defined, but not for general use are
|
|
|
|
# PYTHON_LIBRARY, where to find the python library.
|
2011-06-18 15:53:47 +00:00
|
|
|
|
2011-06-20 02:54:56 +00:00
|
|
|
#=============================================================================
|
|
|
|
# Copyright 2011 Blender Foundation.
|
|
|
|
#
|
|
|
|
# Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
# see accompanying file Copyright.txt for details.
|
|
|
|
#
|
|
|
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# See the License for more information.
|
2011-06-18 15:53:47 +00:00
|
|
|
#=============================================================================
|
|
|
|
|
|
|
|
# If PYTHON_ROOT_DIR was defined in the environment, use it.
|
2011-06-20 02:54:56 +00:00
|
|
|
IF(NOT PYTHON_ROOT_DIR AND NOT $ENV{PYTHON_ROOT_DIR} STREQUAL "")
|
|
|
|
SET(PYTHON_ROOT_DIR $ENV{PYTHON_ROOT_DIR})
|
|
|
|
ENDIF()
|
2011-06-18 15:53:47 +00:00
|
|
|
|
2011-10-01 19:52:33 +00:00
|
|
|
SET(PYTHON_VERSION 3.2 CACHE STRING "Python Version (major and minor only)")
|
2011-06-20 02:54:56 +00:00
|
|
|
MARK_AS_ADVANCED(PYTHON_VERSION)
|
2011-06-18 15:53:47 +00:00
|
|
|
|
2011-10-01 19:52:33 +00:00
|
|
|
|
|
|
|
# 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")
|
2011-06-20 02:54:56 +00:00
|
|
|
MARK_AS_ADVANCED(PYTHON_LINKFLAGS)
|
2011-06-18 15:53:47 +00:00
|
|
|
|
2011-06-20 02:54:56 +00:00
|
|
|
|
2011-11-02 21:35:00 +00:00
|
|
|
# if the user passes these defines as args, we dont want to overwrite
|
|
|
|
SET(_IS_INC_DEF OFF)
|
|
|
|
SET(_IS_LIB_DEF OFF)
|
|
|
|
IF(DEFINED PYTHON_INCLUDE_DIR)
|
|
|
|
SET(_IS_INC_DEF ON)
|
|
|
|
ENDIF()
|
|
|
|
IF(DEFINED PYTHON_LIBRARY)
|
|
|
|
SET(_IS_LIB_DEF ON)
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
|
2011-10-01 19:52:33 +00:00
|
|
|
# only search for the dirs if we havn't already
|
2011-11-02 21:35:00 +00:00
|
|
|
IF((NOT _IS_INC_DEF) OR (NOT _IS_LIB_DEF))
|
2011-10-01 19:52:33 +00:00
|
|
|
|
|
|
|
SET(_python_ABI_FLAGS
|
|
|
|
"m;mu;u; " # release
|
|
|
|
"md;mud;ud;d" # debug
|
2011-06-20 02:54:56 +00:00
|
|
|
)
|
|
|
|
|
2011-10-01 19:52:33 +00:00
|
|
|
STRING(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
|
2011-06-20 02:54:56 +00:00
|
|
|
|
2011-10-01 19:52:33 +00:00
|
|
|
SET(_python_SEARCH_DIRS
|
|
|
|
${PYTHON_ROOT_DIR}
|
|
|
|
"$ENV{HOME}/py${_PYTHON_VERSION_NO_DOTS}"
|
|
|
|
"/opt/py${_PYTHON_VERSION_NO_DOTS}"
|
|
|
|
)
|
2011-06-20 02:54:56 +00:00
|
|
|
|
2011-10-01 19:52:33 +00:00
|
|
|
FOREACH(_CURRENT_ABI_FLAGS ${_python_ABI_FLAGS})
|
|
|
|
#IF(CMAKE_BUILD_TYPE STREQUAL Debug)
|
|
|
|
# SET(_CURRENT_ABI_FLAGS "d${_CURRENT_ABI_FLAGS}")
|
|
|
|
#ENDIF()
|
|
|
|
STRING(REPLACE " " "" _CURRENT_ABI_FLAGS ${_CURRENT_ABI_FLAGS})
|
|
|
|
|
2011-11-02 21:35:00 +00:00
|
|
|
IF(NOT DEFINED PYTHON_INCLUDE_DIR)
|
|
|
|
FIND_PATH(PYTHON_INCLUDE_DIR
|
|
|
|
NAMES
|
|
|
|
Python.h
|
|
|
|
HINTS
|
|
|
|
${_python_SEARCH_DIRS}
|
|
|
|
PATH_SUFFIXES
|
|
|
|
include/python${PYTHON_VERSION}${_CURRENT_ABI_FLAGS}
|
|
|
|
)
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
IF(NOT DEFINED PYTHON_LIBRARY)
|
|
|
|
FIND_LIBRARY(PYTHON_LIBRARY
|
|
|
|
NAMES
|
|
|
|
"python${PYTHON_VERSION}${_CURRENT_ABI_FLAGS}"
|
|
|
|
HINTS
|
|
|
|
${_python_SEARCH_DIRS}
|
|
|
|
PATH_SUFFIXES
|
|
|
|
lib64 lib
|
|
|
|
)
|
|
|
|
ENDIF()
|
2011-10-01 19:52:33 +00:00
|
|
|
|
|
|
|
IF(PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR)
|
|
|
|
break()
|
|
|
|
ELSE()
|
|
|
|
# ensure we dont find values from 2 different ABI versions
|
2011-11-02 21:35:00 +00:00
|
|
|
IF(NOT _IS_INC_DEF)
|
|
|
|
UNSET(PYTHON_INCLUDE_DIR CACHE)
|
|
|
|
ENDIF()
|
|
|
|
IF(NOT _IS_LIB_DEF)
|
|
|
|
UNSET(PYTHON_LIBRARY CACHE)
|
|
|
|
ENDIF()
|
2011-10-01 19:52:33 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDFOREACH()
|
|
|
|
|
|
|
|
UNSET(_CURRENT_ABI_FLAGS)
|
|
|
|
UNSET(_CURRENT_PATH)
|
|
|
|
|
|
|
|
UNSET(_python_ABI_FLAGS)
|
|
|
|
UNSET(_python_SEARCH_DIRS)
|
|
|
|
ENDIF()
|
2011-06-20 02:54:56 +00:00
|
|
|
|
2011-11-02 21:35:00 +00:00
|
|
|
UNSET(_IS_INC_DEF)
|
|
|
|
UNSET(_IS_LIB_DEF)
|
|
|
|
|
2011-06-20 02:54:56 +00:00
|
|
|
# handle the QUIETLY and REQUIRED arguments and SET PYTHONLIBSUNIX_FOUND to TRUE IF
|
2011-06-18 15:53:47 +00:00
|
|
|
# all listed variables are TRUE
|
2011-06-20 02:54:56 +00:00
|
|
|
INCLUDE(FindPackageHandleStandardArgs)
|
2011-06-18 15:53:47 +00:00
|
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibsUnix DEFAULT_MSG
|
2011-06-19 11:04:15 +00:00
|
|
|
PYTHON_LIBRARY PYTHON_INCLUDE_DIR)
|
2011-06-18 15:53:47 +00:00
|
|
|
|
|
|
|
|
2011-06-20 02:54:56 +00:00
|
|
|
IF(PYTHONLIBSUNIX_FOUND)
|
|
|
|
# Assign cache items
|
|
|
|
SET(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIR})
|
|
|
|
SET(PYTHON_LIBRARIES ${PYTHON_LIBRARY})
|
2011-06-19 11:04:15 +00:00
|
|
|
|
2011-06-20 02:54:56 +00:00
|
|
|
# we need this for installation
|
|
|
|
GET_FILENAME_COMPONENT(PYTHON_LIBPATH ${PYTHON_LIBRARY} PATH)
|
2011-06-19 11:04:15 +00:00
|
|
|
|
2011-06-20 02:54:56 +00:00
|
|
|
# not used
|
|
|
|
# SET(PYTHON_BINARY ${PYTHON_EXECUTABLE} CACHE STRING "")
|
|
|
|
ENDIF()
|
2011-11-16 16:38:37 +00:00
|
|
|
|
|
|
|
MARK_AS_ADVANCED(
|
|
|
|
PYTHON_INCLUDE_DIR
|
|
|
|
PYTHON_LIBRARY
|
|
|
|
)
|