Skip to content

Commit 170cbc8

Browse files
committed
Autoconf, CMake: Get the size of a void * and a time_t
With this change we know: whether this is a 32-bit or 64-bit build ; whether the time_t size is 32-bit or 64-bit. At least with CMake, the SIZEOF values could be 0, if somebody's doing a fat build on macOS and that includes both 32-bit and 64-bit instruction sets.
1 parent bd3bfa8 commit 170cbc8

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
124124
#
125125
project(tcpdump C)
126126

127+
#
128+
# Export the size of void * as SIZEOF_VOID_P so that it can be
129+
# tested with #if.
130+
#
131+
set(SIZEOF_VOID_P "${CMAKE_SIZEOF_VOID_P}")
132+
127133
#
128134
# For checking if a compiler flag works and adding it if it does.
129135
#
@@ -328,6 +334,14 @@ include(CheckStructHasMember)
328334
include(CheckVariableExists)
329335
include(CheckTypeSize)
330336

337+
#
338+
# Get the size of a time_t, to know whether it's 32-bit or 64-bit.
339+
#
340+
cmake_push_check_state()
341+
set(CMAKE_EXTRA_INCLUDE_FILES time.h)
342+
check_type_size("time_t" SIZEOF_TIME_T)
343+
cmake_pop_check_state()
344+
331345
#
332346
# Header files.
333347
#

cmakeconfig.h.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@
237237
/* Define to the version of this package. */
238238
#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"
239239

240+
/* The size of `time_t', as computed by sizeof. */
241+
#cmakedefine SIZEOF_TIME_T @SIZEOF_TIME_T@
242+
243+
/* The size of `void *', as computed by sizeof. */
244+
#cmakedefine SIZEOF_VOID_P @SIZEOF_VOID_P@
245+
240246
/* Define to 1 if you have the ANSI C header files. */
241247
#cmakedefine STDC_HEADERS 1
242248

configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ AC_LBL_C_INIT(V_CCOPT, V_INCLS)
3232
AC_C_INLINE
3333

3434
AC_CHECK_HEADERS(fcntl.h rpc/rpc.h rpc/rpcent.h net/if.h)
35+
#
36+
# Get the size of a void *, to know whether this is a 32-bit or 64-bit build.
37+
#
38+
AC_CHECK_SIZEOF([void *])
39+
40+
#
41+
# Get the size of a time_t, to know whether it's 32-bit or 64-bit.
42+
#
43+
AC_CHECK_SIZEOF([time_t],,[#include <time.h>])
3544

3645
case "$host_os" in
3746

0 commit comments

Comments
 (0)