From 02f8cf7af88cc75ed9751b400a4692fb32e0efaa Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 15 Nov 2023 16:12:29 -0500 Subject: [PATCH] chore: use 3.20's cmake_path if available --- CMakeLists.txt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 324964a554..3b1cba6660 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -282,11 +282,17 @@ if(PYBIND11_INSTALL) 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() + if(CMAKE_VERSION VERSION_LESS 3.20) + set(prefix_for_pc_file "\${pcfiledir}/..") + while(pc_datarootdir) + get_filename_component(pc_datarootdir "${pc_datarootdir}" DIRECTORY) + string(APPEND prefix_for_pc_file "/..") + endwhile() + else() + cmake_path(RELATIVE_PATH pcfiledir + BASE_DIRECTORY CMAKE_INSTALL_DATAROOTDIR + OUTPUT_VARIABLE prefix_for_pc_file) + endif() endif() endif() join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")