Skip to content

Commit 588bab6

Browse files
Fix HAVE_LIMITS_H definition in CMake. Also move SIZEOF_LONG and SIZEOF_LONG_LONG definitions to options.h.
1 parent 9328c2c commit 588bab6

4 files changed

Lines changed: 34 additions & 7 deletions

File tree

CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
113113
check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
114114
check_include_file("unistd.h" HAVE_UNISTD_H)
115115

116+
# types.h depends on HAVE_LIMITS_H, and it is defined in options.h (rather than
117+
# config.h) so that applications consuming wolfSSL headers see it. The in-tree
118+
# build, however, is configured through config.h/compile definitions and does
119+
# not include options.h, so define it here as well.
120+
if(HAVE_LIMITS_H)
121+
add_definitions("-DHAVE_LIMITS_H")
122+
endif()
123+
116124
include(CheckFunctionExists)
117125

118126
# TODO: Also check if these functions are declared by the
@@ -140,6 +148,17 @@ check_type_size("long" SIZEOF_LONG)
140148
check_type_size("time_t" SIZEOF_TIME_T)
141149
check_type_size("uintptr_t" HAVE_UINTPTR_T)
142150

151+
# SIZEOF_LONG/SIZEOF_LONG_LONG are exposed to applications through options.h
152+
# (see cmake/options.h.in) so that application code computes the same
153+
# CTC_SETTINGS as the library. The in-tree build does not include options.h,
154+
# so define them here for the library and test programs.
155+
if(HAVE_SIZEOF_LONG)
156+
add_definitions("-DSIZEOF_LONG=${SIZEOF_LONG}")
157+
endif()
158+
if(HAVE_SIZEOF_LONG_LONG)
159+
add_definitions("-DSIZEOF_LONG_LONG=${SIZEOF_LONG_LONG}")
160+
endif()
161+
143162
# By default, HAVE___UINT128_T gets defined as TRUE,
144163
# but we want it as 1.
145164
if(HAVE___UINT128_T)

cmake/config.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@
4949
/* Define to the full name of this package. */
5050
#define PACKAGE_NAME "@CMAKE_PROJECT_NAME@"
5151

52-
/* The size of `long', as computed by sizeof. */
53-
#cmakedefine SIZEOF_LONG @SIZEOF_LONG@
54-
55-
/* The size of `long long', as computed by sizeof. */
56-
#cmakedefine SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@
57-
5852
/* The size of `time_t', as computed by sizeof. */
5953
#cmakedefine SIZEOF_TIME_T @SIZEOF_TIME_T@
6054

cmake/options.h.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ extern "C" {
3838
#undef _POSIX_THREADS
3939
#cmakedefine _POSIX_THREADS
4040
#endif
41-
/* Since types.h depends on HAVE_LIMITS_H, we must define it in options.h. */
41+
/* Since types.h depends on HAVE_LIMITS_H, SIZEOF_LONG and SIZEOF_LONG_LONG,
42+
* we must define them in options.h. */
4243
#undef HAVE_LIMITS_H
4344
#cmakedefine HAVE_LIMITS_H @HAVE_LIMITS_H@
45+
#undef SIZEOF_LONG
46+
#cmakedefine SIZEOF_LONG @SIZEOF_LONG@
47+
#undef SIZEOF_LONG_LONG
48+
#cmakedefine SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@
4449
#undef ASIO_USE_WOLFSSL
4550
#cmakedefine ASIO_USE_WOLFSSL
4651
#undef BOOST_ASIO_USE_WOLFSSL

configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ fi
207207
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])
208208
# Special case: Since types.h depends on HAVE_LIMITS_H, we must define it in options.h.
209209
AC_CHECK_HEADER([limits.h], [AM_CPPFLAGS="$AM_CPPFLAGS -DHAVE_LIMITS_H=1"], [])
210+
# Propagate the measured integer sizes (from AC_CHECK_SIZEOF above) into
211+
# options.h. The library obtains these from config.h, but config.h is not
212+
# available to applications; without them, application code falls back to the
213+
# limits.h/architecture heuristics in types.h and can compute a CTC_SETTINGS
214+
# value that disagrees with the library's CheckRunTimeSettings().
215+
AS_IF([test "x$ac_cv_sizeof_long" != "x"],
216+
[AM_CPPFLAGS="$AM_CPPFLAGS -DSIZEOF_LONG=$ac_cv_sizeof_long"])
217+
AS_IF([test "x$ac_cv_sizeof_long_long" != "x"],
218+
[AM_CPPFLAGS="$AM_CPPFLAGS -DSIZEOF_LONG_LONG=$ac_cv_sizeof_long_long"])
210219
AC_CHECK_LIB([network],[socket])
211220
AC_C_BIGENDIAN
212221
AC_C___ATOMIC

0 commit comments

Comments
 (0)