Skip to content

fix(cmake): pybind11.pc prefix and CMP0190 default across reconfigure - #6165

Draft
henryiii wants to merge 2 commits into
pybind:masterfrom
henryiii:fix/cmake-pc-prefix-and-cmp0190
Draft

fix(cmake): pybind11.pc prefix and CMP0190 default across reconfigure#6165
henryiii wants to merge 2 commits into
pybind:masterfrom
henryiii:fix/cmake-pc-prefix-and-cmp0190

Conversation

@henryiii

@henryiii henryiii commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Two unrelated CMake fixes, one per commit, so they can be cherry-picked separately.

pybind11.pc prefix. The cmake_path(RELATIVE_PATH ...) branch gave the base directory as the literal string CMAKE_INSTALL_DATAROOTDIR instead of its value, so on CMake 3.20 and later the installed pybind11.pc had an empty prefix=. The relative path from the data root to the install prefix is also not what the .pc file needs, which is a path relative to ${pcfiledir}. The while() branch below already computes the correct value, so the cmake_path branch is removed and the loop is used for all CMake versions. With -DCMAKE_INSTALL_PREFIX=/opt/x the file now has prefix=${pcfiledir}/../.., and -DCMAKE_INSTALL_DATAROOTDIR=lib/foo/share gives prefix=${pcfiledir}/../../../...

CMP0190 default across reconfigure. The cross-compiling default used the marker _PYBIND11_USE_CROSSCOMPILING_DEFAULTED, which is not cached, while option() caches PYBIND11_USE_CROSSCOMPILING as OFF. On the second configure the marker was empty and the default became OFF. The default is now computed before option() and given as the option default, so the cache keeps it. An explicit -DPYBIND11_USE_CROSSCOMPILING=OFF is still respected. tools/pybind11Common.cmake keeps the same default for find_package() consumers, where the option does not exist.

Suggested changelog entry:

  • Fix the prefix= value in the installed pybind11.pc, which was empty with CMake 3.20 and later.
  • Keep the CMP0190 cross-compiling default for PYBIND11_USE_CROSSCOMPILING when CMake is configured a second time.

@henryiii
henryiii marked this pull request as draft September 2, 2026 17:48
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