Skip to content

Commit

Permalink
build(CMake): Fix pkg-config for absolute CMAKE_INSTALL_*DIR
Browse files Browse the repository at this point in the history
CMAKE_INSTALL_*DIR can be absolute, and in that case ${prefix} should
not be prepended.

See https://github.com/jtojnar/cmake-snips/?tab=readme-ov-file#concatenating-paths-when-building-pkg-config-files
  • Loading branch information
fgaz authored and BurningEnlightenment committed Oct 8, 2024
1 parent e815576 commit aa3e8ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,31 @@ install(FILES
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/blake3"
)

# Function for joining paths known from most languages
#
# SPDX-License-Identifier: (MIT OR CC0-1.0)
# Copyright 2020 Jan Tojnar
# https://github.com/jtojnar/cmake-snips
#
# Modelled after Python’s os.path.join
# https://docs.python.org/3.7/library/os.path.html#os.path.join
# Windows not supported
function(join_paths joined_path first_path_segment)
set(temp_path "${first_path_segment}")
foreach(current_segment IN LISTS ARGN)
if(NOT ("${current_segment}" STREQUAL ""))
if(IS_ABSOLUTE "${current_segment}")
set(temp_path "${current_segment}")
else()
set(temp_path "${temp_path}/${current_segment}")
endif()
endif()
endforeach()
set(${joined_path} "${temp_path}" PARENT_SCOPE)
endfunction()

join_paths(PKG_CONFIG_INSTALL_LIBDIR "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(PKG_CONFIG_INSTALL_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
configure_file(libblake3.pc.in libblake3.pc @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/libblake3.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
Expand Down
4 changes: 2 additions & 2 deletions c/libblake3.pc.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
prefix="@CMAKE_INSTALL_PREFIX@"
exec_prefix="${prefix}"
libdir="${prefix}/@CMAKE_INSTALL_LIBDIR@"
includedir="${prefix}/@CMAKE_INSTALL_INCLUDEDIR@"
libdir="@PKG_CONFIG_INSTALL_LIBDIR@"
includedir="@PKG_CONFIG_INSTALL_INCLUDEDIR@"

Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
Expand Down

0 comments on commit aa3e8ec

Please sign in to comment.