diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c147ab3..60ad9cce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,26 +58,8 @@ else() endif() # load python and pybind11 +include(Python) include(pybind11) -if(CMAKE_VERSION VERSION_LESS 3.12.0) - if(Python_ROOT_DIR) - MESSAGE(WARNING "Python_ROOT_DIR is set but will be ignored by this version of CMake; set PYTHON_EXECUTABLE instead") - endif() - find_package(PythonInterp) - find_package(PythonLibs) - set(PYTHON_FOUND PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND) -else() - if(PYTHON_EXECUTABLE) - MESSAGE(WARNING "PYTHON_EXECUTABLE is set but will be ignored by this version of CMake; set Python_ROOT_DIR instead") - endif() - find_package(Python COMPONENTS Interpreter Development) - set(PYTHON_FOUND Python_Interpreter_FOUND AND Python_Development_FOUND) - set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}") - set(PYTHON_INCLUDE_DIRS "${Python_INCLUDE_DIRS}") - set(PYTHON_LIBRARIES "${Python_LIBRARIES}") - set(PYTHON_VERSION_MAJOR "${Python_VERSION_MAJOR}") - set(PYTHON_VERSION_MINOR "${Python_VERSION_MINOR}") -endif() # load project dependencies include(rk) diff --git a/cmake/Packages/Python.cmake b/cmake/Packages/Python.cmake index 9b1e6b16..c79b2874 100644 --- a/cmake/Packages/Python.cmake +++ b/cmake/Packages/Python.cmake @@ -2,14 +2,23 @@ IF(CMAKE_VERSION VERSION_LESS 3.12.0) IF(Python_ROOT_DIR) MESSAGE(WARNING "Python_ROOT_DIR is set but will be ignored by this version of CMake; set PYTHON_EXECUTABLE instead") ENDIF(Python_ROOT_DIR) - find_package(PythonInterp) - find_package(PythonLibs) + IF(PYTHON_VERSION) + find_package(PythonInterp ${PYTHON_VERSION}) + find_package(PythonLibs ${PYTHON_VERSION}) + ELSE(PYTHON_VERSION) + find_package(PythonInterp) + find_package(PythonLibs) + ENDIF(PYTHON_VERSION) set(PYTHON_FOUND PYTHONLIBS_FOUND AND PYTHONINTERP_FOUND) ELSE() IF(PYTHON_EXECUTABLE) MESSAGE(WARNING "PYTHON_EXECUTABLE is set but will be ignored by this version of CMake; set Python_ROOT_DIR instead") ENDIF(PYTHON_EXECUTABLE) - FIND_PACKAGE(Python COMPONENTS Interpreter Development) + IF(PYTHON_VERSION) + FIND_PACKAGE(Python ${PYTHON_VERSION} COMPONENTS Interpreter Development) + ELSE(PYTHON_VERSION) + FIND_PACKAGE(Python COMPONENTS Interpreter Development) + ENDIF(PYTHON_VERSION) SET(PYTHON_FOUND "${Python_FOUND}") SET(PYTHON_EXECUTABLE "${Python_EXECUTABLE}") SET(PYTHON_INCLUDE_DIRS "${Python_INCLUDE_DIRS}")