diff options
author | David Gobbi <david.gobbi@gmail.com> | 2015-09-15 04:48:49 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2015-09-17 15:28:49 (GMT) |
commit | a9d32dffb9397ce98806176f759fea4e77acf076 (patch) | |
tree | 45134b7474bb95f0c6153350b487062b8053e274 /Modules | |
parent | ea2db3bb02b356ce46065789f60c1ed1a77eb995 (diff) | |
download | CMake-a9d32dffb9397ce98806176f759fea4e77acf076.zip CMake-a9d32dffb9397ce98806176f759fea4e77acf076.tar.gz CMake-a9d32dffb9397ce98806176f759fea4e77acf076.tar.bz2 |
FindPythonLibs: Match include dir to library version
This commit ensures that FindPythonLibs has found the library before
before the search for the include dir begins. The library prefix and
version can then be used to find the matching include dir.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindPythonLibs.cmake | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/Modules/FindPythonLibs.cmake b/Modules/FindPythonLibs.cmake index 1c8776b..1220860 100644 --- a/Modules/FindPythonLibs.cmake +++ b/Modules/FindPythonLibs.cmake @@ -150,26 +150,41 @@ foreach(_CURRENT_VERSION ${_Python_VERSIONS}) PATH_SUFFIXES python${_CURRENT_VERSION}/config ) - set(PYTHON_FRAMEWORK_INCLUDES) - if(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR) - foreach(dir ${Python_FRAMEWORKS}) - list(APPEND PYTHON_FRAMEWORK_INCLUDES - ${dir}/Versions/${_CURRENT_VERSION}/include) - endforeach() - endif() + # Don't search for include dir until library location is known + if(PYTHON_LIBRARY) + + # Use the library's install prefix as a hint + set(_Python_INCLUDE_PATH_HINT) + get_filename_component(_PREFIX ${PYTHON_LIBRARY} PATH) + get_filename_component(_PREFIX ${_PREFIX} PATH) + if(_PREFIX) + set(_Python_INCLUDE_PATH_HINT ${_PREFIX}/include) + endif() - find_path(PYTHON_INCLUDE_DIR - NAMES Python.h - PATHS - ${PYTHON_FRAMEWORK_INCLUDES} - [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include - [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include - PATH_SUFFIXES - python${_CURRENT_VERSION}mu - python${_CURRENT_VERSION}m - python${_CURRENT_VERSION}u - python${_CURRENT_VERSION} - ) + # Add framework directories to the search paths + set(PYTHON_FRAMEWORK_INCLUDES) + if(Python_FRAMEWORKS AND NOT PYTHON_INCLUDE_DIR) + foreach(dir ${Python_FRAMEWORKS}) + list(APPEND PYTHON_FRAMEWORK_INCLUDES + ${dir}/Versions/${_CURRENT_VERSION}/include) + endforeach() + endif() + + find_path(PYTHON_INCLUDE_DIR + NAMES Python.h + HINTS + ${_Python_INCLUDE_PATH_HINT} + PATHS + ${PYTHON_FRAMEWORK_INCLUDES} + [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include + [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/include + PATH_SUFFIXES + python${_CURRENT_VERSION}mu + python${_CURRENT_VERSION}m + python${_CURRENT_VERSION}u + python${_CURRENT_VERSION} + ) + endif() # For backward compatibility, set PYTHON_INCLUDE_PATH. set(PYTHON_INCLUDE_PATH "${PYTHON_INCLUDE_DIR}") @@ -187,6 +202,8 @@ foreach(_CURRENT_VERSION ${_Python_VERSIONS}) endif() endforeach() +unset(_Python_INCLUDE_PATH_HINT) + mark_as_advanced( PYTHON_DEBUG_LIBRARY PYTHON_LIBRARY |