mirror of
https://github.com/reactos/CMake.git
synced 2024-11-23 19:49:51 +00:00
Python additional version support, bug #10279.
Introduced an additional variable, Python_ADDITIONAL_VERSIONS, to both FindPythonLibs and FindPythonInterp. Changed FindPythonInterp to loop over versions rather than hardcoding all versions (more like libs).
This commit is contained in:
parent
6754b26bf0
commit
2d3594b1bb
@ -2,8 +2,9 @@
|
||||
# This module finds if Python interpreter is installed and determines where the
|
||||
# executables are. This code sets the following variables:
|
||||
#
|
||||
# PYTHONINTERP_FOUND - Was the Python executable found
|
||||
# PYTHON_EXECUTABLE - path to the Python interpreter
|
||||
# PYTHONINTERP_FOUND - Was the Python executable found
|
||||
# PYTHON_EXECUTABLE - path to the Python interpreter
|
||||
# Python_ADDITIONAL_VERSIONS - list of additional Python versions to search for
|
||||
#
|
||||
|
||||
#=============================================================================
|
||||
@ -19,25 +20,32 @@
|
||||
# (To distribute this file outside of CMake, substitute the full
|
||||
# License text for the above reference.)
|
||||
|
||||
FIND_PROGRAM(PYTHON_EXECUTABLE
|
||||
NAMES python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5 python
|
||||
PATHS
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.7\\InstallPath]
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.6\\InstallPath]
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.5\\InstallPath]
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.4\\InstallPath]
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath]
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.2\\InstallPath]
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.1\\InstallPath]
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\2.0\\InstallPath]
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.6\\InstallPath]
|
||||
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\1.5\\InstallPath]
|
||||
)
|
||||
# Set up the versions we know about, in the order we will search. Always add
|
||||
# the user supplied additional versions to the front.
|
||||
set(_Python_VERSIONS
|
||||
${Python_ADDITIONAL_VERSIONS}
|
||||
2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
|
||||
|
||||
# Run first with the Python version in the executable
|
||||
foreach(_CURRENT_VERSION ${_Python_VERSIONS})
|
||||
set(_Python_NAMES python${_CURRENT_VERSION})
|
||||
if(WIN32)
|
||||
list(APPEND _Python_NAMES python)
|
||||
endif()
|
||||
find_program(PYTHON_EXECUTABLE
|
||||
NAMES ${_Python_NAMES}
|
||||
PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]
|
||||
)
|
||||
endforeach()
|
||||
# Now without any version if we still haven't found it
|
||||
if(NOT PYTHON_EXECUTABLE)
|
||||
find_program(PYTHON_EXECUTABLE NAMES python)
|
||||
endif()
|
||||
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set PYTHONINTERP_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
INCLUDE("${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake")
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonInterp DEFAULT_MSG PYTHON_EXECUTABLE)
|
||||
|
||||
MARK_AS_ADVANCED(PYTHON_EXECUTABLE)
|
||||
|
||||
mark_as_advanced(PYTHON_EXECUTABLE)
|
||||
|
@ -3,12 +3,12 @@
|
||||
# include files and libraries are. It also determines what the name of
|
||||
# the library is. This code sets the following variables:
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# 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
|
||||
# Python_ADDITIONAL_VERSIONS - list of additional Python versions to search for
|
||||
|
||||
#=============================================================================
|
||||
# Copyright 2001-2009 Kitware, Inc.
|
||||
@ -27,7 +27,13 @@ INCLUDE(CMakeFindFrameworks)
|
||||
# Search for the python framework on Apple.
|
||||
CMAKE_FIND_FRAMEWORKS(Python)
|
||||
|
||||
FOREACH(_CURRENT_VERSION 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
|
||||
# Set up the versions we know about, in the order we will search. Always add
|
||||
# the user supplied additional versions to the front.
|
||||
set(_Python_VERSIONS
|
||||
${Python_ADDITIONAL_VERSIONS}
|
||||
2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
|
||||
|
||||
FOREACH(_CURRENT_VERSION ${_Python_VERSIONS})
|
||||
STRING(REPLACE "." "" _CURRENT_VERSION_NO_DOTS ${_CURRENT_VERSION})
|
||||
IF(WIN32)
|
||||
FIND_LIBRARY(PYTHON_DEBUG_LIBRARY
|
||||
@ -53,7 +59,7 @@ FOREACH(_CURRENT_VERSION 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
|
||||
PATH_SUFFIXES python${_CURRENT_VERSION}/config
|
||||
)
|
||||
|
||||
# For backward compatibility, honour value of PYTHON_INCLUDE_PATH, if
|
||||
# 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
|
||||
@ -78,9 +84,9 @@ FOREACH(_CURRENT_VERSION 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
|
||||
)
|
||||
|
||||
# For backward compatibility, set PYTHON_INCLUDE_PATH, but make it internal.
|
||||
SET(PYTHON_INCLUDE_PATH "${PYTHON_INCLUDE_DIR}" CACHE INTERNAL
|
||||
SET(PYTHON_INCLUDE_PATH "${PYTHON_INCLUDE_DIR}" CACHE INTERNAL
|
||||
"Path to where Python.h is found (deprecated)")
|
||||
|
||||
|
||||
ENDFOREACH(_CURRENT_VERSION)
|
||||
|
||||
MARK_AS_ADVANCED(
|
||||
@ -103,7 +109,7 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibs DEFAULT_MSG PYTHON_LIBRARIES PYTHON
|
||||
|
||||
|
||||
# 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
|
||||
# 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 )
|
||||
GET_PROPERTY(_TARGET_SUPPORTS_SHARED_LIBS
|
||||
@ -148,7 +154,7 @@ FUNCTION(PYTHON_WRITE_MODULES_HEADER _filename)
|
||||
|
||||
SET(_filenameTmp "${_filename}.in")
|
||||
FILE(WRITE ${_filenameTmp} "/*Created by cmake, do not edit, changes will be lost*/\n")
|
||||
FILE(APPEND ${_filenameTmp}
|
||||
FILE(APPEND ${_filenameTmp}
|
||||
"#ifndef ${_nameUpper}
|
||||
#define ${_nameUpper}
|
||||
|
||||
@ -164,7 +170,7 @@ extern \"C\" {
|
||||
FILE(APPEND ${_filenameTmp} "extern void init${PYTHON_MODULE_PREFIX}${_currentModule}(void);\n\n")
|
||||
ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
||||
|
||||
FILE(APPEND ${_filenameTmp}
|
||||
FILE(APPEND ${_filenameTmp}
|
||||
"#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
@ -182,7 +188,7 @@ extern \"C\" {
|
||||
ENDFOREACH(_currentModule ${PY_STATIC_MODULES_LIST})
|
||||
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")
|
||||
|
||||
|
||||
# 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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user