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 committed Sep 6, 2024
1 parent 60ff2ea commit 1169f56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
# For cmake_path function
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)

# respect C_EXTENSIONS OFF without explicitly setting C_STANDARD
if (POLICY CMP0128)
Expand Down Expand Up @@ -229,6 +230,8 @@ install(FILES
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/blake3"
)

cmake_path(APPEND libdir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
cmake_path(APPEND includedir_for_pc_file "\${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="@libdir_for_pc_file@"
includedir="@includedir_for_pc_file@"

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

0 comments on commit 1169f56

Please sign in to comment.