diff --git a/CMakeLists.txt b/CMakeLists.txt index cc47c96ed8d0..fc671c170fb9 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,21 @@ 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