Skip to content

Commit 2ec7e78

Browse files
committed
CMake: Skip snprintf(3) tests when cross-compiling.
Same as in libpcap.
1 parent f430932 commit 2ec7e78

File tree

2 files changed

+53
-48
lines changed

2 files changed

+53
-48
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
6161
Make illumos build warning-free.
6262
Makefile.in: Update the .c.o build rule (Remove hacks for old SunOS 4).
6363
Autoconf: fix buggy tests for ether_ntohost().
64+
CMake: Skip snprintf(3) tests when cross-compiling.
6465
Documentation:
6566
man: Clarify the "any" pseudo-interface further.
6667

CMakeLists.txt

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -491,56 +491,60 @@ else(STDLIBS_HAVE_GETSERVENT)
491491
endif(STDLIBS_HAVE_GETSERVENT)
492492
cmake_pop_check_state()
493493

494-
#
495-
# Require a proof of suitable snprintf(3), same as in Autoconf.
496-
#
497-
include(CheckCSourceRuns)
498-
check_c_source_runs("
499-
#include <stdio.h>
500-
#include <string.h>
501-
#include <inttypes.h>
502-
#include <sys/types.h>
503-
504-
int main()
505-
{
506-
char buf[100];
507-
uint64_t t = (uint64_t)1 << 32;
508-
509-
snprintf(buf, sizeof(buf), \"%zu\", sizeof(buf));
510-
if (strncmp(buf, \"100\", sizeof(buf)))
511-
return 1;
512-
513-
snprintf(buf, sizeof(buf), \"%zd\", -sizeof(buf));
514-
if (strncmp(buf, \"-100\", sizeof(buf)))
515-
return 2;
516-
517-
snprintf(buf, sizeof(buf), \"%\" PRId64, -t);
518-
if (strncmp(buf, \"-4294967296\", sizeof(buf)))
519-
return 3;
520-
521-
snprintf(buf, sizeof(buf), \"0o%\" PRIo64, t);
522-
if (strncmp(buf, \"0o40000000000\", sizeof(buf)))
523-
return 4;
524-
525-
snprintf(buf, sizeof(buf), \"0x%\" PRIx64, t);
526-
if (strncmp(buf, \"0x100000000\", sizeof(buf)))
527-
return 5;
528-
529-
snprintf(buf, sizeof(buf), \"%\" PRIu64, t);
530-
if (strncmp(buf, \"4294967296\", sizeof(buf)))
531-
return 6;
532-
533-
return 0;
534-
}
535-
536-
"
537-
SUITABLE_SNPRINTF
538-
)
539-
if(NOT SUITABLE_SNPRINTF)
540-
message(FATAL_ERROR
494+
if (NOT CMAKE_CROSSCOMPILING)
495+
#
496+
# Require a proof of suitable snprintf(3), same as in Autoconf.
497+
#
498+
include(CheckCSourceRuns)
499+
check_c_source_runs("
500+
#include <stdio.h>
501+
#include <string.h>
502+
#include <inttypes.h>
503+
#include <sys/types.h>
504+
505+
int main()
506+
{
507+
char buf[100];
508+
uint64_t t = (uint64_t)1 << 32;
509+
510+
snprintf(buf, sizeof(buf), \"%zu\", sizeof(buf));
511+
if (strncmp(buf, \"100\", sizeof(buf)))
512+
return 1;
513+
514+
snprintf(buf, sizeof(buf), \"%zd\", -sizeof(buf));
515+
if (strncmp(buf, \"-100\", sizeof(buf)))
516+
return 2;
517+
518+
snprintf(buf, sizeof(buf), \"%\" PRId64, -t);
519+
if (strncmp(buf, \"-4294967296\", sizeof(buf)))
520+
return 3;
521+
522+
snprintf(buf, sizeof(buf), \"0o%\" PRIo64, t);
523+
if (strncmp(buf, \"0o40000000000\", sizeof(buf)))
524+
return 4;
525+
526+
snprintf(buf, sizeof(buf), \"0x%\" PRIx64, t);
527+
if (strncmp(buf, \"0x100000000\", sizeof(buf)))
528+
return 5;
529+
530+
snprintf(buf, sizeof(buf), \"%\" PRIu64, t);
531+
if (strncmp(buf, \"4294967296\", sizeof(buf)))
532+
return 6;
533+
534+
return 0;
535+
}
536+
537+
"
538+
SUITABLE_SNPRINTF
539+
)
540+
if(NOT SUITABLE_SNPRINTF)
541+
message(FATAL_ERROR
541542
"The snprintf(3) implementation in this libc is not suitable,
542543
tcpdump would not work correctly even if it managed to compile."
543-
)
544+
)
545+
endif()
546+
else()
547+
message(STATUS "Skipped SUITABLE_SNPRINTF because cross-compiling.")
544548
endif()
545549

546550
check_function_exists(getopt_long HAVE_GETOPT_LONG)

0 commit comments

Comments
 (0)