From 1ff9793deee907efcbd4769fe99e133a9608a5f6 Mon Sep 17 00:00:00 2001 From: Theo Buehler Date: Fri, 2 Aug 2024 22:18:05 +0200 Subject: [PATCH] Switch to check_symbol_exists() in simplest cases There are a few exceptions. Some require _GNU_SOURCE, some are in the weird strings.h header, some are probably too new to be found in the standard locations. Fixes #1077 --- CMakeLists.txt | 39 ++++++++++++++++++++++----------------- apps/nc/CMakeLists.txt | 2 +- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 048f6cfe71..a7574afd9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,21 +200,23 @@ else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") endif() +# XXX - needs _GNU_SOURCE on linux check_function_exists(asprintf HAVE_ASPRINTF) if(HAVE_ASPRINTF) add_definitions(-DHAVE_ASPRINTF) endif() -check_function_exists(getopt HAVE_GETOPT) +check_symbol_exists(getopt "unistd.h" HAVE_GETOPT) if(HAVE_GETOPT) add_definitions(-DHAVE_GETOPT) endif() -check_function_exists(reallocarray HAVE_REALLOCARRAY) +check_symbol_exists(reallocarray "stdlib.h" HAVE_REALLOCARRAY) if(HAVE_REALLOCARRAY) add_definitions(-DHAVE_REALLOCARRAY) endif() +# XXX strcasecmp() is in strings.h which isn't available everywhere check_function_exists(strcasecmp HAVE_STRCASECMP) if(HAVE_STRCASECMP) add_definitions(-DHAVE_STRCASECMP) @@ -222,18 +224,18 @@ endif() # Emscripten's strlcat and strlcpy triggers ASAN errors if(NOT EMSCRIPTEN) - check_function_exists(strlcat HAVE_STRLCAT) + check_symbol_exists(strlcat "string.h" HAVE_STRLCAT) if(HAVE_STRLCAT) add_definitions(-DHAVE_STRLCAT) endif() - check_function_exists(strlcpy HAVE_STRLCPY) + check_symbol_exists(strlcpy "string.h" HAVE_STRLCPY) if(HAVE_STRLCPY) add_definitions(-DHAVE_STRLCPY) endif() endif() -check_function_exists(strndup HAVE_STRNDUP) +check_symbol_exists(strndup "string.h" HAVE_STRNDUP) if(HAVE_STRNDUP) add_definitions(-DHAVE_STRNDUP) endif() @@ -242,62 +244,64 @@ if(WIN32) set(HAVE_STRNLEN true) add_definitions(-DHAVE_STRNLEN) else() - check_function_exists(strnlen HAVE_STRNLEN) + check_symbol_exists(strnlen "string.h" HAVE_STRNLEN) if(HAVE_STRNLEN) add_definitions(-DHAVE_STRNLEN) endif() endif() -check_function_exists(strsep HAVE_STRSEP) +check_symbol_exists(strsep "string.h" HAVE_STRSEP) if(HAVE_STRSEP) add_definitions(-DHAVE_STRSEP) endif() -check_function_exists(strtonum HAVE_STRTONUM) +check_symbol_exists(strtonum "stdlib.h" HAVE_STRTONUM) if(HAVE_STRTONUM) add_definitions(-DHAVE_STRTONUM) endif() -check_function_exists(arc4random_buf HAVE_ARC4RANDOM_BUF) +check_symbol_exists(arc4random_buf "stdlib.h" HAVE_ARC4RANDOM_BUF) if(HAVE_ARC4RANDOM_BUF) add_definitions(-DHAVE_ARC4RANDOM_BUF) endif() -check_function_exists(arc4random_uniform HAVE_ARC4RANDOM_UNIFORM) +check_symbol_exists(arc4random_uniform "stdlib.h" HAVE_ARC4RANDOM_UNIFORM) if(HAVE_ARC4RANDOM_UNIFORM) add_definitions(-DHAVE_ARC4RANDOM_UNIFORM) endif() -check_function_exists(explicit_bzero HAVE_EXPLICIT_BZERO) +check_symbol_exists(explicit_bzero "string.h" HAVE_EXPLICIT_BZERO) if(HAVE_EXPLICIT_BZERO) add_definitions(-DHAVE_EXPLICIT_BZERO) endif() -check_function_exists(getauxval HAVE_GETAUXVAL) +check_symbol_exists(getauxval "sys/auxv.h" HAVE_GETAUXVAL) if(HAVE_GETAUXVAL) add_definitions(-DHAVE_GETAUXVAL) endif() +# XXX macos fails to find getentropy with check_symbol_exists() check_function_exists(getentropy HAVE_GETENTROPY) if(HAVE_GETENTROPY) add_definitions(-DHAVE_GETENTROPY) endif() -check_symbol_exists(getpagesize unistd.h HAVE_GETPAGESIZE) +check_symbol_exists(getpagesize "unistd.h" HAVE_GETPAGESIZE) if(HAVE_GETPAGESIZE) add_definitions(-DHAVE_GETPAGESIZE) endif() -check_function_exists(getprogname HAVE_GETPROGNAME) +check_symbol_exists(getprogname "stdlib.h" HAVE_GETPROGNAME) if(HAVE_GETPROGNAME) add_definitions(-DHAVE_GETPROGNAME) endif() -check_function_exists(syslog_r HAVE_SYSLOG_R) +check_symbol_exists(syslog_r "syslog.h stdarg.h" HAVE_SYSLOG_R) if(HAVE_SYSLOG_R) add_definitions(-DHAVE_SYSLOG_R) endif() +# XXX - needs _GNU_SOURCE on linux check_function_exists(syslog HAVE_SYSLOG) if(HAVE_SYSLOG) add_definitions(-DHAVE_SYSLOG) @@ -308,16 +312,17 @@ if(HAVE_TIMESPECSUB) add_definitions(-DHAVE_TIMESPECSUB) endif() -check_function_exists(timingsafe_bcmp HAVE_TIMINGSAFE_BCMP) +check_symbol_exists(timingsafe_bcmp "string.h" HAVE_TIMINGSAFE_BCMP) if(HAVE_TIMINGSAFE_BCMP) add_definitions(-DHAVE_TIMINGSAFE_BCMP) endif() -check_function_exists(timingsafe_memcmp HAVE_TIMINGSAFE_MEMCMP) +check_symbol_exists(timingsafe_memcmp "string.h" HAVE_TIMINGSAFE_MEMCMP) if(HAVE_TIMINGSAFE_MEMCMP) add_definitions(-DHAVE_TIMINGSAFE_MEMCMP) endif() +# XXX - needs _GNU_SOURCE on linux check_function_exists(memmem HAVE_MEMMEM) if(HAVE_MEMMEM) add_definitions(-DHAVE_MEMMEM) diff --git a/apps/nc/CMakeLists.txt b/apps/nc/CMakeLists.txt index 7bbdb025f0..d5f7813dba 100644 --- a/apps/nc/CMakeLists.txt +++ b/apps/nc/CMakeLists.txt @@ -22,7 +22,7 @@ else() set(NC_SRC ${NC_SRC} compat/accept4.c) endif() -check_function_exists(readpassphrase HAVE_READPASSPHRASE) +check_symbol_exists(readpassphrase "readpassphrase.h" HAVE_READPASSPHRASE) if(HAVE_READPASSPHRASE) add_definitions(-DHAVE_READPASSPHRASE) else()