Updating buildsystem files to closest as possible to file-sync plugin.
[gdataplugin.git] / cmake / modules / FindPythonLibs.cmake
blob517fd83afcf0bb2ce4dfbcf7fbb6a8a703148df6
1 # - Find python libraries
2 # This module finds if Python is installed and determines where the
3 # include files and libraries are. It also determines what the name of
4 # the library is. This code sets the following variables:
6 #  PYTHON_LIBRARIES     = path to the python library
7 #  PYTHON_INCLUDE_PATH  = path to where Python.h is found
8 #  PYTHON_DEBUG_LIBRARIES = path to the debug library
9 #  PYTHON_VERSION = version of python library
11 #  The user can set this variable to choose their preferred python 
12 #  version to be found:
14 #  PREFERRED_PYTHON_VERSION = preferred version of the python library 
16 INCLUDE(CMakeFindFrameworks)
18 IF(WIN32)
19   FIND_LIBRARY(PYTHON_DEBUG_LIBRARY
20     NAMES python25_d python24_d python23_d python22_d python21_d python20_d python
21     PATHS
22     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.5\\InstallPath]/libs/Debug
23     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.5\\InstallPath]/libs
24     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath]/libs/Debug
25     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath]/libs
26     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath]/libs/Debug
27     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath]/libs
28     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath]/libs/Debug
29     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath]/libs
30     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]/libs/Debug
31     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]/libs
32     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]/libs/Debug
33     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]/libs
34     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath]/libs/Debug
35     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath]/libs
36     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath]/libs/Debug
37     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath]/libs
38   )
39 ENDIF(WIN32)
41 FIND_LIBRARY(PYTHON_LIBRARY ${PREFERRED_PYTHON_VERSION}
42   NAMES python25 python2.5
43         python24 python2.4
44         python23 python2.3
45         python22 python2.2
46         python21 python2.1
47         python20 python2.0
48         python16 python1.6
49         python15 python1.5
51   PATHS
52     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.5\\InstallPath]/libs
53     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath]/libs
54     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath]/libs
55     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath]/libs
56     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]/libs
57     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]/libs
58     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath]/libs
59     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath]/libs
61   PATH_SUFFIXES
62     python2.5/config
63     python2.4/config
64     python2.3/config
65     python2.2/config
66     python2.1/config
67     python2.0/config
68     python1.6/config
69     python1.5/config
71 IF(PYTHON_LIBRARY)
72 message(STATUS "Found Python: ${PYTHON_LIBRARY}")
73 ENDIF(PYTHON_LIBRARY)
75 # Search for the python framework on Apple.
76 CMAKE_FIND_FRAMEWORKS(Python)
77 SET(PYTHON_FRAMEWORK_INCLUDES)
78 IF(Python_FRAMEWORKS)
79   IF(NOT PYTHON_INCLUDE_PATH)
80     FOREACH(version 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
81       FOREACH(dir ${Python_FRAMEWORKS})
82         SET(PYTHON_FRAMEWORK_INCLUDES ${PYTHON_FRAMEWORK_INCLUDES}
83           ${dir}/Versions/${version}/include/python${version})
84       ENDFOREACH(dir)
85     ENDFOREACH(version)
86   ENDIF(NOT PYTHON_INCLUDE_PATH)
87 ENDIF(Python_FRAMEWORKS)
89 FIND_PATH(PYTHON_INCLUDE_PATH
90   NAMES Python.h
92   PATHS
93     ${PYTHON_FRAMEWORK_INCLUDES}
94     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.5\\InstallPath]/include
95     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath]/include
96     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath]/include
97     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath]/include
98     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]/include
99     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]/include
100     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath]/include
101     [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath]/include
103   PATH_SUFFIXES
104     ${PREFERRED_PYTHON_VERSION}
105     python2.5
106     python2.4
107     python2.3
108     python2.2
109     python2.1
110     python2.0
111     python1.6
112     python1.5
115 IF (WIN32)
116   MARK_AS_ADVANCED(
117     PYTHON_DEBUG_LIBRARY
118     PYTHON_LIBRARY
119     PYTHON_INCLUDE_PATH
120   )
121 ENDIF(WIN32)
124 FIND_PROGRAM( PYTHON_EXECUTABLE NAMES ${PREFERRED_PYTHON_VERSION} python )
126 IF ( PYTHON_EXECUTABLE )
127         EXEC_PROGRAM( ${PYTHON_EXECUTABLE} ARGS "-c \"import sys; print sys.version[:3]\"" OUTPUT_VARIABLE PYTHON_VERSION )
128         STRING( REGEX REPLACE "[\r\n]" " " PYTHON_VERSION "${PYTHON_VERSION}"  )
129 ENDIF ( PYTHON_EXECUTABLE )
131 # Python Should be built and installed as a Framework on OSX
132 IF(Python_FRAMEWORKS)
133   # If a framework has been selected for the include path,
134   # make sure "-framework" is used to link it.
135   IF("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework")
136     SET(PYTHON_LIBRARY "")
137     SET(PYTHON_DEBUG_LIBRARY "")
138   ENDIF("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework")
139   IF(NOT PYTHON_LIBRARY)
140     SET (PYTHON_LIBRARY "-framework Python" CACHE FILEPATH "Python Framework" FORCE)
141   ENDIF(NOT PYTHON_LIBRARY)
142   IF(NOT PYTHON_DEBUG_LIBRARY)
143     SET (PYTHON_DEBUG_LIBRARY "-framework Python" CACHE FILEPATH "Python Framework" FORCE)
144   ENDIF(NOT PYTHON_DEBUG_LIBRARY)
145 ENDIF(Python_FRAMEWORKS)
147 # We use PYTHON_LIBRARY and PYTHON_DEBUG_LIBRARY for the cache entries
148 # because they are meant to specify the location of a single library.
149 # We now set the variables listed by the documentation for this
150 # module.
151 SET(PYTHON_LIBRARIES "${PYTHON_LIBRARY}")
152 SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")