diff --git a/python.cmake b/python.cmake index cc043ddf7..66fe299fa 100644 --- a/python.cmake +++ b/python.cmake @@ -144,9 +144,16 @@ macro(FINDPYTHON) # Provide some hints according to the current PYTHON_EXECUTABLE if(NOT DEFINED PYTHON_INCLUDE_DIR) + if(_PYTHON_VERSION_MAJOR EQUAL "2") + set(PYTHON_INCLUDE_DIR_CMD + "import distutils.sysconfig as sysconfig; print(sysconfig.get_python_inc())" + ) + else() + set(PYTHON_INCLUDE_DIR_CMD + "import sysconfig; print(sysconfig.get_path('include'))") + endif() execute_process( - COMMAND "${PYTHON_EXECUTABLE}" "-c" - "import sysconfig; print(sysconfig.get_path('include'))" + COMMAND "${PYTHON_EXECUTABLE}" "-c" ${PYTHON_INCLUDE_DIR_CMD} OUTPUT_VARIABLE PYTHON_INCLUDE_DIR ERROR_QUIET) string(STRIP "${PYTHON_INCLUDE_DIR}" PYTHON_INCLUDE_DIR) @@ -215,9 +222,16 @@ macro(FINDPYTHON) # Retrieve the corresponding value of PYTHON_INCLUDE_DIR if it is not # defined if(NOT DEFINED PYTHON_INCLUDE_DIR) + if(_PYTHON_VERSION_MAJOR EQUAL "2") + set(PYTHON_INCLUDE_DIR_CMD + "import distutils.sysconfig as sysconfig; print(sysconfig.get_python_inc())" + ) + else() + set(PYTHON_INCLUDE_DIR_CMD + "import sysconfig; print(sysconfig.get_path('include'))") + endif() execute_process( - COMMAND "${PYTHON_EXECUTABLE}" "-c" - "import sysconfig; print(sysconfig.get_path('include'))" + COMMAND "${PYTHON_EXECUTABLE}" "-c" ${PYTHON_INCLUDE_DIR_CMD} OUTPUT_VARIABLE PYTHON_INCLUDE_DIR ERROR_QUIET) string(STRIP "${PYTHON_INCLUDE_DIR}" PYTHON_INCLUDE_DIR) @@ -269,9 +283,15 @@ macro(FINDPYTHON) "import sys, os; print(os.sep.join(['lib', 'python' + '.'.join(sys.version.split('.')[:2]), 'site-packages']))" ) else(PYTHON_STANDARD_LAYOUT) - set(PYTHON_SITELIB_CMD - "import sysconfig; from pathlib import Path; print(Path(sysconfig.get_path('purelib')).relative_to(sysconfig.get_path('data')))" - ) + if(_PYTHON_VERSION_MAJOR EQUAL "2") + set(PYTHON_SITELIB_CMD + "from distutils import sysconfig; print(sysconfig.get_python_lib(prefix='', plat_specific=False))" + ) + else() + set(PYTHON_SITELIB_CMD + "import sysconfig; from pathlib import Path; print(Path(sysconfig.get_path('purelib')).relative_to(sysconfig.get_path('data')))" + ) + endif() endif(PYTHON_STANDARD_LAYOUT) execute_process(