From 59c5cb0010268b7167b7390c39b7a6ce0f60cea2 Mon Sep 17 00:00:00 2001 From: JM Etancelin <jean-matthieu.etancelin@univ-pau.fr> Date: Mon, 15 Mar 2021 16:12:39 +0100 Subject: [PATCH] Fix cmake finding python3 --- CMakeLists.txt | 2 +- cmake/FindPythonFull.cmake | 109 ------------------------------------- 2 files changed, 1 insertion(+), 110 deletions(-) delete mode 100644 cmake/FindPythonFull.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 574912607..c25d53c4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -126,7 +126,7 @@ set(HYSOP_LINK_LIBRARIES CACHE INTERNAL "List of external libraries.") # ============= Python and its packages ============= # - Global setup (interp and lib) - -find_package(PythonFull REQUIRED) +find_package (Python COMPONENTS Interpreter Development) include(FindPythonModule) # - python packages - diff --git a/cmake/FindPythonFull.cmake b/cmake/FindPythonFull.cmake deleted file mode 100644 index ea4146b9c..000000000 --- a/cmake/FindPythonFull.cmake +++ /dev/null @@ -1,109 +0,0 @@ -#.rst: -# FindPythonFull -# -------------- -# -# Find python interpreter and all required libraries and headers. -# -# The default cmake find_package(PythonLibs) process does not work for us. -# -# Usage: -# find_package(PythonFull) -# -# This call will set the following variables : -# :: -# -# PYTHON_FOUND - True if Python executable, libraries and header were found -# PYTHON_EXECUTABLE - python interpreter (full path) -# PYTHON_VERSION_STRING - Python version found e.g. 2.5.2 -# PYTHON_LIBRARIES - full path to the python library -# PYTHON_INCLUDE_DIRS - full path to Python.h -# PYTHONLIBS_VERSION_STRING - version of the Python libs found -# -# By default, we search for the current active python version first. -# If you need another version, use -DPYTHON_EXECUTABLE=full-path-to-python-exe -# during cmake call. -# - -set(PYTHON_FOUND FALSE) - -# Does nothing if vars are already in cache -if(EXISTS "${PYTHON_INCLUDE_DIRS}" AND EXISTS "${PYTHON_LIBRARY}" AND EXISTS "${PYTHON_SITE_PACKAGES_DIR}") - set(PYTHON_FOUND TRUE) -else() - set(PYTHON_FOUND FALSE) - # --- Find python interpreter - set(Python_ADDITIONAL_VERSIONS 3.9 3.8) - find_package(PythonInterp) - - # --- Use distutils to explore python configuration corresponding to - # the python executable found. - find_file(_findpython explore_python_config.py PATHS ${CMAKE_MODULE_PATH}) - - execute_process( - COMMAND ${PYTHON_EXECUTABLE} ${_findpython} - OUTPUT_VARIABLE python_config - ) - - # --- Post-process distutils results - if(python_config) - string(REGEX REPLACE ".*exec_prefix:([^\n]+).*$" "\\1" PYTHON_PREFIX ${python_config}) - string(REGEX REPLACE ".*\nversion:([^\n]+).*$" "\\1" PYTHON_VERSION ${python_config}) - string(REGEX REPLACE ".*\npy_inc_dir:([^\n]+).*$" "\\1" PYTHON_INCLUDE_DIRS ${python_config}) - string(REGEX REPLACE ".*\npy_lib_dir:([^\n]+).*$" "\\1" PYTHON_LIBRARY_DIRS ${python_config}) - string(REGEX REPLACE ".*\nsite_packages_dir:([^\n]+).*$" "\\1" PYTHON_SITE_PACKAGES_DIR ${python_config}) - string(REGEX REPLACE "([0-9]+).([0-9]+)" "\\1\\2" PYTHON_VERSION_NO_DOTS ${PYTHON_VERSION}) - if(WIN32) - string(REPLACE "\\" "/" PYTHON_SITE_PACKAGES_DIR ${PYTHON_SITE_PACKAGES_DIR}) - string(REPLACE "\\" "/" PYTHON_PREFIX ${PYTHON_PREFIX}) - endif(WIN32) - - # --- Search python library corresponding to python exec. - find_library(PYTHON_LIBRARY - NAMES - python${PYTHON_VERSION_NO_DOTS} python${PYTHON_VERSION} - NO_DEFAULT_PATH - HINTS ${PYTHON_LIBRARY_DIRS} ${PYTHON_PREFIX} ${PYTHON_PREFIX}/lib/python${PYTHON_VERSION}/config ${PYTHON_PREFIX}/lib/python${PYTHON_VERSION}/config - PATH_SUFFIXES lib libs lib/${CMAKE_LIBRARY_ARCHITECTURE} ${CMAKE_LIBRARY_ARCHITECTURE}) - - set(PYTHON_LIBRARIES ${PYTHON_LIBRARY} CACHE FILEPATH "Python libraries" FORCE) - - set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} CACHE FILEPATH "Path to Python.h" FORCE) - - # --- Extract python library version for further checks. - if(PYTHON_INCLUDE_DIRS AND EXISTS "${PYTHON_INCLUDE_DIRS}/patchlevel.h") - file(STRINGS "${PYTHON_INCLUDE_DIRS}/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() - - endif() - - unset(PYTHON_FOUND) - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(Python - REQUIRED_VARS PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS PYTHON_EXECUTABLE - VERSION_VAR PYTHONLIBS_VERSION_STRING) - if(PYTHON_FOUND) - set(PYTHONFULL_FOUND TRUE) - if(NOT PythonFull_FIND_QUIETLY) - message("-- Found Python executable: ${PYTHON_EXECUTABLE}") - message("-- Found Python library: ${PYTHON_LIBRARIES}") - message("-- Python version is : ${PYTHON_VERSION_STRING}") - message("-- Python include dir is : ${PYTHON_INCLUDE_DIRS}") - message("-- Python Site package dir is : ${PYTHON_SITE_PACKAGES_DIR}\n") - endif() - else() - if(PythonFull_FIND_REQUIRED) - message(FATAL_ERROR "Could not find Python") - endif() - endif() - -endif() - -if(NOT PYTHONLIBS_VERSION_STRING VERSION_EQUAL PYTHON_VERSION_STRING) - display(PYTHONLIBS_VERSION_STRING) - display(PYTHON_VERSION_STRING) - message(FATAL_ERROR "Python library and executable versions do not match. Please check your python installation.") -endif() -- GitLab