Skip to content

fix(cmake): unset stale PYTHON_MODULE_DEBUG_POSTFIX and correct USE_PYTHON_INCLUDE_DIR variable - #6086

Merged
henryiii merged 1 commit into
pybind:masterfrom
henryiii:fix/cmake-python-cache-and-includedir
Jul 23, 2026
Merged

fix(cmake): unset stale PYTHON_MODULE_DEBUG_POSTFIX and correct USE_PYTHON_INCLUDE_DIR variable#6086
henryiii merged 1 commit into
pybind:masterfrom
henryiii:fix/cmake-python-cache-and-includedir

Conversation

@henryiii

@henryiii henryiii commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Part of #6084

Summary

Two small CMake correctness fixes:

Fix 1 — stale PYTHON_MODULE_DEBUG_POSTFIX on interpreter change (tools/pybind11NewTools.cmake): When the Python executable changes between CMake runs, PYTHON_IS_DEBUG and PYTHON_MODULE_EXTENSION are unset from the cache to force recomputation, but PYTHON_MODULE_DEBUG_POSTFIX was not. The subsequent if(NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX) guard then skips recomputation and the stale postfix from the previous interpreter survives. The fix adds unset(PYTHON_MODULE_DEBUG_POSTFIX CACHE) alongside the other two unsets.

Fix 2 — variable mismatch in USE_PYTHON_INCLUDE_DIR (CMakeLists.txt): The elseif branch checked PYTHON_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}). A Python3_INCLUDE_DIRS branch is also added so USE_PYTHON_INCLUDE_DIR works when pybind11NewTools resolves Python via the Python3 component (the _Python variable is Python3 in that case, so the existing Python_INCLUDE_DIRS branch never matches).

Suggested changelog entry:

  • Unset stale PYTHON_MODULE_DEBUG_POSTFIX and correct USE_PYTHON_INCLUDE_DIR variable.

…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
@henryiii henryiii mentioned this pull request Jun 11, 2026
5 tasks
@henryiii
henryiii marked this pull request as ready for review June 11, 2026 22:51
@henryiii
henryiii merged commit 7478df9 into pybind:master Jul 23, 2026
106 checks passed
@henryiii
henryiii deleted the fix/cmake-python-cache-and-includedir branch July 23, 2026 05:40
@github-actions github-actions Bot added the needs changelog Possibly needs a changelog entry label Jul 23, 2026
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant