cmake: added FindOpenJPEG module.
[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_LINKFLAGS
7 #  PYTHON_ROOT_DIR, The base directory to search for Python.
8 #                   This can also be an environment variable.
9
10 #=============================================================================
11
12 # If PYTHON_ROOT_DIR was defined in the environment, use it.
13 if(NOT PYTHON_ROOT_DIR AND NOT $ENV{PYTHON_ROOT_DIR} STREQUAL "")
14         set(PYTHON_ROOT_DIR $ENV{PYTHON_ROOT_DIR})
15 endif()
16
17
18 set(PYTHON_VERSION 3.2 CACHE STRING "")
19 mark_as_advanced(PYTHON_VERSION)
20
21 set(PYTHON_LINKFLAGS "-Xlinker -export-dynamic")
22 mark_as_advanced(PYTHON_LINKFLAGS)
23
24 set(_python_ABI_FLAGS
25         "m;mu;u; ")
26
27 string(REPLACE "." "" _PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION})
28
29 set(_python_SEARCH_DIRS
30         ${PYTHON_ROOT_DIR}
31         "$ENV{HOME}/py${_PYTHON_VERSION_NO_DOTS}"
32         "/opt/py${_PYTHON_VERSION_NO_DOTS}"
33 )
34
35 foreach(_CURRENT_ABI_FLAGS ${_python_ABI_FLAGS})
36         if(CMAKE_BUILD_TYPE STREQUAL Debug)
37                 set(_CURRENT_ABI_FLAGS "d${_CURRENT_ABI_FLAGS}")
38         endif()
39         string(REPLACE " " "" _CURRENT_ABI_FLAGS ${_CURRENT_ABI_FLAGS})
40
41         find_path(PYTHON_INCLUDE_DIR
42                 NAMES Python.h
43                 HINTS ${_python_SEARCH_DIRS}
44                 PATH_SUFFIXES include/python${PYTHON_VERSION}${_CURRENT_ABI_FLAGS}
45         )
46
47         find_library(PYTHON_LIBRARIES
48                 NAMES "python${PYTHON_VERSION}${_CURRENT_ABI_FLAGS}"
49                 HINTS ${_python_SEARCH_DIRS}
50                 PATH_SUFFIXES lib64 lib
51         )
52
53         if((EXISTS ${PYTHON_LIBRARIES}) AND (EXISTS ${PYTHON_INCLUDE_DIR}))
54                 break()
55         else()
56                 # ensure we dont find values from 2 different ABI versions
57                 unset(PYTHON_INCLUDE_DIR CACHE)
58                 unset(PYTHON_LIBRARIES CACHE)
59         endif()
60 endforeach()
61
62 unset(_CURRENT_ABI_FLAGS)
63 unset(_CURRENT_PATH)
64
65 unset(_python_ABI_FLAGS)
66 unset(_python_SEARCH_DIRS)
67
68 # handle the QUIETLY and REQUIRED arguments and set PYTHONLIBSUNIX_FOUND to TRUE if 
69 # all listed variables are TRUE
70 include(FindPackageHandleStandardArgs)
71 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibsUnix  DEFAULT_MSG
72     PYTHON_LIBRARIES PYTHON_INCLUDE_DIR)
73
74
75 if(PYTHONLIBSUNIX_FOUND)
76         # Assign cache items
77         set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIR} CACHE STRING "")
78         set(PYTHON_LIBRARIES ${PYTHON_LIBRARIES} CACHE STRING "")
79         # not used
80         # set(PYTHON_BINARY ${PYTHON_EXECUTABLE} CACHE STRING "")
81
82         mark_as_advanced(
83                 PYTHON_INCLUDE_DIRS
84                 PYTHON_INCLUDE_DIR
85                 PYTHON_LIBRARIES
86         )
87 endif()