1 # Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # We use a custom FindPYTHON.cmake because the one shipped with cmake doesn't search
24 # properly for the version number.
26 IF (NOT Python_FIND_QUIETLY)
27 MESSAGE(STATUS "Looking for Python...")
28 ENDIF (NOT Python_FIND_QUIETLY)
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)
36 SET(PYTHON_EXECUTABLE ${PYTHON_DEBUG} CACHE STRING "Python interpreter")
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)
45 IF (PYTHON_EXECUTABLE)
46 IF (NOT Python_FIND_QUIETLY)
47 MESSAGE(STATUS "Python executable: ${PYTHON_EXECUTABLE}")
48 ENDIF (NOT Python_FIND_QUIETLY)
51 COMMAND ${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write(sys.version[:3])"
52 OUTPUT_VARIABLE PYTHON_VERSION
55 IF (NOT Python_FIND_QUIETLY)
56 MESSAGE(STATUS "Python version: ${PYTHON_VERSION}")
57 ENDIF (NOT Python_FIND_QUIETLY)
60 COMMAND ${PYTHON_EXECUTABLE} -c "import sys; import distutils.sysconfig; sys.stdout.write(distutils.sysconfig.get_python_inc())"
61 OUTPUT_VARIABLE PYTHON_DETECTED_INCLUDE_DIR
64 SET(PYTHON_HEADER Python.h)
65 FIND_PATH(PYTHON_INCLUDE_DIRS ${PYTHON_HEADER}
66 PATHS ${PYTHON_DETECTED_INCLUDE_DIR}
67 DOC "Python include directories")
69 IF (NOT Python_FIND_QUIETLY)
70 IF (PYTHON_INCLUDE_DIRS)
71 MESSAGE(STATUS "Python include directories: ${PYTHON_INCLUDE_DIRS}")
72 ELSE (PYTHON_INCLUDE_DIRS)
73 MESSAGE(STATUS "Could not find Python include directories (looked for file ${PYTHON_HEADER} in directory ${PYTHON_DETECTED_INCLUDE_DIR})")
74 ENDIF (PYTHON_INCLUDE_DIRS)
75 ENDIF (NOT Python_FIND_QUIETLY)
77 FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/findpythonlib.py
80 "import distutils.sysconfig\n"
81 "libdir = distutils.sysconfig.get_config_var('LIBDIR')\n"
82 "if libdir is None:\n"
83 " prefix = distutils.sysconfig.get_config_var('prefix')\n"
84 " libdir = prefix + ';' + os.path.join(prefix, 'lib') + ';' + os.path.join(prefix, 'libs')\n"
85 "sys.stdout.write(libdir)"
89 COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/findpythonlib.py
90 OUTPUT_VARIABLE PYTHON_DETECTED_LIB_DIRS
94 STRING(REPLACE "." "" PYTHON_VERSION_WITHOUT_DOT ${PYTHON_VERSION})
96 SET(LIB_NAME python${PYTHON_VERSION_WITHOUT_DOT}_d)
98 SET(LIB_NAME python${PYTHON_VERSION_WITHOUT_DOT})
101 SET(LIB_NAME python${PYTHON_VERSION})
104 FIND_LIBRARY(PYTHON_LIBRARIES ${LIB_NAME} ${PYTHON_DETECTED_LIB_DIRS} DOC "Python libraries")
106 IF (NOT Python_FIND_QUIETLY)
107 IF (PYTHON_LIBRARIES)
108 MESSAGE(STATUS "Python libraries: ${PYTHON_LIBRARIES}")
109 ELSE (PYTHON_LIBRARIES)
110 MESSAGE(STATUS "Could not find Python libraries (looked for library ${LIB_NAME} in directory ${PYTHON_DETECTED_LIB_DIRS})")
111 ENDIF (PYTHON_LIBRARIES)
112 ENDIF (NOT Python_FIND_QUIETLY)
114 ENDIF (PYTHON_EXECUTABLE)
116 IF(PYTHON_EXECUTABLE AND PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS)
117 SET(Python_FOUND True)
118 ENDIF(PYTHON_EXECUTABLE AND PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS)
122 IF (NOT Python_FIND_QUIETLY)
123 MESSAGE(STATUS "OK, working Python installation found")
124 ENDIF (NOT Python_FIND_QUIETLY)
128 IF (Python_FIND_REQUIRED)
129 MESSAGE(FATAL_ERROR "No working Python installation found")
130 ELSE (Python_FIND_REQUIRED)
131 IF (NOT Python_FIND_QUIETLY)
132 MESSAGE(STATUS "No working Python installation found")
133 ENDIF (NOT Python_FIND_QUIETLY)
134 ENDIF (Python_FIND_REQUIRED)