From 78cedd81a4dfe1ef1d870df5a5b80751739b35bd Mon Sep 17 00:00:00 2001 From: Mike Vastola Date: Wed, 8 Apr 2026 20:51:33 -0400 Subject: [PATCH 1/2] [DRAFT, WIP] Detect presence of flockfile Just a dry-run at a possible implementation pending clarification on details. Fixes fmtlib/fmt#4646 --- CMakeLists.txt | 13 +++++++++++++ include/fmt/format-inl.h | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc47c96ed8d0..ec224a942e40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,6 +128,7 @@ endif () list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/support/cmake") include(CheckCXXCompilerFlag) +include(CheckCXXSourceCompiles) include(JoinPaths) if (FMT_MASTER_PROJECT AND NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET) @@ -307,6 +308,18 @@ else () message(WARNING "Feature cxx_std_11 is unknown for the CXX compiler") endif () +check_cxx_source_compiles([[ + #include + int main() { + // Use stdout just to prove we can pass a FILE* to it + flockfile(stdout); + funlockfile(stdout); + return 0; + } +]] HAVE_FLOCKFILE_COMPILE_TEST) +target_compile_definitions(fmt PRIVATE + FMT_HAVE_FLOCKFILE_COMPILE_TEST=$) + # Set FMT_LIB_NAME for pkg-config fmt.pc. We cannot use the OUTPUT_NAME target # property because it's not set by default. set(FMT_LIB_NAME fmt) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index cc11019876bd..b679fd505248 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -1490,7 +1490,11 @@ template auto getc_unlocked(F* f) -> decltype(_fgetc_nolock(f)) { #endif #ifndef FMT_USE_FLOCKFILE -# define FMT_USE_FLOCKFILE 1 +# ifdef FMT_HAVE_FLOCKFILE_COMPILE_TEST +# define FMT_USE_FLOCKFILE FMT_HAVE_FLOCKFILE_COMPILE_TEST +# else +# define FMT_USE_FLOCKFILE 1 +# endif #endif template From 7605e0ba7c9fab062b89ff15678567c6bbeea5f4 Mon Sep 17 00:00:00 2001 From: Mike Vastola Date: Thu, 9 Apr 2026 15:17:09 -0400 Subject: [PATCH 2/2] Apply suggested format changes --- CMakeLists.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ec224a942e40..fc671c170fb9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,7 +308,8 @@ else () message(WARNING "Feature cxx_std_11 is unknown for the CXX compiler") endif () -check_cxx_source_compiles([[ +check_cxx_source_compiles( + [[ #include int main() { // Use stdout just to prove we can pass a FILE* to it @@ -316,9 +317,11 @@ check_cxx_source_compiles([[ funlockfile(stdout); return 0; } -]] HAVE_FLOCKFILE_COMPILE_TEST) -target_compile_definitions(fmt PRIVATE - FMT_HAVE_FLOCKFILE_COMPILE_TEST=$) +]] + HAVE_FLOCKFILE_COMPILE_TEST) +target_compile_definitions( + fmt + PRIVATE FMT_HAVE_FLOCKFILE_COMPILE_TEST=$) # Set FMT_LIB_NAME for pkg-config fmt.pc. We cannot use the OUTPUT_NAME target # property because it's not set by default.