Skip to content

Commit

Permalink
pybind11.pc: use pcfiledir for relative destinations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mathstuf committed Aug 31, 2023
1 parent db412e6 commit ee95993
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,16 @@ if(PYBIND11_INSTALL)

# pkg-config support
if(NOT prefix_for_pc_file)
set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")
if(IS_ABSOLUTE "${CMAKE_INSTALL_DATAROOTDIR}")
set(prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}")
else()
set(pc_datarootdir "${CMAKE_INSTALL_DATAROOTDIR}")
set(prefix_for_pc_file "\${pcfiledir}/..")
while(pc_datarootdir)
get_filename_component(pc_datarootdir "${pc_datarootdir}" DIRECTORY)
string(APPEND prefix_for_pc_file "/..")
endwhile()
endif()
endif()
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/pybind11.pc.in"
Expand Down

0 comments on commit ee95993

Please sign in to comment.