Skip to content

Commit

Permalink
[Exp PyROOT] Search for Python once again in SearchIntalledSoftware
Browse files Browse the repository at this point in the history
When PR #4279 was initially sent on Aug 25th, the search for Python was
moved to RootBuildMacros in order to avoid a build failure due ot the
search for another package and the declaration of one of the new CMake
variables.
This seem not to be a problem anymore (something changed in the
meantime?), so the search for Python can be put back to the original
place.
This could also fix the tests failing with cxx17 due to a mismatch
between Python executable and libraries.
  • Loading branch information
maxgalli authored and etejedor committed Dec 16, 2019
1 parent 7e47c42 commit c12a51a
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 105 deletions.
105 changes: 0 additions & 105 deletions cmake/modules/RootBuildOptions.cmake
Expand Up @@ -386,111 +386,6 @@ endforeach()
#---Avoid creating dependencies to 'non-standard' header files -------------------------------
include_regular_expression("^[^.]+$|[.]h$|[.]icc$|[.]hxx$|[.]hpp$")

#---Check for Python installation-------------------------------------------------------

message(STATUS "Looking for python")
unset(PYTHON_INCLUDE_DIR CACHE)
unset(PYTHON_LIBRARY CACHE)
unset(CMAKE_INSTALL_PYROOTDIR)
# Python is required by header and manpage generation

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)

# Determine whether we should prefer Python 2 or Python 3:
set(PYTHON_PREFER_VERSION "3")
# Check whether old `find_package(PythonInterp)` variable was passed.
# If so, it will be passed to find_package(Python) below. Otherwise,
# check what `python` points to: Python 2 or 3:
if(NOT PYTHON_EXECUTABLE)
find_program(PYTHON_BINARY_IN_PATH "python")
if(PYTHON_BINARY_IN_PATH)
execute_process(COMMAND ${PYTHON_BINARY_IN_PATH} -c "import sys;print(sys.version_info[0])"
OUTPUT_VARIABLE PYTHON_PREFER_VERSION
ERROR_VARIABLE PYTHON_PREFER_VERSION_ERR)
if(PYTHON_PREFER_VERSION_ERR)
message(WARNING "Unable to determine version of ${PYTHON_BINARY_IN_PATH}: ${PYTHON_PREFER_VERSION_ERR}")
endif()
string(STRIP "${PYTHON_PREFER_VERSION}" PYTHON_PREFER_VERSION)
endif()
endif()

if(python)
set(REQUIRED_PYTHON_Development Development)
endif()

message(STATUS "Preferring Python version ${PYTHON_PREFER_VERSION}")

if("${PYTHON_PREFER_VERSION}" MATCHES "2")
# Means PYTHON_EXECUTABLE wasn't defined.
if(PYTHON_INCLUDE_DIRS AND NOT Python2_INCLUDE_DIRS)
set(Python2_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS}")
endif()
if(PYTHON_LIBRARIES AND NOT Python2_LIBRARIES)
set(Python2_LIBRARIES "${PYTHON_LIBRARIES}")
endif()
find_package(Python2 COMPONENTS Interpreter ${REQUIRED_PYTHON_Development} REQUIRED)
if(Python2_Development_FOUND)
# Re-run, now with NumPy, but not required:
find_package(Python2 COMPONENTS Interpreter Development NumPy)
# Compat with find_package(PythonInterp), find_package(PythonLibs)
set(PYTHON_INCLUDE_DIRS "${Python2_INCLUDE_DIRS}")
set(PYTHON_LIBRARIES "${Python2_LIBRARIES}")
set(PYTHON_VERSION_STRING "${Python2_VERSION}")
set(PYTHON_VERSION_MAJOR "${Python2_VERSION_MAJOR}")
set(PYTHON_VERSION_MINOR "${Python2_VERSION_MINOR}")
set(NUMPY_FOUND ${Python2_NumPy_FOUND})
set(NUMPY_INCLUDE_DIRS "${Python2_NumPy_INCLUDE_DIRS}")
endif()
else()
if(PYTHON_EXECUTABLE AND NOT Python_EXECUTABLE)
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
endif()
if(PYTHON_INCLUDE_DIRS AND NOT Python_INCLUDE_DIRS)
set(Python_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS}")
endif()
if(PYTHON_LIBRARIES AND NOT Python_LIBRARIES)
set(Python_LIBRARIES "${PYTHON_LIBRARIES}")
endif()
find_package(Python COMPONENTS Interpreter ${REQUIRED_PYTHON_Development} REQUIRED)
if(Python_Development_FOUND)
# Re-run, now with NumPy, but not required:
find_package(Python COMPONENTS Interpreter Development NumPy)
# Compat with find_package(PythonInterp), find_package(PythonLibs), find_package(NumPy)
set(PYTHON_INCLUDE_DIRS "${Python_INCLUDE_DIRS}")
set(PYTHON_LIBRARIES "${Python_LIBRARIES}")
set(PYTHON_VERSION_STRING "${Python_VERSION}")
set(PYTHON_VERSION_MAJOR "${Python_VERSION_MAJOR}")
set(PYTHON_VERSION_MINOR "${Python_VERSION_MINOR}")
set(NUMPY_FOUND ${Python_NumPy_FOUND})
set(NUMPY_INCLUDE_DIRS "${Python_NumPy_INCLUDE_DIRS}")
endif()
endif()

else()
find_package(PythonInterp ${python_version} REQUIRED)

if(python)
find_package(PythonLibs ${python_version} REQUIRED)

if(NOT "${PYTHONLIBS_VERSION_STRING}" MATCHES "${PYTHON_VERSION_STRING}")
message(FATAL_ERROR "Version mismatch between Python interpreter (${PYTHON_VERSION_STRING})"
" and libraries (${PYTHONLIBS_VERSION_STRING}).\nROOT cannot work with this configuration. "
"Please specify only PYTHON_EXECUTABLE to CMake with an absolute path to ensure matching versions are found.")
endif()

find_package(NumPy)
endif()
endif()

# set variables necessary for MultiPython
set(python_dir "python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
if(WIN32)
set(py_localruntimedir ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${python_dir})
else()
set(py_localruntimedir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${python_dir})
endif()


#---Add Installation Variables------------------------------------------------------------------
include(RootInstallDirs)

Expand Down
104 changes: 104 additions & 0 deletions cmake/modules/SearchInstalledSoftware.cmake
Expand Up @@ -492,6 +492,110 @@ if(mathmore OR builtin_gsl)
endif()
endif()

#---Check for Python installation-------------------------------------------------------

message(STATUS "Looking for python")
unset(PYTHON_INCLUDE_DIR CACHE)
unset(PYTHON_LIBRARY CACHE)
unset(CMAKE_INSTALL_PYROOTDIR)
# Python is required by header and manpage generation

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)

# Determine whether we should prefer Python 2 or Python 3:
set(PYTHON_PREFER_VERSION "3")
# Check whether old `find_package(PythonInterp)` variable was passed.
# If so, it will be passed to find_package(Python) below. Otherwise,
# check what `python` points to: Python 2 or 3:
if(NOT PYTHON_EXECUTABLE)
find_program(PYTHON_BINARY_IN_PATH "python")
if(PYTHON_BINARY_IN_PATH)
execute_process(COMMAND ${PYTHON_BINARY_IN_PATH} -c "import sys;print(sys.version_info[0])"
OUTPUT_VARIABLE PYTHON_PREFER_VERSION
ERROR_VARIABLE PYTHON_PREFER_VERSION_ERR)
if(PYTHON_PREFER_VERSION_ERR)
message(WARNING "Unable to determine version of ${PYTHON_BINARY_IN_PATH}: ${PYTHON_PREFER_VERSION_ERR}")
endif()
string(STRIP "${PYTHON_PREFER_VERSION}" PYTHON_PREFER_VERSION)
endif()
endif()

if(python)
set(REQUIRED_PYTHON_Development Development)
endif()

message(STATUS "Preferring Python version ${PYTHON_PREFER_VERSION}")

if("${PYTHON_PREFER_VERSION}" MATCHES "2")
# Means PYTHON_EXECUTABLE wasn't defined.
if(PYTHON_INCLUDE_DIRS AND NOT Python2_INCLUDE_DIRS)
set(Python2_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS}")
endif()
if(PYTHON_LIBRARIES AND NOT Python2_LIBRARIES)
set(Python2_LIBRARIES "${PYTHON_LIBRARIES}")
endif()
find_package(Python2 COMPONENTS Interpreter ${REQUIRED_PYTHON_Development} REQUIRED)
if(Python2_Development_FOUND)
# Re-run, now with NumPy, but not required:
find_package(Python2 COMPONENTS Interpreter Development NumPy)
# Compat with find_package(PythonInterp), find_package(PythonLibs)
set(PYTHON_INCLUDE_DIRS "${Python2_INCLUDE_DIRS}")
set(PYTHON_LIBRARIES "${Python2_LIBRARIES}")
set(PYTHON_VERSION_STRING "${Python2_VERSION}")
set(PYTHON_VERSION_MAJOR "${Python2_VERSION_MAJOR}")
set(PYTHON_VERSION_MINOR "${Python2_VERSION_MINOR}")
set(NUMPY_FOUND ${Python2_NumPy_FOUND})
set(NUMPY_INCLUDE_DIRS "${Python2_NumPy_INCLUDE_DIRS}")
endif()
else()
if(PYTHON_EXECUTABLE AND NOT Python_EXECUTABLE)
set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}")
endif()
if(PYTHON_INCLUDE_DIRS AND NOT Python_INCLUDE_DIRS)
set(Python_INCLUDE_DIRS "${PYTHON_INCLUDE_DIRS}")
endif()
if(PYTHON_LIBRARIES AND NOT Python_LIBRARIES)
set(Python_LIBRARIES "${PYTHON_LIBRARIES}")
endif()
find_package(Python COMPONENTS Interpreter ${REQUIRED_PYTHON_Development} REQUIRED)
if(Python_Development_FOUND)
# Re-run, now with NumPy, but not required:
find_package(Python COMPONENTS Interpreter Development NumPy)
# Compat with find_package(PythonInterp), find_package(PythonLibs), find_package(NumPy)
set(PYTHON_INCLUDE_DIRS "${Python_INCLUDE_DIRS}")
set(PYTHON_LIBRARIES "${Python_LIBRARIES}")
set(PYTHON_VERSION_STRING "${Python_VERSION}")
set(PYTHON_VERSION_MAJOR "${Python_VERSION_MAJOR}")
set(PYTHON_VERSION_MINOR "${Python_VERSION_MINOR}")
set(NUMPY_FOUND ${Python_NumPy_FOUND})
set(NUMPY_INCLUDE_DIRS "${Python_NumPy_INCLUDE_DIRS}")
endif()
endif()

else()
find_package(PythonInterp ${python_version} REQUIRED)

if(python)
find_package(PythonLibs ${python_version} REQUIRED)

if(NOT "${PYTHONLIBS_VERSION_STRING}" MATCHES "${PYTHON_VERSION_STRING}")
message(FATAL_ERROR "Version mismatch between Python interpreter (${PYTHON_VERSION_STRING})"
" and libraries (${PYTHONLIBS_VERSION_STRING}).\nROOT cannot work with this configuration. "
"Please specify only PYTHON_EXECUTABLE to CMake with an absolute path to ensure matching versions are found.")
endif()

find_package(NumPy)
endif()
endif()

# set variables necessary for MultiPython
set(python_dir "python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
if(WIN32)
set(py_localruntimedir ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${python_dir})
else()
set(py_localruntimedir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${python_dir})
endif()

#---Check for OpenGL installation-------------------------------------------------------
if(opengl)
message(STATUS "Looking for OpenGL")
Expand Down

0 comments on commit c12a51a

Please sign in to comment.