64-bit type detection.

This commit is contained in:
Vincent Richard 2013-07-15 10:35:09 +02:00
parent b886cd4864
commit fdeaec5e05
3 changed files with 65 additions and 21 deletions

View File

@ -447,31 +447,61 @@ ELSE(BIGENDIAN EQUAL 0)
SET(VMIME_BYTE_ORDER_LITTLE_ENDIAN 0) SET(VMIME_BYTE_ORDER_LITTLE_ENDIAN 0)
ENDIF(BIGENDIAN EQUAL 0) ENDIF(BIGENDIAN EQUAL 0)
SET(VMIME_DEFAULT_8BIT_TYPE "char")
SET(VMIME_DEFAULT_16BIT_TYPE "short")
SET(VMIME_DEFAULT_32BIT_TYPE "int")
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)
SET( IF(SIZEOF_CHAR EQUAL 1)
VMIME_8BIT_TYPE SET(VMIME_8BIT_TYPE "char")
${VMIME_DEFAULT_8BIT_TYPE} ELSE()
CACHE STRING MESSAGE(FATAL_ERROR "Cannot determine 8-bit type")
"The C-language 8-bit type for your platform" ENDIF()
)
SET( IF(SIZEOF_INT EQUAL 2)
VMIME_16BIT_TYPE SET(VMIME_16BIT_TYPE "int")
${VMIME_DEFAULT_16BIT_TYPE} ELSE()
CACHE STRING IF(SIZEOF_SHORT EQUAL 2)
"The C-language 16-bit type for your platform" SET(VMIME_16BIT_TYPE "short")
) ELSE()
MESSAGE(FATAL_ERROR "Cannot determine 16-bit type")
ENDIF()
ENDIF()
SET( IF(SIZEOF_INT EQUAL 4)
VMIME_32BIT_TYPE SET(VMIME_32BIT_TYPE "int")
${VMIME_DEFAULT_32BIT_TYPE} ELSE()
CACHE STRING IF(SIZEOF_LONG EQUAL 4)
"The C-language 32-bit type for your platform" SET(VMIME_32BIT_TYPE "long")
) ELSE()
IF(SIZEOF_LONG_LONG EQUAL 4)
SET(VMIME_32BIT_TYPE "long long")
ELSE()
MESSAGE(FATAL_ERROR "Cannot determine 32-bit type")
ENDIF()
ENDIF()
ENDIF()
IF(SIZEOF_INT EQUAL 8)
SET(VMIME_64BIT_TYPE "int")
ELSE()
IF(SIZEOF_LONG EQUAL 8)
SET(VMIME_64BIT_TYPE "long")
ELSE()
IF(SIZEOF_LONG_LONG EQUAL 8)
SET(VMIME_64BIT_TYPE "long long")
ELSE()
IF(SIZEOF___INT64 EQUAL 8)
SET(VMIME_64BIT_TYPE "__int64")
ELSE()
MESSAGE(FATAL_ERROR "Cannot determine 64-bit type")
ENDIF()
ENDIF()
ENDIF()
ENDIF()
INCLUDE(cmake/TargetArch.cmake) INCLUDE(cmake/TargetArch.cmake)

View File

@ -605,6 +605,14 @@ opts.AddVariables(
map = { }, map = { },
ignorecase = 1 ignorecase = 1
), ),
EnumVariable(
'pf_64bit_type',
'The C-language 64-bit type for your platform',
'long',
allowed_values = ('char', 'short', 'int', 'long', 'long long'),
map = { },
ignorecase = 1
),
EnumVariable( EnumVariable(
'build_tests', 'build_tests',
'Build unit tests (run with "scons run-tests")', 'Build unit tests (run with "scons run-tests")',
@ -876,6 +884,9 @@ config_hpp.write('typedef unsigned ' + env['pf_16bit_type'] + ' vmime_uint16;\n'
config_hpp.write('// -- 32-bit\n') config_hpp.write('// -- 32-bit\n')
config_hpp.write('typedef signed ' + env['pf_32bit_type'] + ' vmime_int32;\n') config_hpp.write('typedef signed ' + env['pf_32bit_type'] + ' vmime_int32;\n')
config_hpp.write('typedef unsigned ' + env['pf_32bit_type'] + ' vmime_uint32;\n') config_hpp.write('typedef unsigned ' + env['pf_32bit_type'] + ' vmime_uint32;\n')
config_hpp.write('// -- 64-bit\n')
config_hpp.write('typedef signed ' + env['pf_64bit_type'] + ' vmime_int64;\n')
config_hpp.write('typedef unsigned ' + env['pf_64bit_type'] + ' vmime_uint64;\n')
config_hpp.write('\n') config_hpp.write('\n')
config_hpp.write('#define VMIME_HAVE_SIZE_T 1\n') config_hpp.write('#define VMIME_HAVE_SIZE_T 1\n')
config_hpp.write('\n') config_hpp.write('\n')

View File

@ -37,6 +37,9 @@ typedef unsigned @VMIME_16BIT_TYPE@ vmime_uint16;
// -- 32-bit // -- 32-bit
typedef signed @VMIME_32BIT_TYPE@ vmime_int32; typedef signed @VMIME_32BIT_TYPE@ vmime_int32;
typedef unsigned @VMIME_32BIT_TYPE@ vmime_uint32; typedef unsigned @VMIME_32BIT_TYPE@ vmime_uint32;
// -- 64-bit
typedef signed @VMIME_64BIT_TYPE@ vmime_int64;
typedef unsigned @VMIME_64BIT_TYPE@ vmime_uint64;
#cmakedefine01 VMIME_HAVE_SIZE_T #cmakedefine01 VMIME_HAVE_SIZE_T