Skip to content

Commit 78cedd8

Browse files
committed
[DRAFT, WIP] Detect presence of flockfile
Just a dry-run at a possible implementation pending clarification on details. Fixes #4646
1 parent 9396f77 commit 78cedd8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ endif ()
128128
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/support/cmake")
129129

130130
include(CheckCXXCompilerFlag)
131+
include(CheckCXXSourceCompiles)
131132
include(JoinPaths)
132133

133134
if (FMT_MASTER_PROJECT AND NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
@@ -307,6 +308,18 @@ else ()
307308
message(WARNING "Feature cxx_std_11 is unknown for the CXX compiler")
308309
endif ()
309310

311+
check_cxx_source_compiles([[
312+
#include <stdio.h>
313+
int main() {
314+
// Use stdout just to prove we can pass a FILE* to it
315+
flockfile(stdout);
316+
funlockfile(stdout);
317+
return 0;
318+
}
319+
]] HAVE_FLOCKFILE_COMPILE_TEST)
320+
target_compile_definitions(fmt PRIVATE
321+
FMT_HAVE_FLOCKFILE_COMPILE_TEST=$<BOOL:HAVE_FLOCKFILE_COMPILE_TEST>)
322+
310323
# Set FMT_LIB_NAME for pkg-config fmt.pc. We cannot use the OUTPUT_NAME target
311324
# property because it's not set by default.
312325
set(FMT_LIB_NAME fmt)

include/fmt/format-inl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,11 @@ template <typename F> auto getc_unlocked(F* f) -> decltype(_fgetc_nolock(f)) {
14901490
#endif
14911491

14921492
#ifndef FMT_USE_FLOCKFILE
1493-
# define FMT_USE_FLOCKFILE 1
1493+
# ifdef FMT_HAVE_FLOCKFILE_COMPILE_TEST
1494+
# define FMT_USE_FLOCKFILE FMT_HAVE_FLOCKFILE_COMPILE_TEST
1495+
# else
1496+
# define FMT_USE_FLOCKFILE 1
1497+
# endif
14941498
#endif
14951499

14961500
template <typename F = FILE, typename Enable = void>

0 commit comments

Comments
 (0)