From 16a0276413f2c0c8a04694a8a8ecfe80498ad4dd Mon Sep 17 00:00:00 2001 From: silvanshade Date: Mon, 31 Mar 2025 14:18:59 -0600 Subject: [PATCH 1/3] Propagate tbb through pkg-config --- c/CMakeLists.txt | 23 +++++++++++++++++++++++ c/libblake3.pc.in | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt index c929d71f5..ba3b8559e 100644 --- a/c/CMakeLists.txt +++ b/c/CMakeLists.txt @@ -330,6 +330,29 @@ function(join_paths joined_path first_path_segment) set(${joined_path} "${temp_path}" PARENT_SCOPE) endfunction() +# In-place rewrite a list of strings `requires` into a comma separated string. +# +# TODO: Replace function with list(JOIN) when updating to CMake 3.12 +function(join_pkg_config_requires requires) + list(LENGTH ${requires} len) + set(idx 1) + foreach(req ${${requires}}) + string(APPEND acc ${req}) + if(idx LESS len) + string(APPEND acc ", ") + endif() + math(EXPR idx "${idx} + 1") + endforeach() + set(${requires} ${acc} PARENT_SCOPE) +endfunction() + +# calculate pkg-config requirements +if(BLAKE3_USE_TBB) + list(APPEND PKG_CONFIG_REQUIRES "tbb >= ${TBB_VERSION}") +endif() + +# pkg-config support +join_pkg_config_requires(PKG_CONFIG_REQUIRES) 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) diff --git a/c/libblake3.pc.in b/c/libblake3.pc.in index 06f2c7a9b..900913b1f 100644 --- a/c/libblake3.pc.in +++ b/c/libblake3.pc.in @@ -7,6 +7,6 @@ Name: @PROJECT_NAME@ Description: @PROJECT_DESCRIPTION@ Version: @PROJECT_VERSION@ -Requires: +Requires: @PKG_CONFIG_REQUIRES@ Libs: -L"${libdir}" -lblake3 Cflags: -I"${includedir}" @BLAKE3_PKGCONFIG_CFLAGS@ From 510ae9d5339b793b26e9311fba603b556e0bda53 Mon Sep 17 00:00:00 2001 From: silvanshade Date: Mon, 31 Mar 2025 17:48:45 -0600 Subject: [PATCH 2/3] Propagate tbb through CMake config --- c/blake3-config.cmake.in | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/c/blake3-config.cmake.in b/c/blake3-config.cmake.in index 071552be2..92cf395b8 100644 --- a/c/blake3-config.cmake.in +++ b/c/blake3-config.cmake.in @@ -1,5 +1,14 @@ @PACKAGE_INIT@ +include(CMakeFindDependencyMacro) + +# Remember TBB option state +set(BLAKE3_USE_TBB @BLAKE3_USE_TBB@) + +if(BLAKE3_USE_TBB) + find_dependency(TBB @TBB_VERSION@) +endif() + include("${CMAKE_CURRENT_LIST_DIR}/blake3-targets.cmake") -check_required_components(blake3) \ No newline at end of file +check_required_components(blake3) From 544cedf9ae97e619319b48ad20c89f9c26ac4618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Ga=C3=9Fmann?= Date: Wed, 2 Apr 2025 18:29:42 +0200 Subject: [PATCH 3/3] refactor: fix a few nits in the join function The `join_pkg_config_requires` function would misbehave in a few edge cases. Though these edge cases aren't triggered by our current usage. --- c/CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt index ba3b8559e..d7239832b 100644 --- a/c/CMakeLists.txt +++ b/c/CMakeLists.txt @@ -334,16 +334,17 @@ endfunction() # # TODO: Replace function with list(JOIN) when updating to CMake 3.12 function(join_pkg_config_requires requires) - list(LENGTH ${requires} len) + set(_requires "${${requires}}") # avoid shadowing issues, e.g. "${requires}"=len + list(LENGTH "${requires}" len) set(idx 1) - foreach(req ${${requires}}) - string(APPEND acc ${req}) + foreach(req IN LISTS _requires) + string(APPEND acc "${req}") if(idx LESS len) string(APPEND acc ", ") endif() math(EXPR idx "${idx} + 1") endforeach() - set(${requires} ${acc} PARENT_SCOPE) + set("${requires}" "${acc}" PARENT_SCOPE) endfunction() # calculate pkg-config requirements