fix: allow cmake varibles from Python calls to be cached (#2570)

This commit is contained in:
Henry Schreiner 2020-10-09 17:33:45 -04:00 committed by GitHub
parent fecef38864
commit d46f3322a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,30 +80,38 @@ if(NOT DEFINED ${_Python}_EXECUTABLE)
endif() endif()
# Debug check - see https://stackoverflow.com/questions/646518/python-how-to-detect-debug-Interpreter if(NOT DEFINED PYTHON_IS_DEBUG)
execute_process( # Debug check - see https://stackoverflow.com/questions/646518/python-how-to-detect-debug-Interpreter
COMMAND "${${_Python}_EXECUTABLE}" "-c" "import sys; sys.exit(hasattr(sys, 'gettotalrefcount'))" execute_process(
RESULT_VARIABLE PYTHON_IS_DEBUG) COMMAND "${${_Python}_EXECUTABLE}" "-c"
"import sys; sys.exit(hasattr(sys, 'gettotalrefcount'))"
RESULT_VARIABLE _PYTHON_IS_DEBUG)
set(PYTHON_IS_DEBUG
"${_PYTHON_IS_DEBUG}"
CACHE INTERNAL "Python debug status")
endif()
# Get the suffix - SO is deprecated, should use EXT_SUFFIX, but this is # Get the suffix - SO is deprecated, should use EXT_SUFFIX, but this is
# required for PyPy3 (as of 7.3.1) # required for PyPy3 (as of 7.3.1)
execute_process( if(NOT DEFINED PYTHON_MODULE_EXTENSION)
execute_process(
COMMAND "${${_Python}_EXECUTABLE}" "-c" COMMAND "${${_Python}_EXECUTABLE}" "-c"
"from distutils import sysconfig; print(sysconfig.get_config_var('SO'))" "from distutils import sysconfig; print(sysconfig.get_config_var('SO'))"
OUTPUT_VARIABLE _PYTHON_MODULE_EXTENSION OUTPUT_VARIABLE _PYTHON_MODULE_EXTENSION
ERROR_VARIABLE _PYTHON_MODULE_EXTENSION_ERR ERROR_VARIABLE _PYTHON_MODULE_EXTENSION_ERR
OUTPUT_STRIP_TRAILING_WHITESPACE) OUTPUT_STRIP_TRAILING_WHITESPACE)
if(_PYTHON_MODULE_EXTENSION STREQUAL "") if(_PYTHON_MODULE_EXTENSION STREQUAL "")
message( message(
FATAL_ERROR "pybind11 could not query the module file extension, likely the 'distutils'" FATAL_ERROR "pybind11 could not query the module file extension, likely the 'distutils'"
"package is not installed. Full error message:\n${_PYTHON_MODULE_EXTENSION_ERR}") "package is not installed. Full error message:\n${_PYTHON_MODULE_EXTENSION_ERR}")
endif() endif()
# This needs to be available for the pybind11_extension function # This needs to be available for the pybind11_extension function
set(PYTHON_MODULE_EXTENSION set(PYTHON_MODULE_EXTENSION
"${_PYTHON_MODULE_EXTENSION}" "${_PYTHON_MODULE_EXTENSION}"
CACHE INTERNAL "") CACHE INTERNAL "")
endif()
# Python debug libraries expose slightly different objects before 3.8 # Python debug libraries expose slightly different objects before 3.8
# https://docs.python.org/3.6/c-api/intro.html#debugging-builds # https://docs.python.org/3.6/c-api/intro.html#debugging-builds