]> SALOME platform Git repositories - tools/libbatch.git/blob - CMakeModules/FindPython.cmake
Salome HOME
Fixed errors in CMake FindXXX modules. Fixed Windows compilation errors.
[tools/libbatch.git] / CMakeModules / FindPython.cmake
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22
23 # We use a custom FindPYTHON.cmake because the one shipped with cmake doesn't search
24 # properly for the version number.
25
26 IF (NOT Python_FIND_QUIETLY)
27     MESSAGE(STATUS "Looking for Python...")
28 ENDIF (NOT Python_FIND_QUIETLY)
29
30 IF(WIN32 AND NOT CMAKE_BUILD_TYPE STREQUAL Release)
31     FIND_PROGRAM(PYTHON_DEBUG python_d)
32     mark_as_advanced(PYTHON_DEBUG)
33 ENDIF(WIN32 AND NOT CMAKE_BUILD_TYPE STREQUAL Release)
34
35 IF (PYTHON_DEBUG)
36     SET(PYTHON_EXECUTABLE ${PYTHON_DEBUG} CACHE STRING "Python interpreter")
37 ELSE (PYTHON_DEBUG)
38     FIND_PROGRAM(PYTHON_EXECUTABLE python DOC "Python interpreter")
39 ENDIF (PYTHON_DEBUG)
40
41 IF (PYTHON_EXECUTABLE)
42   EXECUTE_PROCESS(
43     COMMAND ${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write(sys.version[:3])"
44     OUTPUT_VARIABLE PYTHON_VERSION
45   )
46
47   SET(PYTHON_ROOT ${PYTHON_EXECUTABLE})
48   GET_FILENAME_COMPONENT(PYTHON_ROOT ${PYTHON_ROOT} PATH)
49   GET_FILENAME_COMPONENT(PYTHON_ROOT ${PYTHON_ROOT} PATH)
50
51   FIND_PATH(PYTHON_INCLUDE_PATH Python.h
52                                 PATHS ${PYTHON_ROOT}/include ${PYTHON_ROOT}/include/python${PYTHON_VERSION}
53                                 DOC "Python include path")
54
55   IF(WIN32)
56     STRING(REPLACE "." "" PYTHON_VERSION_WITHOUT_DOT ${PYTHON_VERSION})
57     IF(PYTHON_DEBUG)
58       FIND_LIBRARY(PYTHON_LIBRARIES python${PYTHON_VERSION_WITHOUT_DOT}_d ${PYTHON_ROOT}/libs DOC "Python libraries")
59     ELSE(PYTHON_DEBUG)
60       FIND_LIBRARY(PYTHON_LIBRARIES python${PYTHON_VERSION_WITHOUT_DOT} ${PYTHON_ROOT}/libs DOC "Python libraries")
61     ENDIF(PYTHON_DEBUG)
62   ELSE(WIN32)
63     FIND_LIBRARY(PYTHON_LIBRARIES python${PYTHON_VERSION} ${PYTHON_ROOT}/lib DOC "Python libraries")
64   ENDIF(WIN32)
65
66   SET(PYTHON_INCLUDES -I${PYTHON_INCLUDE_PATH})
67   SET(PYTHON_LIBS ${PYTHON_LIBRARIES})
68
69   IF(PYTHON_DEBUG)
70       SET(PYTHON_INCLUDES ${PYTHON_INCLUDES} -DHAVE_DEBUG_PYTHON)
71   ENDIF(PYTHON_DEBUG)
72 ENDIF (PYTHON_EXECUTABLE)
73
74 IF(PYTHON_EXECUTABLE AND PYTHON_LIBRARIES AND PYTHON_INCLUDE_PATH)
75   SET(Python_FOUND True)
76 ENDIF(PYTHON_EXECUTABLE AND PYTHON_LIBRARIES AND PYTHON_INCLUDE_PATH)
77
78 IF (Python_FOUND)
79
80     IF (NOT Python_FIND_QUIETLY)
81         MESSAGE(STATUS "Found Python: ${PYTHON_EXECUTABLE} (version ${PYTHON_VERSION})")
82     ENDIF (NOT Python_FIND_QUIETLY)
83
84 ELSE (Python_FOUND)
85
86     IF (Python_FIND_REQUIRED)
87         MESSAGE(FATAL_ERROR "Python not found")
88     ELSE (Python_FIND_REQUIRED)
89         IF (NOT Python_FIND_QUIETLY)
90             MESSAGE(STATUS "Python not found")
91         ENDIF (NOT Python_FIND_QUIETLY)
92     ENDIF (Python_FIND_REQUIRED)
93
94 ENDIF (Python_FOUND)