From fc62f8877c39e69e5221161b578293b67218fc20 Mon Sep 17 00:00:00 2001 From: Jim Hague Date: Thu, 27 May 2021 12:11:49 +0100 Subject: [PATCH] When cross-compiling, assume strptime() is POSIX unless told otherwise. But issue a warning when making that assumption. Add new option FORCE_COMPAT_STRPTIME to force the use of the compat version when cross-compiling and the target platform strptime() is not POSIX-compliant. Poster children for the latter are BSD platforms, including MacOS, where %t is not handled POSIXly. Fix #472 --- CMakeLists.txt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 811525d2..71e744e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,6 +166,8 @@ option(BUILD_LIBUV "Build libuv support library available." ON) option(USE_LIBIDN2 "Use libidn2 if available." ON) option(USE_GNUTLS "Use GnuTLS for TLS connections." OFF) +option(FORCE_COMPAT_STRPTIME "Force use of internal strptime when cross-compiling." OFF) + # Above names chosen for user consistency. Now define substituted names. set(REQ_DEBUG ${ENABLE_DEBUG_REQ}) set(SCHED_DEBUG ${ENABLE_DEBUG_SCHED}) @@ -533,8 +535,15 @@ set(STRPTIME_TEST_SOURCE "\n res = strptime(\"20070207111842\", \"%Y%m%d%H%M%S\", &tm);\n if (!res) return 1; return 0; }") -if (HAVE_STRPTIME AND NOT CMAKE_CROSSCOMPILING) - check_c_source_runs("${STRPTIME_TEST_SOURCE}" STRPTIME_WORKS) +if (HAVE_STRPTIME) + if (CMAKE_CROSSCOMPILING) + if (NOT FORCE_COMPAT_STRPTIME) + message(WARNING "Assuming strptime() is POSIX compliant with %t matching any white space. Specify FORCE_COMPAT_STRPTIME on non-compliant platforms e.g. BSD derived.") + set(STRPTIME_WORKS 1) + endif () + else () + check_c_source_runs("${STRPTIME_TEST_SOURCE}" STRPTIME_WORKS) + endif () endif () try_compile(HAVE___FUNC__