FindPythonLibs: Find the python.org libraries (#14809)

Address the test case

  cmake_minimum_required(VERSION 2.8)
  set(Python_ADDITIONAL_VERSIONS 3.4 3.5 3.6)
  find_package(PythonLibs 3 REQUIRED)

with a Python 3.4.x .pkg installed from python.org on OSX.

Temporarily set CMAKE_FIND_FRAMEWORK to LAST to avoid finding the
system Python.h prematurely.

Add directories inside the frameworks to the search list for the library
as is done for the header.
This commit is contained in:
Matt McCormick 2015-07-02 11:21:08 -04:00 committed by Brad King
parent 74c99d11bc
commit 02fd035689
1 changed files with 32 additions and 7 deletions

View File

@ -53,6 +53,15 @@ include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindFrameworks.cmake)
# Search for the python framework on Apple.
CMAKE_FIND_FRAMEWORKS(Python)
# Save CMAKE_FIND_FRAMEWORK
if(DEFINED CMAKE_FIND_FRAMEWORK)
set(_PythonLibs_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
else()
unset(_PythonLibs_CMAKE_FIND_FRAMEWORK)
endif()
# To avoid picking up the system Python.h pre-maturely.
set(CMAKE_FIND_FRAMEWORK LAST)
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.4 3.3 3.2 3.1 3.0)
@ -111,14 +120,22 @@ foreach(_CURRENT_VERSION ${_Python_VERSIONS})
)
endif()
set(PYTHON_FRAMEWORK_LIBRARIES)
if(Python_FRAMEWORKS AND NOT PYTHON_LIBRARY)
foreach(dir ${Python_FRAMEWORKS})
list(APPEND PYTHON_FRAMEWORK_LIBRARIES
${dir}/Versions/${_CURRENT_VERSION}/lib)
endforeach()
endif()
find_library(PYTHON_LIBRARY
NAMES
python${_CURRENT_VERSION_NO_DOTS}
python${_CURRENT_VERSION}mu
python${_CURRENT_VERSION}m
python${_CURRENT_VERSION}u
python${_CURRENT_VERSION}
python${_CURRENT_VERSION_NO_DOTS}
python${_CURRENT_VERSION}mu
python${_CURRENT_VERSION}m
python${_CURRENT_VERSION}u
python${_CURRENT_VERSION}
PATHS
${PYTHON_FRAMEWORK_LIBRARIES}
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
[HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
# Avoid finding the .dll in the PATH. We want the .lib.
@ -143,8 +160,8 @@ foreach(_CURRENT_VERSION ${_Python_VERSIONS})
set(PYTHON_FRAMEWORK_INCLUDES)
if(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR)
foreach(dir ${Python_FRAMEWORKS})
set(PYTHON_FRAMEWORK_INCLUDES ${PYTHON_FRAMEWORK_INCLUDES}
${dir}/Versions/${_CURRENT_VERSION}/include/python${_CURRENT_VERSION})
list(APPEND PYTHON_FRAMEWORK_INCLUDES
${dir}/Versions/${_CURRENT_VERSION}/include/python${_CURRENT_VERSION})
endforeach()
endif()
@ -201,6 +218,14 @@ SELECT_LIBRARY_CONFIGURATIONS(PYTHON)
# for historical reasons.
unset(PYTHON_FOUND)
# Restore CMAKE_FIND_FRAMEWORK
if(DEFINED _PythonLibs_CMAKE_FIND_FRAMEWORK)
set(CMAKE_FIND_FRAMEWORK ${_PythonLibs_CMAKE_FIND_FRAMEWORK})
unset(_PythonLibs_CMAKE_FIND_FRAMEWORK)
else()
unset(CMAKE_FIND_FRAMEWORK)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PythonLibs
REQUIRED_VARS PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS