diff --git a/CMakeLists.txt b/CMakeLists.txt index 31b77bae8cd..772da1456d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,6 +113,14 @@ check_include_file("sys/stat.h" HAVE_SYS_STAT_H) check_include_file("sys/types.h" HAVE_SYS_TYPES_H) check_include_file("unistd.h" HAVE_UNISTD_H) +# types.h depends on HAVE_LIMITS_H, and it is defined in options.h (rather than +# config.h) so that applications consuming wolfSSL headers see it. The in-tree +# build, however, is configured through config.h/compile definitions and does +# not include options.h, so define it here as well. +if(HAVE_LIMITS_H) + add_definitions("-DHAVE_LIMITS_H") +endif() + include(CheckFunctionExists) # TODO: Also check if these functions are declared by the diff --git a/cmake/config.in b/cmake/config.in index f2524e41e43..6054b6dbe7b 100644 --- a/cmake/config.in +++ b/cmake/config.in @@ -19,9 +19,6 @@ /* Define to 1 if you have the `gmtime_r' function. */ #cmakedefine HAVE_GMTIME_R @HAVE_GMTIME_R@ -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_LIMITS_H @HAVE_LIMITS_H@ - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_PCAP_PCAP_H @HAVE_PCAP_PCAP_H@ diff --git a/cmake/options.h.in b/cmake/options.h.in index 967fe7b2ad1..dfdee642ca6 100644 --- a/cmake/options.h.in +++ b/cmake/options.h.in @@ -38,6 +38,9 @@ extern "C" { #undef _POSIX_THREADS #cmakedefine _POSIX_THREADS #endif +/* Since types.h depends on HAVE_LIMITS_H, we must define it in options.h. */ +#undef HAVE_LIMITS_H +#cmakedefine HAVE_LIMITS_H @HAVE_LIMITS_H@ #undef ASIO_USE_WOLFSSL #cmakedefine ASIO_USE_WOLFSSL #undef BOOST_ASIO_USE_WOLFSSL diff --git a/configure.ac b/configure.ac index 606ed241182..d12f09579a9 100644 --- a/configure.ac +++ b/configure.ac @@ -204,7 +204,9 @@ then fi fi -AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h stddef.h time.h sys/ioctl.h sys/socket.h sys/time.h errno.h sys/un.h ctype.h sys/random.h]) +AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stddef.h time.h sys/ioctl.h sys/socket.h sys/time.h errno.h sys/un.h ctype.h sys/random.h]) +# Special case: Since types.h depends on HAVE_LIMITS_H, we must define it in options.h. +AC_CHECK_HEADER([limits.h], [AM_CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIMITS_H=1"], []) AC_CHECK_LIB([network],[socket]) AC_C_BIGENDIAN AC_C___ATOMIC diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index cf8900f6ee0..3a1efb79556 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -231,6 +231,15 @@ typedef const char wcchar[]; (ULONG_MAX == 0xffffffffUL) #define SIZEOF_LONG 4 #endif + /* On LP64 (e.g. 64-bit Linux/macOS) long is 8 bytes. Detect it from the + * target's own limits.h so CTC_SETTINGS matches the library, which gets + * SIZEOF_LONG=8 from config.h. This must be derived per-target (not + * baked into options.h), so LLP64 targets such as Windows correctly get + * SIZEOF_LONG=4 from the branch above. */ + #if !defined(SIZEOF_LONG) && defined(ULONG_MAX) && \ + (ULONG_MAX == 0xffffffffffffffffULL) + #define SIZEOF_LONG 8 + #endif #if !defined(SIZEOF_LONG_LONG) && defined(ULLONG_MAX) && \ (ULLONG_MAX == 0xffffffffffffffffULL) #define SIZEOF_LONG_LONG 8