fix(cmake): unset stale PYTHON_MODULE_DEBUG_POSTFIX and correct USE_PYTHON_INCLUDE_DIR variable#6086
Open
henryiii wants to merge 1 commit into
Open
Conversation
…YTHON_INCLUDE_DIR variable
When the Python executable changes between CMake runs,
PYTHON_MODULE_DEBUG_POSTFIX was not being unset alongside PYTHON_IS_DEBUG
and PYTHON_MODULE_EXTENSION, allowing a stale postfix to survive interpreter
changes.
In the USE_PYTHON_INCLUDE_DIR block, the elseif branch checked
PYTHON_INCLUDE_DIR (singular) but expanded PYTHON_INCLUDE_DIRS (plural),
always silently resolving to an empty string. Correct it to expand
${PYTHON_INCLUDE_DIR}. Also add a Python3_INCLUDE_DIRS branch so the
option works when pybind11NewTools resolves Python via the Python3
find-package component.
Assisted-by: ClaudeCode:claude-fable-5
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
Part of #6084
Summary
Two small CMake correctness fixes:
Fix 1 — stale
PYTHON_MODULE_DEBUG_POSTFIXon interpreter change (tools/pybind11NewTools.cmake): When the Python executable changes between CMake runs,PYTHON_IS_DEBUGandPYTHON_MODULE_EXTENSIONare unset from the cache to force recomputation, butPYTHON_MODULE_DEBUG_POSTFIXwas not. The subsequentif(NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX)guard then skips recomputation and the stale postfix from the previous interpreter survives. The fix addsunset(PYTHON_MODULE_DEBUG_POSTFIX CACHE)alongside the other two unsets.Fix 2 — variable mismatch in
USE_PYTHON_INCLUDE_DIR(CMakeLists.txt): Theelseifbranch checkedPYTHON_INCLUDE_DIR(singular, the old FindPythonLibs variable) but then expanded${PYTHON_INCLUDE_DIRS}(plural), which is always empty in that path, silently installing headers to a wrong location. The fix uses the variable that was actually checked (${PYTHON_INCLUDE_DIR}). APython3_INCLUDE_DIRSbranch is also added soUSE_PYTHON_INCLUDE_DIRworks when pybind11NewTools resolves Python via thePython3component (the_Pythonvariable isPython3in that case, so the existingPython_INCLUDE_DIRSbranch never matches).