diff options
author | Alexander Neundorf <neundorf@kde.org> | 2007-08-10 17:14:00 (GMT) |
---|---|---|
committer | Alexander Neundorf <neundorf@kde.org> | 2007-08-10 17:14:00 (GMT) |
commit | 578841cce53d476afdb646ed7db29f3752ac9786 (patch) | |
tree | 3697ad9bf2b8c52bb0e8cd15a9f95f41f6379fbb | |
parent | c6092b7e5e9a421d317969eb3230ccdb7acc0065 (diff) | |
download | CMake-578841cce53d476afdb646ed7db29f3752ac9786.zip CMake-578841cce53d476afdb646ed7db29f3752ac9786.tar.gz CMake-578841cce53d476afdb646ed7db29f3752ac9786.tar.bz2 |
STYLE: remove unused CheckTypeSize.c.in
ENH: change test for endianess from TRY_RUN() to TRY_COMPILE() by testing
the binary image of a 16bit integer array, tested on Linux x86, Intel Mac
and Sun (big endian)
Alex
-rw-r--r-- | Modules/CheckTypeSize.c.in | 34 | ||||
-rw-r--r-- | Modules/CheckTypeSize.cmake | 2 | ||||
-rw-r--r-- | Modules/TestBigEndian.c | 17 | ||||
-rw-r--r-- | Modules/TestBigEndian.cmake | 108 | ||||
-rw-r--r-- | Modules/TestEndianess.c.in | 20 |
5 files changed, 99 insertions, 82 deletions
diff --git a/Modules/CheckTypeSize.c.in b/Modules/CheckTypeSize.c.in deleted file mode 100644 index 8c9a016..0000000 --- a/Modules/CheckTypeSize.c.in +++ /dev/null @@ -1,34 +0,0 @@ -#cmakedefine CHECK_TYPE_SIZE_TYPE @CHECK_TYPE_SIZE_TYPE@ -#ifdef CHECK_TYPE_SIZE_TYPE - -@CHECK_TYPE_SIZE_PREINCLUDE@ -#ifdef HAVE_SYS_TYPES_H -# include <sys/types.h> -#endif /* HAVE_SYS_TYPES_H */ - -#ifdef HAVE_STDINT_H -# include <stdint.h> -#endif /* HAVE_STDINT_H */ - -#ifdef HAVE_STDDEF_H -# include <stddef.h> -#endif /* HAVE_STDDEF_H */ - -@CHECK_TYPE_SIZE_PREMAIN@ - -#ifdef __CLASSIC_C__ -int main(){ - int ac; - char*av[]; -#else -int main(int ac, char*av[]){ -#endif - if(ac > 1000){return *av[0];} - return sizeof(CHECK_TYPE_SIZE_TYPE); -} - -#else /* CHECK_TYPE_SIZE_TYPE */ - -# error "CHECK_TYPE_SIZE_TYPE has to specify the type" - -#endif /* CHECK_TYPE_SIZE_TYPE */ diff --git a/Modules/CheckTypeSize.cmake b/Modules/CheckTypeSize.cmake index 058dbaf..0e7e364 100644 --- a/Modules/CheckTypeSize.cmake +++ b/Modules/CheckTypeSize.cmake @@ -78,7 +78,7 @@ MACRO(CHECK_TYPE_SIZE TYPE VARIABLE) ELSE(HAVE_${VARIABLE}) MESSAGE(STATUS "Check size of ${TYPE} - failed") FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining size of ${TYPE} failed with the following output:\n${OUTPUT}\nCheckTypeSize.c:\n${CHECK_TYPE_SIZE_FILE_CONTENT}\n\n") + "Determining size of ${TYPE} failed with the following output:\n${OUTPUT}\nCheckTypeSizeC.c:\n${CHECK_TYPE_SIZE_FILE_CONTENT}\n\n") SET(${VARIABLE}) ENDIF(HAVE_${VARIABLE}) SET(${VARIABLE} "${${VARIABLE}}" CACHE INTERNAL "Result of CHECK_TYPE_SIZE" FORCE) diff --git a/Modules/TestBigEndian.c b/Modules/TestBigEndian.c deleted file mode 100644 index db08ceb..0000000 --- a/Modules/TestBigEndian.c +++ /dev/null @@ -1,17 +0,0 @@ -#ifdef __CLASSIC_C__ -int main(){ - int ac; - char*av[]; -#else -int main(int ac, char*av[]){ -#endif - /* Are we little or big endian? From Harbison&Steele. */ - union - { - long l; - char c[sizeof (long)]; - } u; - u.l = 1; - if(ac > 1000){return *av[0];} - return (u.c[sizeof (long) - 1] == 1)?1:0; -} diff --git a/Modules/TestBigEndian.cmake b/Modules/TestBigEndian.cmake index 2d1853c..bf91fb7 100644 --- a/Modules/TestBigEndian.cmake +++ b/Modules/TestBigEndian.cmake @@ -5,37 +5,85 @@ # MACRO(TEST_BIG_ENDIAN VARIABLE) - SET(CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS 1) - IF(NOT DEFINED ${VARIABLE}) IF("HAVE_${VARIABLE}" MATCHES "^HAVE_${VARIABLE}$") - TRY_RUN(${VARIABLE} HAVE_${VARIABLE} - ${CMAKE_BINARY_DIR} - ${CMAKE_ROOT}/Modules/TestBigEndian.c - COMPILE_OUTPUT_VARIABLE OUTPUT) - IF("${VARIABLE}" STREQUAL "FAILED_TO_RUN") - MESSAGE(SEND_ERROR "TestBigEndian Failed to run with output: ${OUTPUT}") - ENDIF("${VARIABLE}" STREQUAL "FAILED_TO_RUN") MESSAGE(STATUS "Check if the system is big endian") - IF(HAVE_${VARIABLE}) - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining the endianes of the system passed. The system is ") - IF(${VARIABLE}) - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "big endian") - MESSAGE(STATUS "Check if the system is big endian - big endian") - ELSE(${VARIABLE}) - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "little endian") - MESSAGE(STATUS "Check if the system is big endian - little endian") - ENDIF(${VARIABLE}) - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Test produced following output:\n${OUTPUT}\n\n") - ELSE(HAVE_${VARIABLE}) - FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log - "Determining the endianes of the system failed with the following output:\n${OUTPUT}\n\n") - MESSAGE("Check if the system is big endian - failed") - ENDIF(HAVE_${VARIABLE}) + MESSAGE(STATUS "Searching 16 bit integer") + + INCLUDE(CheckTypeSize) + + CHECK_TYPE_SIZE("unsigned short" CMAKE_SIZEOF_UNSIGNED_SHORT) + IF(CMAKE_SIZEOF_UNSIGNED_SHORT EQUAL 2) + MESSAGE(STATUS "Using unsigned short") + SET(CMAKE_16BIT_TYPE "unsigned short") + ELSE(CMAKE_SIZEOF_UNSIGNED_SHORT EQUAL 2) + CHECK_TYPE_SIZE("unsigned int" CMAKE_SIZEOF_UNSIGNED_INT) + IF(CMAKE_SIZEOF_UNSIGNED_INT) + MESSAGE(STATUS "Using unsigned int") + SET(CMAKE_16BIT_TYPE "unsigned int") + + ELSE(CMAKE_SIZEOF_UNSIGNED_INT) + + CHECK_TYPE_SIZE("unsigned long" CMAKE_SIZEOF_UNSIGNED_LONG) + IF(CMAKE_SIZEOF_UNSIGNED_LONG) + MESSAGE(STATUS "Using unsigned long") + SET(CMAKE_16BIT_TYPE "unsigned long") + ELSE(CMAKE_SIZEOF_UNSIGNED_LONG) + MESSAGE(FATAL_ERROR "no suitable type found") + ENDIF(CMAKE_SIZEOF_UNSIGNED_LONG) + + ENDIF(CMAKE_SIZEOF_UNSIGNED_INT) + + ENDIF(CMAKE_SIZEOF_UNSIGNED_SHORT EQUAL 2) + + + CONFIGURE_FILE("${CMAKE_ROOT}/Modules/TestEndianess.c.in" + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c" + IMMEDIATE @ONLY) + + FILE(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c" + TEST_ENDIANESS_FILE_CONTENT) + + TRY_COMPILE(HAVE_${VARIABLE} + "${CMAKE_BINARY_DIR}" + "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/TestEndianess.c" + OUTPUT_VARIABLE OUTPUT + COPY_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin" ) + + IF(HAVE_${VARIABLE}) + + FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin" + CMAKE_TEST_ENDIANESS_STRINGS_LE LIMIT_COUNT 1 REGEX "THIS IS LITTLE ENDIAN") + + FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestEndianess.bin" + CMAKE_TEST_ENDIANESS_STRINGS_BE LIMIT_COUNT 1 REGEX "THIS IS BIG ENDIAN") + + IF(CMAKE_TEST_ENDIANESS_STRINGS_LE) + SET(${VARIABLE} 0 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE) + MESSAGE(STATUS "Check if the system is big endian - little endian") + ENDIF(CMAKE_TEST_ENDIANESS_STRINGS_LE) + + IF(CMAKE_TEST_ENDIANESS_STRINGS_BE) + SET(${VARIABLE} 1 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE) + MESSAGE(STATUS "Check if the system is big endian - big endian") + ENDIF(CMAKE_TEST_ENDIANESS_STRINGS_BE) + + IF(CMAKE_TEST_ENDIANESS_STRINGS_BE AND CMAKE_TEST_ENDIANESS_STRINGS_LE) + MESSAGE(SEND_ERROR "TEST_BIG_ENDIAN found different results, consider setting CMAKE_OSX_ARCHITECTURES or CMAKE_TRY_COMPILE_OSX_ARCHITECTURES to one or no architecture !") + ENDIF(CMAKE_TEST_ENDIANESS_STRINGS_BE AND CMAKE_TEST_ENDIANESS_STRINGS_LE) + IF(NOT CMAKE_TEST_ENDIANESS_STRINGS_BE AND NOT CMAKE_TEST_ENDIANESS_STRINGS_LE) + MESSAGE(SEND_ERROR "TEST_BIG_ENDIAN found no !") + ENDIF(NOT CMAKE_TEST_ENDIANESS_STRINGS_BE AND NOT CMAKE_TEST_ENDIANESS_STRINGS_LE) + + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the system is big endian passed with the following output:\n${OUTPUT}\nTestEndianess.c:\n${TEST_ENDIANESS_FILE_CONTENT}\n\n") + + ELSE(HAVE_${VARIABLE}) + MESSAGE(STATUS "Check if the system is big endian - failed") + FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log + "Determining if the system is big endian failed with the following output:\n${OUTPUT}\nTestEndianess.c:\n${TEST_ENDIANESS_FILE_CONTENT}\n\n") + SET(${VARIABLE}) + ENDIF(HAVE_${VARIABLE}) ENDIF("HAVE_${VARIABLE}" MATCHES "^HAVE_${VARIABLE}$") - ENDIF(NOT DEFINED ${VARIABLE}) - SET(CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS) ENDMACRO(TEST_BIG_ENDIAN) + + diff --git a/Modules/TestEndianess.c.in b/Modules/TestEndianess.c.in new file mode 100644 index 0000000..68094d4 --- /dev/null +++ b/Modules/TestEndianess.c.in @@ -0,0 +1,20 @@ +/* A 16 bit integer is required. */ +typedef @CMAKE_16BIT_TYPE@ cmakeint16; + +/* On a little endian machine, these 16bit ints will give "THIS IS LITTLE ENDIAN." + On a big endian machine the characters will be exchanged pairwise. */ +const cmakeint16 info_little[] = {0x4854, 0x5349, 0x4920, 0x2053, 0x494c, 0x5454, 0x454c, 0x4520, 0x444e, 0x4149, 0x2e4e, 0x0000}; + +/* on a big endian machine, these 16bit ints will give "THIS IS BIG ENDIAN." + On a little endian machine the characters will be exchanged pairwise. */ +const cmakeint16 info_big[] = {0x5448, 0x4953, 0x2049, 0x5320, 0x4249, 0x4720, 0x454e, 0x4449, 0x414e, 0x2e2e, 0x0000}; + +#ifdef __CLASSIC_C__ +int main(){ + int ac; + char*av[]; +#else +int main(int ac, char*av[]){ +#endif + return (&info_little[0] != &info_big[0]); +} |