2005-12-14 21:51:08 +03:00
|
|
|
# - Find python libraries
|
2001-05-11 18:27:46 +04:00
|
|
|
# This module finds if Python is installed and determines where the
|
|
|
|
# include files and libraries are. It also determines what the name of
|
|
|
|
# the library is. This code sets the following variables:
|
|
|
|
#
|
2009-09-14 17:34:57 +04:00
|
|
|
# PYTHONLIBS_FOUND - have the Python libs been found
|
|
|
|
# PYTHON_LIBRARIES - path to the python library
|
|
|
|
# PYTHON_INCLUDE_PATH - path to where Python.h is found (deprecated)
|
|
|
|
# PYTHON_INCLUDE_DIRS - path to where Python.h is found
|
|
|
|
# PYTHON_DEBUG_LIBRARIES - path to the debug library
|
2001-05-11 18:27:46 +04:00
|
|
|
#
|
|
|
|
|
2009-09-28 19:45:50 +04:00
|
|
|
#=============================================================================
|
|
|
|
# Copyright 2001-2009 Kitware, Inc.
|
|
|
|
#
|
|
|
|
# Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
# see accompanying file Copyright.txt for details.
|
|
|
|
#
|
|
|
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# See the License for more information.
|
|
|
|
#=============================================================================
|
2010-08-07 04:48:47 +04:00
|
|
|
# (To distribute this file outside of CMake, substitute the full
|
2009-09-28 19:45:50 +04:00
|
|
|
# License text for the above reference.)
|
|
|
|
|
2004-08-27 06:52:53 +04:00
|
|
|
INCLUDE(CMakeFindFrameworks)
|
2007-07-19 17:00:51 +04:00
|
|
|
# Search for the python framework on Apple.
|
|
|
|
CMAKE_FIND_FRAMEWORKS(Python)
|
|
|
|
|
2007-08-30 21:35:54 +04:00
|
|
|
FOREACH(_CURRENT_VERSION 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
|
2007-07-19 17:00:51 +04:00
|
|
|
STRING(REPLACE "." "" _CURRENT_VERSION_NO_DOTS ${_CURRENT_VERSION})
|
|
|
|
IF(WIN32)
|
|
|
|
FIND_LIBRARY(PYTHON_DEBUG_LIBRARY
|
|
|
|
NAMES python${_CURRENT_VERSION_NO_DOTS}_d python
|
|
|
|
PATHS
|
|
|
|
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug
|
|
|
|
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs )
|
|
|
|
ENDIF(WIN32)
|
2003-12-30 00:18:18 +03:00
|
|
|
|
2007-07-19 17:00:51 +04:00
|
|
|
FIND_LIBRARY(PYTHON_LIBRARY
|
|
|
|
NAMES python${_CURRENT_VERSION_NO_DOTS} python${_CURRENT_VERSION}
|
2001-11-30 18:23:00 +03:00
|
|
|
PATHS
|
2007-07-19 17:00:51 +04:00
|
|
|
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
|
|
|
|
# Avoid finding the .dll in the PATH. We want the .lib.
|
|
|
|
NO_SYSTEM_ENVIRONMENT_PATH
|
2001-11-30 18:23:00 +03:00
|
|
|
)
|
2009-12-14 22:15:31 +03:00
|
|
|
# Look for the static library in the Python config directory
|
|
|
|
FIND_LIBRARY(PYTHON_LIBRARY
|
|
|
|
NAMES python${_CURRENT_VERSION_NO_DOTS} python${_CURRENT_VERSION}
|
|
|
|
# Avoid finding the .dll in the PATH. We want the .lib.
|
|
|
|
NO_SYSTEM_ENVIRONMENT_PATH
|
|
|
|
# This is where the static library is usually located
|
|
|
|
PATH_SUFFIXES python${_CURRENT_VERSION}/config
|
|
|
|
)
|
2003-12-30 00:18:18 +03:00
|
|
|
|
2009-09-14 17:34:57 +04:00
|
|
|
# For backward compatibility, honour value of PYTHON_INCLUDE_PATH, if
|
|
|
|
# PYTHON_INCLUDE_DIR is not set.
|
|
|
|
IF(DEFINED PYTHON_INCLUDE_PATH AND NOT DEFINED PYTHON_INCLUDE_DIR)
|
|
|
|
SET(PYTHON_INCLUDE_DIR "${PYTHON_INCLUDE_PATH}" CACHE PATH
|
|
|
|
"Path to where Python.h is found" FORCE)
|
|
|
|
ENDIF(DEFINED PYTHON_INCLUDE_PATH AND NOT DEFINED PYTHON_INCLUDE_DIR)
|
|
|
|
|
2007-07-19 17:00:51 +04:00
|
|
|
SET(PYTHON_FRAMEWORK_INCLUDES)
|
2009-09-14 17:34:57 +04:00
|
|
|
IF(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR)
|
2007-07-19 17:00:51 +04:00
|
|
|
FOREACH(dir ${Python_FRAMEWORKS})
|
|
|
|
SET(PYTHON_FRAMEWORK_INCLUDES ${PYTHON_FRAMEWORK_INCLUDES}
|
|
|
|
${dir}/Versions/${_CURRENT_VERSION}/include/python${_CURRENT_VERSION})
|
|
|
|
ENDFOREACH(dir)
|
2009-09-14 17:34:57 +04:00
|
|
|
ENDIF(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR)
|
2001-05-11 18:27:46 +04:00
|
|
|
|
2009-09-14 17:34:57 +04:00
|
|
|
FIND_PATH(PYTHON_INCLUDE_DIR
|
2007-07-19 17:00:51 +04:00
|
|
|
NAMES Python.h
|
|
|
|
PATHS
|
|
|
|
${PYTHON_FRAMEWORK_INCLUDES}
|
|
|
|
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include
|
|
|
|
PATH_SUFFIXES
|
|
|
|
python${_CURRENT_VERSION}
|
2001-12-04 18:27:04 +03:00
|
|
|
)
|
2009-09-14 17:34:57 +04:00
|
|
|
|
|
|
|
# For backward compatibility, set PYTHON_INCLUDE_PATH, but make it internal.
|
|
|
|
SET(PYTHON_INCLUDE_PATH "${PYTHON_INCLUDE_DIR}" CACHE INTERNAL
|
|
|
|
"Path to where Python.h is found (deprecated)")
|
2007-07-19 17:00:51 +04:00
|
|
|
|
|
|
|
ENDFOREACH(_CURRENT_VERSION)
|
|
|
|
|
|
|
|
MARK_AS_ADVANCED(
|
|
|
|
PYTHON_DEBUG_LIBRARY
|
|
|
|
PYTHON_LIBRARY
|
2009-09-14 17:34:57 +04:00
|
|
|
PYTHON_INCLUDE_DIR
|
2007-07-19 17:00:51 +04:00
|
|
|
)
|
2002-12-27 19:14:52 +03:00
|
|
|
|
2009-09-14 17:34:57 +04:00
|
|
|
# We use PYTHON_INCLUDE_DIR, PYTHON_LIBRARY and PYTHON_DEBUG_LIBRARY for the
|
|
|
|
# cache entries because they are meant to specify the location of a single
|
|
|
|
# library. We now set the variables listed by the documentation for this
|
2003-11-20 23:41:29 +03:00
|
|
|
# module.
|
2009-09-14 17:34:57 +04:00
|
|
|
SET(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
|
2003-11-20 23:41:29 +03:00
|
|
|
SET(PYTHON_LIBRARIES "${PYTHON_LIBRARY}")
|
|
|
|
SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")
|
2007-07-18 21:26:02 +04:00
|
|
|
|
|
|
|
|
|
|
|
INCLUDE(FindPackageHandleStandardArgs)
|
2009-09-14 17:34:57 +04:00
|
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibs DEFAULT_MSG PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
|
2007-07-19 17:00:51 +04:00
|
|
|
|
2007-07-19 19:47:23 +04:00
|
|
|
|
2008-02-16 02:26:37 +03:00
|
|
|
# PYTHON_ADD_MODULE(<name> src1 src2 ... srcN) is used to build modules for python.
|
|
|
|
# PYTHON_WRITE_MODULES_HEADER(<filename>) writes a header file you can include
|
|
|
|
# in your sources to initialize the static python modules
|
|
|
|
FUNCTION(PYTHON_ADD_MODULE _NAME )
|
2010-08-13 22:49:29 +04:00
|
|
|
GET_PROPERTY(_TARGET_SUPPORTS_SHARED_LIBS
|
|
|
|
GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
|
2007-07-19 17:00:51 +04:00
|
|
|
OPTION(PYTHON_ENABLE_MODULE_${_NAME} "Add module ${_NAME}" TRUE)
|
2010-02-17 19:37:37 +03:00
|
|
|
OPTION(PYTHON_MODULE_${_NAME}_BUILD_SHARED
|
|
|
|
"Add module ${_NAME} shared" ${_TARGET_SUPPORTS_SHARED_LIBS})
|
|
|
|
|
|
|
|
# Mark these options as advanced
|
|
|
|
MARK_AS_ADVANCED(PYTHON_ENABLE_MODULE_${_NAME}
|
|
|
|
PYTHON_MODULE_${_NAME}_BUILD_SHARED)
|
2007-07-19 17:00:51 +04:00
|
|
|
|
|
|
|
IF(PYTHON_ENABLE_MODULE_${_NAME})
|
2007-07-25 23:08:37 +04:00
|
|
|
IF(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
|
2007-07-19 17:00:51 +04:00
|
|
|
SET(PY_MODULE_TYPE MODULE)
|
2007-07-25 23:08:37 +04:00
|
|
|
ELSE(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
|
2007-07-19 17:00:51 +04:00
|
|
|
SET(PY_MODULE_TYPE STATIC)
|
2008-02-16 02:26:37 +03:00
|
|
|
SET_PROPERTY(GLOBAL APPEND PROPERTY PY_STATIC_MODULES_LIST ${_NAME})
|
2007-07-25 23:08:37 +04:00
|
|
|
ENDIF(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
|
2007-07-19 17:00:51 +04:00
|
|
|
|
2008-02-16 02:26:37 +03:00
|
|
|
SET_PROPERTY(GLOBAL APPEND PROPERTY PY_MODULES_LIST ${_NAME})
|
2007-07-19 17:00:51 +04:00
|
|
|
ADD_LIBRARY(${_NAME} ${PY_MODULE_TYPE} ${ARGN})
|
2007-07-19 18:20:21 +04:00
|
|
|
# TARGET_LINK_LIBRARIES(${_NAME} ${PYTHON_LIBRARIES})
|
2008-02-16 02:26:37 +03:00
|
|
|
|
2007-07-19 17:00:51 +04:00
|
|
|
ENDIF(PYTHON_ENABLE_MODULE_${_NAME})
|
2008-02-16 02:26:37 +03:00
|
|
|
ENDFUNCTION(PYTHON_ADD_MODULE)
|
|
|
|
|
|
|
|
FUNCTION(PYTHON_WRITE_MODULES_HEADER _filename)
|
|
|
|
|
|
|
|
GET_PROPERTY(PY_STATIC_MODULES_LIST GLOBAL PROPERTY PY_STATIC_MODULES_LIST)
|
2007-07-19 17:00:51 +04:00
|
|
|
|
|
|
|
GET_FILENAME_COMPONENT(_name "${_filename}" NAME)
|
|
|
|
STRING(REPLACE "." "_" _name "${_name}")
|
2010-02-17 19:37:37 +03:00
|
|
|
STRING(TOUPPER ${_name} _nameUpper)
|
2007-08-02 23:48:51 +04:00
|
|
|
|
|
|
|
SET(_filenameTmp "${_filename}.in")
|
|
|
|
FILE(WRITE ${_filenameTmp} "/*Created by cmake, do not edit, changes will be lost*/\n")
|
|
|
|
FILE(APPEND ${_filenameTmp}
|
2010-02-17 19:37:37 +03:00
|
|
|
"#ifndef ${_nameUpper}
|
|
|
|
#define ${_nameUpper}
|
2007-08-02 23:48:51 +04:00
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern \"C\" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
")
|
2007-07-19 17:00:51 +04:00
|
|
|
|
2007-07-25 23:08:37 +04:00
|
|
|
FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2007-08-02 23:48:51 +04:00
|
|
|
FILE(APPEND ${_filenameTmp} "extern void init${PYTHON_MODULE_PREFIX}${_currentModule}(void);\n\n")
|
2007-07-25 23:08:37 +04:00
|
|
|
ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2007-07-19 17:00:51 +04:00
|
|
|
|
2007-08-02 23:48:51 +04:00
|
|
|
FILE(APPEND ${_filenameTmp}
|
|
|
|
"#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
")
|
|
|
|
|
|
|
|
|
2007-07-25 23:08:37 +04:00
|
|
|
FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2010-02-17 22:36:17 +03:00
|
|
|
FILE(APPEND ${_filenameTmp} "int ${_name}_${_currentModule}(void) \n{\n static char name[]=\"${PYTHON_MODULE_PREFIX}${_currentModule}\"; return PyImport_AppendInittab(name, init${PYTHON_MODULE_PREFIX}${_currentModule});\n}\n\n")
|
2007-07-25 23:08:37 +04:00
|
|
|
ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2007-07-19 17:00:51 +04:00
|
|
|
|
2010-02-17 19:37:37 +03:00
|
|
|
FILE(APPEND ${_filenameTmp} "void ${_name}_LoadAllPythonModules(void)\n{\n")
|
2007-07-19 18:20:21 +04:00
|
|
|
FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2010-02-17 22:36:17 +03:00
|
|
|
FILE(APPEND ${_filenameTmp} " ${_name}_${_currentModule}();\n")
|
2007-07-19 18:20:21 +04:00
|
|
|
ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2010-02-17 19:37:37 +03:00
|
|
|
FILE(APPEND ${_filenameTmp} "}\n\n")
|
|
|
|
FILE(APPEND ${_filenameTmp} "#ifndef EXCLUDE_LOAD_ALL_FUNCTION\nvoid CMakeLoadAllPythonModules(void)\n{\n ${_name}_LoadAllPythonModules();\n}\n#endif\n\n#endif\n")
|
2007-08-02 23:48:51 +04:00
|
|
|
|
|
|
|
# with CONFIGURE_FILE() cmake complains that you may not use a file created using FILE(WRITE) as input file for CONFIGURE_FILE()
|
|
|
|
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_filenameTmp}" "${_filename}" OUTPUT_QUIET ERROR_QUIET)
|
|
|
|
|
2008-02-16 02:26:37 +03:00
|
|
|
ENDFUNCTION(PYTHON_WRITE_MODULES_HEADER)
|