Skip to content

Commit 8c53564

Browse files
committed
pybind11.pc: use pcfiledir for relative destinations
If the datarootdir is absolute, just use the absolute path directly. However, if it is relative, we can compute the prefix from the location of the `.pc` file itself. This allows the install to be relocatable.
1 parent db412e6 commit 8c53564

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,16 @@ if(PYBIND11_INSTALL)
278278

279279
# pkg-config support
280280
if(NOT prefix_for_pc_file)
281-
set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")
281+
if (IS_ABSOLUTE "${CMAKE_INSTALL_DATAROOTDIR}")
282+
set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")
283+
else ()
284+
set(pc_datarootdir "${CMAKE_INSTALL_DATAROOTDIR}")
285+
set(prefix_for_pc_file "\${pcfiledir}/..")
286+
while (pc_datarootdir)
287+
get_filename_component(pc_datarootdir "${pc_datarootdir}" DIRECTORY)
288+
string(APPEND prefix_for_pc_file "/..")
289+
endwhile ()
290+
endif ()
282291
endif()
283292
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
284293
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11.pc.in"

0 commit comments

Comments
 (0)