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:
|
|
|
|
#
|
2011-01-10 18:44:45 +00: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
|
2012-02-21 20:40:02 +00:00
|
|
|
# PYTHON_DEBUG_LIBRARIES - path to the debug library (deprecated)
|
2012-02-21 20:12:16 +00:00
|
|
|
# PYTHONLIBS_VERSION_STRING - version of the Python libs found (since CMake 2.8.8)
|
2012-02-21 19:52:27 +00:00
|
|
|
#
|
|
|
|
# The Python_ADDITIONAL_VERSIONS variable can be used to specify a list of
|
|
|
|
# version numbers that should be taken into account when searching for Python.
|
|
|
|
# You need to set this variable before calling find_package(PythonLibs).
|
2012-05-21 15:12:03 +00:00
|
|
|
#
|
|
|
|
# If you'd like to specify the installation of Python to use, you should modify
|
|
|
|
# the following cache variables:
|
|
|
|
# PYTHON_LIBRARY - path to the python library
|
|
|
|
# PYTHON_INCLUDE_DIR - path to where Python.h is found
|
2001-05-11 14:27:46 +00:00
|
|
|
|
2009-09-28 15:45:50 +00: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 00:48:47 +00:00
|
|
|
# (To distribute this file outside of CMake, substitute the full
|
2009-09-28 15:45:50 +00:00
|
|
|
# License text for the above reference.)
|
|
|
|
|
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)
|
|
|
|
|
2012-02-21 20:00:15 +00:00
|
|
|
SET(_PYTHON1_VERSIONS 1.6 1.5)
|
|
|
|
SET(_PYTHON2_VERSIONS 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0)
|
|
|
|
SET(_PYTHON3_VERSIONS 3.3 3.2 3.1 3.0)
|
|
|
|
|
|
|
|
IF(PythonLibs_FIND_VERSION)
|
|
|
|
IF(PythonLibs_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+.*)?$")
|
|
|
|
STRING(REGEX REPLACE "^([0-9]+\\.[0-9]+).*" "\\1" _PYTHON_FIND_MAJ_MIN "${PythonLibs_FIND_VERSION}")
|
|
|
|
STRING(REGEX REPLACE "^([0-9]+).*" "\\1" _PYTHON_FIND_MAJ "${_PYTHON_FIND_MAJ_MIN}")
|
|
|
|
UNSET(_PYTHON_FIND_OTHER_VERSIONS)
|
2012-06-05 18:02:58 +00:00
|
|
|
IF(PythonLibs_FIND_VERSION_EXACT)
|
|
|
|
IF(_PYTHON_FIND_MAJ_MIN STREQUAL PythonLibs_FIND_VERSION)
|
|
|
|
SET(_PYTHON_FIND_OTHER_VERSIONS "${PythonLibs_FIND_VERSION}")
|
|
|
|
ELSE(_PYTHON_FIND_MAJ_MIN STREQUAL PythonLibs_FIND_VERSION)
|
|
|
|
SET(_PYTHON_FIND_OTHER_VERSIONS "${PythonLibs_FIND_VERSION}" "${_PYTHON_FIND_MAJ_MIN}")
|
|
|
|
ENDIF(_PYTHON_FIND_MAJ_MIN STREQUAL PythonLibs_FIND_VERSION)
|
|
|
|
ELSE(PythonLibs_FIND_VERSION_EXACT)
|
2012-02-21 20:00:15 +00:00
|
|
|
FOREACH(_PYTHON_V ${_PYTHON${_PYTHON_FIND_MAJ}_VERSIONS})
|
|
|
|
IF(NOT _PYTHON_V VERSION_LESS _PYTHON_FIND_MAJ_MIN)
|
|
|
|
LIST(APPEND _PYTHON_FIND_OTHER_VERSIONS ${_PYTHON_V})
|
|
|
|
ENDIF()
|
|
|
|
ENDFOREACH()
|
2012-06-05 18:02:58 +00:00
|
|
|
ENDIF(PythonLibs_FIND_VERSION_EXACT)
|
2012-02-21 20:00:15 +00:00
|
|
|
UNSET(_PYTHON_FIND_MAJ_MIN)
|
|
|
|
UNSET(_PYTHON_FIND_MAJ)
|
|
|
|
ELSE(PythonLibs_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+.*)?$")
|
|
|
|
SET(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON${PythonLibs_FIND_VERSION}_VERSIONS})
|
|
|
|
ENDIF(PythonLibs_FIND_VERSION MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+.*)?$")
|
|
|
|
ELSE(PythonLibs_FIND_VERSION)
|
|
|
|
SET(_PYTHON_FIND_OTHER_VERSIONS ${_PYTHON3_VERSIONS} ${_PYTHON2_VERSIONS} ${_PYTHON1_VERSIONS})
|
|
|
|
ENDIF(PythonLibs_FIND_VERSION)
|
|
|
|
|
2011-01-10 18:44:45 +00:00
|
|
|
# Set up the versions we know about, in the order we will search. Always add
|
|
|
|
# the user supplied additional versions to the front.
|
2012-02-21 20:00:15 +00:00
|
|
|
SET(_Python_VERSIONS
|
2011-01-10 18:44:45 +00:00
|
|
|
${Python_ADDITIONAL_VERSIONS}
|
2012-02-21 20:00:15 +00:00
|
|
|
${_PYTHON_FIND_OTHER_VERSIONS}
|
|
|
|
)
|
|
|
|
|
|
|
|
UNSET(_PYTHON_FIND_OTHER_VERSIONS)
|
|
|
|
UNSET(_PYTHON1_VERSIONS)
|
|
|
|
UNSET(_PYTHON2_VERSIONS)
|
|
|
|
UNSET(_PYTHON3_VERSIONS)
|
2011-01-10 18:44:45 +00:00
|
|
|
|
|
|
|
FOREACH(_CURRENT_VERSION ${_Python_VERSIONS})
|
2007-07-19 13:00:51 +00: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
|
2012-01-10 14:55:42 +00:00
|
|
|
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug
|
|
|
|
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
|
|
|
|
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
|
|
|
|
)
|
2007-07-19 13:00:51 +00:00
|
|
|
ENDIF(WIN32)
|
2003-12-29 21:18:18 +00:00
|
|
|
|
2007-07-19 13:00:51 +00:00
|
|
|
FIND_LIBRARY(PYTHON_LIBRARY
|
2012-03-27 20:24:43 +00:00
|
|
|
NAMES
|
|
|
|
python${_CURRENT_VERSION_NO_DOTS}
|
|
|
|
python${_CURRENT_VERSION}mu
|
|
|
|
python${_CURRENT_VERSION}m
|
|
|
|
python${_CURRENT_VERSION}u
|
|
|
|
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
|
2012-01-10 14:55:42 +00:00
|
|
|
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
|
2007-07-19 13:00:51 +00:00
|
|
|
# Avoid finding the .dll in the PATH. We want the .lib.
|
|
|
|
NO_SYSTEM_ENVIRONMENT_PATH
|
2001-11-30 15:23:00 +00:00
|
|
|
)
|
2009-12-14 19:15:31 +00: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-29 21:18:18 +00:00
|
|
|
|
2011-01-10 18:44:45 +00:00
|
|
|
# For backward compatibility, honour value of PYTHON_INCLUDE_PATH, if
|
2009-09-14 13:34:57 +00:00
|
|
|
# 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 13:00:51 +00:00
|
|
|
SET(PYTHON_FRAMEWORK_INCLUDES)
|
2009-09-14 13:34:57 +00:00
|
|
|
IF(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR)
|
2007-07-19 13:00:51 +00: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 13:34:57 +00:00
|
|
|
ENDIF(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR)
|
2001-05-11 14:27:46 +00:00
|
|
|
|
2009-09-14 13:34:57 +00:00
|
|
|
FIND_PATH(PYTHON_INCLUDE_DIR
|
2007-07-19 13:00:51 +00:00
|
|
|
NAMES Python.h
|
|
|
|
PATHS
|
|
|
|
${PYTHON_FRAMEWORK_INCLUDES}
|
|
|
|
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include
|
2012-01-10 14:55:42 +00:00
|
|
|
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include
|
2007-07-19 13:00:51 +00:00
|
|
|
PATH_SUFFIXES
|
2012-03-27 20:24:43 +00:00
|
|
|
python${_CURRENT_VERSION}mu
|
|
|
|
python${_CURRENT_VERSION}m
|
|
|
|
python${_CURRENT_VERSION}u
|
2007-07-19 13:00:51 +00:00
|
|
|
python${_CURRENT_VERSION}
|
2001-12-04 15:27:04 +00:00
|
|
|
)
|
2009-09-14 13:34:57 +00:00
|
|
|
|
2012-03-27 20:21:06 +00:00
|
|
|
# For backward compatibility, set PYTHON_INCLUDE_PATH.
|
|
|
|
SET(PYTHON_INCLUDE_PATH "${PYTHON_INCLUDE_DIR}")
|
2011-01-10 18:44:45 +00:00
|
|
|
|
2012-02-21 20:12:16 +00:00
|
|
|
IF(PYTHON_INCLUDE_DIR AND EXISTS "${PYTHON_INCLUDE_DIR}/patchlevel.h")
|
|
|
|
FILE(STRINGS "${PYTHON_INCLUDE_DIR}/patchlevel.h" python_version_str
|
|
|
|
REGEX "^#define[ \t]+PY_VERSION[ \t]+\"[^\"]+\"")
|
|
|
|
STRING(REGEX REPLACE "^#define[ \t]+PY_VERSION[ \t]+\"([^\"]+)\".*" "\\1"
|
|
|
|
PYTHONLIBS_VERSION_STRING "${python_version_str}")
|
|
|
|
UNSET(python_version_str)
|
|
|
|
ENDIF(PYTHON_INCLUDE_DIR AND EXISTS "${PYTHON_INCLUDE_DIR}/patchlevel.h")
|
2012-02-22 16:25:08 +00:00
|
|
|
|
|
|
|
IF(PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR)
|
|
|
|
BREAK()
|
|
|
|
ENDIF(PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR)
|
2007-07-19 13:00:51 +00:00
|
|
|
ENDFOREACH(_CURRENT_VERSION)
|
|
|
|
|
|
|
|
MARK_AS_ADVANCED(
|
|
|
|
PYTHON_DEBUG_LIBRARY
|
|
|
|
PYTHON_LIBRARY
|
2009-09-14 13:34:57 +00:00
|
|
|
PYTHON_INCLUDE_DIR
|
2007-07-19 13:00:51 +00:00
|
|
|
)
|
2002-12-27 16:14:52 +00:00
|
|
|
|
2009-09-14 13:34:57 +00: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 20:41:29 +00:00
|
|
|
# module.
|
2009-09-14 13:34:57 +00:00
|
|
|
SET(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}")
|
2003-11-20 20:41:29 +00:00
|
|
|
SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}")
|
2007-07-18 17:26:02 +00:00
|
|
|
|
2012-02-21 20:40:02 +00:00
|
|
|
# These variables have been historically named in this module different from
|
|
|
|
# what SELECT_LIBRARY_CONFIGURATIONS() expects.
|
|
|
|
SET(PYTHON_LIBRARY_DEBUG "${PYTHON_DEBUG_LIBRARY}")
|
|
|
|
SET(PYTHON_LIBRARY_RELEASE "${PYTHON_LIBRARY}")
|
|
|
|
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
|
|
|
|
SELECT_LIBRARY_CONFIGURATIONS(PYTHON)
|
|
|
|
# SELECT_LIBRARY_CONFIGURATIONS() sets ${PREFIX}_FOUND if it has a library.
|
|
|
|
# Unset this, this prefix doesn't match the module prefix, they are different
|
|
|
|
# for historical reasons.
|
|
|
|
UNSET(PYTHON_FOUND)
|
2007-07-18 17:26:02 +00:00
|
|
|
|
Modules: Include builtin FindPackageHandleStandardArgs directly
The FindPackageHandleStandardArgs module was originally created outside
of CMake. It was added for CMake 2.6.0 by commit e118a627 (add a macro
FIND_PACKAGE_HANDLE_STANDARD_ARGS..., 2007-07-18). However, it also
proliferated into a number of other projects that at the time required
only CMake 2.4 and thus could not depend on CMake to provide the module.
CMake's own find modules started using the module in commit b5f656e0
(use the new FIND_PACKAGE_HANDLE_STANDARD_ARGS in some of the FindXXX
modules..., 2007-07-18).
Then commit d358cf5c (add 2nd, more powerful mode to
find_package_handle_standard_args, 2010-07-29) added a new feature to
the interface of the module that was fully optional and backward
compatible with all existing users of the module. Later commit 5f183caa
(FindZLIB: use the FPHSA version mode, 2010-08-04) and others shortly
thereafter started using the new interface in CMake's own find modules.
This change was also backward compatible because it was only an
implementation detail within each module.
Unforutnately these changes introduced a problem for projects that still
have an old copy of FindPackageHandleStandardArgs in CMAKE_MODULE_PATH.
When any such project uses one of CMake's builtin find modules the line
include(FindPackageHandleStandardArgs)
loads the copy from the project which does not have the new interface!
Then the including find module tries to use the new interface with the
old module and fails.
Whether this breakage can be considered a backward incompatible change
in CMake is debatable. The situation is analagous to copying a standard
library header from one version of a compiler into a project and then
observing problems when the next version of the compiler reports errors
in its other headers that depend on its new version of the original
header. Nevertheless it is a change to CMake that causes problems for
projects that worked with previous versions.
This problem was discovered during the 2.8.3 release candidate cycle.
It is an instance of a more general problem with projects that provide
their own versions of CMake modules when other CMake modules depend on
them. At the time we resolved this instance of the problem with commit
b0118402 (Use absolute path to FindPackageHandleStandardArgs.cmake
everywhere, 2010-09-28) for the 2.8.3 release.
In order to address the more general problem we introduced policy
CMP0017 in commit db44848f (Prefer files from CMAKE_ROOT when including
from CMAKE_ROOT, 2010-11-17). That change was followed by commit
ce28737c (Remove usage of CMAKE_CURRENT_LIST_DIR now that we have
CMP0017, 2010-12-20) which reverted the original workaround in favor of
using the policy. However, existing project releases do not set the
policy behavior to NEW and therefore still exhibit the problem.
We introduced in commit a364daf1 (Allow users to specify defaults for
unset policies, 2011-01-03) an option for users to build existing
projects by adding -DCMAKE_POLICY_DEFAULT_CMP0017=NEW to the command
line. Unfortunately this solution still does not allow such projects to
build out of the box, and there is no good way to suggest the use of the
new option.
The only remaining solution to keep existing projects that exhibit this
problem building is to restore the change originally made in commit
b0118402 (Use absolute path to FindPackageHandleStandardArgs.cmake
everywhere, 2010-09-28). This also avoids policy CMP0017 warnings for
this particular instance of the problem the policy addresses.
2011-01-20 15:56:49 +00:00
|
|
|
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
2012-02-21 20:12:16 +00:00
|
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibs
|
|
|
|
REQUIRED_VARS PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS
|
|
|
|
VERSION_VAR PYTHONLIBS_VERSION_STRING)
|
2007-07-19 15:47:23 +00:00
|
|
|
|
2008-02-15 23:26:37 +00:00
|
|
|
# PYTHON_ADD_MODULE(<name> src1 src2 ... srcN) is used to build modules for python.
|
2011-01-10 18:44:45 +00:00
|
|
|
# PYTHON_WRITE_MODULES_HEADER(<filename>) writes a header file you can include
|
2008-02-15 23:26:37 +00:00
|
|
|
# in your sources to initialize the static python modules
|
|
|
|
FUNCTION(PYTHON_ADD_MODULE _NAME )
|
2010-08-13 18:49:29 +00:00
|
|
|
GET_PROPERTY(_TARGET_SUPPORTS_SHARED_LIBS
|
|
|
|
GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
|
2007-07-19 13:00:51 +00:00
|
|
|
OPTION(PYTHON_ENABLE_MODULE_${_NAME} "Add module ${_NAME}" TRUE)
|
2010-02-17 16:37:37 +00: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 13:00:51 +00:00
|
|
|
|
|
|
|
IF(PYTHON_ENABLE_MODULE_${_NAME})
|
2007-07-25 19:08:37 +00:00
|
|
|
IF(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
|
2007-07-19 13:00:51 +00:00
|
|
|
SET(PY_MODULE_TYPE MODULE)
|
2007-07-25 19:08:37 +00:00
|
|
|
ELSE(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
|
2007-07-19 13:00:51 +00:00
|
|
|
SET(PY_MODULE_TYPE STATIC)
|
2008-02-15 23:26:37 +00:00
|
|
|
SET_PROPERTY(GLOBAL APPEND PROPERTY PY_STATIC_MODULES_LIST ${_NAME})
|
2007-07-25 19:08:37 +00:00
|
|
|
ENDIF(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
|
2007-07-19 13:00:51 +00:00
|
|
|
|
2008-02-15 23:26:37 +00:00
|
|
|
SET_PROPERTY(GLOBAL APPEND PROPERTY PY_MODULES_LIST ${_NAME})
|
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})
|
2008-02-15 23:26:37 +00:00
|
|
|
|
2010-09-24 19:04:24 +00:00
|
|
|
IF(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
|
|
|
|
SET_TARGET_PROPERTIES(${_NAME} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}")
|
|
|
|
IF(WIN32 AND NOT CYGWIN)
|
|
|
|
SET_TARGET_PROPERTIES(${_NAME} PROPERTIES SUFFIX ".pyd")
|
|
|
|
ENDIF(WIN32 AND NOT CYGWIN)
|
|
|
|
ENDIF(PYTHON_MODULE_${_NAME}_BUILD_SHARED)
|
|
|
|
|
2007-07-19 13:00:51 +00:00
|
|
|
ENDIF(PYTHON_ENABLE_MODULE_${_NAME})
|
2008-02-15 23:26:37 +00: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 13:00:51 +00:00
|
|
|
|
|
|
|
GET_FILENAME_COMPONENT(_name "${_filename}" NAME)
|
|
|
|
STRING(REPLACE "." "_" _name "${_name}")
|
2010-02-17 16:37:37 +00:00
|
|
|
STRING(TOUPPER ${_name} _nameUpper)
|
2011-01-17 20:29:01 +00:00
|
|
|
SET(_filename ${CMAKE_CURRENT_BINARY_DIR}/${_filename})
|
2007-08-02 19:48:51 +00:00
|
|
|
|
|
|
|
SET(_filenameTmp "${_filename}.in")
|
|
|
|
FILE(WRITE ${_filenameTmp} "/*Created by cmake, do not edit, changes will be lost*/\n")
|
2011-01-10 18:44:45 +00:00
|
|
|
FILE(APPEND ${_filenameTmp}
|
2010-02-17 16:37:37 +00:00
|
|
|
"#ifndef ${_nameUpper}
|
|
|
|
#define ${_nameUpper}
|
2007-08-02 19:48:51 +00:00
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern \"C\" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
")
|
2007-07-19 13:00:51 +00:00
|
|
|
|
2007-07-25 19:08:37 +00:00
|
|
|
FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2007-08-02 19:48:51 +00:00
|
|
|
FILE(APPEND ${_filenameTmp} "extern void init${PYTHON_MODULE_PREFIX}${_currentModule}(void);\n\n")
|
2007-07-25 19:08:37 +00:00
|
|
|
ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2007-07-19 13:00:51 +00:00
|
|
|
|
2011-01-10 18:44:45 +00:00
|
|
|
FILE(APPEND ${_filenameTmp}
|
2007-08-02 19:48:51 +00:00
|
|
|
"#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
")
|
|
|
|
|
|
|
|
|
2007-07-25 19:08:37 +00:00
|
|
|
FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2010-02-17 19:36:17 +00: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 19:08:37 +00:00
|
|
|
ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2007-07-19 13:00:51 +00:00
|
|
|
|
2010-02-17 16:37:37 +00:00
|
|
|
FILE(APPEND ${_filenameTmp} "void ${_name}_LoadAllPythonModules(void)\n{\n")
|
2007-07-19 14:20:21 +00:00
|
|
|
FOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2010-02-17 19:36:17 +00:00
|
|
|
FILE(APPEND ${_filenameTmp} " ${_name}_${_currentModule}();\n")
|
2007-07-19 14:20:21 +00:00
|
|
|
ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
2010-02-17 16:37:37 +00: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")
|
2011-01-10 18:44:45 +00:00
|
|
|
|
2007-08-02 19:48:51 +00: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-15 23:26:37 +00:00
|
|
|
ENDFUNCTION(PYTHON_WRITE_MODULES_HEADER)
|