2005-12-14 18:51:08 +00:00
|
|
|
# - Find python libraries
|
2001-05-11 14:27:46 +00: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:
|
|
|
|
#
|
2007-07-18 17:26:02 +00:00
|
|
|
# PYTHONLIBS_FOUND = have the Python libs been found
|
2005-12-15 19:17:43 +00:00
|
|
|
# PYTHON_LIBRARIES = path to the python library
|
|
|
|
# PYTHON_INCLUDE_PATH = path to where Python.h is found
|
|
|
|
# PYTHON_DEBUG_LIBRARIES = path to the debug library
|
2001-05-11 14:27:46 +00:00
|
|
|
#
|
|
|
|
|
2004-08-27 02:52:53 +00:00
|
|
|
INCLUDE(CMakeFindFrameworks)
|
2007-07-19 13:00:51 +00:00
|
|
|
# Search for the python framework on Apple.
|
|
|
|
CMAKE_FIND_FRAMEWORKS(Python)
|
|
|
|
|
|
|
|
FOREACH(_CURRENT_VERSION 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
|
|
|
|
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-29 21:18:18 +00:00
|
|
|
|
2007-07-19 13:00:51 +00:00
|
|
|
FIND_LIBRARY(PYTHON_LIBRARY
|
|
|
|
NAMES python${_CURRENT_VERSION_NO_DOTS} python${_CURRENT_VERSION}
|
2001-11-30 15:23:00 +00:00
|
|
|
PATHS
|
2007-07-19 13:00:51 +00:00
|
|
|
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
|
|
|
|
PATH_SUFFIXES
|
|
|
|
python${_CURRENT_VERSION}/config
|
|
|
|
# Avoid finding the .dll in the PATH. We want the .lib.
|
|
|
|
NO_SYSTEM_ENVIRONMENT_PATH
|
2001-11-30 15:23:00 +00:00
|
|
|
)
|
2003-12-29 21:18:18 +00:00
|
|
|
|
2007-07-19 13:00:51 +00:00
|
|
|
SET(PYTHON_FRAMEWORK_INCLUDES)
|
|
|
|
IF(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_PATH)
|
|
|
|
FOREACH(dir ${Python_FRAMEWORKS})
|
|
|
|
SET(PYTHON_FRAMEWORK_INCLUDES ${PYTHON_FRAMEWORK_INCLUDES}
|
|
|
|
${dir}/Versions/${_CURRENT_VERSION}/include/python${_CURRENT_VERSION})
|
|
|
|
ENDFOREACH(dir)
|
|
|
|
ENDIF(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_PATH)
|
2001-05-11 14:27:46 +00:00
|
|
|
|
2007-07-19 13:00:51 +00:00
|
|
|
FIND_PATH(PYTHON_INCLUDE_PATH
|
|
|
|
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 15:27:04 +00:00
|
|
|
)
|
2007-07-19 13:00:51 +00:00
|
|
|
|
|
|
|
ENDFOREACH(_CURRENT_VERSION)
|
|
|
|
|
|
|
|
MARK_AS_ADVANCED(
|
|
|
|
PYTHON_DEBUG_LIBRARY
|
|
|
|
PYTHON_LIBRARY
|
|
|
|
PYTHON_INCLUDE_PATH
|
|
|
|
)
|
2002-12-27 16:14:52 +00:00
|
|
|
|
|
|
|
# Python Should be built and installed as a Framework on OSX
|
2003-12-29 21:18:18 +00:00
|
|
|
IF(Python_FRAMEWORKS)
|
|
|
|
# If a framework has been selected for the include path,
|
|
|
|
# make sure "-framework" is used to link it.
|
2003-01-03 22:36:34 +00:00
|
|
|
IF("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework")
|
|
|
|
SET(PYTHON_LIBRARY "")
|
|
|
|
SET(PYTHON_DEBUG_LIBRARY "")
|
|
|
|
ENDIF("${PYTHON_INCLUDE_PATH}" MATCHES "Python\\.framework")
|
2003-12-29 21:18:18 +00:00
|
|
|
IF(NOT PYTHON_LIBRARY)
|
|
|
|
SET (PYTHON_LIBRARY "-framework Python" CACHE FILEPATH "Python Framework" FORCE)
|
|
|
|
ENDIF(NOT PYTHON_LIBRARY)
|
|
|
|
IF(NOT PYTHON_DEBUG_LIBRARY)
|
|
|
|
SET (PYTHON_DEBUG_LIBRARY "-framework Python" CACHE FILEPATH "Python Framework" FORCE)
|
|
|
|
ENDIF(NOT PYTHON_DEBUG_LIBRARY)
|
|
|
|
ENDIF(Python_FRAMEWORKS)
|
2003-11-20 20:41:29 +00:00
|
|
|
|
|
|
|
# We use 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
|
|
|
|
# module.
|
|
|
|
SET(PYTHON_LIBRARIES "${PYTHON_LIBRARY}")
|
|
|
|
SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")
|
2007-07-18 17:26:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
INCLUDE(FindPackageHandleStandardArgs)
|
2007-07-23 13:49:52 +00:00
|
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibs DEFAULT_MSG PYTHON_LIBRARIES PYTHON_INCLUDE_PATH)
|
2007-07-19 13:00:51 +00:00
|
|
|
|
2007-07-19 15:47:23 +00:00
|
|
|
|
2007-07-19 15:59:04 +00:00
|
|
|
GET_TARGET_PROPERTY(_FIND_PYTHONLIBS_ALREADY_INCLUDED __FindPythonLibsHelper TYPE)
|
2007-07-19 15:47:23 +00:00
|
|
|
IF(NOT _FIND_PYTHONLIBS_ALREADY_INCLUDED)
|
|
|
|
ADD_CUSTOM_TARGET(__FindPythonLibsHelper) # so if this file is included several times the next time GET_TARGET_PROPERTIES() will work
|
|
|
|
SET(PY_STATIC_MODULES_LIST "" CACHE STRING "Collect a list of all added static python modules" FORCE)
|
|
|
|
SET(PY_MODULES_LIST "" CACHE STRING "Collect a list of all added python modules" FORCE)
|
|
|
|
ENDIF(NOT _FIND_PYTHONLIBS_ALREADY_INCLUDED)
|
|
|
|
|
2007-07-19 13:00:51 +00:00
|
|
|
MACRO(PYTHON_ADD_MODULE _NAME )
|
|
|
|
OPTION(PYTHON_ENABLE_MODULE_${_NAME} "Add module ${_NAME}" TRUE)
|
|
|
|
|
|
|
|
IF(PYTHON_ENABLE_MODULE_${_NAME})
|
|
|
|
OPTION(PYTHON_MODULE_${_NAME}_SHARED "Add module ${_NAME} shared" FALSE)
|
|
|
|
IF(PYTHON_MODULE_${_NAME}_SHARED)
|
|
|
|
SET(PY_MODULE_TYPE MODULE)
|
|
|
|
ELSE(PYTHON_MODULE_${_NAME}_SHARED)
|
|
|
|
SET(PY_MODULE_TYPE STATIC)
|
2007-07-19 15:47:23 +00:00
|
|
|
SET(PY_STATIC_MODULES_LIST ${PY_STATIC_MODULES_LIST} ${_NAME} CACHE STRING "Collect a list of all added static python modules" FORCE)
|
2007-07-19 13:00:51 +00:00
|
|
|
ENDIF(PYTHON_MODULE_${_NAME}_SHARED)
|
|
|
|
|
2007-07-19 15:47:23 +00:00
|
|
|
SET(PY_MODULES_LIST ${PY_MODULES_LIST} ${_NAME} CACHE STRING "Collect a list of all added python modules" FORCE)
|
2007-07-19 13:00:51 +00:00
|
|
|
ADD_LIBRARY(${_NAME} ${PY_MODULE_TYPE} ${ARGN})
|
2007-07-19 14:20:21 +00:00
|
|
|
# TARGET_LINK_LIBRARIES(${_NAME} ${PYTHON_LIBRARIES})
|
2007-07-19 13:00:51 +00:00
|
|
|
ENDIF(PYTHON_ENABLE_MODULE_${_NAME})
|
|
|
|
ENDMACRO(PYTHON_ADD_MODULE)
|
|
|
|
|
|
|
|
MACRO(PYTHON_WRITE_MODULES_HEADER _filename)
|
|
|
|
GET_FILENAME_COMPONENT(_name "${_filename}" NAME)
|
|
|
|
STRING(REPLACE "." "_" _name "${_name}")
|
|
|
|
STRING(TOUPPER ${_name} _name)
|
|
|
|
FILE(WRITE ${_filename} "/*Created by cmake, do not edit, changes will be lost*/\n")
|
|
|
|
FILE(APPEND ${_filename} "#ifndef ${_name}\n")
|
|
|
|
FILE(APPEND ${_filename} "#define ${_name}\n\n")
|
|
|
|
FILE(APPEND ${_filename} "#include <Python.h>\n\n")
|
|
|
|
|
|
|
|
FOREACH(_currentModule ${PY_MODULES_LIST})
|
|
|
|
FILE(APPEND ${_filename} "extern void init${_currentModule}(void);\n\n")
|
|
|
|
ENDFOREACH(_currentModule ${PY_MODULES_LIST})
|
|
|
|
|
|
|
|
FOREACH(_currentModule ${PY_MODULES_LIST})
|
|
|
|
FILE(APPEND ${_filename} "int CMakeLoadPythonModule_${_currentModule}(void) \n{\n return PyImport_AppendInittab(\"${_currentModule}\", init${_currentModule});\n}\n\n")
|
|
|
|
ENDFOREACH(_currentModule ${PY_MODULES_LIST})
|
|
|
|
|
|
|
|
FILE(APPEND ${_filename} "#ifndef EXCLUDE_LOAD_ALL_FUNCTION\nvoid CMakeLoadAllPythonModules(void)\n{\n")
|
2007-07-19 14:20:21 +00:00
|
|
|
FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2007-07-19 13:00:51 +00:00
|
|
|
FILE(APPEND ${_filename} " CMakeLoadPythonModule_${_currentModule}();\n")
|
2007-07-19 14:20:21 +00:00
|
|
|
ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2007-07-19 13:00:51 +00:00
|
|
|
FILE(APPEND ${_filename} "}\n#endif\n\n#endif\n")
|
|
|
|
ENDMACRO(PYTHON_WRITE_MODULES_HEADER)
|