diff options
author | Brad King <brad.king@kitware.com> | 2005-07-26 15:37:30 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2005-07-26 15:37:30 (GMT) |
commit | 82a8e9be99ca26f6941d5cf7dc7d79db82f8128c (patch) | |
tree | bbe99eb6483278113759570fbe1ba17261df1bd3 /Source | |
parent | a5483acc0ec3c86fff58f861be04a9da4fa0f5fa (diff) | |
download | CMake-82a8e9be99ca26f6941d5cf7dc7d79db82f8128c.zip CMake-82a8e9be99ca26f6941d5cf7dc7d79db82f8128c.tar.gz CMake-82a8e9be99ca26f6941d5cf7dc7d79db82f8128c.tar.bz2 |
ENH: Added FundamentalType header defining platform-independent fixed size/signedness integer types.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/kwsys/CMakeLists.txt | 75 | ||||
-rw-r--r-- | Source/kwsys/FundamentalType.h.in | 143 |
2 files changed, 217 insertions, 1 deletions
diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index 71d0761..6493bc2 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -82,6 +82,7 @@ IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) SET(KWSYS_USE_RegularExpression 1) SET(KWSYS_USE_SystemTools 1) SET(KWSYS_USE_CommandLineArguments 1) + SET(KWSYS_USE_FundamentalType 1) ENDIF(KWSYS_STANDALONE OR CMake_SOURCE_DIR) #----------------------------------------------------------------------------- @@ -243,6 +244,78 @@ IF(UNIX) "Checking whether struct stat has st_mtim member" DIRECT) ENDIF(UNIX) +IF(KWSYS_USE_FundamentalType) + # Determine type sizes. + INCLUDE(CheckTypeSize) + CHECK_TYPE_SIZE("char" KWSYS_SIZEOF_CHAR) + CHECK_TYPE_SIZE("short" KWSYS_SIZEOF_SHORT) + CHECK_TYPE_SIZE("int" KWSYS_SIZEOF_INT) + CHECK_TYPE_SIZE("long" KWSYS_SIZEOF_LONG) + CHECK_TYPE_SIZE("long long" KWSYS_SIZEOF_LONG_LONG) + CHECK_TYPE_SIZE("__int64" KWSYS_SIZEOF___INT64) + IF(NOT KWSYS_SIZEOF_LONG_LONG) + SET(KWSYS_SIZEOF_LONG_LONG 0) + ENDIF(NOT KWSYS_SIZEOF_LONG_LONG) + IF(NOT KWSYS_SIZEOF___INT64) + SET(KWSYS_SIZEOF___INT64 0) + ENDIF(NOT KWSYS_SIZEOF___INT64) + + # Check uniqueness of types. + IF(KWSYS_SIZEOF___INT64) + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_SAME_LONG_AND___INT64 + "Checking whether long and __int64 are the same type" DIRECT) + IF(KWSYS_SIZEOF_LONG_LONG) + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_SAME_LONG_LONG_AND___INT64 + "Checking whether long long and __int64 are the same type" DIRECT) + ENDIF(KWSYS_SIZEOF_LONG_LONG) + ENDIF(KWSYS_SIZEOF___INT64) + + # Enable the "long long" type if it is available. It is standard in + # C99 and C++03 but not in earlier standards. + IF(KWSYS_SIZEOF_LONG_LONG) + SET(KWSYS_USE_LONG_LONG 1) + ELSE(KWSYS_SIZEOF_LONG_LONG) + SET(KWSYS_USE_LONG_LONG 0) + ENDIF(KWSYS_SIZEOF_LONG_LONG) + + # Enable the "__int64" type if it is available and unique. It is not + # standard. + SET(KWSYS_USE___INT64 0) + IF(KWSYS_SIZEOF___INT64) + IF(NOT KWSYS_CXX_SAME_LONG_AND___INT64) + IF(NOT KWSYS_CXX_SAME_LONG_LONG_AND___INT64) + SET(KWSYS_USE___INT64 1) + ENDIF(NOT KWSYS_CXX_SAME_LONG_LONG_AND___INT64) + ENDIF(NOT KWSYS_CXX_SAME_LONG_AND___INT64) + ENDIF(KWSYS_SIZEOF___INT64) + IF(KWSYS_USE___INT64) + KWSYS_PLATFORM_CXX_TEST(KWSYS_CAN_CONVERT_UI64_TO_DOUBLE + "Checking whether unsigned __int64 can convert to double" DIRECT) + ELSE(KWSYS_USE___INT64) + SET(KWSYS_CAN_CONVERT_UI64_TO_DOUBLE 1) + ENDIF(KWSYS_USE___INT64) + + # Check signedness of "char" type. + IF("KWSYS_CHAR_IS_SIGNED" MATCHES "^KWSYS_CHAR_IS_SIGNED$") + MESSAGE(STATUS "Checking signedness of char") + TRY_RUN(KWSYS_CHAR_IS_SIGNED KWSYS_CHAR_IS_SIGNED_COMPILED + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/kwsysPlatformCxxTests.cxx + COMPILE_DEFINITIONS -DTEST_KWSYS_CHAR_IS_SIGNED) + IF(KWSYS_CHAR_IS_SIGNED_COMPILED) + IF(KWSYS_CHAR_IS_SIGNED) + MESSAGE(STATUS "Checking signedness of char -- signed") + SET(KWSYS_CHAR_IS_SIGNED 1 CACHE INTERNAL "Whether char is signed.") + ELSE(KWSYS_CHAR_IS_SIGNED) + MESSAGE(STATUS "Checking signedness of char -- unsigned") + SET(KWSYS_CHAR_IS_SIGNED 0 CACHE INTERNAL "Whether char is signed.") + ENDIF(KWSYS_CHAR_IS_SIGNED) + ELSE(KWSYS_CHAR_IS_SIGNED_COMPILED) + MESSAGE(FATAL_ERROR "Checking signedness of char -- failed") + ENDIF(KWSYS_CHAR_IS_SIGNED_COMPILED) + ENDIF("KWSYS_CHAR_IS_SIGNED" MATCHES "^KWSYS_CHAR_IS_SIGNED$") +ENDIF(KWSYS_USE_FundamentalType) + IF(KWSYS_NAMESPACE MATCHES "^kwsys$") SET(KWSYS_NAME_IS_KWSYS 1) ELSE(KWSYS_NAMESPACE MATCHES "^kwsys$") @@ -343,7 +416,7 @@ FOREACH(c Directory RegularExpression SystemTools CommandLineArguments) ENDFOREACH(c) # Add selected C components. -FOREACH(c Process Base64) +FOREACH(c Process Base64 FundamentalType) IF(KWSYS_USE_${c}) SET(KWSYS_H_FILES ${KWSYS_H_FILES} ${c}) ENDIF(KWSYS_USE_${c}) diff --git a/Source/kwsys/FundamentalType.h.in b/Source/kwsys/FundamentalType.h.in new file mode 100644 index 0000000..6f8b079 --- /dev/null +++ b/Source/kwsys/FundamentalType.h.in @@ -0,0 +1,143 @@ +/*========================================================================= + + Program: KWSys - Kitware System Library + Module: $RCSfile$ + + Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef @KWSYS_NAMESPACE@_FundamentalType_h +#define @KWSYS_NAMESPACE@_FundamentalType_h + +#include <@KWSYS_NAMESPACE@/Configure.h> + +/* Redefine all public interface symbol names to be in the proper + namespace. These macros are used internally to kwsys only, and are + not visible to user code. Use kwsysHeaderDump.pl to reproduce + these macros after making changes to the interface. */ +#if !defined(KWSYS_NAMESPACE) +# define kwsys_ns(x) @KWSYS_NAMESPACE@##x +# define kwsysEXPORT @KWSYS_NAMESPACE@_EXPORT +#endif +#define kwsysFundamentalType kwsys_ns(FundamentalType) +#define kwsysFundamentalType_Int8 kwsys_ns(FundamentalType_Int8) +#define kwsysFundamentalType_UInt8 kwsys_ns(FundamentalType_UInt8) +#define kwsysFundamentalType_Int16 kwsys_ns(FundamentalType_Int16) +#define kwsysFundamentalType_UInt16 kwsys_ns(FundamentalType_UInt16) +#define kwsysFundamentalType_Int32 kwsys_ns(FundamentalType_Int32) +#define kwsysFundamentalType_UInt32 kwsys_ns(FundamentalType_UInt32) +#define kwsysFundamentalType_Int64 kwsys_ns(FundamentalType_Int64) +#define kwsysFundamentalType_UInt64 kwsys_ns(FundamentalType_UInt64) + +/* The size of fundamental types. Types that do not exist have size 0. */ +#define @KWSYS_NAMESPACE@_SIZEOF_CHAR @KWSYS_SIZEOF_CHAR@ +#define @KWSYS_NAMESPACE@_SIZEOF_SHORT @KWSYS_SIZEOF_SHORT@ +#define @KWSYS_NAMESPACE@_SIZEOF_INT @KWSYS_SIZEOF_INT@ +#define @KWSYS_NAMESPACE@_SIZEOF_LONG @KWSYS_SIZEOF_LONG@ +#define @KWSYS_NAMESPACE@_SIZEOF_LONG_LONG @KWSYS_SIZEOF_LONG_LONG@ +#define @KWSYS_NAMESPACE@_SIZEOF___INT64 @KWSYS_SIZEOF___INT64@ + +/* Whether types "long long" and "__int64" are enabled. If a type is + enabled then it is a unique fundamental type. */ +#define @KWSYS_NAMESPACE@_USE_LONG_LONG @KWSYS_USE_LONG_LONG@ +#define @KWSYS_NAMESPACE@_USE___INT64 @KWSYS_USE___INT64@ + +/* Whether type "char" is signed (it may be signed or unsigned). */ +#define @KWSYS_NAMESPACE@_CHAR_IS_SIGNED @KWSYS_CHAR_IS_SIGNED@ + +#if defined(__cplusplus) +extern "C" +{ +#endif + +/* Select an 8-bit integer type. */ +#if @KWSYS_NAMESPACE@_SIZEOF_CHAR == 1 +typedef signed char kwsysFundamentalType_Int8; +typedef unsigned char kwsysFundamentalType_UInt8; +#else +# error "No native data type can represent an 8-bit integer." +#endif + +/* Select a 16-bit integer type. */ +#if @KWSYS_NAMESPACE@_SIZEOF_SHORT == 2 +typedef short kwsysFundamentalType_Int16; +typedef unsigned short kwsysFundamentalType_UInt16; +#elif @KWSYS_NAMESPACE@_SIZEOF_INT == 2 +typedef int kwsysFundamentalType_Int16; +typedef unsigned int kwsysFundamentalType_UInt16; +#else +# error "No native data type can represent a 16-bit integer." +#endif + +/* Select a 32-bit integer type. */ +#if @KWSYS_NAMESPACE@_SIZEOF_INT == 4 +typedef int kwsysFundamentalType_Int32; +typedef unsigned int kwsysFundamentalType_UInt32; +#elif @KWSYS_NAMESPACE@_SIZEOF_LONG == 4 +typedef long kwsysFundamentalType_Int32; +typedef unsigned long kwsysFundamentalType_UInt32; +#else +# error "No native data type can represent a 32-bit integer." +#endif + +/* Select a 64-bit integer type. */ +#if @KWSYS_NAMESPACE@_SIZEOF_LONG == 8 +typedef signed long kwsysFundamentalType_Int64; +typedef unsigned long kwsysFundamentalType_UInt64; +/* Whether UInt64 can be converted to double. */ +# define @KWSYS_NAMESPACE@_CAN_CONVERT_UI64_TO_DOUBLE 1 +#elif @KWSYS_NAMESPACE@_USE_LONG_LONG && @KWSYS_NAMESPACE@_SIZEOF_LONG_LONG == 8 +typedef signed long long kwsysFundamentalType_Int64; +typedef unsigned long long kwsysFundamentalType_UInt64; +/* Whether UInt64 can be converted to double. */ +# define @KWSYS_NAMESPACE@_CAN_CONVERT_UI64_TO_DOUBLE 1 +#elif @KWSYS_NAMESPACE@_USE___INT64 && @KWSYS_NAMESPACE@_SIZEOF___INT64 == 8 +typedef signed __int64 kwsysFundamentalType_Int64; +typedef unsigned __int64 kwsysFundamentalType_UInt64; +/* Whether UInt64 can be converted to double. */ +# define @KWSYS_NAMESPACE@_CAN_CONVERT_UI64_TO_DOUBLE @KWSYS_CAN_CONVERT_UI64_TO_DOUBLE@ +#else +# error "No native data type can represent a 64-bit integer." +#endif + +#if defined(__cplusplus) +} /* extern "C" */ +#endif + +/* If we are building a kwsys .c or .cxx file, let it use these macros. + Otherwise, undefine them to keep the namespace clean. */ +#if !defined(KWSYS_NAMESPACE) +# undef kwsys_ns +# undef kwsysEXPORT +# undef kwsysFundamentalType +# undef kwsysFundamentalType_Int8 +# undef kwsysFundamentalType_UInt8 +# undef kwsysFundamentalType_Int16 +# undef kwsysFundamentalType_UInt16 +# undef kwsysFundamentalType_Int32 +# undef kwsysFundamentalType_UInt32 +# undef kwsysFundamentalType_Int64 +# undef kwsysFundamentalType_UInt64 +#endif + +/* If building a C or C++ file in kwsys itself, give the source file + access to the configured macros without a configured namespace. */ +#if defined(KWSYS_NAMESPACE) +# define KWSYS_SIZEOF_CHAR @KWSYS_NAMESPACE@_SIZEOF_CHAR +# define KWSYS_SIZEOF_SHORT @KWSYS_NAMESPACE@_SIZEOF_SHORT +# define KWSYS_SIZEOF_INT @KWSYS_NAMESPACE@_SIZEOF_INT +# define KWSYS_SIZEOF_LONG @KWSYS_NAMESPACE@_SIZEOF_LONG +# define KWSYS_SIZEOF_LONG_LONG @KWSYS_NAMESPACE@_SIZEOF_LONG_LONG +# define KWSYS_SIZEOF___INT64 @KWSYS_NAMESPACE@_SIZEOF___INT64 +# define KWSYS_USE_LONG_LONG @KWSYS_NAMESPACE@_USE_LONG_LONG +# define KWSYS_USE___INT64 @KWSYS_NAMESPACE@_USE___INT64 +# define KWSYS_CHAR_IS_SIGNED @KWSYS_NAMESPACE@_CHAR_IS_SIGNED +# define KWSYS_CAN_CONVERT_UI64_TO_DOUBLE @KWSYS_NAMESPACE@_CAN_CONVERT_UI64_TO_DOUBLE +#endif + +#endif |