add back PYTHON_LIBPATH, needed for installing on python
[blender.git] / build_files / cmake / Modules / FindPythonLibsUnix.cmake
1 # - Find python libraries
2 #
3 #  PYTHON_VERSION
4 #  PYTHON_INCLUDE_DIRS
5 #  PYTHON_LIBRARIES
6 #  PYTHON_LIBPATH, Used for installation
7 #  PYTHON_LINKFLAGS
8 #  PYTHON_ROOT_DIR, The base directory to search for Python.
9 #                   This can also be an environment variable.
10
11 #=============================================================================
12
13 # If PYTHON_ROOT_DIR was defined in the environment, use it.
14 if(NOT PYTHON_ROOT_DIR AND NOT $ENV{PYTHON_ROOT_DIR} STREQUAL "")
15         set(PYTHON_ROOT_DIR $ENV{PYTHON_ROOT_DIR})
16 endif()
17
18
19 set(PYTHON_VERSION 3.2 CACHE STRING "")
20 mark_as_advanced(PYTHON_VERSION)
21
22 set(PYTHON_LINKFLAGS "-Xlinker -export-dynamic")
23 mark_as_advanced(PYTHON_LINKFLAGS)
24
25 set(_python_ABI_FLAGS
26         "m;mu;u; "  # release
27         "md;mud;ud" # debug
28 )
29
30 string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
31
32 set(_python_SEARCH_DIRS
33         ${PYTHON_ROOT_DIR}
34         "$ENV{HOME}/py${_PYTHON_VERSION_NO_DOTS}"
35         "/opt/py${_PYTHON_VERSION_NO_DOTS}"
36 )
37
38 foreach(_CURRENT_ABI_FLAGS ${_python_ABI_FLAGS})
39         #if(CMAKE_BUILD_TYPE STREQUAL Debug)
40         #       set(_CURRENT_ABI_FLAGS "d${_CURRENT_ABI_FLAGS}")
41         #endif()
42         string(REPLACE " " "" _CURRENT_ABI_FLAGS ${_CURRENT_ABI_FLAGS})
43
44         find_path(PYTHON_INCLUDE_DIR
45                 NAMES Python.h
46                 HINTS ${_python_SEARCH_DIRS}
47                 PATH_SUFFIXES include/python${PYTHON_VERSION}${_CURRENT_ABI_FLAGS}
48         )
49
50         find_library(PYTHON_LIBRARY
51                 NAMES "python${PYTHON_VERSION}${_CURRENT_ABI_FLAGS}"
52                 HINTS ${_python_SEARCH_DIRS}
53                 PATH_SUFFIXES lib64 lib
54         )
55
56         if(PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR)
57                 break()
58         else()
59                 # ensure we dont find values from 2 different ABI versions
60                 unset(PYTHON_INCLUDE_DIR CACHE)
61                 unset(PYTHON_LIBRARY CACHE)
62         endif()
63 endforeach()
64
65 unset(_CURRENT_ABI_FLAGS)
66 unset(_CURRENT_PATH)
67
68 unset(_python_ABI_FLAGS)
69 unset(_python_SEARCH_DIRS)
70
71 # handle the QUIETLY and REQUIRED arguments and set PYTHONLIBSUNIX_FOUND to TRUE if 
72 # all listed variables are TRUE
73 include(FindPackageHandleStandardArgs)
74 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibsUnix  DEFAULT_MSG
75     PYTHON_LIBRARY PYTHON_INCLUDE_DIR)
76
77
78 if(PYTHONLIBSUNIX_FOUND)
79         # Assign cache items
80         set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIR} CACHE STRING "")
81         set(PYTHON_LIBRARIES ${PYTHON_LIBRARY} CACHE STRING "")
82
83         # we need this for installation
84         get_filename_component(PYTHON_LIBPATH ${PYTHON_LIBRARY} PATH)
85
86         # not used
87         # set(PYTHON_BINARY ${PYTHON_EXECUTABLE} CACHE STRING "")
88
89         mark_as_advanced(
90                 PYTHON_INCLUDE_DIRS
91                 PYTHON_INCLUDE_DIR
92                 PYTHON_LIBRARIES
93                 PYTHON_LIBRARY
94                 PYTHON_LIBPATH
95         )
96 endif()