#5937·pybind11

[BUG]: CMake add_subdirectory() interference from system-installed pybind11

Author: mheistermannCreated Dec 15, 2025Updated Sep 3, 2026
Labelstriage

Required prerequisites

What version (or hash if on master) of pybind11 are you using?

d4f9cfbc2866f2156e1b17cb478a67088c6063f6

Problem description

When using pybind11 with add_subdirectory, pybind sets pybind11_system to SYSTEM and then uses this to pass SYSTEM to target_include_directories().

When this is combined with the parent project adding some global include folder like /usr/include or /opt/homebrew/include as a "normal" include directory, and a version of pybind11 is installed, that folder will take precedence over pybind11's own include folder (cf. CMake target_include_directories doc)

The result are strange compile errors in the best case.

I'd be happy to create a PR that either removes the SYSTEM argument or adds a CMake configuration option to disable it. Currently I am relying on an ugly workaround in our project.

Reproducible example code

Is this a regression? Put the last known working version here if it is.

Not a regression