Skip to content
Snippets Groups Projects
Commit 7620bc75 authored by Marco Biasini's avatar Marco Biasini
Browse files

prefer versioned python binaries to non-versioned ones

On many systems, there are several parallel python
installations. There is usually a "python" symlink that
points to the currently active python version. That might
not be the one we need. Instead of picking up that one, we
now search for python$VERSION and as a last resort use
python.
parent 917295f7
No related branches found
No related tags found
No related merge requests found
...@@ -42,7 +42,7 @@ endmacro() ...@@ -42,7 +42,7 @@ endmacro()
macro(_find_python PYTHON_ROOT VERSION) macro(_find_python PYTHON_ROOT VERSION)
string(REPLACE "." "" _VERSION_NO_DOTS ${VERSION}) string(REPLACE "." "" _VERSION_NO_DOTS "${VERSION}")
if(PYTHON_ROOT) if(PYTHON_ROOT)
find_library(PYTHON_LIBRARIES find_library(PYTHON_LIBRARIES
NAMES "python${_VERSION_NO_DOTS}" "python${VERSION}" NAMES "python${_VERSION_NO_DOTS}" "python${VERSION}"
...@@ -69,17 +69,17 @@ macro(_find_python PYTHON_ROOT VERSION) ...@@ -69,17 +69,17 @@ macro(_find_python PYTHON_ROOT VERSION)
endmacro() endmacro()
macro(_find_python_bin PYTHON_ROOT VERSION) macro(_find_python_bin PYTHON_ROOT VERSION)
string(REPLACE "." "" _VERSION_NO_DOTS ${VERSION}) string(REPLACE "." "" _VERSION_NO_DOTS "${VERSION}")
if(PYTHON_ROOT) if(PYTHON_ROOT)
find_program(PYTHON_BINARY find_program(PYTHON_BINARY
NAMES "python" "python${_VERSION_NO_DOTS}" "python${VERSION}" NAMES "python${_VERSION_NO_DOTS}" "python${VERSION}"
HINTS "${PYTHON_ROOT}" HINTS "${PYTHON_ROOT}"
PATH_SUFFIXES bin PATH_SUFFIXES bin
NO_SYSTEM_ENVIRONMENT_PATH NO_DEFAULT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_DEFAULT_PATH
) )
else() else()
find_program(PYTHON_BINARY find_program(PYTHON_BINARY
NAMES "python" "python${_VERSION_NO_DOTS}" "python${VERSION}" NAMES "python${_VERSION_NO_DOTS}" "python${VERSION}"
HINTS "${CMAKE_PREFIX_PATH}" HINTS "${CMAKE_PREFIX_PATH}"
PATH_SUFFIXES bin PATH_SUFFIXES bin
) )
...@@ -105,6 +105,10 @@ macro(check_for_python_lib) ...@@ -105,6 +105,10 @@ macro(check_for_python_lib)
endif() endif()
endforeach() endforeach()
endif() endif()
# fallback to non-versioned naming scheme
if (NOT $PYTHON_LIBRARIES)
_find_python("${PYTHON_ROOT}" "")
endif()
endmacro() endmacro()
macro(check_for_python_binary) macro(check_for_python_binary)
...@@ -121,6 +125,9 @@ macro(check_for_python_binary) ...@@ -121,6 +125,9 @@ macro(check_for_python_binary)
endif() endif()
endforeach() endforeach()
endif() endif()
if (NOT PYTHON_BINARY)
_find_python("${PYTHON_ROOT}" "")
endif()
endmacro() endmacro()
if(NOT PYTHON_ROOT) if(NOT PYTHON_ROOT)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment