Test the CheckTypeSize module
We create test "Module.CheckTypeSize" to verify that type sizes get detected correctly.
This commit is contained in:
parent
c9b726c314
commit
11e6b513c2
|
@ -172,6 +172,8 @@ IF(BUILD_TESTING)
|
|||
"${CMake_BINARY_DIR}/Tests/CMakeBuildTest.cmake")
|
||||
LIST(APPEND TEST_BUILD_DIRS ${CMAKE_BUILD_TEST_BINARY_DIR})
|
||||
|
||||
ADD_TEST_MACRO(Module.CheckTypeSize CheckTypeSize)
|
||||
|
||||
# If we are running right now with a UnixMakefiles based generator,
|
||||
# build the "Simple" test with the ExtraGenerators, if available
|
||||
# This doesn't test whether the generated project files work (unfortunately),
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
cmake_minimum_required(VERSION 2.8.1 FATAL_ERROR)
|
||||
project(CheckTypeSize C)
|
||||
|
||||
include(CheckTypeSize)
|
||||
check_type_size("void*" SIZEOF_DATA_PTR)
|
||||
check_type_size(char SIZEOF_CHAR)
|
||||
check_type_size(short SIZEOF_SHORT)
|
||||
check_type_size(int SIZEOF_INT)
|
||||
check_type_size(long SIZEOF_LONG)
|
||||
check_type_size("long long" SIZEOF_LONG_LONG)
|
||||
check_type_size(__int64 SIZEOF___INT64)
|
||||
check_type_size(size_t SIZEOF_SIZE_T)
|
||||
check_type_size(ssize_t SIZEOF_SSIZE_T)
|
||||
|
||||
configure_file(config.h.in config.h)
|
||||
include_directories(${CheckTypeSize_BINARY_DIR})
|
||||
|
||||
add_executable(CheckTypeSize CheckTypeSize.c)
|
|
@ -0,0 +1,122 @@
|
|||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDDEF_H
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define CHECK(t,m) do { \
|
||||
if(sizeof(t) != m) \
|
||||
{ \
|
||||
printf(#m ": expected %d, got %d (line %d)\n", \
|
||||
(int)sizeof(t), (int)m, __LINE__); \
|
||||
result = 1; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
#define NODEF(m) do { \
|
||||
printf(#m": not defined (line %d)\n", __LINE__); \
|
||||
result = 1; \
|
||||
} while(0)
|
||||
|
||||
int main()
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
/* void* */
|
||||
#if !defined(HAVE_SIZEOF_DATA_PTR)
|
||||
NODEF(HAVE_SIZEOF_DATA_PTR);
|
||||
#endif
|
||||
#if defined(SIZEOF_DATA_PTR)
|
||||
CHECK(void*, SIZEOF_DATA_PTR);
|
||||
#else
|
||||
NODEF(SIZEOF_DATA_PTR);
|
||||
#endif
|
||||
|
||||
/* char */
|
||||
#if !defined(HAVE_SIZEOF_CHAR)
|
||||
NODEF(HAVE_SIZEOF_CHAR);
|
||||
#endif
|
||||
#if defined(SIZEOF_CHAR)
|
||||
CHECK(char, SIZEOF_CHAR);
|
||||
#else
|
||||
NODEF(SIZEOF_CHAR);
|
||||
#endif
|
||||
|
||||
/* short */
|
||||
#if !defined(HAVE_SIZEOF_SHORT)
|
||||
NODEF(HAVE_SIZEOF_SHORT);
|
||||
#endif
|
||||
#if defined(SIZEOF_SHORT)
|
||||
CHECK(short, SIZEOF_SHORT);
|
||||
#else
|
||||
NODEF(SIZEOF_SHORT);
|
||||
#endif
|
||||
|
||||
/* int */
|
||||
#if !defined(HAVE_SIZEOF_INT)
|
||||
NODEF(HAVE_SIZEOF_INT);
|
||||
#endif
|
||||
#if defined(SIZEOF_INT)
|
||||
CHECK(int, SIZEOF_INT);
|
||||
#else
|
||||
NODEF(SIZEOF_INT);
|
||||
#endif
|
||||
|
||||
/* long */
|
||||
#if !defined(HAVE_SIZEOF_LONG)
|
||||
NODEF(HAVE_SIZEOF_LONG);
|
||||
#endif
|
||||
#if defined(SIZEOF_LONG)
|
||||
CHECK(long, SIZEOF_LONG);
|
||||
#else
|
||||
NODEF(SIZEOF_LONG);
|
||||
#endif
|
||||
|
||||
/* long long */
|
||||
#if defined(SIZEOF_LONG_LONG)
|
||||
CHECK(long long, SIZEOF_LONG_LONG);
|
||||
# if !defined(HAVE_SIZEOF_LONG_LONG)
|
||||
NODEF(HAVE_SIZEOF_LONG_LONG);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* __int64 */
|
||||
#if defined(SIZEOF___INT64)
|
||||
CHECK(__int64, SIZEOF___INT64);
|
||||
# if !defined(HAVE_SIZEOF___INT64)
|
||||
NODEF(HAVE_SIZEOF___INT64);
|
||||
# endif
|
||||
#elif defined(HAVE_SIZEOF___INT64)
|
||||
NODEF(SIZEOF___INT64);
|
||||
#endif
|
||||
|
||||
/* size_t */
|
||||
#if !defined(HAVE_SIZEOF_SIZE_T)
|
||||
NODEF(HAVE_SIZEOF_SIZE_T);
|
||||
#endif
|
||||
#if defined(SIZEOF_SIZE_T)
|
||||
CHECK(size_t, SIZEOF_SIZE_T);
|
||||
#else
|
||||
NODEF(SIZEOF_SIZE_T);
|
||||
#endif
|
||||
|
||||
/* ssize_t */
|
||||
#if defined(SIZEOF_SSIZE_T)
|
||||
CHECK(ssize_t, SIZEOF_SSIZE_T);
|
||||
# if !defined(HAVE_SIZEOF_SSIZE_T)
|
||||
NODEF(HAVE_SIZEOF_SSIZE_T);
|
||||
# endif
|
||||
#elif defined(HAVE_SIZEOF_SSIZE_T)
|
||||
NODEF(SIZEOF_SSIZE_T);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
#cmakedefine HAVE_SYS_TYPES_H
|
||||
#cmakedefine HAVE_STDINT_H
|
||||
#cmakedefine HAVE_STDDEF_H
|
||||
|
||||
/* void* */
|
||||
#cmakedefine HAVE_SIZEOF_DATA_PTR
|
||||
@SIZEOF_DATA_PTR_CODE@
|
||||
|
||||
/* char */
|
||||
#cmakedefine HAVE_SIZEOF_CHAR
|
||||
@SIZEOF_CHAR_CODE@
|
||||
|
||||
/* short */
|
||||
#cmakedefine HAVE_SIZEOF_SHORT
|
||||
@SIZEOF_SHORT_CODE@
|
||||
|
||||
/* int */
|
||||
#cmakedefine HAVE_SIZEOF_INT
|
||||
@SIZEOF_INT_CODE@
|
||||
|
||||
/* long */
|
||||
#cmakedefine HAVE_SIZEOF_LONG
|
||||
@SIZEOF_LONG_CODE@
|
||||
|
||||
/* long long */
|
||||
#cmakedefine HAVE_SIZEOF_LONG_LONG
|
||||
@SIZEOF_LONG_LONG_CODE@
|
||||
|
||||
/* __int64 */
|
||||
#cmakedefine HAVE_SIZEOF___INT64
|
||||
@SIZEOF___INT64_CODE@
|
||||
|
||||
/* size_t */
|
||||
#cmakedefine HAVE_SIZEOF_SIZE_T
|
||||
@SIZEOF_SIZE_T_CODE@
|
||||
|
||||
/* ssize_t */
|
||||
#cmakedefine HAVE_SIZEOF_SSIZE_T
|
||||
@SIZEOF_SSIZE_T_CODE@
|
Loading…
Reference in New Issue