From bbddaeef7e2c65994812ccee0a92744f4777175c Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Tue, 21 Feb 2012 20:52:27 +0100 Subject: [PATCH 1/5] FindPython{Interp,Libs}: document Python_ADDITIONAL_VERSIONS as input The current documentation could be read as if that variable is output from the module, which is nonsense. --- Modules/FindPythonInterp.cmake | 4 +++- Modules/FindPythonLibs.cmake | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Modules/FindPythonInterp.cmake b/Modules/FindPythonInterp.cmake index 5c1d56bbf..930f6756f 100644 --- a/Modules/FindPythonInterp.cmake +++ b/Modules/FindPythonInterp.cmake @@ -10,7 +10,9 @@ # PYTHON_VERSION_MINOR - Python minor version found e.g. 5 # PYTHON_VERSION_PATCH - Python patch version found e.g. 2 # -# Python_ADDITIONAL_VERSIONS - list of additional Python versions to search for +# 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(PythonInterp). #============================================================================= # Copyright 2005-2010 Kitware, Inc. diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake index da7a1ac93..049a36f3d 100644 --- a/Modules/FindPythonLibs.cmake +++ b/Modules/FindPythonLibs.cmake @@ -8,7 +8,10 @@ # 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 +# +# 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). #============================================================================= # Copyright 2001-2009 Kitware, Inc. From f7723786e7ecdd29a430df396d6cce64b9ccdcb6 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Tue, 21 Feb 2012 21:00:15 +0100 Subject: [PATCH 2/5] FindPythonLibs: make the version selection work as for PythonInterp --- Modules/FindPythonLibs.cmake | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake index 049a36f3d..8ba2d398c 100644 --- a/Modules/FindPythonLibs.cmake +++ b/Modules/FindPythonLibs.cmake @@ -30,11 +30,42 @@ INCLUDE(CMakeFindFrameworks) # Search for the python framework on Apple. CMAKE_FIND_FRAMEWORKS(Python) +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) + IF(NOT PythonLibs_FIND_VERSION_EXACT) + 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() + ENDIF(NOT PythonLibs_FIND_VERSION_EXACT) + 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) + # 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 +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) + ${_PYTHON_FIND_OTHER_VERSIONS} + ) + +UNSET(_PYTHON_FIND_OTHER_VERSIONS) +UNSET(_PYTHON1_VERSIONS) +UNSET(_PYTHON2_VERSIONS) +UNSET(_PYTHON3_VERSIONS) FOREACH(_CURRENT_VERSION ${_Python_VERSIONS}) STRING(REPLACE "." "" _CURRENT_VERSION_NO_DOTS ${_CURRENT_VERSION}) From c9c1a176092593ce7c47e7a473e24363d9395c79 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Tue, 21 Feb 2012 21:12:16 +0100 Subject: [PATCH 3/5] FindPythonLibs: get the exact version of the found library (#3080) --- Modules/FindPythonLibs.cmake | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake index 8ba2d398c..9401dbb58 100644 --- a/Modules/FindPythonLibs.cmake +++ b/Modules/FindPythonLibs.cmake @@ -8,6 +8,7 @@ # 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_VERSION_STRING - version of the Python libs found (since CMake 2.8.8) # # 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. @@ -126,6 +127,14 @@ FOREACH(_CURRENT_VERSION ${_Python_VERSIONS}) SET(PYTHON_INCLUDE_PATH "${PYTHON_INCLUDE_DIR}" CACHE INTERNAL "Path to where Python.h is found (deprecated)") + 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") + ENDFOREACH(_CURRENT_VERSION) MARK_AS_ADVANCED( @@ -144,8 +153,9 @@ SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}") INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibs DEFAULT_MSG PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS) - +FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibs + REQUIRED_VARS PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS + VERSION_VAR PYTHONLIBS_VERSION_STRING) # PYTHON_ADD_MODULE( src1 src2 ... srcN) is used to build modules for python. # PYTHON_WRITE_MODULES_HEADER() writes a header file you can include From 91d5a2a386051cb7903044267c5364402bbe190b Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Tue, 21 Feb 2012 21:40:02 +0100 Subject: [PATCH 4/5] FindPythonLibs: put debug libraries into PYTHON_LIBRARIES --- Modules/FindPythonLibs.cmake | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake index 9401dbb58..c9a240cb8 100644 --- a/Modules/FindPythonLibs.cmake +++ b/Modules/FindPythonLibs.cmake @@ -7,7 +7,7 @@ # 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_DEBUG_LIBRARIES - path to the debug library (deprecated) # PYTHONLIBS_VERSION_STRING - version of the Python libs found (since CMake 2.8.8) # # The Python_ADDITIONAL_VERSIONS variable can be used to specify a list of @@ -134,7 +134,6 @@ FOREACH(_CURRENT_VERSION ${_Python_VERSIONS}) PYTHONLIBS_VERSION_STRING "${python_version_str}") UNSET(python_version_str) ENDIF(PYTHON_INCLUDE_DIR AND EXISTS "${PYTHON_INCLUDE_DIR}/patchlevel.h") - ENDFOREACH(_CURRENT_VERSION) MARK_AS_ADVANCED( @@ -148,9 +147,18 @@ MARK_AS_ADVANCED( # library. We now set the variables listed by the documentation for this # module. SET(PYTHON_INCLUDE_DIRS "${PYTHON_INCLUDE_DIR}") -SET(PYTHON_LIBRARIES "${PYTHON_LIBRARY}") SET(PYTHON_DEBUG_LIBRARIES "${PYTHON_DEBUG_LIBRARY}") +# 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) INCLUDE(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibs From 53d02ea1eae3af89c6802f3f9c32c0284d6e3367 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Wed, 22 Feb 2012 17:25:08 +0100 Subject: [PATCH 5/5] FindPythonLibs: stop scanning when libraries are found --- Modules/FindPythonLibs.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake index c9a240cb8..fcd0838f1 100644 --- a/Modules/FindPythonLibs.cmake +++ b/Modules/FindPythonLibs.cmake @@ -134,6 +134,10 @@ FOREACH(_CURRENT_VERSION ${_Python_VERSIONS}) PYTHONLIBS_VERSION_STRING "${python_version_str}") UNSET(python_version_str) ENDIF(PYTHON_INCLUDE_DIR AND EXISTS "${PYTHON_INCLUDE_DIR}/patchlevel.h") + + IF(PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR) + BREAK() + ENDIF(PYTHON_LIBRARY AND PYTHON_INCLUDE_DIR) ENDFOREACH(_CURRENT_VERSION) MARK_AS_ADVANCED(