X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/21f46b9600c4886b83dd2dbc4db1efb2bfdc722d..refs/pull/1036/head:/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a915c32..fa865703 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ if(WIN32) # # We need 3.12 or later, so that we can set policy CMP0074; see # below. + # cmake_minimum_required(VERSION 3.12) else(WIN32) # @@ -85,7 +86,13 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) # -# OK, this is a royal pain. +# We explicitly indicate what languages are used in tcpdump to avoid +# checking for a C++ compiler. +# +# One reason to avoid that check is that there's no need to waste +# configuration time performing it. +# +# Another reason is that: # # CMake will try to determine the sizes of some data types, including # void *, early in the process of configuration; apparently, it's done @@ -111,24 +118,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) # building 32-bit, the size for C++ will win, and, again, hilarity # will ensue. # -# So we *explicitly* state that only C is used; there is currently no -# C++ code in tcpdump. -# project(tcpdump C) -if(CMAKE_SYSTEM_NAME STREQUAL "Haiku") - # - # Due to Haiku bug 18258, it is difficult if not impossible - # to get Clang to be usable as a compiler for CMake projects. - # - # If CMAKE_SIZEOF_VOID_P is undefined, we assume that means - # that the attempt to determine the compiler ABI failed, due - # the the consequences of that bug, and tell the user that - # this compiler doesn't work wel with CMake on Haiku - # - if(NOT CMAKE_SIZEOF_VOID_P) - message(FATAL_ERROR "${CMAKE_C_COMPILER} does not work well on Haiku for projects using CMake") - endif() -endif() # # For checking if a compiler flag works and adding it if it does. @@ -349,7 +339,6 @@ endif(HAVE_RPC_RPC_H) # check_function_exists(strlcat HAVE_STRLCAT) check_function_exists(strlcpy HAVE_STRLCPY) -check_function_exists(strdup HAVE_STRDUP) check_function_exists(strsep HAVE_STRSEP) # @@ -415,20 +404,68 @@ endif(STDLIBS_HAVE_GETSERVENT) cmake_pop_check_state() # -# Make sure we have vsnprintf() and snprintf(); we require them. -# We use check_symbol_exists(), as they aren't necessarily external -# functions - in Visual Studio, for example, they're inline functions -# calling a common external function. +# Make sure we have snprintf(); we require it. +# We use check_symbol_exists(), as it isn't necessarily an external +# function - in Visual Studio, for example, it is an inline function +# calling an external function. # -check_symbol_exists(vsnprintf "stdio.h" HAVE_VSNPRINTF) -if(NOT HAVE_VSNPRINTF) - message(FATAL_ERROR "vsnprintf() is required but wasn't found") -endif(NOT HAVE_VSNPRINTF) check_symbol_exists(snprintf "stdio.h" HAVE_SNPRINTF) if(NOT HAVE_SNPRINTF) message(FATAL_ERROR "snprintf() is required but wasn't found") endif() +# +# Require a proof of suitable snprintf(3), same as in Autoconf. +# +include(CheckCSourceRuns) +check_c_source_runs(" +#include +#include +#include +#include + +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() + check_function_exists(getopt_long HAVE_GETOPT_LONG) check_function_exists(setlinebuf HAVE_SETLINEBUF) # @@ -596,22 +633,10 @@ cmake_pop_check_state() # # -# Check for IPv6 support. -# We just check for AF_INET6 and struct in6_addr. +# FIXME: This check does not influence the build logic, but without it CMake +# 3.18.4 fails trying to make the next check_type_size() check later on. # -cmake_push_check_state() -if(WIN32) - set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h ws2tcpip.h) - check_symbol_exists(AF_INET6 "sys/types.h;ws2tcpip.h" HAVE_AF_INET6) -else(WIN32) - set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h sys/socket.h netinet/in.h) - check_symbol_exists(AF_INET6 "sys/types.h;sys/socket.h;netinet/in.h" HAVE_AF_INET6) -endif(WIN32) check_type_size("struct in6_addr" HAVE_STRUCT_IN6_ADDR) -cmake_pop_check_state() -if(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR) - set(HAVE_OS_IPV6_SUPPORT TRUE) -endif(HAVE_AF_INET6 AND HAVE_STRUCT_IN6_ADDR) ###################################### # External dependencies @@ -1223,7 +1248,7 @@ set(NETDISSECT_SOURCE_LIST_C # # Replace missing functions # -foreach(FUNC strlcat strlcpy strdup strsep getservent getopt_long) +foreach(FUNC strlcat strlcpy strsep getservent getopt_long) string(TOUPPER ${FUNC} FUNC_UPPERCASE) set(HAVE_FUNC_UPPERCASE HAVE_${FUNC_UPPERCASE}) if(NOT ${HAVE_FUNC_UPPERCASE})