From 83d30f0888d5e4a277f0e4833dc21bb8b64f5246 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sun, 15 May 2022 08:50:40 +0200 Subject: [PATCH] keep the path for pkg-config path if they are absolute Fixes #97 --- CMakeLists.txt | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae1d0220..52a1c142 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,8 +120,34 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ebml_export.h DESTINATION ${CMAKE_INST 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}) if (HAVE_WINAPIFAMILY_H) set(WINAPIFAMILY_PC -DHAVE_WINAPIFAMILY_H)