Skip to content

Commit

Permalink
Only prepend $prefix for relative paths
Browse files Browse the repository at this point in the history
In cases where CMAKE_INSTALL_LIBDIR is already
an absolut path adding a $prefix will be incorrect.

See also issue on nix pkgs:
NixOS/nixpkgs#144170
And current workaround:
https://github.com/NixOS/nixpkgs/blob/7eee17a8a5868ecf596bbb8c8beb527253ea8f4d/pkgs/development/libraries/magic-enum/default.nix#L21
  • Loading branch information
fliiiix committed Nov 15, 2024
1 parent e046b69 commit 94febac
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions cmake/GenPkgConfig/GenPkgConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,23 @@ function(configure_pkg_config_file_vars TARGET _NAME _INSTALL_LIB_DIR _INSTALL_I
string(REPLACE "," "$<COMMA>" NEEDS_LIBS_ESCAPED "${NEEDS_LIBS}")
string(REPLACE ">" "$<ANGLE-R>" NEEDS_LIBS_ESCAPED "${NEEDS_LIBS_ESCAPED}")

list(APPEND header "prefix=${CMAKE_INSTALL_PREFIX}")
list(APPEND header "$<IF:$<OR:$<BOOL:${PUBLIC_LIBS}>,${NEEDS_LIB_DIR}>,libdir=\${prefix}/${INSTALL_LIB_DIR},>")
list(APPEND header "$<IF:$<BOOL:${PUBLIC_INCLUDES}>,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 "$<IF:$<OR:$<BOOL:${PUBLIC_LIBS}>,${NEEDS_LIB_DIR}>,libdir=${INSTALL_LIB_DIR},>")
else()
list(APPEND header "$<IF:$<OR:$<BOOL:${PUBLIC_LIBS}>,${NEEDS_LIB_DIR}>,libdir=\${prefix}/${INSTALL_LIB_DIR},>")
endif()

if(IS_ABSOLUTE ${INSTALL_INCLUDE_DIR})
list(APPEND header "$<IF:$<BOOL:${PUBLIC_INCLUDES}>,includedir=${INSTALL_INCLUDE_DIR},>")
else()
list(APPEND header "$<IF:$<BOOL:${PUBLIC_INCLUDES}>,includedir=\${prefix}/${INSTALL_INCLUDE_DIR},>")
endif()

list(APPEND libSpecific "Name: ${_NAME}")
if(_DESCRIPTION)
Expand Down

0 comments on commit 94febac

Please sign in to comment.