1 # - Find Python libraries
2 # Find the native Python includes and library
4 # Note:, This is not _yet_ intended to be a general python module for other
5 # projects to use since its hard coded to python 3.2 as blender only supports
6 # a single python version.
7 # This is for blender/unix python only.
13 # PYTHON_LIBPATH, Used for installation
15 # PYTHON_ROOT_DIR, The base directory to search for Python.
16 # This can also be an environment variable.
18 # also defined, but not for general use are
19 # PYTHON_LIBRARY, where to find the python library.
21 #=============================================================================
22 # Copyright 2011 Blender Foundation.
24 # Distributed under the OSI-approved BSD License (the "License");
25 # see accompanying file Copyright.txt for details.
27 # This software is distributed WITHOUT ANY WARRANTY; without even the
28 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
29 # See the License for more information.
30 #=============================================================================
32 # If PYTHON_ROOT_DIR was defined in the environment, use it.
33 IF(NOT PYTHON_ROOT_DIR AND NOT $ENV{PYTHON_ROOT_DIR} STREQUAL "")
34 SET(PYTHON_ROOT_DIR $ENV{PYTHON_ROOT_DIR})
37 SET(PYTHON_VERSION 3.2 CACHE STRING "Python Version (major and minor only)")
38 MARK_AS_ADVANCED(PYTHON_VERSION)
41 # See: http://docs.python.org/extending/embedding.html#linking-requirements
42 # for why this is needed
43 SET(PYTHON_LINKFLAGS "-Xlinker -export-dynamic" CACHE STRING "Linker flags for python")
44 MARK_AS_ADVANCED(PYTHON_LINKFLAGS)
47 # if the user passes these defines as args, we dont want to overwrite
50 IF(DEFINED PYTHON_INCLUDE_DIR)
53 IF(DEFINED PYTHON_LIBRARY)
58 # only search for the dirs if we havn't already
59 IF((NOT _IS_INC_DEF) OR (NOT _IS_LIB_DEF))
66 STRING(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
68 SET(_python_SEARCH_DIRS
70 "$ENV{HOME}/py${_PYTHON_VERSION_NO_DOTS}"
71 "/opt/py${_PYTHON_VERSION_NO_DOTS}"
74 FOREACH(_CURRENT_ABI_FLAGS ${_python_ABI_FLAGS})
75 #IF(CMAKE_BUILD_TYPE STREQUAL Debug)
76 # SET(_CURRENT_ABI_FLAGS "d${_CURRENT_ABI_FLAGS}")
78 STRING(REPLACE " " "" _CURRENT_ABI_FLAGS ${_CURRENT_ABI_FLAGS})
80 IF(NOT DEFINED PYTHON_INCLUDE_DIR)
81 FIND_PATH(PYTHON_INCLUDE_DIR
85 ${_python_SEARCH_DIRS}
87 include/python${PYTHON_VERSION}${_CURRENT_ABI_FLAGS}
91 IF(NOT DEFINED PYTHON_LIBRARY)
92 FIND_LIBRARY(PYTHON_LIBRARY
94 "python${PYTHON_VERSION}${_CURRENT_ABI_FLAGS}"
96 ${_python_SEARCH_DIRS}
102 IF(PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR)
105 # ensure we dont find values from 2 different ABI versions
107 UNSET(PYTHON_INCLUDE_DIR CACHE)
110 UNSET(PYTHON_LIBRARY CACHE)
115 UNSET(_CURRENT_ABI_FLAGS)
118 UNSET(_python_ABI_FLAGS)
119 UNSET(_python_SEARCH_DIRS)
125 # handle the QUIETLY and REQUIRED arguments and SET PYTHONLIBSUNIX_FOUND to TRUE IF
126 # all listed variables are TRUE
127 INCLUDE(FindPackageHandleStandardArgs)
128 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibsUnix DEFAULT_MSG
129 PYTHON_LIBRARY PYTHON_INCLUDE_DIR)
132 IF(PYTHONLIBSUNIX_FOUND)
134 SET(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIR})
135 SET(PYTHON_LIBRARIES ${PYTHON_LIBRARY})
137 # we need this for installation
138 GET_FILENAME_COMPONENT(PYTHON_LIBPATH ${PYTHON_LIBRARY} PATH)
141 # SET(PYTHON_BINARY ${PYTHON_EXECUTABLE} CACHE STRING "")