cmake/modules: avoid using distutils

to address following warning from python 3.9:

<string>:1: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
<string>:1: DeprecationWarning: The distutils.sysconfig module is deprecated, use sysconfig instead

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
This commit is contained in:
Kefu Chai 2022-03-25 23:06:46 +08:00
parent f0fc04fbea
commit 637dd7b404
2 changed files with 9 additions and 2 deletions

View File

@ -64,7 +64,7 @@ function(distutils_add_cython_module target name src)
set(PY_LDSHARED ${link_launcher} ${CMAKE_C_COMPILER} ${c_compiler_arg1} "-shared")
execute_process(COMMAND "${Python3_EXECUTABLE}" -c
"from distutils import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
RESULT_VARIABLE result
OUTPUT_VARIABLE ext_suffix
ERROR_VARIABLE error

View File

@ -32,7 +32,14 @@ endif(CMAKE_INSTALL_PREFIX)
execute_process(
COMMAND
${Python3_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(prefix='${PYTHON_INSTALL_TEMPLATE}'))"
${Python3_EXECUTABLE} -c
"import sysconfig;\
print(\
sysconfig.get_path(\
name='purelib',\
vars=\
{'base': '${PYTHON_INSTALL_TEMPLATE}',\
'py_version_short': sysconfig.get_config_var('py_version_short')}))"
OUTPUT_VARIABLE "PYTHON3_INSTDIR"
OUTPUT_STRIP_TRAILING_WHITESPACE)