summaryrefslogtreecommitdiffstats
path: root/Modules/FindPython
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2024-03-20 22:09:44 (GMT)
committerEven Rouault <even.rouault@spatialys.com>2024-03-21 15:07:49 (GMT)
commitdf551ee53875bbfc888d92c7c523c9b6b2154283 (patch)
tree691b1d7de72e613bf652c33044fd4d0bba872fe9 /Modules/FindPython
parent9ac78c777fb942b2b9c24cbeea36ca3cd202af53 (diff)
downloadCMake-df551ee53875bbfc888d92c7c523c9b6b2154283.zip
CMake-df551ee53875bbfc888d92c7c523c9b6b2154283.tar.gz
CMake-df551ee53875bbfc888d92c7c523c9b6b2154283.tar.bz2
FindPython: fix NumPy detection when Intel MKL library is installed
In an environment where both NumPy and a recent Intel MKL library are installed, the detection of numpy include directory fails because a 'import numpy' outputs a MKL related warning message on stdout... (namely "Intel MKL WARNING: Support of Intel(R) Advanced Vector Extensions (Intel(R) AVX) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library will use Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) instructions instead.") I've successfully tested the workaround mentioned at https://github.com/numpy/numpy/issues/23775#issuecomment-1923327310 which consists in setting the MKL_ENABLE_INSTRUCTIONS=SSE4_2 environment before importing numpy, hence this proposed workaround.
Diffstat (limited to 'Modules/FindPython')
-rw-r--r--Modules/FindPython/Support.cmake16
1 files changed, 16 insertions, 0 deletions
diff --git a/Modules/FindPython/Support.cmake b/Modules/FindPython/Support.cmake
index 08ab9c0..0256867 100644
--- a/Modules/FindPython/Support.cmake
+++ b/Modules/FindPython/Support.cmake
@@ -3782,6 +3782,14 @@ if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS AND ${_PYTHON_PREFIX}_Inte
endif()
endif()
+ # Workaround Intel MKL library outputting a message in stdout, which cause
+ # incorrect detection of numpy.get_include() and numpy.__version__
+ # See https://github.com/numpy/numpy/issues/23775
+ if(DEFINED ENV{MKL_ENABLE_INSTRUCTIONS})
+ set(_${_PYTHON_PREFIX}_BACKUP_ENV_VAR_MKL_ENABLE_INSTRUCTIONS ENV{MKL_ENABLE_INSTRUCTIONS})
+ endif()
+ set(ENV{MKL_ENABLE_INSTRUCTIONS} "SSE4_2")
+
if (NOT _${_PYTHON_PREFIX}_NumPy_INCLUDE_DIR)
execute_process(COMMAND ${${_PYTHON_PREFIX}_INTERPRETER_LAUNCHER} "${_${_PYTHON_PREFIX}_EXECUTABLE}" -c
"import sys\ntry: import numpy; sys.stdout.write(numpy.get_include())\nexcept:pass\n"
@@ -3822,6 +3830,14 @@ if ("NumPy" IN_LIST ${_PYTHON_PREFIX}_FIND_COMPONENTS AND ${_PYTHON_PREFIX}_Inte
set (${_PYTHON_PREFIX}_NumPy_FOUND FALSE)
endif()
+ # Restore previous value of MKL_ENABLE_INSTRUCTIONS
+ if(DEFINED _${_PYTHON_PREFIX}_BACKUP_ENV_VAR_MKL_ENABLE_INSTRUCTIONS)
+ set(ENV{MKL_ENABLE_INSTRUCTIONS} ${_${_PYTHON_PREFIX}_BACKUP_ENV_VAR_MKL_ENABLE_INSTRUCTIONS})
+ unset(_${_PYTHON_PREFIX}_BACKUP_ENV_VAR_MKL_ENABLE_INSTRUCTIONS)
+ else()
+ unset(ENV{MKL_ENABLE_INSTRUCTIONS})
+ endif()
+
if (${_PYTHON_PREFIX}_NumPy_FOUND)
unset (_${_PYTHON_PREFIX}_NumPy_REASON_FAILURE CACHE)