aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorWenzel Jakob <wenzel.jakob@epfl.ch>2021-09-24 13:03:57 +0200
committerWenzel Jakob <wenzel.jakob@epfl.ch>2021-09-24 17:42:06 +0200
commit409be8336f4c597bcca9d9eaa09df0abc065afff (patch)
tree3c2db5ff24c276418b3f69af433cb589c974c458 /tools
parent6ad3f874a797ed554b2fea82dd2b798826a83fa8 (diff)
downloadpybind11-409be8336f4c597bcca9d9eaa09df0abc065afff.tar.gz
CMake: react to python version changes
The new FindPython-based variant of the CMake scripts caches information about the chosen Python version that can become stale. For example, suppose I configure a simple pybind11-based project as follows ``` cmake -S . -B build -GNinja -DPython_ROOT=<path to python 3.8> ``` which will generate `my_extension.cpython-38-x86_64-linux-gnu.so`. A subsequent change to the python version like ``` cmake -S . -B build -GNinja -DPython_ROOT=<path to python 3.9> ``` does not update all necessary build system information. In particular, the compiled file is still called `my_extension.cpython-38-x86_64-linux-gnu.so`. This commit fixes the problem by detecting changes in `Python_EXECUTABLE` and re-running Python as needed. Note that the previous way of detecting Python does not seem to be affected, it always specifies the right suffix.
Diffstat (limited to 'tools')
-rw-r--r--tools/pybind11NewTools.cmake9
1 files changed, 9 insertions, 0 deletions
diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake
index a20803bc..b93f9145 100644
--- a/tools/pybind11NewTools.cmake
+++ b/tools/pybind11NewTools.cmake
@@ -82,6 +82,15 @@ if(NOT DEFINED ${_Python}_EXECUTABLE)
endif()
+if(NOT ${_Python}_EXECUTABLE STREQUAL PYTHON_EXECUTABLE_LAST)
+ # Detect changes to the Python version/binary in subsequent CMake runs, and refresh config if needed
+ unset(PYTHON_IS_DEBUG CACHE)
+ unset(PYTHON_MODULE_EXTENSION CACHE)
+ set(PYTHON_EXECUTABLE_LAST
+ "${${_Python}_EXECUTABLE}"
+ CACHE INTERNAL "Python executable during the last CMake run")
+endif()
+
if(NOT DEFINED PYTHON_IS_DEBUG)
# Debug check - see https://stackoverflow.com/questions/646518/python-how-to-detect-debug-Interpreter
execute_process(