pybind / pybind/pybind11

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

Open
#5,937 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in CMakeLists.txt at the pybind11_system setting around line 90 and the target_include_directories() call around line 284. Reproduce the issue with add_subdirectory(), a parent global include directory such as /usr/include or /opt/homebrew/include, and an installed pybind11. Done means the parent include path no longer causes the installed headers to take precedence, with the chosen behavior validated against CMake's include-order rules.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.