In CMake, check for thousands-grouping support in the GLib printf routines.
authorGuy Harris <guy@alum.mit.edu>
Mon, 5 Jan 2015 01:43:19 +0000 (17:43 -0800)
committerGuy Harris <guy@alum.mit.edu>
Mon, 5 Jan 2015 01:44:12 +0000 (01:44 +0000)
We do that with the autotools; do it with CMake as well.

We could, in theory, handle thosands-grouping ourselves, on all
platforms supporting ANSI C (for which read "all platforms we care
about") by using localeconv()'s thousands_sep and grouping items, but
that's a bit more work.

Fix autotools' comment for that item while we're at it (it checks the
GLib printf routines, not the system printf routines).

Change-Id: I000f0f3b955d9b192ade15e3fabc46d6b48a052e
Reviewed-on: https://code.wireshark.org/review/6317
Reviewed-by: Guy Harris <guy@alum.mit.edu>
ConfigureChecks.cmake
cmakeconfig.h.in
configure.ac

index fcf3535d49819828baf31899ff937d0f24f3c5a3..d24f55213a3c068bdd4f0193e3d20bbb451ae713 100644 (file)
@@ -147,3 +147,34 @@ if (NL_FOUND)
                HAVE_NL80211_SPLIT_WIPHY_DUMP
        )
 endif()
+
+#
+# Check whether GLib's printf supports thousands grouping. (This might
+# be different from the system's printf since GLib can optionally use
+# its own printf implementation.)
+#
+if (CMAKE_CROSSCOMPILING)
+       #
+       # Play it safe when cross-compiling.
+       #
+       set(HAVE_GLIB_PRINTF_GROUPING FALSE)
+else()
+       cmake_push_check_state()
+       set(CMAKE_REQUIRED_INCLUDES ${GLIB2_INCLUDE_DIRS})
+       set(CMAKE_REQUIRED_LIBRARIES ${GLIB2_LIBRARIES})
+       check_c_source_runs(
+               "#include <glib.h>
+               #include <locale.h>
+               #include <stdio.h>
+               #include <string.h>
+
+               int
+               main ()
+               {
+                 gchar *str;
+                 setlocale(LC_ALL, \"en_US.UTF-8\");
+                 str = g_strdup_printf(\"%'u\", 123456);
+                 return (strcmp (str, \"123,456\") != 0);
+               }" HAVE_GLIB_PRINTF_GROUPING)
+       cmake_pop_check_state()
+endif()
index b334cd82bfe455c8b6bf2192e22c1e182ef6afb8..f90a561a51e981b25479e47ca47ecb1280068197 100644 (file)
@@ -78,6 +78,9 @@
 /* Define to 1 if you have the <getopt.h> header file. */
 #cmakedefine HAVE_GETOPT_H 1
 
+/* Define if GLib's printf functions support thousands grouping. */
+#cmakedefine HAVE_GLIB_PRINTF_GROUPING 1
+
 /* Define to 1 if you have the `getprotobynumber' function. */
 #cmakedefine HAVE_GETPROTOBYNUMBER 1
 
index 89a15d44478e32a1fca70b05762adc53bb9d9155..1194aa8e541800d6229e571abfe2196387054b04 100644 (file)
@@ -1880,7 +1880,7 @@ CFLAGS="$ac_save_CFLAGS"
 LIBS="$ac_save_LIBS"
 if test "$ac_cv_glib_supports_printf_grouping" = yes ; then
   AC_MSG_RESULT(yes)
-  AC_DEFINE(HAVE_GLIB_PRINTF_GROUPING, 1, [Define if your printf() function supports thousands grouping.])
+  AC_DEFINE(HAVE_GLIB_PRINTF_GROUPING, 1, [Define if GLib's printf functions support thousands grouping.])
 else
   AC_MSG_RESULT(no)
 fi