Salome HOME
Fixed compilation problem with gcc 4.4.5
[tools/libbatch.git] / CMakeModules / FindPython.cmake
1 #  Copyright (C) 2007-2010  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     IF(MSVC AND NOT CMAKE_BUILD_TYPE STREQUAL Release)
39         MESSAGE(STATUS "Warning! Python debug executable not found. To build Swig module, you will need to install it or compile in Release mode")
40     ELSE(MSVC AND NOT CMAKE_BUILD_TYPE STREQUAL Release)
41         FIND_PROGRAM(PYTHON_EXECUTABLE python DOC "Python interpreter")
42     ENDIF(MSVC AND NOT CMAKE_BUILD_TYPE STREQUAL Release)
43 ENDIF (PYTHON_DEBUG)
44
45 IF (PYTHON_EXECUTABLE)
46   EXECUTE_PROCESS(
47     COMMAND ${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write(sys.version[:3])"
48     OUTPUT_VARIABLE PYTHON_VERSION
49   )
50
51   SET(PYTHON_ROOT ${PYTHON_EXECUTABLE})
52   GET_FILENAME_COMPONENT(PYTHON_ROOT ${PYTHON_ROOT} PATH)
53   GET_FILENAME_COMPONENT(PYTHON_ROOT ${PYTHON_ROOT} PATH)
54
55   FIND_PATH(PYTHON_INCLUDE_PATH Python.h
56                                 PATHS ${PYTHON_ROOT}/include ${PYTHON_ROOT}/include/python${PYTHON_VERSION}
57                                 DOC "Python include path")
58
59   IF(WIN32)
60     STRING(REPLACE "." "" PYTHON_VERSION_WITHOUT_DOT ${PYTHON_VERSION})
61     IF(PYTHON_DEBUG)
62       FIND_LIBRARY(PYTHON_LIBRARIES python${PYTHON_VERSION_WITHOUT_DOT}_d ${PYTHON_ROOT}/libs DOC "Python libraries")
63     ELSE(PYTHON_DEBUG)
64       FIND_LIBRARY(PYTHON_LIBRARIES python${PYTHON_VERSION_WITHOUT_DOT} ${PYTHON_ROOT}/libs DOC "Python libraries")
65     ENDIF(PYTHON_DEBUG)
66   ELSE(WIN32)
67     FIND_LIBRARY(PYTHON_LIBRARIES python${PYTHON_VERSION} ${PYTHON_ROOT}/lib DOC "Python libraries")
68   ENDIF(WIN32)
69
70   SET(PYTHON_INCLUDES -I${PYTHON_INCLUDE_PATH})
71   SET(PYTHON_LIBS ${PYTHON_LIBRARIES})
72
73   IF(PYTHON_DEBUG)
74       SET(PYTHON_INCLUDES ${PYTHON_INCLUDES} -DHAVE_DEBUG_PYTHON)
75   ENDIF(PYTHON_DEBUG)
76 ENDIF (PYTHON_EXECUTABLE)
77
78 IF(PYTHON_EXECUTABLE AND PYTHON_LIBRARIES AND PYTHON_INCLUDE_PATH)
79   SET(Python_FOUND True)
80 ENDIF(PYTHON_EXECUTABLE AND PYTHON_LIBRARIES AND PYTHON_INCLUDE_PATH)
81
82 IF (Python_FOUND)
83
84     IF (NOT Python_FIND_QUIETLY)
85         MESSAGE(STATUS "Found Python:")
86         MESSAGE(STATUS "Python executable: ${PYTHON_EXECUTABLE} (version ${PYTHON_VERSION})")
87         MESSAGE(STATUS "Python include directory: ${PYTHON_INCLUDE_PATH}")
88         MESSAGE(STATUS "Python library: ${PYTHON_LIBRARIES}")
89     ENDIF (NOT Python_FIND_QUIETLY)
90
91 ELSE (Python_FOUND)
92
93     IF (Python_FIND_REQUIRED)
94         MESSAGE(FATAL_ERROR "Python not found")
95     ELSE (Python_FIND_REQUIRED)
96         IF (NOT Python_FIND_QUIETLY)
97             MESSAGE(STATUS "Python not found")
98         ENDIF (NOT Python_FIND_QUIETLY)
99     ENDIF (Python_FIND_REQUIRED)
100
101 ENDIF (Python_FOUND)