From eab77a27c513f7c4c712528cca95eadd21c25fc5 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sun, 15 May 2022 08:52:16 +0200 Subject: [PATCH] keep the path for pkg-config path if they are absolute Fixes #62 --- CMakeLists.txt | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2d4f7d..07892c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,8 +104,34 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/matroska_export.h DESTINATION ${CMAKE_ if(NOT DISABLE_PKGCONFIG) set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix "\$\{prefix\}") - set(libdir "\$\{prefix\}/${CMAKE_INSTALL_LIBDIR}") - set(includedir "\$\{prefix\}/${CMAKE_INSTALL_INCLUDEDIR}") + if(${CMAKE_VERSION} VERSION_LESS "3.20.0") + get_filename_component(absdir ${CMAKE_INSTALL_LIBDIR} ABSOLUTE) + if (absdir STREQUAL CMAKE_INSTALL_LIBDIR) + set(abs_libdir ON) + else() + set(abs_libdir OFF) + endif() + get_filename_component(absdir ${CMAKE_INSTALL_INCLUDEDIR} ABSOLUTE) + if (absdir STREQUAL CMAKE_INSTALL_INCLUDEDIR) + set(abs_incdir ON) + else() + set(abs_incdir OFF) + endif() + else() + cmake_path(IS_ABSOLUTE CMAKE_INSTALL_LIBDIR abs_libdir) + cmake_path(IS_ABSOLUTE CMAKE_INSTALL_INCLUDEDIR abs_incdir) + endif() + if (${abs_libdir}) + set(libdir "${CMAKE_INSTALL_LIBDIR}") + else() + message(STATUS "using relative \$\{prefix\}/${CMAKE_INSTALL_LIBDIR}") + set(libdir "\$\{prefix\}/${CMAKE_INSTALL_LIBDIR}") + endif() + if (${abs_incdir}) + set(includedir "${CMAKE_INSTALL_INCLUDEDIR}") + else() + set(includedir "\$\{prefix\}/${CMAKE_INSTALL_INCLUDEDIR}") + endif() set(PACKAGE_VERSION ${PROJECT_VERSION}) configure_file(libmatroska.pc.in libmatroska.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libmatroska.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) -- 2.40.0