]> The Tcpdump Group git mirrors - tcpdump/commitdiff
CMake: Skip snprintf(3) tests when cross-compiling.
authorDenis Ovsienko <[email protected]>
Tue, 17 Sep 2024 23:22:58 +0000 (00:22 +0100)
committerGuy Harris <[email protected]>
Mon, 16 Dec 2024 02:18:11 +0000 (18:18 -0800)
Same as in libpcap.

(cherry picked from commit 2ec7e78bacc1d211af8765af4b4675eb6f1532ef)

CMakeLists.txt

index 9de318a28c82402887247903c638284b61c82b8a..b72b3df42bfdd656fa183386fcb71acd02d8ffcd 100644 (file)
@@ -500,56 +500,60 @@ else(STDLIBS_HAVE_GETSERVENT)
 endif(STDLIBS_HAVE_GETSERVENT)
 cmake_pop_check_state()
 
-#
-# Require a proof of suitable snprintf(3), same as in Autoconf.
-#
-include(CheckCSourceRuns)
-check_c_source_runs("
-#include <stdio.h>
-#include <string.h>
-#include <inttypes.h>
-#include <sys/types.h>
-
-int main()
-{
-  char buf[100];
-  uint64_t t = (uint64_t)1 << 32;
-
-  snprintf(buf, sizeof(buf), \"%zu\", sizeof(buf));
-  if (strncmp(buf, \"100\", sizeof(buf)))
-    return 1;
-
-  snprintf(buf, sizeof(buf), \"%zd\", -sizeof(buf));
-  if (strncmp(buf, \"-100\", sizeof(buf)))
-    return 2;
-
-  snprintf(buf, sizeof(buf), \"%\" PRId64, -t);
-  if (strncmp(buf, \"-4294967296\", sizeof(buf)))
-    return 3;
-
-  snprintf(buf, sizeof(buf), \"0o%\" PRIo64, t);
-  if (strncmp(buf, \"0o40000000000\", sizeof(buf)))
-    return 4;
-
-  snprintf(buf, sizeof(buf), \"0x%\" PRIx64, t);
-  if (strncmp(buf, \"0x100000000\", sizeof(buf)))
-    return 5;
-
-  snprintf(buf, sizeof(buf), \"%\" PRIu64, t);
-  if (strncmp(buf, \"4294967296\", sizeof(buf)))
-    return 6;
-
-  return 0;
-}
-
-"
-    SUITABLE_SNPRINTF
-)
-if(NOT SUITABLE_SNPRINTF)
-    message(FATAL_ERROR
+if (NOT CMAKE_CROSSCOMPILING)
+    #
+    # Require a proof of suitable snprintf(3), same as in Autoconf.
+    #
+    include(CheckCSourceRuns)
+    check_c_source_runs("
+    #include <stdio.h>
+    #include <string.h>
+    #include <inttypes.h>
+    #include <sys/types.h>
+
+    int main()
+    {
+      char buf[100];
+      uint64_t t = (uint64_t)1 << 32;
+
+      snprintf(buf, sizeof(buf), \"%zu\", sizeof(buf));
+      if (strncmp(buf, \"100\", sizeof(buf)))
+        return 1;
+
+      snprintf(buf, sizeof(buf), \"%zd\", -sizeof(buf));
+      if (strncmp(buf, \"-100\", sizeof(buf)))
+        return 2;
+
+      snprintf(buf, sizeof(buf), \"%\" PRId64, -t);
+      if (strncmp(buf, \"-4294967296\", sizeof(buf)))
+        return 3;
+
+      snprintf(buf, sizeof(buf), \"0o%\" PRIo64, t);
+      if (strncmp(buf, \"0o40000000000\", sizeof(buf)))
+        return 4;
+
+      snprintf(buf, sizeof(buf), \"0x%\" PRIx64, t);
+      if (strncmp(buf, \"0x100000000\", sizeof(buf)))
+        return 5;
+
+      snprintf(buf, sizeof(buf), \"%\" PRIu64, t);
+      if (strncmp(buf, \"4294967296\", sizeof(buf)))
+        return 6;
+
+      return 0;
+    }
+
+    "
+        SUITABLE_SNPRINTF
+    )
+    if(NOT SUITABLE_SNPRINTF)
+        message(FATAL_ERROR
 "The snprintf(3) implementation in this libc is not suitable,
 tcpdump would not work correctly even if it managed to compile."
-    )
+        )
+    endif()
+else()
+    message(STATUS "Skipped SUITABLE_SNPRINTF because cross-compiling.")
 endif()
 
 check_function_exists(getopt_long HAVE_GETOPT_LONG)