handle SpaceType and UserPref popups
[blender-staging.git] / build_files / cmake / FindPythonLibsUnix.cmake
1 # - Find python libraries
2 #
3 #  PYTHON_VERSION
4 #  PYTHON_INCLUDE_DIRS
5 #  PYTHON_LIBRARY
6 #  PYTHON_LIBPATH
7 #  PYTHON_LINKFLAGS
8
9 #=============================================================================
10
11 set(PYTHON_VERSION 3.2 CACHE STRING "")
12 mark_as_advanced(PYTHON_VERSION)
13
14 set(PYTHON_LINKFLAGS "-Xlinker -export-dynamic")
15 mark_as_advanced(PYTHON_LINKFLAGS)
16
17 set(_Python_ABI_FLAGS
18         "m;mu;u; ")
19
20 string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
21 set(_Python_PATHS
22   "$ENV{HOME}/py${_PYTHON_VERSION_NO_DOTS}" "/opt/py${_PYTHON_VERSION_NO_DOTS}" "/usr" "/usr/local")
23
24 if(NOT DEFINED PYTHON_INCLUDE_DIRS)
25         message(STATUS "Looking for include Python.h")
26         set(_Found_PYTHON_H OFF)
27
28         foreach(_CURRENT_PATH ${_Python_PATHS})
29                 foreach(_CURRENT_ABI_FLAGS ${_Python_ABI_FLAGS})
30                         if(CMAKE_BUILD_TYPE STREQUAL Debug)
31                                 set(_CURRENT_ABI_FLAGS "d${_CURRENT_ABI_FLAGS}")
32                         endif()
33                         string(REPLACE " " "" _CURRENT_ABI_FLAGS ${_CURRENT_ABI_FLAGS})
34
35                         set(_Python_HEADER "${_CURRENT_PATH}/include/python${PYTHON_VERSION}${_CURRENT_ABI_FLAGS}/Python.h")
36
37                         if(EXISTS ${_Python_HEADER})
38                                 message(STATUS "Checking for header: ${_Python_HEADER} - found")
39                                 set(_Found_PYTHON_H ON)
40                                 set(PYTHON ${_CURRENT_PATH})
41                                 set(PYTHON_ABI_FLAGS ${_CURRENT_ABI_FLAGS})
42                                 break()
43                         else()
44                                 message(STATUS "Checking for header: ${_Python_HEADER}")
45                         endif()
46                 endforeach()
47                 
48                 if(_Found_PYTHON_H)
49                         break()
50                 endif()
51         endforeach()
52
53         if(NOT _Found_PYTHON_H)
54                 message(FATAL_ERROR "Python.h not found")
55         endif()
56         
57         unset(_Found_PYTHON_H)
58         unset(_Python_HEADER)
59         unset(_CURRENT_ABI_FLAGS)
60         unset(_CURRENT_PATH)
61         
62 endif()
63
64 unset(_Python_ABI_FLAGS)
65 unset(_Python_PATHS)
66
67 #=============================================================================
68 # now the python versions are found
69
70
71 set(PYTHON_INCLUDE_DIRS "${PYTHON}/include/python${PYTHON_VERSION}${PYTHON_ABI_FLAGS}" CACHE STRING "")
72 mark_as_advanced(PYTHON_INCLUDE_DIRS)
73 set(PYTHON_LIBRARY "python${PYTHON_VERSION}${PYTHON_ABI_FLAGS}" CACHE STRING "")
74 mark_as_advanced(PYTHON_LIBRARY)
75 set(PYTHON_LIBPATH ${PYTHON}/lib CACHE STRING "")
76 mark_as_advanced(PYTHON_LIBPATH)
77 # set(PYTHON_BINARY ${PYTHON_EXECUTABLE} CACHE STRING "")
78
79 if(NOT EXISTS "${PYTHON_INCLUDE_DIRS}/Python.h")
80         message(FATAL_ERROR " Missing python header: ${PYTHON_INCLUDE_DIRS}/Python.h")
81 endif()