From f5244973bd46edac7e750ea497cc6221224cfa1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= <159546+serprex@users.noreply.github.com> Date: Thu, 6 Aug 2026 18:36:38 +0000 Subject: [PATCH] Fix clang constexpr issues with system fmt (#7024) --- CMakeLists.txt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 663b507b28..a176a8b245 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -198,10 +198,26 @@ find_package(ZLIB REQUIRED) include(FetchContent) +# spdlog runs fmt's consteval format check in every log macro, and clang >= 21 rejects it as +# not constant with fmt < 11.1: FMT_STRING's compile string converts to two distinct literal +# objects, so the pointer subtraction fmt does while parsing crosses objects (#7017). Ignore a +# system spdlog built against such an fmt; the fetched one bundles fmt 12. +set(_use_system_spdlog ON) +if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" + AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "21.0") + find_package(fmt QUIET) + if(fmt_FOUND AND fmt_VERSION VERSION_LESS "11.1") + message(STATUS "clang ${CMAKE_CXX_COMPILER_VERSION} can't build against fmt ${fmt_VERSION}, fetching spdlog") + set(_use_system_spdlog OFF) + endif() +endif() + # Workaround: torch declares spdlog without OVERRIDE_FIND_PACKAGE and the first declaration # wins, which leaves libultraship's find_package(spdlog REQUIRED) with no config to find. # Declaring it here first keeps that working. See HarbourMasters/Torch#233. -find_package(spdlog QUIET) +if(_use_system_spdlog) + find_package(spdlog QUIET) +endif() if(NOT spdlog_FOUND) FetchContent_Declare( spdlog