From e27a94596f2a1f5e04722a16165717cc6e891d36 Mon Sep 17 00:00:00 2001 From: will Date: Mon, 23 Jun 2025 10:56:58 +0100 Subject: [PATCH] build: add root dir to CMAKE_PREFIX_PATH Nix patches cmake to remove the root directory `/` from `CMAKE_SYSTEM_PREFIX_PATH`: https://github.com/NixOS/nixpkgs/blob/428b49b28ebc8938a6d9f6c540d32d7a06713972/pkgs/by-name/cm/cmake/001-search-path.diff#L10 Without this, and when using the toolchain for depends builds, cmake's `find_path()` and `find_package()` do not know where to find dependencies, causing issues like: https://github.com/bitcoin/bitcoin/issues/32428 Adding this path back via CMAKE_PREFIX_PATH is harmless on other systems, and fixes the toolchain for Nix users. We append the `/` dir a maximum of once, as the toolchain may be called repeatedly during builds. Co-authored-by: Russell Yanofsky Co-authored-by: josibake --- depends/toolchain.cmake.in | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/depends/toolchain.cmake.in b/depends/toolchain.cmake.in index a38cb6135b0..b2d02214003 100644 --- a/depends/toolchain.cmake.in +++ b/depends/toolchain.cmake.in @@ -92,6 +92,22 @@ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(QT_TRANSLATIONS_DIR "${CMAKE_CURRENT_LIST_DIR}/translations") +# The following is only necessary when using cmake from Nix or NixOS, because +# Nix patches cmake to remove the root directory `/` from +# CMAKE_SYSTEM_PREFIX_PATH. Adding it back is harmless on other platforms and +# necessary on Nix because without it cmake find_path, find_package, etc +# functions do not know where to look in CMAKE_FIND_ROOT_PATH for dependencies +# (https://github.com/bitcoin/bitcoin/issues/32428). +# +# TODO: longer term, it may be possible to use a dependency provider, which +# would bring the find_package calls completely under our control, making this +# patch unnecessary. +# +# Make sure we only append once, as this file may be called repeatedly. +if(NOT "/" IN_LIST CMAKE_PREFIX_PATH) + list(APPEND CMAKE_PREFIX_PATH "/") +endif() + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT CMAKE_HOST_APPLE) # The find_package(Qt ...) function internally uses find_library() # calls for all dependencies to ensure their availability.