Skip to content

Commit 7cc0ebb

Browse files
authored
fix: the CMake config in Python package had a hard coded path (#3144)
1 parent a0b9759 commit 7cc0ebb

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ if(PYBIND11_INSTALL)
203203
"${CMAKE_INSTALL_DATAROOTDIR}/cmake/${PROJECT_NAME}"
204204
CACHE STRING "install path for pybind11Config.cmake")
205205

206+
if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
207+
set(pybind11_INCLUDEDIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
208+
else()
209+
set(pybind11_INCLUDEDIR "\$\{PACKAGE_PREFIX_DIR\}/${CMAKE_INSTALL_INCLUDEDIR}")
210+
endif()
211+
206212
configure_package_config_file(
207213
tools/${PROJECT_NAME}Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
208214
INSTALL_DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR})

tests/extra_python_package/test_files.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ def test_build_sdist(monkeypatch, tmpdir):
138138
) as f:
139139
pyproject_toml = f.read()
140140

141+
with contextlib.closing(
142+
tar.extractfile(
143+
tar.getmember(
144+
start + "pybind11/share/cmake/pybind11/pybind11Config.cmake"
145+
)
146+
)
147+
) as f:
148+
contents = f.read().decode("utf8")
149+
assert 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")' in contents
150+
141151
files = {"pybind11/{}".format(n) for n in all_files}
142152
files |= sdist_files
143153
files |= {"pybind11{}".format(n) for n in local_sdist_files}
@@ -151,11 +161,11 @@ def test_build_sdist(monkeypatch, tmpdir):
151161
.substitute(version=version, extra_cmd="")
152162
.encode()
153163
)
154-
assert setup_py == contents
164+
assert setup_py == contents
155165

156166
with open(os.path.join(MAIN_DIR, "tools", "pyproject.toml"), "rb") as f:
157167
contents = f.read()
158-
assert pyproject_toml == contents
168+
assert pyproject_toml == contents
159169

160170

161171
def test_build_global_dist(monkeypatch, tmpdir):

tools/pybind11Config.cmake.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ Using ``find_package`` with version info is not recommended except for release v
201201
@PACKAGE_INIT@
202202

203203
# Location of pybind11/pybind11.h
204-
set(pybind11_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@")
204+
# This will be relative unless explicitly set as absolute
205+
set(pybind11_INCLUDE_DIR "@pybind11_INCLUDEDIR@")
205206

206207
set(pybind11_LIBRARY "")
207208
set(pybind11_DEFINITIONS USING_pybind11)

0 commit comments

Comments
 (0)