From 94febacc1262977f03bd7462fe838599e37875c7 Mon Sep 17 00:00:00 2001 From: fliiiix Date: Fri, 15 Nov 2024 20:20:01 +0100 Subject: [PATCH] Only prepend $prefix for relative paths In cases where CMAKE_INSTALL_LIBDIR is already an absolut path adding a $prefix will be incorrect. See also issue on nix pkgs: https://github.com/NixOS/nixpkgs/issues/144170 And current workaround: https://github.com/NixOS/nixpkgs/blob/7eee17a8a5868ecf596bbb8c8beb527253ea8f4d/pkgs/development/libraries/magic-enum/default.nix#L21 --- cmake/GenPkgConfig/GenPkgConfig.cmake | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/cmake/GenPkgConfig/GenPkgConfig.cmake b/cmake/GenPkgConfig/GenPkgConfig.cmake index 28ef4a050..3cb4cd722 100644 --- a/cmake/GenPkgConfig/GenPkgConfig.cmake +++ b/cmake/GenPkgConfig/GenPkgConfig.cmake @@ -120,10 +120,23 @@ function(configure_pkg_config_file_vars TARGET _NAME _INSTALL_LIB_DIR _INSTALL_I string(REPLACE "," "$" NEEDS_LIBS_ESCAPED "${NEEDS_LIBS}") string(REPLACE ">" "$" NEEDS_LIBS_ESCAPED "${NEEDS_LIBS_ESCAPED}") - list(APPEND header "prefix=${CMAKE_INSTALL_PREFIX}") - list(APPEND header "$,${NEEDS_LIB_DIR}>,libdir=\${prefix}/${INSTALL_LIB_DIR},>") - list(APPEND header "$,includedir=\${prefix}/${INSTALL_INCLUDE_DIR},>") - + # Only use prefix if paths are not absolute like they are with nix + # See also: https://github.com/NixOS/nixpkgs/issues/144170 + if(IS_ABSOLUTE ${INSTALL_LIB_DIR} OR IS_ABSOLUTE ${INSTALL_INCLUDE_DIR}) + list(APPEND header "prefix=${CMAKE_INSTALL_PREFIX}") + endif() + + if(IS_ABSOLUTE ${INSTALL_LIB_DIR}) + list(APPEND header "$,${NEEDS_LIB_DIR}>,libdir=${INSTALL_LIB_DIR},>") + else() + list(APPEND header "$,${NEEDS_LIB_DIR}>,libdir=\${prefix}/${INSTALL_LIB_DIR},>") + endif() + + if(IS_ABSOLUTE ${INSTALL_INCLUDE_DIR}) + list(APPEND header "$,includedir=${INSTALL_INCLUDE_DIR},>") + else() + list(APPEND header "$,includedir=\${prefix}/${INSTALL_INCLUDE_DIR},>") + endif() list(APPEND libSpecific "Name: ${_NAME}") if(_DESCRIPTION)